InfoPrintTask.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. <template>
  2. <div class="info-print-task">
  3. <p v-if="IS_MODEL2" class="tips-info mb-2">
  4. 考试需要命题老师提交具体印刷份数
  5. </p>
  6. <p v-else class="tips-info mb-2">
  7. 考试需要命题老师提交完整的考务数据,每个卷袋表示一个考场,人数字段为应考人数,备份数量为该考场试卷题卡备用数量
  8. </p>
  9. <el-form ref="modalFormComp" label-position="top">
  10. <el-form-item label="考试时间:" required>
  11. <el-date-picker
  12. v-model="createDate"
  13. type="date"
  14. value-format="timestamp"
  15. placeholder="考试日期"
  16. style="width: 150px"
  17. :editable="false"
  18. @change="timeChange"
  19. >
  20. </el-date-picker>
  21. <el-time-picker
  22. is-range
  23. v-model="createTime"
  24. range-separator="至"
  25. start-placeholder="考试开始时间"
  26. end-placeholder="考试结束时间"
  27. placeholder="选择时间范围"
  28. value-format="timestamp"
  29. :editable="false"
  30. @change="timeChange"
  31. >
  32. </el-time-picker>
  33. </el-form-item>
  34. <el-form-item
  35. label="考试对象:"
  36. required
  37. style="margin-bottom: 0"
  38. ></el-form-item>
  39. </el-form>
  40. <div v-if="IS_MODEL2" class="part-box">
  41. <div class="box-justify mb-1">
  42. <div></div>
  43. <el-button type="primary" @click="toSelectClass">选择班级</el-button>
  44. </div>
  45. <table class="table">
  46. <colgroup>
  47. <col width="90" />
  48. <col width="120" />
  49. <col width="120" />
  50. <col width="200" />
  51. <col width="300" />
  52. </colgroup>
  53. <tr>
  54. <th>卷袋序号</th>
  55. <th>印刷份数</th>
  56. <th>备份数量</th>
  57. <th>印刷室</th>
  58. <th>班级</th>
  59. </tr>
  60. <tr>
  61. <td>1</td>
  62. <td>
  63. <el-input-number
  64. v-model="modalForm.totalSubjects"
  65. class="width-full"
  66. :min="1"
  67. :max="999999"
  68. :step="1"
  69. step-strictly
  70. :controls="false"
  71. ></el-input-number>
  72. </td>
  73. <td>
  74. <el-input-number
  75. v-model="modalForm.backupCount"
  76. class="width-full"
  77. :min="infoExamPrintPlan.backupCount"
  78. :max="999999"
  79. :step="1"
  80. step-strictly
  81. :controls="false"
  82. ></el-input-number>
  83. </td>
  84. <td>
  85. <el-select
  86. v-model="modalForm.printHouseId"
  87. placeholder="请选择"
  88. class="width-full"
  89. filterable
  90. >
  91. <el-option
  92. v-for="room in printHouses"
  93. :key="room.printHouseId"
  94. :value="room.printHouseId"
  95. :label="room.printHouseName"
  96. ></el-option>
  97. </el-select>
  98. </td>
  99. <td>
  100. {{ model2ClassList.map((item) => item.clazzName).join(",") }}
  101. </td>
  102. </tr>
  103. </table>
  104. </div>
  105. <div v-else class="part-box">
  106. <div class="box-justify mb-2">
  107. <div>
  108. <p>
  109. 每个卷袋包含一个考场全部文件(试卷、题卡、卷袋贴、签到表等文件)
  110. </p>
  111. <p>
  112. 共{{ packageInfos.packageCount }}个卷袋,{{
  113. packageInfos.studentCount
  114. }}个考生,共印试卷{{ packageInfos.paperCount }}份(正式{{
  115. packageInfos.paperReleaseCount
  116. }}份,备用{{ packageInfos.paperBackupCount }}份)
  117. </p>
  118. </div>
  119. <div>
  120. <el-button
  121. v-if="checkPrivilege('button', 'ExamTaskStudentObjectImport')"
  122. type="success"
  123. icon="el-icon-download"
  124. @click="downloadTemplate('examTaskStudent')"
  125. >模板下载</el-button
  126. >
  127. <upload-button
  128. v-if="checkPrivilege('button', 'ExamTaskStudentObjectImport')"
  129. btn-icon="el-icon-circle-plus-outline"
  130. btn-content="批量导入"
  131. btn-type="success"
  132. :upload-url="uploadUrl"
  133. :format="['xls', 'xlsx']"
  134. accept=".xls,.xlsx"
  135. @valid-error="validError"
  136. @upload-success="uploadSuccess"
  137. >
  138. </upload-button>
  139. <el-button
  140. v-if="checkPrivilege('button', 'ExamTaskStudentObject')"
  141. type="primary"
  142. :disabled="studentUploaded && !!tableData.length"
  143. @click="toAdd"
  144. >新增考试对象</el-button
  145. >
  146. </div>
  147. </div>
  148. <el-table ref="TableList" :data="tableData" border>
  149. <el-table-column type="index" width="80" label="卷袋序号">
  150. </el-table-column>
  151. <el-table-column prop="className" label="考试对象" width="160">
  152. </el-table-column>
  153. <el-table-column prop="studentCount" label="人数" width="60">
  154. </el-table-column>
  155. <el-table-column prop="backupCount" label="备份数量" width="90">
  156. <template slot-scope="scope">
  157. <el-input-number
  158. v-model="scope.row.backupCount"
  159. style="width: 60px"
  160. :min="scope.row.minBackupCount"
  161. :max="99999"
  162. :step="1"
  163. step-strictly
  164. :controls="false"
  165. @change="backupCountChange"
  166. ></el-input-number>
  167. </template>
  168. </el-table-column>
  169. <el-table-column prop="examPlace" label="校区" width="140">
  170. <template slot-scope="scope">
  171. <el-input
  172. v-model.trim="scope.row.examPlace"
  173. :maxlength="100"
  174. clearable
  175. ></el-input>
  176. </template>
  177. </el-table-column>
  178. <el-table-column prop="examRoom" label="考试地点" width="140">
  179. <template slot-scope="scope">
  180. <el-input
  181. v-model.trim="scope.row.examRoom"
  182. :maxlength="50"
  183. clearable
  184. ></el-input>
  185. </template>
  186. </el-table-column>
  187. <el-table-column prop="printHouseName" label="印刷室" width="140">
  188. <template slot-scope="scope">
  189. <el-select
  190. v-model="scope.row.printHouseId"
  191. placeholder="请选择"
  192. filterable
  193. @change="() => printHouseChange(scope.row)"
  194. >
  195. <el-option
  196. v-for="room in printHouses"
  197. :key="room.printHouseId"
  198. :value="room.printHouseId"
  199. :label="room.printHouseName"
  200. ></el-option>
  201. </el-select>
  202. </template>
  203. </el-table-column>
  204. <el-table-column
  205. v-for="item in extendFields"
  206. :key="item.code"
  207. :label="item.name"
  208. width="120"
  209. >
  210. <div slot-scope="scope">
  211. <el-input
  212. v-model="scope.row.extends[item.code]"
  213. placeholder="请输入"
  214. clearable
  215. ></el-input>
  216. </div>
  217. </el-table-column>
  218. <el-table-column
  219. label="操作"
  220. width="120"
  221. class-name="action-column"
  222. align="center"
  223. fixed="right"
  224. >
  225. <template slot-scope="scope">
  226. <el-button
  227. class="btn-danger"
  228. type="text"
  229. @click="toDelete(scope.$index)"
  230. >取消</el-button
  231. >
  232. <el-button
  233. class="btn-primary"
  234. type="text"
  235. @click="toViewStudent(scope.row)"
  236. >查看考生</el-button
  237. >
  238. </template>
  239. </el-table-column>
  240. </el-table>
  241. </div>
  242. <!-- ModifyExamTaskStudent -->
  243. <modify-exam-task-student
  244. ref="ModifyExamTaskStudent"
  245. :disabled-ids="disabledStudentIds"
  246. :filter-params="{
  247. courseCode: infoExamTask.courseCode,
  248. examId: infoExamTask.examId,
  249. teachingRoomId: infoExamTask.teachingRoomId,
  250. }"
  251. :show-student="showStudent"
  252. :selected-ids="IS_MODEL2 ? model2ClassIds : null"
  253. @modified="examStudentModified"
  254. ></modify-exam-task-student>
  255. <!-- PreviewTaskStudent -->
  256. <preview-task-student
  257. ref="PreviewTaskStudent"
  258. :student-list="curRow.examTaskStudentObjectParamList"
  259. :show-student="showStudent"
  260. @close="previewStudentClosed"
  261. ></preview-task-student>
  262. </div>
  263. </template>
  264. <script>
  265. import { calcSum, getTimeDatestamp } from "@/plugins/utils";
  266. import { examRuleDetail } from "../../../base/api";
  267. import { listTaskPrintHouse } from "../../api";
  268. import ModifyExamTaskStudent from "./ModifyExamTaskStudent.vue";
  269. import PreviewTaskStudent from "./PreviewTaskStudent.vue";
  270. import { mapState, mapMutations } from "vuex";
  271. import UploadButton from "@/components/UploadButton";
  272. import templateDownload from "@/mixins/templateDownload";
  273. export default {
  274. name: "info-print-task",
  275. components: { ModifyExamTaskStudent, PreviewTaskStudent, UploadButton },
  276. mixins: [templateDownload],
  277. data() {
  278. return {
  279. modalForm: {
  280. examStartTime: "",
  281. examEndTime: "",
  282. paperNumber: "",
  283. courseName: "",
  284. courseCode: "",
  285. totalSubjects: 1,
  286. printHouseId: "",
  287. backupCount: null,
  288. classId: "",
  289. },
  290. tableData: [],
  291. model2ClassList: [],
  292. model2ClassIds: [],
  293. curRow: {},
  294. printHouses: [],
  295. extendFields: [],
  296. packageInfos: {
  297. packageCount: 0,
  298. studentCount: 0,
  299. paperCount: 0,
  300. paperReleaseCount: 0,
  301. paperBackupCount: 0,
  302. },
  303. selectedStudentIds: [],
  304. disabledStudentIds: [],
  305. examStudentList: [],
  306. showStudent: false,
  307. // date-picker
  308. curCreateTime: [],
  309. createDate: "",
  310. createTime: [],
  311. // import
  312. uploadUrl: "/api/admin/exam/task/exam_task_exam_student_import",
  313. dfilename: "学生导入模板.xlsx",
  314. studentUploaded: false,
  315. };
  316. },
  317. computed: {
  318. ...mapState("exam", [
  319. "infoExamTask",
  320. "infoExamTaskDetail",
  321. "infoPrintTask",
  322. "infoExamPrintPlan",
  323. ]),
  324. IS_MODEL2() {
  325. return this.infoExamTask.examModel === "MODEL2";
  326. },
  327. },
  328. watch: {
  329. "infoExamTask.courseCode": function (val, oldval) {
  330. if (val !== oldval) this.initData();
  331. },
  332. "infoExamPrintPlan.backupCount": function (val, oldval) {
  333. if (val !== oldval) this.planBackupCountChange();
  334. },
  335. },
  336. mounted() {
  337. this.getExtendFields();
  338. this.getPrintHouses();
  339. const curDate = getTimeDatestamp(Date.now());
  340. const hour = 60 * 60 * 1000;
  341. this.curCreateTime = [curDate + 8 * hour, curDate + 10 * hour];
  342. this.createTime = [...this.curCreateTime];
  343. },
  344. methods: {
  345. ...mapMutations("exam", ["updateTaskInfo"]),
  346. initData() {
  347. if (this.IS_MODEL2) {
  348. this.modalForm.backupCount = this.infoExamPrintPlan.backupCount;
  349. return;
  350. }
  351. this.modalForm = Object.assign(this.modalForm, {
  352. paperNumber: this.infoExamTask.paperNumber,
  353. courseName: this.infoExamTask.courseName,
  354. courseCode: this.infoExamTask.courseCode,
  355. });
  356. const { examStartTime, examEndTime } = this.infoPrintTask;
  357. if (examStartTime && examEndTime) {
  358. this.createTime = [examStartTime, examEndTime];
  359. this.createDate = getTimeDatestamp(examStartTime);
  360. this.modalForm.examStartTime = this.createTime[0];
  361. this.modalForm.examEndTime = this.createTime[1];
  362. }
  363. this.tableData = [];
  364. this.updatePackageInfos();
  365. this.updateData();
  366. },
  367. planBackupCountChange() {
  368. this.tableData.forEach((item) => {
  369. Object.assign(item, this.getBackupCount(item.studentCount));
  370. });
  371. this.updatePackageInfos();
  372. },
  373. getBackupCount(studentCount) {
  374. const { backupCount } = this.infoExamPrintPlan;
  375. if (backupCount < 1) {
  376. const count = Math.ceil(backupCount * studentCount);
  377. return { backupCount: count, minBackupCount: count };
  378. }
  379. return { backupCount, minBackupCount: backupCount };
  380. },
  381. checkTime() {
  382. if (!this.modalForm.examStartTime || !this.modalForm.examEndTime) {
  383. this.$message.error("请选择考试时间!");
  384. return false;
  385. }
  386. if (this.modalForm.examStartTime >= this.modalForm.examEndTime) {
  387. this.$message.error("考试开始时间必须小于考试结束时间!");
  388. return false;
  389. }
  390. return true;
  391. },
  392. checkData() {
  393. if (!this.checkTime()) return Promise.reject();
  394. if (this.IS_MODEL2) {
  395. if (!this.modalForm.totalSubjects) {
  396. this.$message.error("请输入印刷份数!");
  397. return Promise.reject();
  398. }
  399. if (!this.modalForm.printHouseId) {
  400. this.$message.error("请选择印刷室!");
  401. return Promise.reject();
  402. }
  403. if (!this.modalForm.classId) {
  404. this.$message.error("请选择班级!");
  405. return Promise.reject();
  406. }
  407. return Promise.resolve(true);
  408. }
  409. if (!this.tableData.length) {
  410. this.$message.error("请添加考试对象!");
  411. return Promise.reject();
  412. }
  413. let errorMsg = [];
  414. this.tableData.forEach((row) => {
  415. let errorFields = [];
  416. this.extendFields.forEach((field) => {
  417. if (!row.extends[field.code]) {
  418. errorFields.push(field.name);
  419. }
  420. });
  421. if (!row.backupCount) {
  422. errorFields.push("备份数量");
  423. }
  424. if (!row.printHouseId) {
  425. errorFields.push("印刷室");
  426. }
  427. if (errorFields.length) {
  428. errorMsg.push(
  429. `考试对象${row.className}中,${errorFields.join("、")}必须填写`
  430. );
  431. }
  432. });
  433. if (errorMsg.length) {
  434. this.$message.error(errorMsg.join("。"));
  435. return Promise.reject();
  436. }
  437. return Promise.resolve(true);
  438. },
  439. updateData() {
  440. const tableData = this.tableData.map((row) => {
  441. let nrow = { ...row };
  442. let extendFields = this.extendFields.map((field) => {
  443. let info = { ...field };
  444. info.value = row.extends[field.code];
  445. return info;
  446. });
  447. nrow.extendFields = JSON.stringify(extendFields);
  448. nrow.examStartTime = this.modalForm.examStartTime;
  449. nrow.examEndTime = this.modalForm.examEndTime;
  450. return nrow;
  451. });
  452. this.updateTaskInfo({
  453. infoPrintTask: {
  454. ...this.modalForm,
  455. list: tableData,
  456. },
  457. });
  458. },
  459. updatePackageInfos() {
  460. this.packageInfos.packageCount = this.tableData.length;
  461. this.packageInfos.studentCount = calcSum(
  462. this.tableData.map((item) => item.studentCount)
  463. );
  464. this.packageInfos.paperReleaseCount = this.packageInfos.studentCount;
  465. this.packageInfos.paperBackupCount = calcSum(
  466. this.tableData.map((item) => item.backupCount || 0)
  467. );
  468. this.packageInfos.paperCount =
  469. this.packageInfos.paperReleaseCount +
  470. this.packageInfos.paperBackupCount;
  471. },
  472. async getExtendFields() {
  473. const examRule = await examRuleDetail();
  474. this.extendFields = examRule.extendFields
  475. ? JSON.parse(examRule.extendFields)
  476. : [];
  477. this.extendFields = this.extendFields.filter((item) => item.enable);
  478. },
  479. async getPrintHouses() {
  480. this.printHouses = await listTaskPrintHouse();
  481. },
  482. timeChange() {
  483. if (!this.createDate || !this.createTime) {
  484. this.modalForm.examStartTime = null;
  485. this.modalForm.examEndTime = null;
  486. return;
  487. }
  488. const curDate = getTimeDatestamp(this.createDate);
  489. const timeDate = getTimeDatestamp(this.createTime[0]);
  490. this.modalForm.examStartTime = curDate + this.createTime[0] - timeDate;
  491. this.modalForm.examEndTime = curDate + this.createTime[1] - timeDate;
  492. },
  493. backupCountChange() {
  494. this.updatePackageInfos();
  495. },
  496. printHouseChange(row) {
  497. const curHouse = this.printHouses.find(
  498. (item) => item.printHouseId === row.printHouseId
  499. );
  500. if (curHouse) {
  501. row.printHouseName = curHouse.printHouseName;
  502. }
  503. },
  504. toAdd() {
  505. if (!this.infoExamTask.courseCode) {
  506. this.$message.error("请先选择课程");
  507. return;
  508. }
  509. this.disabledStudentIds = this.getTabelStudentIds();
  510. this.showStudent = this.checkPrivilege("button", "SelectStudent");
  511. this.$refs.ModifyExamTaskStudent.open();
  512. },
  513. getTabelStudentIds() {
  514. let ids = [];
  515. this.tableData.forEach((item) => {
  516. item.examTaskStudentObjectParamList.forEach((elem) => {
  517. ids.push(elem.id);
  518. });
  519. });
  520. return ids;
  521. },
  522. getInitTableRow() {
  523. let modalFormData = { ...this.modalForm };
  524. delete modalFormData.printHouseId;
  525. let data = {
  526. id: this.$randomCode(),
  527. examPlace: "",
  528. examRoom: "",
  529. classId: "",
  530. className: "",
  531. studentCount: "",
  532. printHouseId: "",
  533. printHouseName: "",
  534. extendFields: "",
  535. backupCount: 0,
  536. minBackupCount: 0,
  537. isSelectStudent: true,
  538. examTaskStudentObjectParamList: [],
  539. ...modalFormData,
  540. };
  541. let extendFieldModal = {};
  542. this.extendFields.forEach((field) => {
  543. extendFieldModal[field.code] = "";
  544. });
  545. data.extends = extendFieldModal;
  546. return data;
  547. },
  548. examStudentModified({ selectedStudents, isSelectStudent }) {
  549. if (this.IS_MODEL2) {
  550. this.model2ClassList = selectedStudents.map((item) => {
  551. return {
  552. clazzId: item.clazzId,
  553. clazzName: item.clazzName,
  554. };
  555. });
  556. this.model2ClassIds = this.model2ClassList.map((item) => item.clazzId);
  557. this.modalForm.classId = this.model2ClassIds.join();
  558. return;
  559. }
  560. if (this.studentUploaded) {
  561. this.tableData = [];
  562. this.studentUploaded = false;
  563. }
  564. let examTaskStudentObjectParamList = [];
  565. selectedStudents.forEach((item) => {
  566. item.children.forEach((student) => {
  567. examTaskStudentObjectParamList.push({ ...student, enable: true });
  568. });
  569. });
  570. let tableRow = this.$objAssign(this.getInitTableRow(), {
  571. classId: selectedStudents.map((item) => item.clazzId).join(),
  572. className: selectedStudents.map((item) => item.clazzName).join(),
  573. studentCount: examTaskStudentObjectParamList.length,
  574. examTaskStudentObjectParamList,
  575. isSelectStudent,
  576. ...this.getBackupCount(examTaskStudentObjectParamList.length),
  577. });
  578. this.tableData.push(tableRow);
  579. this.updatePackageInfos();
  580. },
  581. toDelete(index) {
  582. this.tableData.splice(index, 1);
  583. this.updatePackageInfos();
  584. },
  585. toViewStudent(row) {
  586. // console.log(row);
  587. this.curRow = row;
  588. this.$refs.PreviewTaskStudent.open();
  589. },
  590. previewStudentClosed() {
  591. const studentCount = this.curRow.examTaskStudentObjectParamList.filter(
  592. (item) => item.enable
  593. ).length;
  594. Object.assign(this.curRow, {
  595. ...this.getBackupCount(studentCount),
  596. studentCount,
  597. });
  598. },
  599. // import
  600. validError(errorData) {
  601. this.$message.error(errorData.message);
  602. },
  603. uploadSuccess(res) {
  604. this.studentUploaded = true;
  605. this.$message.success("导入成功!");
  606. this.tableData = res.data.map((item) => {
  607. const initRow = this.getInitTableRow();
  608. let examTaskStudentObjectParamList = [];
  609. item.examTaskStudentObjectResultList.forEach((elem) => {
  610. elem.studentInfoList.forEach((std) => {
  611. examTaskStudentObjectParamList.push({
  612. ...std,
  613. studentClazzType: elem.studentClazzType,
  614. id: `${elem.clazzId}_${std.studentId}`,
  615. });
  616. });
  617. });
  618. let tableRow = this.$objAssign(initRow, {
  619. classId: item.examTaskStudentObjectResultList
  620. .map((item) => item.clazzId)
  621. .join(),
  622. className: item.examTaskStudentObjectResultList
  623. .map((item) => item.clazzName)
  624. .join(),
  625. examRoom: item.examRoom,
  626. examPlace: item.examPlace,
  627. studentCount: examTaskStudentObjectParamList.length,
  628. examTaskStudentObjectParamList,
  629. ...this.getBackupCount(examTaskStudentObjectParamList.length),
  630. });
  631. return tableRow;
  632. });
  633. this.updatePackageInfos();
  634. },
  635. // model2 select class
  636. toSelectClass() {
  637. if (!this.infoExamTask.courseCode) {
  638. this.$message.error("请先选择课程");
  639. return;
  640. }
  641. this.disabledStudentIds = [];
  642. this.showStudent = false;
  643. this.$refs.ModifyExamTaskStudent.open();
  644. },
  645. },
  646. };
  647. </script>