index.tsx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. import { computed, defineComponent, onMounted, reactive, ref } from 'vue';
  2. import styles from './index.module.less';
  3. import {
  4. NButton,
  5. NDataTable,
  6. NForm,
  7. NFormItem,
  8. NImage,
  9. NModal,
  10. NProgress,
  11. NSpace
  12. } from 'naive-ui';
  13. import SearchInput from '@/components/searchInput';
  14. import CSelect from '@/components/CSelect';
  15. import Pagination from '@/components/pagination';
  16. import { api_trainingDetail, api_trainingStudentList } from '../api';
  17. import { useRoute } from 'vue-router';
  18. import CBreadcrumb from '/src/components/CBreadcrumb';
  19. import defultHeade from '@/components/layout/images/teacherIcon.png';
  20. import { trainingStatusArray } from '@/utils/searchArray';
  21. import dayjs from 'dayjs';
  22. import TheEmpty from '/src/components/TheEmpty';
  23. import TrainingDetails from '../../classList/modals/TrainingDetails';
  24. export default defineComponent({
  25. name: 'homewrok-record-detail',
  26. setup() {
  27. const route = useRoute();
  28. const state = reactive({
  29. searchForm: {
  30. keyword: '',
  31. trainingStatus: '' as any,
  32. classGroupId: '' as any
  33. },
  34. loading: false,
  35. pagination: {
  36. page: 1,
  37. rows: 10,
  38. pageTotal: 4
  39. },
  40. studentClassList: [] as any,
  41. tableList: [] as any,
  42. workInfo: {} as any,
  43. detailVisiable: false,
  44. activeRow: null as any,
  45. index: 0
  46. });
  47. const TrainingDetailsRef = ref();
  48. const routerList = ref([
  49. { name: '作业', path: '/homework-record' },
  50. { name: route.query.name, path: '/homework-record-detail' }
  51. ] as any);
  52. const search = () => {
  53. state.pagination.page = 1;
  54. getList();
  55. };
  56. const onReset = () => {
  57. state.searchForm = {
  58. keyword: '',
  59. trainingStatus: '' as any,
  60. classGroupId: '' as any
  61. };
  62. search();
  63. };
  64. const getList = async (type?: string, page?: number) => {
  65. state.loading = true;
  66. try {
  67. const res = await api_trainingStudentList({
  68. trainingId: route.query.id,
  69. ...state.searchForm,
  70. ...state.pagination,
  71. page: page || state.pagination.page
  72. });
  73. state.tableList = res.data.rows;
  74. state.pagination.pageTotal = res.data.total;
  75. state.pagination.page = res.data.current;
  76. state.loading = false;
  77. if (type === 'next') {
  78. state.index = 0;
  79. goToNext();
  80. } else if (type === 'prev') {
  81. state.index = state.tableList.length + 1;
  82. gotoPre();
  83. }
  84. } catch (e) {
  85. state.loading = false;
  86. console.log(e);
  87. }
  88. };
  89. const getWorkInfo = async () => {
  90. try {
  91. const res = await api_trainingDetail({ id: route.query.id });
  92. const result = res.data || {};
  93. // state.workInfo
  94. let pTitle = '';
  95. let eTitle = '';
  96. if (
  97. result.studentLessonTrainingDetails &&
  98. result.studentLessonTrainingDetails.length > 0
  99. ) {
  100. result.studentLessonTrainingDetails.forEach((child: any) => {
  101. // if (child.trainingType === 'PRACTICE' && child.musicName) {
  102. // pTitle += pTitle ? '、' + child.musicName : child.musicName;
  103. // }
  104. // if (child.trainingType === 'EVALUATION' && child.musicName) {
  105. // eTitle += eTitle ? '、' + child.musicName : child.musicName;
  106. // }
  107. if (child.trainingType === 'PRACTICE' && child.musicName) {
  108. pTitle += pTitle
  109. ? '、《' + child.musicName + '》'
  110. : '练习曲目《' + child.musicName + '》';
  111. }
  112. if (child.trainingType === 'EVALUATION' && child.musicName) {
  113. eTitle += eTitle
  114. ? '、《' + child.musicName + '》'
  115. : '评测曲目《' + child.musicName + '》';
  116. }
  117. });
  118. }
  119. result.pTitle = pTitle;
  120. result.eTitle = eTitle;
  121. state.workInfo = result;
  122. // 班级列表
  123. const classList = result.studentClassGroup || [];
  124. classList.forEach((item: any) => {
  125. state.studentClassList.push({
  126. label: item.name,
  127. value: item.id
  128. });
  129. });
  130. } catch (e) {
  131. console.log(e);
  132. }
  133. };
  134. const lookDetail = (row: any, index: number) => {
  135. console.log(index, 'index');
  136. state.index = index + 1;
  137. state.activeRow = row;
  138. state.detailVisiable = true;
  139. };
  140. onMounted(() => {
  141. getWorkInfo();
  142. getList();
  143. });
  144. const columns = () => {
  145. return [
  146. {
  147. title: '学生姓名',
  148. key: 'studentName'
  149. },
  150. {
  151. title: '最后提交时间',
  152. key: 'submitTime',
  153. render(row: any) {
  154. return row.submitTime
  155. ? dayjs(row.submitTime).format('YYYY-MM-DD')
  156. : '--';
  157. }
  158. },
  159. {
  160. title: '所属班级',
  161. key: 'classGroupName'
  162. },
  163. {
  164. title: '作业状态',
  165. key: 'sex',
  166. render(row: any) {
  167. return (
  168. <div>
  169. {row.trainingStatus == 'UNSUBMITTED' ? (
  170. <p class={styles.nosub}>未提交</p>
  171. ) : null}
  172. {row.trainingStatus == 'SUBMITTED' ? (
  173. <p class={styles.ison}>不合格</p>
  174. ) : null}
  175. {row.trainingStatus == 'TARGET' ? (
  176. <p class={styles.isok}>合格</p>
  177. ) : null}
  178. </div>
  179. );
  180. }
  181. },
  182. {
  183. title: '操作',
  184. key: 'id',
  185. render(row: any, index: number) {
  186. return (
  187. <NButton
  188. text
  189. type="primary"
  190. onClick={() => {
  191. lookDetail(row, index);
  192. }}>
  193. 详情
  194. </NButton>
  195. );
  196. }
  197. }
  198. ];
  199. };
  200. const goToNext = () => {
  201. if (state.index >= state.tableList.length) {
  202. getList('next', state.pagination.page + 1);
  203. } else {
  204. ++state.index;
  205. state.activeRow = state.tableList[state.index - 1];
  206. TrainingDetailsRef.value.getTrainingDetail(
  207. state.activeRow.studentLessonTrainingId
  208. );
  209. }
  210. };
  211. const gotoPre = () => {
  212. if (state.index === 1 && state.pagination.page !== 1) {
  213. getList('prev', state.pagination.page - 1);
  214. } else {
  215. --state.index;
  216. state.activeRow = state.tableList[state.index - 1];
  217. TrainingDetailsRef.value.getTrainingDetail(
  218. state.activeRow.studentLessonTrainingId
  219. );
  220. }
  221. };
  222. const currentStudentIndex = computed(() => {
  223. return state.index + (state.pagination.page - 1) * state.pagination.rows;
  224. });
  225. return () => (
  226. <div>
  227. <CBreadcrumb list={routerList.value}></CBreadcrumb>
  228. <div class={styles.listWrap}>
  229. <div class={styles.teacherSection}>
  230. <div class={styles.teacherList}>
  231. <div class={styles.tTemp}>
  232. <div class={styles.teacherHeader}>
  233. <div class={styles.teacherHeaderBorder}>
  234. <NImage
  235. class={styles.teacherHeaderImg}
  236. src={state.workInfo.teacherAvatar || defultHeade}
  237. previewDisabled></NImage>
  238. </div>
  239. </div>
  240. <div class={styles.workafterInfo}>
  241. <h4>{state.workInfo.teacherName}</h4>
  242. {state.workInfo.createTime && (
  243. <p>
  244. 布置时间:
  245. {state.workInfo.createTime &&
  246. dayjs(state.workInfo.createTime).format(
  247. 'YYYY-MM-DD HH:mm'
  248. )}{' '}
  249. |{' '}
  250. <span>
  251. 截止时间:
  252. {state.workInfo.expireDate &&
  253. dayjs(state.workInfo.expireDate).format(
  254. 'YYYY-MM-DD HH:mm'
  255. )}
  256. </span>
  257. </p>
  258. )}
  259. </div>
  260. </div>
  261. <div class={styles.infos}>
  262. <div class={styles.homeTitle}>{state.workInfo.name}</div>
  263. <div class={[styles.homeContent, styles.homeworkText]}>
  264. <div class={styles.pSection}>
  265. {state.workInfo.pTitle && (
  266. <p class={[styles.text, styles.p1]}>
  267. {state.workInfo.pTitle}
  268. </p>
  269. )}
  270. {state.workInfo.eTitle && (
  271. <p class={[styles.text, styles.p2]}>
  272. {state.workInfo.eTitle}
  273. </p>
  274. )}
  275. </div>
  276. </div>
  277. </div>
  278. </div>
  279. <div>
  280. <div class={styles.stitcTitle}>作业完成情况</div>
  281. <div class={styles.stitcConent}>
  282. <NSpace size={[38, 0]}>
  283. <NProgress
  284. percentage={state.workInfo.trainingRate || 0}
  285. // percentage={20}
  286. offset-degree={180}
  287. type="circle"
  288. strokeWidth={6}
  289. rail-color={'EDEFFA'}
  290. color={'#64A5FF'}>
  291. <div class={styles.contentRect}>
  292. <div class={styles.nums}>
  293. {state.workInfo.trainingNum || 0}
  294. <i>/</i>
  295. {state.workInfo.expectNum || 0}
  296. <span>人</span>
  297. </div>
  298. <div class={styles.text}>已提交</div>
  299. </div>
  300. </NProgress>
  301. <NProgress
  302. percentage={state.workInfo.trainingRate || 0}
  303. offset-degree={180}
  304. strokeWidth={6}
  305. type="circle"
  306. rail-color={'EDEFFA'}
  307. color={'#64A5FF'}>
  308. <div class={styles.contentRect}>
  309. <div class={styles.nums}>
  310. {state.workInfo.trainingRate || 0}%
  311. </div>
  312. <div class={styles.text}>提交率</div>
  313. </div>
  314. </NProgress>
  315. <NProgress
  316. percentage={state.workInfo.qualifiedRate || 0}
  317. offset-degree={180}
  318. strokeWidth={6}
  319. type="circle"
  320. rail-color={'EDEFFA'}
  321. color={'#40CEAE'}>
  322. <div class={styles.contentRect}>
  323. <div class={styles.nums}>
  324. {state.workInfo.standardNum || 0}
  325. <span>人</span>
  326. </div>
  327. <div class={styles.text}>合格人数</div>
  328. </div>
  329. </NProgress>
  330. <NProgress
  331. percentage={state.workInfo.qualifiedRate || 0}
  332. offset-degree={180}
  333. strokeWidth={6}
  334. type="circle"
  335. rail-color={'EDEFFA'}
  336. color={'#40CEAE'}>
  337. <div class={styles.contentRect}>
  338. <div class={styles.nums}>
  339. {state.workInfo.qualifiedRate || 0}%
  340. </div>
  341. <div class={styles.text}>合格率</div>
  342. </div>
  343. </NProgress>
  344. </NSpace>
  345. </div>
  346. </div>
  347. </div>
  348. <div class={styles.searchList}>
  349. <NForm label-placement="left" inline>
  350. <NFormItem>
  351. <SearchInput
  352. {...{ placeholder: '请输入学生姓名' }}
  353. class={styles.searchInput}
  354. searchWord={state.searchForm.keyword}
  355. onChangeValue={(val: string) =>
  356. (state.searchForm.keyword = val)
  357. }></SearchInput>
  358. </NFormItem>
  359. <NFormItem>
  360. <CSelect
  361. {...({
  362. options: [
  363. {
  364. label: '全部班级',
  365. value: ''
  366. },
  367. ...state.studentClassList
  368. ],
  369. placeholder: '全部班级',
  370. clearable: true,
  371. inline: true
  372. } as any)}
  373. v-model:value={state.searchForm.classGroupId}></CSelect>
  374. </NFormItem>
  375. <NFormItem>
  376. <CSelect
  377. {...({
  378. options: [
  379. {
  380. label: '全部状态',
  381. value: ''
  382. },
  383. ...trainingStatusArray
  384. ],
  385. placeholder: '作业状态',
  386. clearable: true,
  387. inline: true
  388. } as any)}
  389. v-model:value={state.searchForm.trainingStatus}></CSelect>
  390. </NFormItem>
  391. <NFormItem>
  392. <NSpace justify="end">
  393. <NButton type="primary" class="searchBtn" onClick={search}>
  394. 搜索
  395. </NButton>
  396. <NButton
  397. type="primary"
  398. ghost
  399. class="resetBtn"
  400. onClick={onReset}>
  401. 重置
  402. </NButton>
  403. </NSpace>
  404. </NFormItem>
  405. </NForm>
  406. </div>
  407. <div class={styles.tableWrap}>
  408. <NDataTable
  409. v-slots={{
  410. empty: () => <TheEmpty></TheEmpty>
  411. }}
  412. class={styles.classTable}
  413. loading={state.loading}
  414. columns={columns()}
  415. data={state.tableList}></NDataTable>
  416. <Pagination
  417. v-model:page={state.pagination.page}
  418. v-model:pageSize={state.pagination.rows}
  419. v-model:pageTotal={state.pagination.pageTotal}
  420. onList={getList}
  421. // sync
  422. />
  423. </div>
  424. </div>
  425. <NModal
  426. v-model:show={state.detailVisiable}
  427. preset="card"
  428. class={['modalTitle background', styles.wordDetailModel]}
  429. title={'作业详情'}>
  430. <TrainingDetails
  431. onNext={() => goToNext()}
  432. onPre={() => gotoPre()}
  433. ref={TrainingDetailsRef}
  434. onClose={() => (state.detailVisiable = false)}
  435. total={state.pagination.pageTotal}
  436. current={currentStudentIndex.value}
  437. activeRow={state.activeRow}></TrainingDetails>
  438. </NModal>
  439. </div>
  440. );
  441. }
  442. });