home.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. <template>
  2. <view v-if="showTeacher && showStudent">
  3. <official-account></official-account>
  4. <uni-swiper-dot :info="info" :current="current">
  5. <swiper class="swiper-box" autoplay circular @change="change">
  6. <swiper-item v-for="(item ,index) in info" :key="index">
  7. <view class="swiper-item">
  8. <image :src="item.url"></image>
  9. </view>
  10. </swiper-item>
  11. </swiper>
  12. </uni-swiper-dot>
  13. <!-- 热门教员区域 -->
  14. <view>
  15. <!-- 热门教员 -->
  16. <view class="hotTitle">
  17. <uni-icons type="star" size="20" color="#b2b2b2" ></uni-icons>
  18. <text style ="color:#b2b2b2;font-size: 12px;" >教员</text>
  19. </view>
  20. <view v-for="(Info,index) in hotTeacherList" :key="index">
  21. <view class="publicItem" @click="goTeacherDetail(Info)">
  22. <view class="hotTeacher">
  23. <image class="teachImg" :src="Info.profilePhoto"></image>
  24. <view class="teachTitle">{{Info.nickname}}教员</view>
  25. <view class="publicSex">{{Info.sex}}</view>
  26. <view class="teachCollege">{{Info.school}}</view>
  27. <view class="teachEdu">{{Info.education}}</view>
  28. <view class="teachDistance" v-if="isShowDistance">
  29. <uni-icons type="location" color="#3ed598" ></uni-icons>
  30. <text>{{Info.kil}}</text>km
  31. </view>
  32. <view class="teachSubject">{{Info.subject}}</view>
  33. <view class="teachYears">教龄 {{Info.teachAge}}</view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. <!-- 热门学员区域 -->
  39. <view>
  40. <!-- 热门学员标题 -->
  41. <view class="hotTitle">
  42. <uni-icons type="staff" size="20" color="#b2b2b2" ></uni-icons>
  43. <text style ="color:#b2b2b2;font-size: 12px;" >学员</text>
  44. </view>
  45. <view v-for="(item, index) in hotstuNeed" :key="index">
  46. <view class="publicItem" @click="goStudentDetail(item.requireId)">
  47. <view class="hotStudent">
  48. <template v-if="item.sex === '女'">
  49. <image class="teachImg" src="../../static/girl.png"></image>
  50. </template>
  51. <template v-else>
  52. <image class="teachImg" src="../../static/boy.png"></image>
  53. </template>
  54. <view class="hotStudentText">
  55. <view class="studentTitle">{{item.nickname}}学员</view>
  56. <view class="publicSex">{{item.sex}}</view>
  57. <view class="stuGoal">{{item.goal}}</view>
  58. <view class="studentDistance" v-if="isShowDistance">
  59. <uni-icons type="location" color="#3ed598" ></uni-icons>
  60. <text>{{item.kil}}</text>km
  61. </view>
  62. </view>
  63. <view class="stuSubject">{{item.subjectBig + "/" + item.subjectSmall}}</view>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. <!-- 攻略 -->
  69. <view>
  70. <view class="hotTitle">
  71. <uni-icons type="map" size="20" color="#b2b2b2" ></uni-icons>
  72. <text style ="color:#b2b2b2;font-size: 12px;" >攻略</text>
  73. </view>
  74. <view class="cooperationContent" @click="gotoStrategy">
  75. <scroll-view class="cooperationScroll" enable-flex scroll-x>
  76. <view class="scrollItem" v-for="(item, index) in strategyImg" :key="index">
  77. <image :src="item"></image>
  78. </view>
  79. </scroll-view>
  80. </view>
  81. </view>
  82. </view>
  83. </template>
  84. <script>
  85. import badgeMix from '@/mixins/tabbar-badge.js'
  86. import computeDistance from '@/mixins/compute-distance.js'
  87. import { mapState, mapMutations } from 'vuex'
  88. export default {
  89. mixins: [badgeMix, computeDistance],
  90. computed: {
  91. ...mapState('m_user', ['location', 'token', 'recoUID'])
  92. },
  93. data() {
  94. return {
  95. showTeacher: false,
  96. showStudent: false,
  97. info: [],
  98. current: 0,
  99. hotTeacherList: [],
  100. hotstuNeed: [],
  101. isShowDistance: false,
  102. strategyImg: []
  103. }
  104. },
  105. watch: {
  106. 'token': {
  107. handler() {
  108. if (this.token !== '') {
  109. this.isShowDistance = true
  110. } else {
  111. this.isShowDistance = false
  112. }
  113. }
  114. }
  115. },
  116. /**
  117. * 如果是从分享的卡片打开的,则可以取到分享者的uid,否则recomID是undefined
  118. * recoUID为推荐者的uid,当用户作为新用户注册时,如果取到了这个uid,才做为推荐者的uid存入
  119. * 老用户,取到这个uid也不存入了。
  120. */
  121. onLoad(options) {
  122. this.updateRecoUID(options.uid) // 久化存储到本地,可在其它页面调用
  123. // console.log("推荐码为:" + this.recoUID)
  124. this.getSwiperList()
  125. this.getStrategyImg()
  126. },
  127. onShow() {
  128. if (this.token !== '') {
  129. this.isShowDistance = true
  130. }
  131. this.hotTeacher()
  132. this.hotStudent()
  133. },
  134. methods: {
  135. // 调用 mapMutations 辅助方法,把 m_user 模块中的 updateRecoUID 映射到当前组件中使用
  136. ...mapMutations('m_user', ['updateRecoUID']),
  137. goStudentDetail(id) {
  138. uni.navigateTo({
  139. url: '/subpkg/student/require/student_require_all_detail?requireId=' + encodeURIComponent(id)
  140. })
  141. },
  142. goTeacherDetail(item) {
  143. uni.navigateTo({
  144. url: '/subpkg/teacher/course/teacher_course_all_detail?item=' + encodeURIComponent(JSON.stringify(item))
  145. })
  146. },
  147. async hotTeacher() {
  148. const { data: result } = await uni.$http.get('/education/home/getHottestTeacher')
  149. for (let i = 0; i < result.data.teacher.length; i++) {
  150. let arr = result.data.teacher[i].locationAl.split(",")
  151. let kil = this.space(arr[0], arr[1], this.location.latitude, this.location.longitude)
  152. result.data.teacher[i].kil = kil
  153. result.data.teacher[i].nickname = result.data.teacher[i].name.slice(0,1)
  154. }
  155. this.hotTeacherList = result.data.teacher
  156. this.showTeacher = true
  157. },
  158. async hotStudent(){
  159. const { data: result } = await uni.$http.get('/education/home/getHottestStuNeed')
  160. for (let i = 0; i < result.data.stuNeed.length; i++) {
  161. let arr = result.data.stuNeed[i].locationAl.split(",")
  162. let kil = this.space(arr[0], arr[1], this.location.latitude, this.location.longitude)
  163. result.data.stuNeed[i].kil = kil
  164. result.data.stuNeed[i].nickname = result.data.stuNeed[i].name.slice(0,1)
  165. if (result.data.stuNeed[i].goal.length == 0) {
  166. result.data.stuNeed[i].goal = "无"
  167. }
  168. }
  169. this.hotstuNeed = result.data.stuNeed
  170. this.showStudent = true
  171. },
  172. // 获取轮播图列表
  173. async getSwiperList() {
  174. const {
  175. data: result
  176. } = await uni.$http.get('/education/swiper/getSwiperList')
  177. this.info = result.data.list
  178. },
  179. // 滑动轮播图触发
  180. change(e) {
  181. this.current = e.detail.current
  182. },
  183. gotoStrategy() {
  184. uni.navigateTo({
  185. url: '/subpkg/my/home/my_home_strategy'
  186. })
  187. },
  188. async getStrategyImg() {
  189. const {
  190. data: result
  191. } = await uni.$http.get('/education/strategy/getBigPig')
  192. this.strategyImg = result.data.list
  193. }
  194. }
  195. }
  196. </script>
  197. <style scoped lang="scss">
  198. .swiper-box {
  199. height: 500rpx;
  200. }
  201. .swiper-item {
  202. display: block;
  203. height: 500rpx;
  204. line-height: 500rpx;
  205. text-align: center;
  206. image {
  207. width: 100%;
  208. height: 100%;
  209. display: block;
  210. border-radius: 60rpx;
  211. }
  212. }
  213. /* 轮播图 */
  214. .swWrapper {
  215. height: 400rpx;
  216. }
  217. .swImg {
  218. width: 100%;
  219. height: 400rpx;
  220. }
  221. /* 热门教员、热门学员标题 */
  222. .hotTitle {
  223. display: flex;
  224. margin-top: 5rpx;
  225. justify-content: center;
  226. align-items: center;
  227. }
  228. /* 热门教员、热门学员标题前后的线条 */
  229. .hotTitle::before {
  230. content: "";
  231. margin-right: 20rpx;
  232. margin-left: 40rpx;
  233. height: 1px;
  234. border: none;
  235. border-top: 1px solid #b2b2b2;
  236. flex: 1 1 0rpx;
  237. }
  238. .hotTitle::after {
  239. content: "";
  240. margin-right: 40rpx;
  241. margin-left: 20rpx;
  242. height: 1px;
  243. border: none;
  244. border-top: 1px solid #b2b2b2;
  245. flex: 1 1 0rpx;
  246. }
  247. .scrollItem{
  248. margin-right: 20rpx;
  249. width: 350rpx;
  250. }
  251. .scrollItem image{
  252. width: 350rpx;
  253. height: 300rpx;
  254. border-radius: 40rpx;
  255. }
  256. /* 攻略区 */
  257. .cooperationContent{
  258. height: 350rpx;
  259. margin-left: 20rpx;
  260. }
  261. /* 攻略图片 */
  262. .cooperationScroll{
  263. display: flex;
  264. height: 300rpx;
  265. }
  266. /* 热门教员、热门学员 */
  267. .hotTeacher,
  268. .hotStudent{
  269. position: relative;
  270. display: flex;
  271. padding: 10rpx;
  272. height: 170rpx;
  273. align-items: center;
  274. }
  275. /* 教员、学员头像 */
  276. .teachImg,
  277. .studentImg{
  278. width: 25%;
  279. height: 95%;
  280. border-radius: 20%;
  281. }
  282. /* 教员、学员性别 */
  283. .publicSex{
  284. position: absolute;
  285. right: 10rpx;
  286. top: 5rpx;
  287. // border: 0rpx solid gray;
  288. padding: 5rpx 10rpx;
  289. border-radius: 50%;
  290. background-color: #3ed598;
  291. color: #ffffff;
  292. font-size: 12px;
  293. }
  294. /* teachEdu */
  295. .teachEdu{
  296. position: absolute;
  297. right: 10rpx;
  298. top: 60rpx;
  299. // border: 0rpx solid gray;
  300. padding: 5rpx 10rpx;
  301. border-radius: 30rpx;
  302. background-color: #3ed598;
  303. color: #ffffff;
  304. font-size: 12px;
  305. }
  306. /* teach课程 */
  307. .teachSubject{
  308. position: absolute;
  309. left: 200rpx;
  310. top: 115rpx;
  311. // border: 0rpx solid gray;
  312. padding: 5rpx 10rpx;
  313. border-radius: 30rpx;
  314. background-color: #3ed598;
  315. color: #ffffff;
  316. font-size: 12px;
  317. }
  318. /* 教龄 */
  319. .teachYears{
  320. position: absolute;
  321. right: 10rpx;
  322. top: 115rpx;
  323. border: 2px solid #3ed598;
  324. padding: 2rpx 20rpx;
  325. border-radius: 30rpx;
  326. color: #3ed598;
  327. font-size: 12px;
  328. font-weight: bold;
  329. }
  330. /* stu课程 */
  331. .stuSubject{
  332. position: absolute;
  333. left: 200rpx;
  334. top: 60rpx;
  335. // border: 0rpx solid gray;
  336. padding: 5rpx 20rpx;
  337. border-radius: 30rpx;
  338. background-color: #3ed598;
  339. color: #ffffff;
  340. font-size: 12px;
  341. }
  342. .teachTitle,
  343. .studentTitle{
  344. font-size: 14px;
  345. position: absolute;
  346. left: 200rpx;
  347. top: 10rpx;
  348. font-weight: bold;
  349. color: #6d6d6d;
  350. }
  351. /* 距离 */
  352. .teachDistance,
  353. .studentDistance{
  354. position: absolute;
  355. left: 300rpx;
  356. top: 10rpx;
  357. font-weight: bold;
  358. color: #3ed598;
  359. font-size: 12px;
  360. }
  361. .teachCollege{
  362. border: 2px solid #3ed598;
  363. border-radius: 30rpx;
  364. padding: 0rpx 10rpx;
  365. font-size: 12px;
  366. position: absolute;
  367. left: 200rpx;
  368. top: 60rpx;
  369. color: #3ed598;
  370. }
  371. .stuGoal{
  372. margin-top: 10rpx;
  373. border: 2px solid #3ed598;
  374. border-radius: 30rpx;
  375. padding: 0rpx 10rpx;
  376. font-size: 12px;
  377. position: absolute;
  378. left: 200rpx;
  379. top: 125rpx;
  380. color: #3ed598;
  381. overflow: hidden;
  382. text-overflow: ellipsis;
  383. display: -webkit-box;
  384. -webkit-box-orient: vertical;
  385. -webkit-line-clamp: 1;
  386. }
  387. /* item */
  388. .publicItem{
  389. margin: 10rpx 20rpx;
  390. // border: 0rpx solid gray;
  391. padding: 10rpx 20rpx;
  392. border-radius: 30rpx;
  393. background-color: #ffffff;
  394. }
  395. </style>