index.tsx 11 KB

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