home.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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">
  75. <scroll-view class="cooperationScroll" enable-flex scroll-x>
  76. <view class="scrollItem" v-for="(item, index) in strategyImg" :key="index" @click="clickpreviewImg(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. previewImg: []
  104. }
  105. },
  106. watch: {
  107. 'token': {
  108. handler() {
  109. if (this.token !== '') {
  110. this.isShowDistance = true
  111. } else {
  112. this.isShowDistance = false
  113. }
  114. }
  115. }
  116. },
  117. /**
  118. * 如果是从分享的卡片打开的,则可以取到分享者的uid,否则recomID是undefined
  119. * recoUID为推荐者的uid,当用户作为新用户注册时,如果取到了这个uid,才做为推荐者的uid存入
  120. * 老用户,取到这个uid也不存入了。
  121. */
  122. onLoad(options) {
  123. this.updateRecoUID(options.uid) // 久化存储到本地,可在其它页面调用
  124. // console.log("推荐码为:" + this.recoUID)
  125. this.getSwiperList()
  126. this.getStrategyImg()
  127. this.getPreviewImg()
  128. },
  129. onShow() {
  130. if (this.token !== '') {
  131. this.isShowDistance = true
  132. }
  133. this.hotTeacher()
  134. this.hotStudent()
  135. },
  136. methods: {
  137. // 调用 mapMutations 辅助方法,把 m_user 模块中的 updateRecoUID 映射到当前组件中使用
  138. ...mapMutations('m_user', ['updateRecoUID']),
  139. goStudentDetail(id) {
  140. uni.navigateTo({
  141. url: '/subpkg/student/require/student_require_all_detail?requireId=' + encodeURIComponent(id)
  142. })
  143. },
  144. goTeacherDetail(item) {
  145. uni.navigateTo({
  146. url: '/subpkg/teacher/course/teacher_course_all_detail?item=' + encodeURIComponent(JSON.stringify(item))
  147. })
  148. },
  149. async hotTeacher() {
  150. const { data: result } = await uni.$http.get('/education/home/getHottestTeacher')
  151. if (result.data.teacher !== undefined) {
  152. for (let i = 0; i < result.data.teacher.length; i++) {
  153. let arr = result.data.teacher[i].locationAl.split(",")
  154. let kil = this.space(arr[0], arr[1], this.location.latitude, this.location.longitude)
  155. result.data.teacher[i].kil = kil
  156. result.data.teacher[i].nickname = result.data.teacher[i].name.slice(0,1)
  157. }
  158. this.hotTeacherList = result.data.teacher
  159. this.showTeacher = true
  160. }
  161. },
  162. async hotStudent(){
  163. const { data: result } = await uni.$http.get('/education/home/getHottestStuNeed')
  164. if (result.data.stuNeed !== undefined) {
  165. for (let i = 0; i < result.data.stuNeed.length; i++) {
  166. let arr = result.data.stuNeed[i].locationAl.split(",")
  167. let kil = this.space(arr[0], arr[1], this.location.latitude, this.location.longitude)
  168. result.data.stuNeed[i].kil = kil
  169. result.data.stuNeed[i].nickname = result.data.stuNeed[i].name.slice(0,1)
  170. if (result.data.stuNeed[i].goal.length == 0) {
  171. result.data.stuNeed[i].goal = "无"
  172. }
  173. }
  174. this.hotstuNeed = result.data.stuNeed
  175. this.showStudent = true
  176. }
  177. },
  178. // 获取轮播图列表
  179. async getSwiperList() {
  180. const {
  181. data: result
  182. } = await uni.$http.get('/education/swiper/getSwiperList')
  183. this.info = result.data.list
  184. },
  185. // 滑动轮播图触发
  186. change(e) {
  187. this.current = e.detail.current
  188. },
  189. clickpreviewImg(index) {
  190. uni.previewImage({
  191. current: index,
  192. urls: this.previewImg
  193. })
  194. },
  195. async getStrategyImg() {
  196. const {
  197. data: result
  198. } = await uni.$http.get('/education/strategy/getBigPig')
  199. this.strategyImg = result.data.list
  200. },
  201. async getPreviewImg() {
  202. const {
  203. data: result
  204. } = await uni.$http.get('/education/strategy/getSmallPig')
  205. this.previewImg = result.data.list
  206. }
  207. }
  208. }
  209. </script>
  210. <style scoped lang="scss">
  211. .swiper-box {
  212. height: 500rpx;
  213. }
  214. .swiper-item {
  215. display: block;
  216. height: 500rpx;
  217. line-height: 500rpx;
  218. text-align: center;
  219. image {
  220. width: 100%;
  221. height: 100%;
  222. display: block;
  223. border-radius: 60rpx;
  224. }
  225. }
  226. /* 轮播图 */
  227. .swWrapper {
  228. height: 400rpx;
  229. }
  230. .swImg {
  231. width: 100%;
  232. height: 400rpx;
  233. }
  234. /* 热门教员、热门学员标题 */
  235. .hotTitle {
  236. display: flex;
  237. margin-top: 5rpx;
  238. justify-content: center;
  239. align-items: center;
  240. }
  241. /* 热门教员、热门学员标题前后的线条 */
  242. .hotTitle::before {
  243. content: "";
  244. margin-right: 20rpx;
  245. margin-left: 40rpx;
  246. height: 1px;
  247. border: none;
  248. border-top: 1px solid #b2b2b2;
  249. flex: 1 1 0rpx;
  250. }
  251. .hotTitle::after {
  252. content: "";
  253. margin-right: 40rpx;
  254. margin-left: 20rpx;
  255. height: 1px;
  256. border: none;
  257. border-top: 1px solid #b2b2b2;
  258. flex: 1 1 0rpx;
  259. }
  260. .scrollItem{
  261. margin-right: 20rpx;
  262. width: 350rpx;
  263. }
  264. .scrollItem image{
  265. width: 350rpx;
  266. height: 300rpx;
  267. border-radius: 40rpx;
  268. }
  269. /* 攻略区 */
  270. .cooperationContent{
  271. height: 350rpx;
  272. margin-left: 20rpx;
  273. }
  274. /* 攻略图片 */
  275. .cooperationScroll{
  276. display: flex;
  277. height: 300rpx;
  278. }
  279. /* 热门教员、热门学员 */
  280. .hotTeacher,
  281. .hotStudent{
  282. position: relative;
  283. display: flex;
  284. padding: 10rpx;
  285. height: 170rpx;
  286. align-items: center;
  287. }
  288. /* 教员、学员头像 */
  289. .teachImg,
  290. .studentImg{
  291. width: 25%;
  292. height: 95%;
  293. border-radius: 20%;
  294. }
  295. /* 教员、学员性别 */
  296. .publicSex{
  297. position: absolute;
  298. right: 10rpx;
  299. top: 5rpx;
  300. // border: 0rpx solid gray;
  301. padding: 5rpx 10rpx;
  302. border-radius: 50%;
  303. background-color: #3ed598;
  304. color: #ffffff;
  305. font-size: 12px;
  306. }
  307. /* teachEdu */
  308. .teachEdu{
  309. position: absolute;
  310. right: 10rpx;
  311. top: 60rpx;
  312. // border: 0rpx solid gray;
  313. padding: 5rpx 10rpx;
  314. border-radius: 30rpx;
  315. background-color: #3ed598;
  316. color: #ffffff;
  317. font-size: 12px;
  318. }
  319. /* teach课程 */
  320. .teachSubject{
  321. position: absolute;
  322. left: 200rpx;
  323. top: 115rpx;
  324. // border: 0rpx solid gray;
  325. padding: 5rpx 10rpx;
  326. border-radius: 30rpx;
  327. background-color: #3ed598;
  328. color: #ffffff;
  329. font-size: 12px;
  330. }
  331. /* 教龄 */
  332. .teachYears{
  333. position: absolute;
  334. right: 10rpx;
  335. top: 115rpx;
  336. border: 2px solid #3ed598;
  337. padding: 2rpx 20rpx;
  338. border-radius: 30rpx;
  339. color: #3ed598;
  340. font-size: 12px;
  341. font-weight: bold;
  342. }
  343. /* stu课程 */
  344. .stuSubject{
  345. position: absolute;
  346. left: 200rpx;
  347. top: 60rpx;
  348. // border: 0rpx solid gray;
  349. padding: 5rpx 20rpx;
  350. border-radius: 30rpx;
  351. background-color: #3ed598;
  352. color: #ffffff;
  353. font-size: 12px;
  354. }
  355. .teachTitle,
  356. .studentTitle{
  357. font-size: 14px;
  358. position: absolute;
  359. left: 200rpx;
  360. top: 10rpx;
  361. font-weight: bold;
  362. color: #6d6d6d;
  363. }
  364. /* 距离 */
  365. .teachDistance,
  366. .studentDistance{
  367. position: absolute;
  368. left: 300rpx;
  369. top: 10rpx;
  370. font-weight: bold;
  371. color: #3ed598;
  372. font-size: 12px;
  373. }
  374. .teachCollege{
  375. border: 2px solid #3ed598;
  376. border-radius: 30rpx;
  377. padding: 0rpx 10rpx;
  378. font-size: 12px;
  379. position: absolute;
  380. left: 200rpx;
  381. top: 60rpx;
  382. color: #3ed598;
  383. }
  384. .stuGoal{
  385. margin-top: 10rpx;
  386. border: 2px solid #3ed598;
  387. border-radius: 30rpx;
  388. padding: 0rpx 10rpx;
  389. font-size: 12px;
  390. position: absolute;
  391. left: 200rpx;
  392. top: 125rpx;
  393. color: #3ed598;
  394. overflow: hidden;
  395. text-overflow: ellipsis;
  396. display: -webkit-box;
  397. -webkit-box-orient: vertical;
  398. -webkit-line-clamp: 1;
  399. }
  400. /* item */
  401. .publicItem{
  402. margin: 10rpx 20rpx;
  403. // border: 0rpx solid gray;
  404. padding: 10rpx 20rpx;
  405. border-radius: 30rpx;
  406. background-color: #ffffff;
  407. }
  408. </style>