home.vue 11 KB

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