information.tsx 10 KB

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