testRecode.tsx 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. import { defineComponent, nextTick, onMounted, reactive, ref } from 'vue';
  2. import styles from '../index.module.less';
  3. import {
  4. NButton,
  5. NDataTable,
  6. NForm,
  7. NFormItem,
  8. NGi,
  9. NGrid,
  10. NImage,
  11. NModal,
  12. NNumberAnimation,
  13. NSelect,
  14. NSpace,
  15. NTooltip
  16. } from 'naive-ui';
  17. import SearchInput from '@/components/searchInput';
  18. import CSelect from '@/components/CSelect';
  19. import Pagination from '@/components/pagination';
  20. import add from './images/add.png';
  21. import {
  22. getNowDateAndMonday,
  23. getNowDateAndSunday,
  24. getTimes,
  25. getMinutes,
  26. getSecend,
  27. formateSeconds,
  28. getHours,
  29. getLastMinutes
  30. } from '/src/utils/dateFormat';
  31. import { getTestList, getTrainingStat } from '../api';
  32. import CDatePicker from '/src/components/CDatePicker';
  33. import { useRoute, useRouter } from 'vue-router';
  34. import TheEmpty from '/src/components/TheEmpty';
  35. import { initCache, setCache } from '/src/hooks/use-async';
  36. import iconSortDefault from '@/common/images/icon-sort-default.png';
  37. import iconSortDesc from '@/common/images/icon-sort-desc.png';
  38. import iconSortAsc from '@/common/images/icon-sort-asc.png';
  39. export default defineComponent({
  40. name: 'student-studentList',
  41. setup(props, { emit }) {
  42. const state = reactive({
  43. searchForm: {
  44. ase: 0,
  45. sortType: 1,
  46. keyword: '',
  47. trainingStatus: null as any,
  48. vipFlag: '' as any
  49. },
  50. searchWord: '',
  51. orchestraType: null,
  52. courseTypeCode: null,
  53. subjectId: null,
  54. classId: null,
  55. studentType: null,
  56. loading: false,
  57. pagination: {
  58. page: 1,
  59. rows: 10,
  60. pageTotal: 4
  61. },
  62. tableList: [] as any,
  63. memberNumber: 0,
  64. testInfo: {
  65. practiceDurationAvg: 0,
  66. vipUserCount: 0,
  67. practiceUserCount: 0
  68. },
  69. activeRow: null
  70. });
  71. const route = useRoute();
  72. const router = useRouter();
  73. const search = () => {
  74. state.pagination.page = 1;
  75. getInfo();
  76. getList();
  77. setCache({
  78. current: { ...state.searchForm, timer: timer.value },
  79. saveKey: 'classDetailTestRecord'
  80. });
  81. };
  82. const timer = ref<[number, number]>([
  83. getNowDateAndMonday(new Date().getTime()),
  84. getNowDateAndSunday(new Date().getTime())
  85. ]);
  86. const onReset = () => {
  87. timer.value = [
  88. getNowDateAndMonday(new Date().getTime()),
  89. getNowDateAndSunday(new Date().getTime())
  90. ];
  91. state.searchForm = {
  92. ase: 0,
  93. sortType: 1,
  94. keyword: '',
  95. trainingStatus: null as any,
  96. vipFlag: ''
  97. };
  98. search();
  99. setCache({
  100. current: { ...state.searchForm, timer: timer.value },
  101. saveKey: 'classDetailTestRecord'
  102. });
  103. };
  104. initCache({
  105. current: { ...state.searchForm, timer: timer.value },
  106. saveKey: 'classDetailTestRecord',
  107. callBack: (active: any) => {
  108. state.searchForm = active;
  109. timer.value = active.timer;
  110. }
  111. });
  112. const getList = async () => {
  113. state.loading = true;
  114. try {
  115. const res = await getTestList({
  116. classGroupId: route.query.id,
  117. ...state.searchForm,
  118. ...state.pagination,
  119. ...getTimes(timer.value, ['startTime', 'endTime'], 'YYYY-MM-DD')
  120. });
  121. state.tableList = res.data.rows;
  122. state.pagination.pageTotal = res.data.total;
  123. state.loading = false;
  124. } catch (e) {
  125. state.loading = false;
  126. console.log(e);
  127. }
  128. };
  129. const getInfo = async () => {
  130. try {
  131. const res = await getTrainingStat({
  132. classGroupId: route.query.id,
  133. ...getTimes(timer.value, ['startTime', 'endTime'], 'YYYY-MM-DD')
  134. });
  135. state.testInfo.practiceDurationAvg = res.data.practiceDurationAvg;
  136. state.testInfo.practiceUserCount = res.data.practiceUserCount;
  137. state.testInfo.vipUserCount = res.data.vipUserCount;
  138. } catch (e) {
  139. console.log(e);
  140. }
  141. };
  142. onMounted(() => {
  143. getInfo();
  144. getList();
  145. // nextTick(() => {
  146. // // 把默认的排序删除
  147. // const dom = document.querySelectorAll('.n-data-table-sorter');
  148. // dom.forEach((item: any) => {
  149. // item.style.display = 'none';
  150. // });
  151. // });
  152. });
  153. const gotoStudentDetail = (row: any) => {
  154. router.push({
  155. path: '/classStudentRecode',
  156. query: {
  157. ...route.query,
  158. studentId: row.studentId,
  159. studentName: row.studentName
  160. }
  161. });
  162. };
  163. const practiceDaysRef = reactive({
  164. title() {
  165. return (
  166. <NTooltip showArrow={false} placement="top-start">
  167. {{
  168. trigger: () => (
  169. <div class={styles.cell}>
  170. 练习天数
  171. <img
  172. class={styles.sortIcon}
  173. src={
  174. practiceDaysRef.sortOrder === 'descend'
  175. ? iconSortDesc
  176. : practiceDaysRef.sortOrder === 'ascend'
  177. ? iconSortAsc
  178. : iconSortDefault
  179. }
  180. />
  181. </div>
  182. ),
  183. default:
  184. practiceDaysRef.sortOrder === 'descend'
  185. ? '点击升序'
  186. : practiceDaysRef.sortOrder === 'ascend'
  187. ? '取消排序'
  188. : '点击降序'
  189. }}
  190. </NTooltip>
  191. );
  192. },
  193. key: 'practiceDays',
  194. sorter: true,
  195. sortOrder: false as any,
  196. render(row: any) {
  197. return <>{row.practiceDays ? row.practiceDays : 0}天</>;
  198. }
  199. });
  200. const practiceDurationRef = reactive({
  201. title() {
  202. return (
  203. <NTooltip showArrow={false} placement="top-start">
  204. {{
  205. trigger: () => (
  206. <div class={styles.cell}>
  207. 学练时长
  208. <img
  209. class={styles.sortIcon}
  210. src={
  211. practiceDurationRef.sortOrder === 'descend'
  212. ? iconSortDesc
  213. : practiceDurationRef.sortOrder === 'ascend'
  214. ? iconSortAsc
  215. : iconSortDefault
  216. }
  217. />
  218. </div>
  219. ),
  220. default:
  221. practiceDurationRef.sortOrder === 'descend'
  222. ? '点击升序'
  223. : practiceDurationRef.sortOrder === 'ascend'
  224. ? '取消排序'
  225. : '点击降序'
  226. }}
  227. </NTooltip>
  228. );
  229. },
  230. key: 'practiceDuration',
  231. sorter: true,
  232. sortOrder: false as any,
  233. render(row: any) {
  234. return (
  235. <>
  236. {row.practiceDuration
  237. ? formateSeconds(row.practiceDuration, 1)
  238. : 0 + '秒'}
  239. </>
  240. );
  241. }
  242. });
  243. const columns = () => {
  244. return [
  245. {
  246. title: '学生姓名',
  247. key: 'studentName'
  248. },
  249. {
  250. title: '手机号',
  251. key: 'studentPhone'
  252. },
  253. {
  254. title: '性别',
  255. key: 'sex',
  256. render(row: any) {
  257. return (
  258. <>
  259. {row.gender + '' != 'null'
  260. ? row.gender == '0'
  261. ? '女'
  262. : '男'
  263. : '--'}
  264. </>
  265. );
  266. }
  267. },
  268. {
  269. title: '学生类型',
  270. key: 'studentType',
  271. render(row: any) {
  272. return <>{row.vipFlag ? '会员' : '普通'}</>;
  273. }
  274. },
  275. practiceDaysRef,
  276. practiceDurationRef,
  277. // {
  278. // title: '练习天数',
  279. // key: 'practiceDays',
  280. // render(row: any) {
  281. // return <>{row.practiceDays ? row.practiceDays : 0}天</>;
  282. // }
  283. // },
  284. // {
  285. // title: '学练时长',
  286. // key: 'studentType',
  287. // render(row: any) {
  288. // return (
  289. // <>
  290. // {row.practiceDuration
  291. // ? getMinutes(row.practiceDuration) > 0
  292. // ? getMinutes(row.practiceDuration) +
  293. // '分' +
  294. // getSecend(row.practiceDuration) +
  295. // '秒'
  296. // : getSecend(row.practiceDuration) + '秒'
  297. // : 0 + '秒'}
  298. // </>
  299. // );
  300. // }
  301. // },
  302. {
  303. title: '操作',
  304. key: 'id',
  305. render(row: any) {
  306. return (
  307. <NButton
  308. text
  309. type="primary"
  310. onClick={() => {
  311. gotoStudentDetail(row);
  312. }}>
  313. 详情
  314. </NButton>
  315. );
  316. }
  317. }
  318. ];
  319. };
  320. const handleSorterChange = (sroter: any) => {
  321. if (!sroter) {
  322. state.searchForm.ase = 0;
  323. state.searchForm.sortType = 1;
  324. practiceDaysRef.sortOrder = false;
  325. practiceDurationRef.sortOrder = false;
  326. } else {
  327. const list = {
  328. practiceDuration: 1,
  329. practiceDays: 2
  330. };
  331. state.searchForm.sortType =
  332. list[sroter.columnKey as 'practiceDuration' | 'practiceDays'];
  333. if (sroter.columnKey == 'practiceDuration') {
  334. practiceDurationRef.sortOrder = sroter.order;
  335. practiceDaysRef.sortOrder = false;
  336. }
  337. if (sroter.columnKey == 'practiceDays') {
  338. practiceDaysRef.sortOrder = sroter.order;
  339. practiceDurationRef.sortOrder = false;
  340. }
  341. state.searchForm.ase = sroter.order == 'ascend' ? 1 : 0;
  342. }
  343. getList();
  344. };
  345. return () => (
  346. <div>
  347. <div class={styles.searchList}>
  348. <NForm label-placement="left" inline>
  349. <NFormItem>
  350. <SearchInput
  351. {...{ placeholder: '请输入学生姓名' }}
  352. class={styles.searchInput}
  353. searchWord={state.searchForm.keyword}
  354. onChangeValue={(val: string) =>
  355. (state.searchForm.keyword = val)
  356. }></SearchInput>
  357. </NFormItem>
  358. <NFormItem>
  359. <CSelect
  360. {...({
  361. options: [
  362. {
  363. label: '全部类型',
  364. value: ''
  365. },
  366. {
  367. label: '会员',
  368. value: true
  369. },
  370. {
  371. label: '普通',
  372. value: false
  373. }
  374. ],
  375. placeholder: '学生类型',
  376. clearable: true,
  377. inline: true
  378. } as any)}
  379. v-model:value={state.searchForm.vipFlag}></CSelect>
  380. </NFormItem>
  381. <NFormItem>
  382. <CDatePicker
  383. v-model:value={timer.value}
  384. separator={'至'}
  385. type="daterange"
  386. timerValue={timer.value}></CDatePicker>
  387. </NFormItem>
  388. <NFormItem>
  389. <NSpace justify="end">
  390. <NButton type="primary" class="searchBtn" onClick={search}>
  391. 搜索
  392. </NButton>
  393. <NButton
  394. type="primary"
  395. ghost
  396. class="resetBtn"
  397. onClick={onReset}>
  398. 重置
  399. </NButton>
  400. </NSpace>
  401. </NFormItem>
  402. </NForm>
  403. </div>
  404. <div class={['section-container']}>
  405. <NGrid x-gap="12" cols={8}>
  406. <NGi>
  407. <div class={styles.TrainDataItem}>
  408. <div>
  409. <p class={styles.TrainDataItemTitle}>
  410. <div>
  411. <span>
  412. <NNumberAnimation
  413. from={0}
  414. to={
  415. state.testInfo.practiceUserCount
  416. }></NNumberAnimation>
  417. </span>{' '}
  418. </div>
  419. </p>
  420. </div>
  421. <p class={styles.TrainDataItemsubTitle}>练习人数</p>
  422. </div>
  423. </NGi>
  424. <NGi>
  425. <div class={styles.TrainDataItem}>
  426. <p class={styles.TrainDataItemTitle}>
  427. <div>
  428. <span>
  429. <NNumberAnimation
  430. from={0}
  431. to={state.testInfo.vipUserCount}></NNumberAnimation>
  432. </span>{' '}
  433. </div>
  434. </p>
  435. <p class={styles.TrainDataItemsubTitle}>会员人数</p>
  436. </div>
  437. </NGi>
  438. <NGi>
  439. <div class={styles.TrainDataItem}>
  440. <p class={styles.TrainDataItemTitle}>
  441. {getHours(state.testInfo.practiceDurationAvg) > 0 ? (
  442. <div>
  443. <span>
  444. <NNumberAnimation
  445. from={0}
  446. to={getHours(
  447. state.testInfo.practiceDurationAvg
  448. )}></NNumberAnimation>
  449. </span>
  450. <i style={{ width: '4px', display: 'inline-block' }}></i>
  451. <i style={{ width: '4px', display: 'inline-block' }}></i>
  452. </div>
  453. ) : null}
  454. {getHours(state.testInfo.practiceDurationAvg) > 0 || getLastMinutes(state.testInfo.practiceDurationAvg) > 0 ? (
  455. <div>
  456. <span>
  457. <NNumberAnimation
  458. from={0}
  459. to={getLastMinutes(
  460. state.testInfo.practiceDurationAvg
  461. )}></NNumberAnimation>
  462. </span>{' '}
  463. </div>
  464. ) : null}
  465. <div>
  466. <span>
  467. <NNumberAnimation
  468. from={0}
  469. to={getSecend(
  470. state.testInfo.practiceDurationAvg
  471. )}></NNumberAnimation>
  472. </span>{' '}
  473. </div>
  474. </p>
  475. <p class={styles.TrainDataItemsubTitle}>平均每天练习时长</p>
  476. </div>
  477. </NGi>
  478. </NGrid>
  479. </div>
  480. <div class={[styles.tableWrap, styles.noSort]}>
  481. <NDataTable
  482. v-slots={{
  483. empty: () => <TheEmpty></TheEmpty>
  484. }}
  485. class={styles.classTable}
  486. loading={state.loading}
  487. columns={columns()}
  488. data={state.tableList}
  489. onUpdate:sorter={handleSorterChange}></NDataTable>
  490. <Pagination
  491. v-model:page={state.pagination.page}
  492. v-model:pageSize={state.pagination.rows}
  493. v-model:pageTotal={state.pagination.pageTotal}
  494. onList={getList}
  495. sync
  496. />
  497. </div>
  498. </div>
  499. );
  500. }
  501. });