index.tsx 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import { defineComponent } from 'vue'
  2. import styles from './index.module.less'
  3. import ColHeader from '@/components/col-header'
  4. import {
  5. Button,
  6. Icon,
  7. Popup,
  8. RadioGroup,
  9. Sticky,
  10. Radio,
  11. Tag,
  12. List,
  13. ActionSheet
  14. } from 'vant'
  15. import ColSearch from '@/components/col-search'
  16. import PracticeItem from './practice-item'
  17. import request from '@/helpers/request'
  18. import ColResult from '@/components/col-result'
  19. import AllSearch from './model/all-search'
  20. import OrganSearch from './model/organ-search'
  21. import { state } from '@/state'
  22. import { useElementSize } from '@vueuse/core'
  23. // {"subjectId":null,"search":"","sort":"starGrade ASC,expTime DESC,subjectPrice DESC"}
  24. const actions = [
  25. {
  26. name: '不限制',
  27. value: '',
  28. color: 'var(--van-primary)'
  29. },
  30. {
  31. name: '单价最高',
  32. value: 'subjectPrice DESC',
  33. color: '#333'
  34. },
  35. {
  36. name: '单价最低',
  37. value: 'subjectPrice ASC',
  38. color: '#333'
  39. },
  40. {
  41. name: '课时数最多',
  42. value: 'expTime DESC',
  43. color: '#333'
  44. },
  45. {
  46. name: '评分最高',
  47. value: 'starGrade DESC',
  48. color: '#333'
  49. }
  50. ]
  51. export default defineComponent({
  52. name: 'practiceClass',
  53. data() {
  54. return {
  55. openStatus: false,
  56. searchStatus: false,
  57. subjectList: [],
  58. list: [],
  59. dataShow: true, // 判断是否有数据
  60. loading: false,
  61. finished: false,
  62. searchType: 'organ' as 'organ' | 'all',
  63. tempSort: {
  64. starGrade: 'ALL',
  65. expTime: 'ALL',
  66. subjectPrice: 'ALL'
  67. },
  68. dataLoading: false,
  69. params: {
  70. search: '',
  71. sort: '',
  72. subjectName: '',
  73. subjectId: null as any,
  74. page: 1,
  75. rows: 20
  76. },
  77. show: false,
  78. height: 'auto' as any
  79. }
  80. },
  81. async mounted() {
  82. this.params.subjectId = state.user.data?.subjectId || null
  83. this.params.subjectName = state.user.data?.subjectName || ''
  84. try {
  85. const res = await request.get('/api-student/subject/subjectSelect')
  86. this.subjectList = res.data || []
  87. } catch {}
  88. this.getList()
  89. // this.$nextTick(() => {
  90. const { width, height } = useElementSize((this as any).$refs.headers)
  91. console.log(width.value, height.value, width, height)
  92. this.height = height
  93. // })
  94. },
  95. methods: {
  96. onSearch(_search?: any) {
  97. this.params.search = _search
  98. this.onSort()
  99. },
  100. onSort() {
  101. this.params.page = 1
  102. this.list = []
  103. this.dataShow = true // 判断是否有数据
  104. this.loading = false
  105. this.finished = false
  106. this.searchStatus = false
  107. this.getList()
  108. },
  109. onSheetSelect(item: any) {
  110. actions.forEach((v: any) => {
  111. v.color = '#333'
  112. if (v.value === item.value) {
  113. v.color = 'var(--van-primary)'
  114. }
  115. })
  116. this.params.sort = item.value
  117. this.show = false
  118. this.onSort()
  119. },
  120. async getList() {
  121. try {
  122. if (this.dataLoading) {
  123. return
  124. }
  125. this.dataLoading = true
  126. const res = await request.post(
  127. '/api-student/courseSchedule/teacherList',
  128. {
  129. data: {
  130. ...this.params
  131. }
  132. }
  133. )
  134. this.dataLoading = false
  135. this.loading = false
  136. const result = res.data || {}
  137. // 处理重复请求数据
  138. if (this.list.length > 0 && result.pageNo === 1) {
  139. return
  140. }
  141. this.list = this.list.concat(result.rows || [])
  142. this.finished = result.pageNo >= result.totalPage
  143. this.params.page = result.pageNo + 1
  144. this.dataShow = this.list.length > 0
  145. } catch {
  146. this.dataShow = false
  147. this.finished = true
  148. }
  149. }
  150. },
  151. render() {
  152. return (
  153. <div style={{ overflow: 'hidden' }}>
  154. <Sticky
  155. class={'sticky'}
  156. style={{
  157. background: 'var(--van-primary)',
  158. height: this.height + 'px !important',
  159. width: '100%'
  160. }}
  161. >
  162. <div ref="headers">
  163. <ColHeader
  164. title="陪练课"
  165. isFixed={false}
  166. border={false}
  167. backIconColor="white"
  168. background="var(--van-primary)"
  169. color="#fff"
  170. />
  171. <ColSearch
  172. placeholder="请输入老师名称"
  173. inputBackground="white"
  174. background="var(--van-primary)"
  175. onSearch={this.onSearch}
  176. />
  177. <div class={styles.filterSection}>
  178. <div>
  179. <Button
  180. class={[styles.btn]}
  181. type="primary"
  182. size="small"
  183. round
  184. plain
  185. onClick={() => {
  186. this.searchStatus = !this.searchStatus
  187. this.openStatus = !this.openStatus
  188. this.searchType = 'organ'
  189. }}
  190. >
  191. {this.params.subjectName}
  192. <Icon
  193. classPrefix="iconfont"
  194. name="down"
  195. size={8}
  196. style={{ marginLeft: '4px' }}
  197. color="var(--van-primary)"
  198. />
  199. </Button>
  200. <Button class={[styles.btn]} size="small" round plain>
  201. 30天内未约满
  202. </Button>
  203. </div>
  204. <div>
  205. <div
  206. class={styles.dataItem}
  207. onClick={() => {
  208. this.show = true
  209. }}
  210. >
  211. 筛选
  212. <Icon
  213. classPrefix="iconfont"
  214. name="down"
  215. size={8}
  216. style={{ marginLeft: '4px' }}
  217. color="var(--van-primary)"
  218. />
  219. </div>
  220. </div>
  221. </div>
  222. </div>
  223. </Sticky>
  224. {this.dataShow ? (
  225. <List
  226. v-model:loading={this.loading}
  227. finished={this.finished}
  228. finishedText=" "
  229. immediateCheck={false}
  230. class={[styles.practiceList, 'mb12']}
  231. onLoad={this.getList}
  232. >
  233. {this.list.map((item: any) => (
  234. <PracticeItem
  235. item={item}
  236. onClick={() => {
  237. this.$router.push({
  238. path: '/teacherHome',
  239. query: {
  240. teacherId: item.teacherId,
  241. tabs: 'practice',
  242. subjectId: this.params.subjectId
  243. }
  244. })
  245. }}
  246. />
  247. ))}
  248. </List>
  249. ) : (
  250. <ColResult
  251. btnStatus={false}
  252. classImgSize="SMALL"
  253. tips="暂无陪练老师"
  254. />
  255. )}
  256. <ActionSheet
  257. show={this.show}
  258. actions={actions}
  259. cancelText="取消"
  260. onSelect={this.onSheetSelect}
  261. onCancel={() => (this.show = false)}
  262. />
  263. <Popup
  264. show={this.searchStatus}
  265. position="bottom"
  266. round
  267. closeable
  268. safe-area-inset-bottom
  269. onClose={() => (this.searchStatus = false)}
  270. onClosed={() => (this.openStatus = false)}
  271. >
  272. {/* {this.searchType === 'all' && <AllSearch onSort={this.onSort} />} */}
  273. {this.searchType === 'organ' && this.openStatus && (
  274. <OrganSearch
  275. subjectList={this.subjectList}
  276. onSort={this.onSort}
  277. v-model={this.params.subjectId}
  278. v-model:subjectName={this.params.subjectName}
  279. />
  280. )}
  281. </Popup>
  282. </div>
  283. )
  284. }
  285. })