index.tsx 10 KB

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