plan.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. import OEmpty from '@/components/o-empty'
  2. import request from '@/helpers/request'
  3. import dayjs from 'dayjs'
  4. import { Cell, DatePicker, Icon, Image, List, Popover, Popup } from 'vant'
  5. import { defineComponent, onMounted, reactive } from 'vue'
  6. import { useRoute } from 'vue-router'
  7. import styles from './plan.module.less'
  8. import iconTeacher from '@common/images/icon_teacher.png'
  9. export default defineComponent({
  10. name: 'plan',
  11. setup() {
  12. const route = useRoute()
  13. const state = reactive({
  14. timeShow: false,
  15. currentData: [dayjs().year() + ''],
  16. showPopover: false,
  17. actionText: '上学期',
  18. actionType: 'up',
  19. actionTerm: [
  20. { text: '上学期', color: 'var(--van-primary-color)', value: 'up' },
  21. { text: '下学期', value: 'down' }
  22. ],
  23. oPopover: false,
  24. check: [],
  25. checkboxRefs: [] as any,
  26. showQrcode: false,
  27. isLoading: false,
  28. list: [] as any,
  29. listState: {
  30. dataShow: true, // 判断是否有数据
  31. loading: false,
  32. finished: false
  33. },
  34. params: {
  35. startTime: dayjs().year() + '-03-01 00:00:00',
  36. endTime: dayjs().year() + '-09-01 00:00:00',
  37. page: 1,
  38. rows: 20
  39. }
  40. })
  41. // 选择学期
  42. const onSelect = (val: any) => {
  43. console.log(val)
  44. state.actionTerm.forEach((item: any) => {
  45. item.color = null
  46. })
  47. val.color = 'var(--van-primary-color)'
  48. state.actionText = val.text
  49. state.actionType = val.value
  50. if (val.value === 'up') {
  51. state.params.startTime = dayjs().year() + '-03-01 00:00:00'
  52. state.params.endTime = dayjs().year() + '-09-01 00:00:00'
  53. } else if (val.value === 'down') {
  54. console.log(dayjs().add(1, 'year'), 'dayjs().add(1, ')
  55. state.params.startTime = dayjs().year() + '-09-01 00:00:00'
  56. state.params.endTime = dayjs().add(1, 'year').year() + '-03-01 00:00:00'
  57. }
  58. onSearch()
  59. }
  60. const onConfirmDate = (date: any) => {
  61. state.currentData = date.selectedValues
  62. if (state.actionType == 'up') {
  63. state.params.startTime = date.selectedValues[0] + '-03-01 00:00:00'
  64. state.params.endTime = date.selectedValues[0] + '-09-01 00:00:00'
  65. } else if (state.actionType == 'down') {
  66. state.params.startTime = date.selectedValues[0] + '-09-01 00:00:00'
  67. state.params.endTime = Number(date.selectedValues[0]) + 1 + '-03-01 00:00:00'
  68. }
  69. state.timeShow = false
  70. onSearch()
  71. }
  72. // 班级列表
  73. const getList = async () => {
  74. try {
  75. if (state.isLoading) return
  76. state.isLoading = true
  77. const res = await request.post('/api-school/classGroup/page', {
  78. data: {
  79. ...state.params,
  80. orchestraId: route.query.id
  81. }
  82. })
  83. state.listState.loading = false
  84. const result = res.data || {}
  85. // 处理重复请求数据
  86. if (state.list.length > 0 && result.current === 1) {
  87. return
  88. }
  89. const rows = result.rows || []
  90. state.list = state.list.concat(rows)
  91. state.listState.finished = result.current >= result.pages
  92. state.params.page = result.current + 1
  93. state.listState.dataShow = state.list.length > 0
  94. state.isLoading = false
  95. } catch {
  96. state.listState.dataShow = false
  97. state.listState.finished = true
  98. state.isLoading = false
  99. }
  100. }
  101. const onSearch = () => {
  102. state.params.page = 1
  103. state.list = []
  104. state.listState.dataShow = true // 判断是否有数据
  105. state.listState.loading = false
  106. state.listState.finished = false
  107. getList()
  108. }
  109. onMounted(() => {
  110. getList()
  111. })
  112. return () => (
  113. <div>
  114. <div style={{ padding: '12px 13px 16px', background: '#F8F8F8' }}>
  115. <div class={styles.searchBand} onClick={() => (state.timeShow = true)}>
  116. {state.currentData[0]}年 <Icon name={state.showPopover ? 'arrow-up' : 'arrow-down'} />
  117. </div>
  118. <Popover
  119. v-model:show={state.oPopover}
  120. actions={state.actionTerm}
  121. showArrow={false}
  122. placement="bottom"
  123. offset={[0, 12]}
  124. style={{ zIndex: '9999' }}
  125. onSelect={onSelect}
  126. >
  127. {{
  128. reference: () => (
  129. <div class={styles.searchBand} style="margin-left: 16px">
  130. {state.actionText} <Icon name={state.oPopover ? 'arrow-up' : 'arrow-down'} />
  131. </div>
  132. )
  133. }}
  134. </Popover>
  135. </div>
  136. {state.listState.dataShow ? (
  137. <List
  138. v-model:loading={state.listState.loading}
  139. finished={state.listState.finished}
  140. finishedText=" "
  141. class={[styles.liveList]}
  142. onLoad={getList}
  143. immediateCheck={false}
  144. >
  145. {state.list.map((item: any) => (
  146. // <div class={[styles.gridContainer, styles.gridClass]}>
  147. // <div class={styles.className}>
  148. // <i class={styles.line}></i>
  149. // {item.name}
  150. // </div>
  151. // <Grid border={false} columnNum={3}>
  152. // <GridItem>
  153. // <p class={styles.title}>{item.preStudentNum || 0}</p>
  154. // <p class={styles.name}>在读学生</p>
  155. // </GridItem>
  156. // <GridItem>
  157. // <p class={[styles.title, styles.teacher]}>{item.teacherName || '/'}</p>
  158. // <p class={styles.name}>伴学指导</p>
  159. // </GridItem>
  160. // <GridItem>
  161. // <p class={styles.title}>
  162. // {item.completeCourseScheduleNum || 0}/{item.courseScheduleNum || 0}
  163. // </p>
  164. // <p class={styles.name}>课时</p>
  165. // </GridItem>
  166. // </Grid>
  167. // </div>
  168. <div class={[styles.gridContainer, styles.gridClass]}>
  169. <div class={styles.className}>
  170. <i class={styles.line}></i>
  171. {item.name}
  172. </div>
  173. <Cell center>
  174. {{
  175. icon: () => (
  176. <Image class={styles.img} src={item.teacherAvatar || iconTeacher} />
  177. ),
  178. title: () => (
  179. <>
  180. <p class={styles.class}>
  181. {item.completeCourseScheduleNum || 0}/{item.courseScheduleNum || 0}
  182. </p>
  183. <p class={styles.teacherDesc}>课时</p>
  184. </>
  185. ),
  186. value: () => (
  187. <>
  188. <p class={styles.courseware}>{item.newestLessonPlanDetailName || '/'}</p>
  189. <p class={styles.teacherDesc}>最新课件</p>
  190. </>
  191. )
  192. }}
  193. </Cell>
  194. </div>
  195. ))}
  196. </List>
  197. ) : (
  198. <OEmpty btnStatus={false} classImgSize="SMALL" tips="暂无班级" />
  199. )}
  200. <Popup v-model:show={state.timeShow} position="bottom" round>
  201. <DatePicker
  202. v-model={state.currentData}
  203. columnsType={['year']}
  204. minDate={new Date(2010, 0, 1)}
  205. maxDate={new Date(2055, 11, 31)}
  206. onConfirm={onConfirmDate}
  207. onCancel={() => (state.timeShow = false)}
  208. />
  209. </Popup>
  210. </div>
  211. )
  212. }
  213. })