index.tsx 9.5 KB

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