index.tsx 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. import OHeader from '@/components/o-header'
  2. import OSearch from '@/components/o-search'
  3. import OSticky from '@/components/o-sticky'
  4. import dayjs from 'dayjs'
  5. import {
  6. Cell,
  7. Icon,
  8. Popover,
  9. Tag,
  10. DatePicker,
  11. DatePickerColumnType,
  12. Popup,
  13. List,
  14. PullRefresh,
  15. ActionSheet,
  16. showToast
  17. } from 'vant'
  18. import StudentItem from './modals/student-item'
  19. import { defineComponent, reactive, ref } from 'vue'
  20. import { useRouter } from 'vue-router'
  21. import styles from './index.module.less'
  22. import request from '@/helpers/request'
  23. export default defineComponent({
  24. name: 'exercise-record',
  25. setup() {
  26. const router = useRouter()
  27. const state = reactive({
  28. showPopoverTime: false,
  29. showPopoverOrchestra: false,
  30. showPopoverSubject: false,
  31. showPopoverSort: false,
  32. actions: [
  33. { text: '全部乐团', color: 'var(--van-primary-color)' },
  34. { text: '交付团' },
  35. { text: '晋升团' }
  36. ],
  37. actionSorts: [
  38. { text: '按天数', value: 'PRACTICE_DAY' },
  39. { text: '按时长', value: 'PRACTICE_TIMES' }
  40. ],
  41. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  42. })
  43. const forms = reactive({
  44. practiceMonth: state.currentDate[0] + '' + state.currentDate[1],
  45. practiceMonthName: state.currentDate[0] + '年' + state.currentDate[1] + '月',
  46. orchestraId: '',
  47. orchestraName: '',
  48. subjectId: '',
  49. subjectName: '',
  50. sortType: '',
  51. sortTypeName: '',
  52. page: 1,
  53. rows: 20
  54. })
  55. const minDate = ref(new Date(dayjs().subtract(5, 'year').format('YYYY-MM-DD')))
  56. const maxDate = ref(new Date(dayjs().add(5, 'year').format('YYYY-MM-DD')))
  57. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  58. const refreshing = ref(false)
  59. const loading = ref(false)
  60. const finished = ref(false)
  61. const showContact = ref(false)
  62. const list = ref([])
  63. const onDetail = (item: any) => {
  64. console.log(item)
  65. router.push({
  66. path: '/orchestra-detail',
  67. query: {
  68. id: item
  69. }
  70. })
  71. }
  72. const getList = async () => {
  73. loading.value = true
  74. try {
  75. const res = await request.post('/api-school/student/page', {
  76. data: { ...forms }
  77. })
  78. if (refreshing.value) {
  79. list.value = []
  80. refreshing.value = false
  81. }
  82. if (list.value.length > 0 && res.data.pageNo === 1) {
  83. return
  84. }
  85. showContact.value = list.value.length > 0
  86. forms.page = res.data.current + 1
  87. list.value = list.value.concat(res.data.rows || [])
  88. loading.value = false
  89. finished.value = res.data.current >= res.data.pages
  90. } catch (e: any) {
  91. // console.log(e, 'e')
  92. const message = e.message
  93. showToast(message)
  94. showContact.value = false
  95. finished.value = true
  96. }
  97. }
  98. const onBack = () => {
  99. console.log('返回')
  100. }
  101. const checkTimer = (val: any) => {
  102. forms.practiceMonth = val.selectedValues[0] + val.selectedValues[1]
  103. forms.practiceMonthName = val.selectedValues[0] + '年' + val.selectedValues[1] + '月'
  104. state.showPopoverTime = false
  105. getList()
  106. }
  107. const checkSort = (val: any) => {
  108. forms.sortType = val.value
  109. forms.sortTypeName = val.text
  110. getList()
  111. }
  112. const onRefresh = () => {
  113. finished.value = false
  114. // 重新加载数据
  115. // 将 loading 设置为 true,表示处于加载状态
  116. loading.value = true
  117. getList()
  118. }
  119. return () => (
  120. <>
  121. <OSticky position="top" background="#F8F8F8">
  122. <OHeader isBack={true} onHeaderBack={onBack}></OHeader>
  123. <OSearch placeholder="学生编号" onSearch={getList}></OSearch>
  124. <div class={styles.chioseWrap}>
  125. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  126. <div
  127. class={styles.searchBand}
  128. onClick={() => {
  129. state.showPopoverTime = true
  130. }}
  131. >
  132. {forms.practiceMonthName}
  133. <Icon name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'} />
  134. </div>
  135. </div>
  136. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  137. <Popover
  138. v-model:show={state.showPopoverSubject}
  139. actions={state.actions}
  140. showArrow={false}
  141. placement="bottom-start"
  142. offset={[0, 12]}
  143. >
  144. {{
  145. reference: () => (
  146. <div class={styles.searchBand}>
  147. 全部乐团
  148. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  149. </div>
  150. )
  151. }}
  152. </Popover>
  153. </div>
  154. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  155. <Popover
  156. v-model:show={state.showPopoverSubject}
  157. actions={state.actions}
  158. showArrow={false}
  159. placement="bottom-start"
  160. offset={[0, 12]}
  161. >
  162. {{
  163. reference: () => (
  164. <div class={styles.searchBand}>
  165. 全部声部
  166. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  167. </div>
  168. )
  169. }}
  170. </Popover>
  171. </div>
  172. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  173. <Popover
  174. v-model:show={state.showPopoverSort}
  175. actions={state.actionSorts}
  176. showArrow={false}
  177. placement="bottom-end"
  178. offset={[0, 12]}
  179. onSelect={checkSort}
  180. >
  181. {{
  182. reference: () => (
  183. <div class={styles.searchBand}>
  184. 按天数
  185. <Icon name={state.showPopoverSort ? 'arrow-up' : 'arrow-down'} />
  186. </div>
  187. )
  188. }}
  189. </Popover>
  190. </div>
  191. </div>
  192. </OSticky>
  193. <PullRefresh v-model={refreshing.value} onRefresh={onRefresh}>
  194. <List
  195. v-model:loading={loading.value}
  196. finished={finished.value}
  197. finished-text="没有更多了"
  198. onLoad={getList}
  199. >
  200. {list.value.map((item: any) => (
  201. <StudentItem item={item} />
  202. ))}
  203. </List>
  204. </PullRefresh>
  205. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  206. <DatePicker
  207. onCancel={() => {
  208. state.showPopoverTime = false
  209. }}
  210. onConfirm={checkTimer}
  211. v-model={state.currentDate}
  212. title="选择年月"
  213. minDate={minDate.value}
  214. maxDate={maxDate.value}
  215. columnsType={columnsType.value}
  216. />
  217. </Popup>
  218. </>
  219. )
  220. }
  221. })