student.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  1. <template>
  2. <view>
  3. <view v-for="(item, index) in stuNeeds" :key="index">
  4. <view class="publicItem" @click="goDetail(item.requireId)">
  5. <view class="hotStudent">
  6. <template v-if="item.sex === '女'">
  7. <image class="teachImg" src="../../static/girl.png"></image>
  8. </template>
  9. <template v-else>
  10. <image class="teachImg" src="../../static/boy.png"></image>
  11. </template>
  12. <view class="hotStudentText">
  13. <view class="studentTitle">{{item.nickname}}学员</view>
  14. <view class="publicSex">{{item.sex}}</view>
  15. <view class="stuGoal">{{item.goal}}</view>
  16. <view class="studentDistance" v-if="isShowDistance">
  17. <uni-icons type="location" color="#3ed598" ></uni-icons>
  18. <text>{{item.kil}}</text>km
  19. </view>
  20. </view>
  21. <view class="stuSubject">{{item.subjectBig + "/" + item.subjectSmall}}</view>
  22. </view>
  23. </view>
  24. </view>
  25. <uni-fab :pattern="pattern" horizontal="left" vertical="bottom" @fabClick="fabClick"></uni-fab>
  26. <uni-drawer ref="showRight" mode="left" width="280">
  27. <scroll-view style="height: 100%;" scroll-y="true">
  28. <uni-section title="条件搜索" type="line"></uni-section>
  29. <view class="searchInput" >
  30. <uni-data-select v-model="queryObj.sex" :localdata="sexs" placeholder="学员性别" />
  31. </view>
  32. <view class="searchInput" >
  33. <uni-data-select v-model="queryObj.time" :localdata="time" placeholder="上课时间" />
  34. </view>
  35. <view class="searchInput" >
  36. <uni-data-select v-model="queryObj.money" :localdata="money" placeholder="需求金额" />
  37. </view>
  38. <view class="searchInput" >
  39. <uni-data-picker placeholder="课程类别" popup-title="课程大纲-具体课程" v-model="queryObj.subject" :localdata="courseTree" preload="true" />
  40. </view>
  41. <view class="button-group">
  42. <button @click="submit" class="myButton1">搜索</button>
  43. <button @click="closeDrawer" class="myButton2">取消</button>
  44. </view>
  45. </scroll-view>
  46. </uni-drawer>
  47. </view>
  48. </template>
  49. <script>
  50. import badgeMix from '@/mixins/tabbar-badge.js'
  51. import computeDistance from '@/mixins/compute-distance.js'
  52. import { mapState } from 'vuex'
  53. export default {
  54. mixins: [badgeMix, computeDistance],
  55. computed: {
  56. ...mapState('m_user', ['location','token'])
  57. },
  58. data() {
  59. return {
  60. isShowDistance: false,
  61. pattern: {
  62. color: '#7A7E83',
  63. backgroundColor: '#fff',
  64. selectedColor: '#3ed598',
  65. buttonColor: '#3ed598',
  66. iconColor: '#fff'
  67. },
  68. stuNeeds: [],
  69. queryObj: {
  70. pageNum: 1,
  71. pageSize: 7,
  72. sex: '',
  73. time: '',
  74. money: '',
  75. subject: '1-1',
  76. subjectBig: '',
  77. },
  78. total: 0,
  79. isloading: false,
  80. // 选择课程
  81. courseTree: [{
  82. text: '一年级',
  83. value: '1-0',
  84. children: [{
  85. text: '1.1班',
  86. value: '1-1'
  87. }
  88. ]
  89. }
  90. ],
  91. // 单选性别数据源
  92. sexs: [{
  93. text: '男',
  94. value: '男'
  95. }, {
  96. text: '女',
  97. value: '女'
  98. }],
  99. time: [{
  100. text: '上午',
  101. value: '上午'
  102. }, {
  103. text: '下午',
  104. value: '下午'
  105. }, {
  106. text: '晚上',
  107. value: '晚上'
  108. }],
  109. money: [{
  110. text: '100以内',
  111. value: '0-100'
  112. }, {
  113. text: '100到200以内',
  114. value: '100-200'
  115. }, {
  116. text: '200-400以内',
  117. value: '200-400'
  118. }, {
  119. text: '400以上',
  120. value: '400-2000'
  121. }]
  122. };
  123. },
  124. watch: {
  125. 'token': {
  126. handler() {
  127. if (this.token !== '') {
  128. this.isShowDistance = true
  129. this.stuNeeds = []
  130. this.getAllStuNeeds()
  131. } else {
  132. this.isShowDistance = false
  133. }
  134. }
  135. }
  136. },
  137. created() {
  138. if (this.token !== '') {
  139. this.isShowDistance = true
  140. }
  141. this.getAllStuNeeds(),
  142. this.getPriceAndTree()
  143. },
  144. methods: {
  145. // 树形结构的课程和价格表
  146. async getPriceAndTree() {
  147. const {
  148. data: result
  149. } = await uni.$http.get('/education/course-price/treeAndPrice')
  150. this.courseTree = result.data.treeCourse
  151. },
  152. submit() {
  153. this.$refs.showRight.close();
  154. if (this.queryObj.subject !== '1-1') {
  155. // 课程科目
  156. for (let x = 0; x < this.courseTree.length; x++) {
  157. for (let y = 0; y < this.courseTree[x].children.length; y++) {
  158. if (this.courseTree[x].children[y].value === this.queryObj.subject) {
  159. this.queryObj.subjectBig = this.courseTree[x].value
  160. }
  161. }
  162. }
  163. }
  164. this.stuNeeds = []
  165. this.getAllStuNeeds()
  166. },
  167. closeDrawer() {
  168. this.$refs.showRight.close();
  169. this.queryObj.sex = ''
  170. this.queryObj.time = ''
  171. this.queryObj.money = ''
  172. this.queryObj.subject = '1-1'
  173. this.queryObj.subjectBig = ''
  174. this.stuNeeds = []
  175. this.getAllStuNeeds()
  176. },
  177. fabClick() {
  178. this.$refs.showRight.open();
  179. },
  180. async getAllStuNeeds(cb) {
  181. // 打开节流阀
  182. this.isloading = true
  183. // 发起请求
  184. const {
  185. data: result
  186. } = await uni.$http.post('/education/student-requirements/getAllRequirements', this.queryObj)
  187. // 关闭节流阀
  188. this.isloading = false
  189. // 只要数据请求完毕,就立即按需调用 cb 回调函数
  190. cb && cb()
  191. for (let i = 0; i < result.data.list.length; i++) {
  192. let arr = result.data.list[i].locationAl.split(",")
  193. let kil = this.space(arr[0], arr[1], this.location.latitude, this.location.longitude)
  194. result.data.list[i].kil = kil
  195. result.data.list[i].nickname = result.data.list[i].name.slice(0,1)
  196. if (result.data.list[i].goal.length > 15) {
  197. result.data.list[i].goal = result.data.list[i].goal.slice(0,15) + "..."
  198. }
  199. }
  200. // 新旧拼接
  201. this.stuNeeds = [...this.stuNeeds, ...result.data.list]
  202. this.total = result.data.total
  203. },
  204. // 下拉刷新
  205. onPullDownRefresh() {
  206. if (this.isloading) return
  207. this.queryObj.pageNum = 1
  208. this.total = 0
  209. this.stuNeeds = []
  210. this.isloading = false
  211. this.getAllStuNeeds(() => uni.stopPullDownRefresh())
  212. },
  213. // 触底事件
  214. onReachBottom() {
  215. // 判断是否有下一页
  216. if (this.queryObj.pageNum * this.queryObj.pageSize >= this.total) return uni.$showMsg('数据加载完毕!')
  217. // 判断是否正在请求数据
  218. if (this.isloading) return
  219. this.queryObj.pageNum += 1
  220. this.getAllStuNeeds()
  221. },
  222. goDetail(id) {
  223. uni.navigateTo({
  224. url: '/subpkg/student/require/student_require_all_detail?requireId=' + encodeURIComponent(id)
  225. })
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang="scss" scoped>
  231. .button-group {
  232. padding: 100rpx 100rpx;
  233. display: flex;
  234. justify-content: space-between;
  235. }
  236. .searchInput {
  237. margin-bottom: 40rpx;
  238. }
  239. /* 教员、学员头像 */
  240. .teachImg,
  241. .studentImg{
  242. width: 25%;
  243. height: 95%;
  244. border-radius: 20%;
  245. }
  246. .stuSubject{
  247. position: absolute;
  248. left: 200rpx;
  249. top: 60rpx;
  250. border: 0rpx solid gray;
  251. padding: 10rpx 20rpx;
  252. border-radius: 30rpx;
  253. background-color: #3ed598;
  254. color: #ffffff;
  255. font-size: 12px;
  256. }
  257. .studentTitle{
  258. font-size: 14px;
  259. position: absolute;
  260. left: 200rpx;
  261. top: 10rpx;
  262. font-weight: bold;
  263. color: #6d6d6d;
  264. }
  265. /* 距离 */
  266. .studentDistance{
  267. position: absolute;
  268. left: 300rpx;
  269. top: 10rpx;
  270. font-weight: bold;
  271. color: #3ed598;
  272. font-size: 12px;
  273. }
  274. .stuGoal{
  275. border: 2px solid #3ed598;
  276. border-radius: 30rpx;
  277. padding: 0rpx 10rpx;
  278. font-size: 12px;
  279. position: absolute;
  280. left: 200rpx;
  281. top: 125rpx;
  282. color: #3ed598;
  283. }
  284. /* item */
  285. .publicItem{
  286. margin-left: 20rpx;
  287. margin-right: 20rpx;
  288. margin-top: 10rpx ;
  289. margin-bottom: 10rpx ;
  290. border: 0rpx solid gray;
  291. padding: 10rpx 20rpx;
  292. border-radius: 30rpx;
  293. background-color: #ffffff;
  294. }
  295. .hotStudent{
  296. position: relative;
  297. display: flex;
  298. padding: 10rpx;
  299. height: 170rpx;
  300. align-items: center;
  301. }
  302. /* teachsex */
  303. .publicSex{
  304. position: absolute;
  305. right: 10rpx;
  306. top: 5rpx;
  307. border: 0rpx solid gray;
  308. padding: 5rpx 10rpx;
  309. border-radius: 30rpx;
  310. background-color: #3ed598;
  311. color: #ffffff;
  312. font-size: 12px;
  313. }
  314. .myButton1{
  315. border: 0rpx solid gray;
  316. padding: 15rpx 60rpx;
  317. border-radius: 30rpx;
  318. background-color: #35b882;
  319. color: #ffffff;
  320. font-size: 14px;
  321. }
  322. /* myButton1 */
  323. .myButton2{
  324. border: 0rpx solid gray;
  325. padding: 15rpx 60rpx;
  326. border-radius: 30rpx;
  327. background-color: #3ed598;
  328. color: #ffffff;
  329. font-size: 14px;
  330. }
  331. </style>