timer-bang.tsx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. import OSearch from '@/components/o-search'
  2. import oEmpty from '@/components/o-empty'
  3. import dayjs from 'dayjs'
  4. import {
  5. Icon,
  6. Popover,
  7. DatePicker,
  8. DatePickerColumnType,
  9. Popup,
  10. List,
  11. PullRefresh,
  12. ActionSheet,
  13. showToast
  14. } from 'vant'
  15. import { defineComponent, reactive, ref, onMounted } from 'vue'
  16. import { useRouter } from 'vue-router'
  17. import styles from './timer-bang.module.less'
  18. import request from '@/helpers/request'
  19. import { state as globalState } from '@/state'
  20. export default defineComponent({
  21. name: 'attend-student',
  22. setup() {
  23. const router = useRouter()
  24. const state = reactive({
  25. showPopoverTime: false,
  26. showPopoverOrchestra: false,
  27. showPopoverSubject: false,
  28. actions: [] as any,
  29. subjects: [] as any,
  30. currentDate: [dayjs().format('YYYY'), dayjs().format('MM')]
  31. })
  32. const forms = reactive({
  33. time: state.currentDate[0] + '' + state.currentDate[1],
  34. timeName: state.currentDate[0] + '年' + state.currentDate[1] + '月',
  35. orchestraId: '',
  36. orchestraName: '全部乐团',
  37. subjectId: '',
  38. subjectName: '全部声部',
  39. page: 1,
  40. rows: 50,
  41. sortType: 'PRACTICE_DAY'
  42. })
  43. const minDate = ref(new Date(dayjs().subtract(5, 'year').format('YYYY-MM-DD')))
  44. const maxDate = ref(new Date(dayjs().add(5, 'year').format('YYYY-MM-DD')))
  45. const columnsType = ref<DatePickerColumnType[]>(['year', 'month'])
  46. const refreshing = ref(false)
  47. const loading = ref(false)
  48. const finished = ref(false)
  49. const showContact = ref(false)
  50. const list = ref([])
  51. const getList = async () => {
  52. console.log('getList')
  53. loading.value = true
  54. try {
  55. if (refreshing.value) {
  56. forms.page = 1
  57. list.value = []
  58. refreshing.value = false
  59. }
  60. const res = await request.post('/api-school/student/page', {
  61. data: { ...forms }
  62. })
  63. if (list.value.length > 0 && res.data.pages === 1) {
  64. return
  65. }
  66. forms.page = res.data.current + 1
  67. // list.value = list.value.concat(res.data.rows || [])
  68. list.value = res.data.rows
  69. showContact.value = list.value.length > 0
  70. console.log(showContact.value, ' showContact.value ')
  71. loading.value = false
  72. finished.value = true
  73. // finished.value = res.data.current >= res.data.pages
  74. } catch (e: any) {
  75. // console.log(e, 'e')
  76. const message = e.message
  77. showToast(message)
  78. showContact.value = false
  79. finished.value = true
  80. }
  81. }
  82. const checkTimer = (val: any) => {
  83. forms.time = val.selectedValues[0] + val.selectedValues[1]
  84. forms.timeName = val.selectedValues[0] + '年' + val.selectedValues[1] + '月'
  85. state.showPopoverTime = false
  86. getList()
  87. }
  88. const checkOrchestra = (val: any) => {
  89. forms.orchestraId = val.value
  90. forms.orchestraName = val.name
  91. state.showPopoverOrchestra = false
  92. refreshing.value = true
  93. getList()
  94. }
  95. const checkSubject = (val: any) => {
  96. forms.subjectId = val.value
  97. forms.subjectName = val.name
  98. console.log(val, forms)
  99. refreshing.value = true
  100. getList()
  101. }
  102. const getOrchestraList = async () => {
  103. const schoolId = globalState.user.data.schoolInfos
  104. .map((item) => {
  105. return item.id
  106. })
  107. .join(',')
  108. try {
  109. const res = await request.post('/api-school/orchestra/page', {
  110. data: { page: 1, rows: 9999, schoolId }
  111. })
  112. state.actions = res.data.rows.map((item) => {
  113. return {
  114. name: item.name,
  115. value: item.id as string
  116. }
  117. })
  118. state.actions.unshift({ name: '全部乐团', value: '' })
  119. } catch (e: any) {
  120. const message = e.message
  121. showToast(message)
  122. }
  123. }
  124. const getSubjects = async () => {
  125. try {
  126. const res = await request.post('/api-school/subject/page', {
  127. data: { page: 1, rows: 9999 }
  128. })
  129. state.subjects = res.data.rows.map((item) => {
  130. return {
  131. name: item.name,
  132. value: item.id as string
  133. }
  134. })
  135. state.subjects.unshift({ name: '全部声部', value: '' })
  136. } catch (e: any) {
  137. const message = e.message
  138. showToast(message)
  139. }
  140. }
  141. onMounted(() => {
  142. getSubjects()
  143. getOrchestraList()
  144. getList()
  145. })
  146. const onRefresh = () => {
  147. finished.value = false
  148. // 重新加载数据
  149. // 将 loading 设置为 true,表示处于加载状态
  150. loading.value = true
  151. getList()
  152. }
  153. return () => (
  154. <>
  155. {/* <OSticky position="top" background="#FFF"> */}
  156. <div class={styles.chioseWrap}>
  157. <div style={{ padding: '0 13px', background: '#FFF' }}>
  158. <div
  159. class={styles.searchBand}
  160. onClick={() => {
  161. state.showPopoverTime = true
  162. }}
  163. >
  164. {forms.timeName}
  165. <Icon name={state.showPopoverTime ? 'arrow-up' : 'arrow-down'} />
  166. </div>
  167. </div>
  168. <div style={{ padding: '0 13px', background: '#FFF' }}>
  169. <div
  170. class={styles.searchBand}
  171. onClick={() => {
  172. state.showPopoverOrchestra = true
  173. }}
  174. >
  175. {forms.orchestraName}
  176. <Icon name={state.showPopoverOrchestra ? 'arrow-up' : 'arrow-down'} />
  177. </div>
  178. </div>
  179. <div style={{ padding: '0 13px', background: '#FFF' }}>
  180. <div
  181. class={styles.searchBand}
  182. onClick={() => {
  183. state.showPopoverSubject = true
  184. }}
  185. >
  186. {forms.subjectName}
  187. <Icon name={state.showPopoverSubject ? 'arrow-up' : 'arrow-down'} />
  188. </div>
  189. </div>
  190. </div>
  191. {/* </OSticky> */}
  192. {}
  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) => 111)}
  201. </List>
  202. </PullRefresh>
  203. <Popup v-model:show={state.showPopoverTime} position="bottom" style="{ height: '30%' }">
  204. <DatePicker
  205. onCancel={() => {
  206. state.showPopoverTime = false
  207. }}
  208. onConfirm={checkTimer}
  209. v-model={state.currentDate}
  210. title="选择年月"
  211. minDate={minDate.value}
  212. maxDate={maxDate.value}
  213. columnsType={columnsType.value}
  214. />
  215. </Popup>
  216. <ActionSheet
  217. v-model:show={state.showPopoverOrchestra}
  218. title="选择乐团"
  219. actions={state.actions}
  220. onSelect={checkOrchestra}
  221. ></ActionSheet>
  222. <ActionSheet
  223. style={{ height: '40%' }}
  224. close-on-click-action
  225. v-model:show={state.showPopoverSubject}
  226. title="选择声部"
  227. actions={state.subjects}
  228. onSelect={checkSubject}
  229. ></ActionSheet>
  230. </>
  231. )
  232. }
  233. })