information.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. import OSticky from '@/components/o-sticky'
  2. import { Button, DatePicker, Grid, GridItem, Icon, Image, List, Picker, Popover, Popup } from 'vant'
  3. import { defineComponent, nextTick, onMounted, reactive } from 'vue'
  4. import styles from './information.module.less'
  5. import iconSaveImage from '../images/icon-save-image.png'
  6. import iconWechat from '../images/icon-wechat.png'
  7. import OQrcode from '@/components/o-qrcode'
  8. import request from '@/helpers/request'
  9. import { useRoute } from 'vue-router'
  10. import { CountUp } from 'countup.js'
  11. import OEmpty from '@/components/o-empty'
  12. import dayjs from 'dayjs'
  13. export default defineComponent({
  14. name: 'detail-information',
  15. setup() {
  16. const route = useRoute()
  17. const state = reactive({
  18. timeShow: false,
  19. currentData: [dayjs().year() + ''],
  20. actionText: '上学期',
  21. actionType: 'up',
  22. actionTerm: [
  23. { text: '上学期', color: 'var(--van-primary-color)', value: 'up' },
  24. { text: '下学期', value: 'down' }
  25. ],
  26. oPopover: false,
  27. check: [],
  28. checkboxRefs: [] as any,
  29. showQrcode: false,
  30. qrcodeUrl: '',
  31. isLoading: false,
  32. list: [] as any,
  33. listState: {
  34. dataShow: true, // 判断是否有数据
  35. loading: false,
  36. finished: false
  37. },
  38. params: {
  39. startTime: dayjs().year() - 1 + '-09-01 00:00:00',
  40. endTime: dayjs(dayjs().year() + '-03-01 00:00:00')
  41. .subtract(1, 'day')
  42. .format('YYYY-MM-DD HH:mm:ss'),
  43. page: 1,
  44. rows: 20
  45. },
  46. orchestraInfo: {} as any // 乐团详情
  47. })
  48. // 选择学期
  49. const onSelect = (val: any) => {
  50. console.log(val)
  51. state.actionTerm.forEach((item: any) => {
  52. item.color = null
  53. })
  54. val.color = 'var(--van-primary-color)'
  55. state.actionText = val.text
  56. state.actionType = val.value
  57. if (val.value === 'up') {
  58. state.params.startTime = Number(state.currentData[0]) - 1 + '-09-01 00:00:00'
  59. state.params.endTime = dayjs(state.currentData[0] + '-03-01 00:00:00')
  60. .subtract(1, 'day')
  61. .format('YYYY-MM-DD HH:mm:ss')
  62. } else if (val.value === 'down') {
  63. console.log(dayjs().add(1, 'year'), 'dayjs().add(1, ')
  64. state.params.startTime = dayjs(state.currentData[0] + '-03-01 00:00:00')
  65. .subtract(1, 'day')
  66. .format('YYYY-MM-DD HH:mm:ss')
  67. state.params.endTime = Number(state.currentData[0]) + '-09-01 00:00:00'
  68. }
  69. onSearch()
  70. }
  71. const onConfirmDate = (date: any) => {
  72. state.currentData = date.selectedValues
  73. if (state.actionType == 'up') {
  74. state.params.startTime = Number(date.selectedValues[0]) - 1 + '-09-01 00:00:00'
  75. state.params.endTime = dayjs(date.selectedValues[0] + '-03-01 00:00:00')
  76. .subtract(1, 'day')
  77. .format('YYYY-MM-DD HH:mm:ss')
  78. } else if (state.actionType == 'down') {
  79. state.params.startTime = dayjs(date.selectedValues[0] + '-03-01 00:00:00')
  80. .subtract(1, 'day')
  81. .format('YYYY-MM-DD HH:mm:ss')
  82. state.params.endTime = Number(date.selectedValues[0]) + '-09-01 00:00:00'
  83. }
  84. state.timeShow = false
  85. onSearch()
  86. }
  87. const getDetails = async () => {
  88. try {
  89. const { data } = await request.get('/api-school/orchestra/detail/' + route.query.id)
  90. state.orchestraInfo = data || {}
  91. } catch {
  92. //
  93. }
  94. }
  95. // 班级列表
  96. const getList = async () => {
  97. try {
  98. if (state.isLoading) return
  99. state.isLoading = true
  100. const res = await request.post('/api-school/classGroup/page', {
  101. data: {
  102. ...state.params,
  103. orchestraId: route.query.id
  104. }
  105. })
  106. state.listState.loading = false
  107. const result = res.data || {}
  108. // 处理重复请求数据
  109. if (state.list.length > 0 && result.current === 1) {
  110. return
  111. }
  112. const rows = result.rows || []
  113. state.list = state.list.concat(rows)
  114. state.listState.finished = result.current >= result.pages
  115. state.params.page = result.current + 1
  116. state.listState.dataShow = state.list.length > 0
  117. state.isLoading = false
  118. } catch {
  119. state.listState.dataShow = false
  120. state.listState.finished = true
  121. state.isLoading = false
  122. }
  123. }
  124. const onSearch = () => {
  125. state.params.page = 1
  126. state.list = []
  127. state.listState.dataShow = true // 判断是否有数据
  128. state.listState.loading = false
  129. state.listState.finished = false
  130. getList()
  131. }
  132. const initNumCountUp = () => {
  133. nextTick(() => {
  134. // 在读学生
  135. new CountUp('currentStudentNum', Math.random() * 1000).start()
  136. new CountUp('time1', Math.random() * 100).start()
  137. new CountUp('time2', Math.random() * 100).start()
  138. new CountUp('time3', Math.random() * 100).start()
  139. })
  140. }
  141. onMounted(() => {
  142. getDetails()
  143. getList()
  144. initNumCountUp()
  145. })
  146. return () => (
  147. <>
  148. <div style={{ padding: '12px 13px 16px', background: '#F8F8F8' }}>
  149. <div class={styles.searchBand} onClick={() => (state.timeShow = true)}>
  150. {state.currentData[0]}年 <Icon name={state.timeShow ? 'arrow-up' : 'arrow-down'} />
  151. </div>
  152. <Popover
  153. v-model:show={state.oPopover}
  154. actions={state.actionTerm}
  155. showArrow={false}
  156. placement="bottom"
  157. offset={[0, 12]}
  158. style={{ zIndex: '9999' }}
  159. onSelect={onSelect}
  160. >
  161. {{
  162. reference: () => (
  163. <div class={styles.searchBand} style="margin-left: 16px">
  164. {state.actionText} <Icon name={state.oPopover ? 'arrow-up' : 'arrow-down'} />
  165. </div>
  166. )
  167. }}
  168. </Popover>
  169. </div>
  170. <Grid border={false} class={styles.gridContainer}>
  171. <GridItem>
  172. <p class={[styles.title, styles.red]}>
  173. <span id="currentStudentNum">0</span>
  174. <i>名</i>
  175. </p>
  176. <p class={styles.name}>在读学生</p>
  177. </GridItem>
  178. <GridItem>
  179. <p class={[styles.title, styles.red]}>
  180. <span id="time1">0</span>%
  181. </p>
  182. <p class={styles.name}>到课率</p>
  183. </GridItem>
  184. <GridItem>
  185. <p class={[styles.title, styles.red]}>
  186. <span id="time2">0</span>%
  187. </p>
  188. <p class={styles.name}>作业提交率</p>
  189. </GridItem>
  190. <GridItem>
  191. <p class={[styles.title, styles.red]}>
  192. <span id="time3">0</span>%
  193. </p>
  194. <p class={styles.name}>练习合格率</p>
  195. </GridItem>
  196. </Grid>
  197. {state.listState.dataShow ? (
  198. <List
  199. v-model:loading={state.listState.loading}
  200. finished={state.listState.finished}
  201. finishedText=" "
  202. class={[styles.liveList]}
  203. onLoad={getList}
  204. immediateCheck={false}
  205. >
  206. {state.list.map((item: any) => (
  207. <div class={[styles.gridContainer, styles.gridClass]}>
  208. <div class={styles.className}>
  209. <i class={styles.line}></i>
  210. {item.name}
  211. </div>
  212. <Grid border={false} columnNum={3}>
  213. <GridItem>
  214. <p class={styles.title}>{item.preStudentNum || 0}</p>
  215. <p class={styles.name}>在读学生</p>
  216. </GridItem>
  217. <GridItem>
  218. <p class={[styles.title, styles.teacher, 'van-ellipsis']}>
  219. {item.teacherName || '-'}
  220. </p>
  221. <p class={styles.name}>伴学指导</p>
  222. </GridItem>
  223. <GridItem>
  224. <p class={styles.title}>
  225. {item.completeCourseScheduleNum || 0}/{item.courseScheduleNum || 0}
  226. </p>
  227. <p class={styles.name}>课时</p>
  228. </GridItem>
  229. </Grid>
  230. </div>
  231. ))}
  232. </List>
  233. ) : (
  234. <OEmpty btnStatus={false} classImgSize="SMALL" tips="暂无班级" />
  235. )}
  236. {/* */}
  237. {state.orchestraInfo.type === 'DELIVERY' &&
  238. ['REGISTER', 'DOING', 'DONE'].includes(state.orchestraInfo.status) && (
  239. <OSticky position="bottom">
  240. <div class={'btnGroup'}>
  241. <Button
  242. round
  243. block
  244. type="primary"
  245. onClick={() => {
  246. state.showQrcode = true
  247. state.qrcodeUrl =
  248. window.location.origin + '/orchestra-student/#/preApply?id=' + route.query.id
  249. }}
  250. >
  251. 报名二维码
  252. </Button>
  253. </div>
  254. </OSticky>
  255. )}
  256. <Popup
  257. v-model:show={state.showQrcode}
  258. position="bottom"
  259. style={{ background: 'transparent' }}
  260. safeAreaInsetBottom={true}
  261. >
  262. <div class={styles.codeContainer}>
  263. <div class={styles.codeImg}>
  264. <div class={styles.codeContent}>
  265. <h2 class={styles.codeTitle}>乐团报名</h2>
  266. <div class={[styles.codeName, 'van-ellipsis']}>{state.orchestraInfo.name}</div>
  267. <div class={styles.codeQr}>
  268. <OQrcode text={state.qrcodeUrl} size={'400'} />
  269. </div>
  270. <div style={{ textAlign: 'center' }}>
  271. <span class={styles.codeBtnText}>扫描上方二维码完成资料填写</span>
  272. </div>
  273. <div class={styles.codeTips}>二维码将在两小时后失效,请及时登记</div>
  274. </div>
  275. </div>
  276. <div class={styles.codeBottom}>
  277. <Icon
  278. name="cross"
  279. size={22}
  280. class={styles.close}
  281. color="#666"
  282. onClick={() => (state.showQrcode = false)}
  283. />
  284. <h3 class={styles.title}>
  285. <i></i>分享方式
  286. </h3>
  287. <Grid columnNum={2} border={false}>
  288. <GridItem>
  289. {{
  290. icon: () => <Image class={styles.shareImg} src={iconSaveImage} />,
  291. text: () => <div class={styles.shareText}>保存图片</div>
  292. }}
  293. </GridItem>
  294. <GridItem>
  295. {{
  296. icon: () => <Image class={styles.shareImg} src={iconWechat} />,
  297. text: () => <div class={styles.shareText}>微信</div>
  298. }}
  299. </GridItem>
  300. </Grid>
  301. </div>
  302. </div>
  303. </Popup>
  304. <Popup v-model:show={state.timeShow} position="bottom" round>
  305. <DatePicker
  306. v-model={state.currentData}
  307. columnsType={['year']}
  308. onConfirm={onConfirmDate}
  309. onCancel={() => (state.timeShow = false)}
  310. />
  311. </Popup>
  312. </>
  313. )
  314. }
  315. })