index.tsx 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. import OHeader from '@/components/o-header'
  2. import OSearch from '@/components/o-search'
  3. import OSticky from '@/components/o-sticky'
  4. import OEmpty from '@/components/o-empty'
  5. import dayjs from 'dayjs'
  6. import {
  7. Cell,
  8. Icon,
  9. Popover,
  10. Tag,
  11. DatePicker,
  12. DatePickerColumnType,
  13. Popup,
  14. List,
  15. PullRefresh,
  16. ActionSheet,
  17. showToast
  18. } from 'vant'
  19. import StudentItem from './modals/student-item'
  20. import { defineComponent, reactive, ref, onMounted } from 'vue'
  21. import { state as globalState } from '@/state'
  22. import { useRouter } from 'vue-router'
  23. import styles from './index.module.less'
  24. import request from '@/helpers/request'
  25. export default defineComponent({
  26. name: 'exercise-record',
  27. setup() {
  28. const router = useRouter()
  29. const state = reactive({
  30. showPopoverTime: false,
  31. showPopoverOrchestra: false,
  32. showPopoverSubject: false,
  33. showPopoverSort: false,
  34. actions: [] as any,
  35. subjects: [] as any,
  36. actionSorts: [
  37. {
  38. text: '按天数',
  39. value: 'PRACTICE_DAY',
  40. color: '#f67146'
  41. },
  42. {
  43. text: '按时长',
  44. value: 'PRACTICE_TIMES',
  45. color: '#333'
  46. }
  47. // color: forms.sortType == 'PRACTICE_DAY' ? '#FF8057' : '#333'
  48. ],
  49. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  50. })
  51. const forms = reactive({
  52. practiceMonth: state.currentDate[0] + '' + state.currentDate[1],
  53. practiceMonthName: state.currentDate[0] + '年' + state.currentDate[1] + '月',
  54. orchestraId: '',
  55. orchestraName: '全部乐团',
  56. subjectId: '',
  57. subjectName: '全部声部',
  58. sortType: 'PRACTICE_DAY',
  59. sortTypeName: '按天数',
  60. keyword: '',
  61. page: 1,
  62. rows: 20
  63. })
  64. const minDate = ref(new Date(dayjs().subtract(10, 'year').format('YYYY-MM-DD')))
  65. const maxDate = ref(new Date(dayjs().add(10, 'year').format('YYYY-MM-DD')))
  66. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  67. const refreshing = ref(false)
  68. const loading = ref(false)
  69. const finished = ref(false)
  70. const showContact = ref(false)
  71. const list = ref([])
  72. const getList = async () => {
  73. loading.value = true
  74. try {
  75. if (refreshing.value) {
  76. forms.page = 1
  77. list.value = []
  78. refreshing.value = false
  79. }
  80. const res = await request.post('/api-school/student/page', {
  81. data: { ...forms }
  82. })
  83. if (list.value.length > 0 && res.data.pages === 1) {
  84. return
  85. }
  86. forms.page = res.data.current + 1
  87. list.value = list.value.concat(res.data.rows || [])
  88. showContact.value = list.value.length > 0
  89. console.log(showContact.value, ' showContact.value ')
  90. loading.value = false
  91. finished.value = res.data.current >= res.data.pages
  92. } catch (e: any) {
  93. // console.log(e, 'e')
  94. const message = e.message
  95. showToast(message)
  96. showContact.value = false
  97. finished.value = true
  98. }
  99. }
  100. onMounted(() => {
  101. getList()
  102. getOrchestraList()
  103. getSubjects()
  104. })
  105. const onBack = () => {
  106. console.log('返回')
  107. }
  108. const checkSort = (val: any) => {
  109. forms.sortType = val.value
  110. forms.sortTypeName = val.text
  111. state.actionSorts.forEach((element) => {
  112. if (element.value == val.value) {
  113. element.color = '#f67146'
  114. } else {
  115. element.color = '#333'
  116. }
  117. })
  118. refreshing.value = true
  119. getList()
  120. }
  121. const checkTimer = (val: any) => {
  122. forms.practiceMonth = val.selectedValues[0] + val.selectedValues[1]
  123. forms.practiceMonthName = val.selectedValues[0] + '年' + val.selectedValues[1] + '月'
  124. state.showPopoverTime = false
  125. refreshing.value = true
  126. getList()
  127. }
  128. const checkOrchestra = (val: any) => {
  129. forms.orchestraId = val.value
  130. forms.orchestraName = val.name
  131. state.showPopoverOrchestra = false
  132. refreshing.value = true
  133. getList()
  134. }
  135. const checkSubject = (val: any) => {
  136. forms.subjectId = val.value
  137. forms.subjectName = val.name
  138. console.log(val, forms)
  139. refreshing.value = true
  140. getList()
  141. }
  142. const getOrchestraList = async () => {
  143. const schoolId = globalState.user.data.schoolInfos
  144. .map((item) => {
  145. return item.id
  146. })
  147. .join(',')
  148. try {
  149. const res = await request.post('/api-school/orchestra/page', {
  150. data: { page: 1, rows: 9999, schoolId }
  151. })
  152. state.actions = res.data.rows.map((item) => {
  153. return {
  154. name: item.name,
  155. value: item.id as string
  156. }
  157. })
  158. state.actions.unshift({ name: '全部乐团', value: '' })
  159. } catch (e: any) {
  160. const message = e.message
  161. showToast(message)
  162. }
  163. }
  164. const getSubjects = async () => {
  165. try {
  166. const res = await request.post('/api-school/subject/page', {
  167. data: { page: 1, rows: 9999 }
  168. })
  169. state.subjects = res.data.rows.map((item) => {
  170. return {
  171. name: item.name,
  172. value: item.id as string
  173. }
  174. })
  175. state.subjects.unshift({ name: '全部声部', value: '' })
  176. } catch (e: any) {
  177. const message = e.message
  178. showToast(message)
  179. }
  180. }
  181. const onRefresh = () => {
  182. finished.value = false
  183. // 重新加载数据
  184. // 将 loading 设置为 true,表示处于加载状态
  185. loading.value = true
  186. getList()
  187. }
  188. return () => (
  189. <>
  190. <OSticky position="top" background="#F8F8F8">
  191. <OHeader onHeaderBack={onBack}></OHeader>
  192. <OSearch
  193. placeholder="请输入学生姓名"
  194. onSearch={(val: any) => {
  195. forms.keyword = val
  196. refreshing.value = true
  197. getList()
  198. }}
  199. ></OSearch>
  200. <div class={styles.chioseWrap}>
  201. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  202. <div
  203. class={styles.searchBand}
  204. onClick={() => {
  205. state.showPopoverTime = true
  206. }}
  207. >
  208. {forms.practiceMonthName}
  209. <Icon name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'} />
  210. </div>
  211. </div>
  212. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  213. <div
  214. class={styles.searchBand}
  215. onClick={() => {
  216. state.showPopoverOrchestra = true
  217. }}
  218. >
  219. {forms.orchestraName}
  220. <Icon name={state.showPopoverOrchestra ? 'arrow-up' : 'arrow-down'} />
  221. </div>
  222. </div>
  223. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  224. <div
  225. class={styles.searchBand}
  226. onClick={() => {
  227. state.showPopoverSubject = true
  228. }}
  229. >
  230. {forms.subjectName}
  231. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  232. </div>
  233. </div>
  234. <div style={{ padding: '12px 13px', background: '#F8F8F8' }}>
  235. <Popover
  236. v-model:show={state.showPopoverSort}
  237. actions={state.actionSorts}
  238. showArrow={false}
  239. placement="bottom-end"
  240. offset={[0, 12]}
  241. onSelect={checkSort}
  242. >
  243. {{
  244. reference: () => (
  245. <div class={styles.searchBand}>
  246. 按天数
  247. <Icon name={state.showPopoverSort ? 'arrow-up' : 'arrow-down'} />
  248. </div>
  249. )
  250. }}
  251. </Popover>
  252. </div>
  253. </div>
  254. </OSticky>
  255. {showContact.value ? (
  256. <PullRefresh v-model={refreshing.value} onRefresh={onRefresh}>
  257. <List
  258. v-model:loading={loading.value}
  259. finished={finished.value}
  260. finished-text="没有更多了"
  261. onLoad={getList}
  262. >
  263. {list.value.map((item: any) => (
  264. <StudentItem item={item} forms={forms} />
  265. ))}
  266. </List>
  267. </PullRefresh>
  268. ) : (
  269. <OEmpty></OEmpty>
  270. )}
  271. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  272. <DatePicker
  273. onCancel={() => {
  274. state.showPopoverTime = false
  275. }}
  276. onConfirm={checkTimer}
  277. v-model={state.currentDate}
  278. title="选择年月"
  279. minDate={minDate.value}
  280. maxDate={maxDate.value}
  281. columnsType={columnsType.value}
  282. />
  283. </Popup>
  284. <ActionSheet
  285. v-model:show={state.showPopoverOrchestra}
  286. title="选择乐团"
  287. actions={state.actions}
  288. onSelect={checkOrchestra}
  289. ></ActionSheet>
  290. <ActionSheet
  291. style={{ height: '40%' }}
  292. close-on-click-action
  293. v-model:show={state.showPopoverSubject}
  294. title="选择声部"
  295. actions={state.subjects}
  296. onSelect={checkSubject}
  297. ></ActionSheet>
  298. </>
  299. )
  300. }
  301. })