InfoPrintTask.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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. <!-- ModifyExamStudent -->
  243. <modify-exam-student
  244. ref="ModifyExamStudent"
  245. :disabled-ids="disabledStudentIds"
  246. :course-code="infoExamTask.courseCode"
  247. :show-student="showStudent"
  248. :object-types="objectTypes"
  249. :selected-ids="IS_MODEL2 ? model2ClassIds : null"
  250. @modified="examStudentModified"
  251. ></modify-exam-student>
  252. <!-- PreviewTaskStudent -->
  253. <preview-task-student
  254. ref="PreviewTaskStudent"
  255. :student-list="examStudentList"
  256. ></preview-task-student>
  257. </div>
  258. </template>
  259. <script>
  260. import { calcSum, getTimeDatestamp } from "@/plugins/utils";
  261. import { examRuleDetail } from "../../../base/api";
  262. import { listTaskPrintHouse } from "../../api";
  263. import ModifyExamStudent from "./ModifyExamStudent";
  264. import PreviewTaskStudent from "./PreviewTaskStudent";
  265. import { mapState, mapMutations } from "vuex";
  266. import UploadButton from "@/components/UploadButton";
  267. import templateDownload from "@/mixins/templateDownload";
  268. export default {
  269. name: "info-print-task",
  270. components: { ModifyExamStudent, PreviewTaskStudent, UploadButton },
  271. mixins: [templateDownload],
  272. data() {
  273. return {
  274. modalForm: {
  275. examStartTime: "",
  276. examEndTime: "",
  277. paperNumber: "",
  278. courseName: "",
  279. courseCode: "",
  280. totalSubjects: 1,
  281. printHouseId: "",
  282. backupCount: null,
  283. classId: "",
  284. },
  285. tableData: [],
  286. model2ClassList: [],
  287. model2ClassIds: [],
  288. curRow: {},
  289. printHouses: [],
  290. extendFields: [],
  291. packageInfos: {
  292. packageCount: 0,
  293. studentCount: 0,
  294. paperCount: 0,
  295. paperReleaseCount: 0,
  296. paperBackupCount: 0,
  297. },
  298. selectedStudentIds: [],
  299. disabledStudentIds: [],
  300. examStudentList: [],
  301. showStudent: false,
  302. objectTypes: [],
  303. // date-picker
  304. curCreateTime: [],
  305. createDate: "",
  306. createTime: [],
  307. // import
  308. uploadUrl: "/api/admin/exam/task/exam_task_exam_student_import",
  309. dfilename: "学生导入模板.xlsx",
  310. studentUploaded: false,
  311. };
  312. },
  313. computed: {
  314. ...mapState("exam", [
  315. "infoExamTask",
  316. "infoExamTaskDetail",
  317. "infoPrintTask",
  318. "infoExamPrintPlan",
  319. ]),
  320. IS_MODEL2() {
  321. return this.infoExamTask.examModel === "MODEL2";
  322. },
  323. },
  324. watch: {
  325. "infoExamTask.courseCode": function (val, oldval) {
  326. if (val !== oldval) this.initData();
  327. },
  328. "infoExamPrintPlan.backupCount": function (val, oldval) {
  329. if (val !== oldval) this.planBackupCountChange();
  330. },
  331. },
  332. mounted() {
  333. this.getExtendFields();
  334. this.getPrintHouses();
  335. const curDate = getTimeDatestamp(Date.now());
  336. const hour = 60 * 60 * 1000;
  337. this.curCreateTime = [curDate + 8 * hour, curDate + 10 * hour];
  338. this.createTime = [...this.curCreateTime];
  339. },
  340. methods: {
  341. ...mapMutations("exam", ["updateTaskInfo"]),
  342. initData() {
  343. if (this.IS_MODEL2) {
  344. this.modalForm.backupCount = this.infoExamPrintPlan.backupCount;
  345. return;
  346. }
  347. this.modalForm = Object.assign(this.modalForm, {
  348. paperNumber: this.infoExamTask.paperNumber,
  349. courseName: this.infoExamTask.courseName,
  350. courseCode: this.infoExamTask.courseCode,
  351. });
  352. const { examStartTime, examEndTime } = this.infoPrintTask;
  353. if (examStartTime && examEndTime) {
  354. this.createTime = [examStartTime, examEndTime];
  355. this.createDate = getTimeDatestamp(examStartTime);
  356. this.modalForm.examStartTime = this.createTime[0];
  357. this.modalForm.examEndTime = this.createTime[1];
  358. }
  359. this.tableData = [];
  360. this.updatePackageInfos();
  361. this.updateData();
  362. },
  363. planBackupCountChange() {
  364. this.tableData.forEach((item) => {
  365. Object.assign(item, this.getBackupCount(item.studentCount));
  366. });
  367. this.updatePackageInfos();
  368. },
  369. getBackupCount(studentCount) {
  370. const { backupCount } = this.infoExamPrintPlan;
  371. if (backupCount < 1) {
  372. const count = Math.ceil(backupCount * studentCount);
  373. return { backupCount: count, minBackupCount: count };
  374. }
  375. return { backupCount, minBackupCount: backupCount };
  376. },
  377. checkTime() {
  378. if (!this.modalForm.examStartTime || !this.modalForm.examEndTime) {
  379. this.$message.error("请选择考试时间!");
  380. return false;
  381. }
  382. if (this.modalForm.examStartTime >= this.modalForm.examEndTime) {
  383. this.$message.error("考试开始时间必须小于考试结束时间!");
  384. return false;
  385. }
  386. return true;
  387. },
  388. checkData() {
  389. if (!this.checkTime()) return Promise.reject();
  390. if (this.IS_MODEL2) {
  391. if (!this.modalForm.totalSubjects) {
  392. this.$message.error("请输入印刷份数!");
  393. return Promise.reject();
  394. }
  395. if (!this.modalForm.printHouseId) {
  396. this.$message.error("请选择印刷室!");
  397. return Promise.reject();
  398. }
  399. if (!this.modalForm.classId) {
  400. this.$message.error("请选择班级!");
  401. return Promise.reject();
  402. }
  403. return Promise.resolve(true);
  404. }
  405. if (!this.tableData.length) {
  406. this.$message.error("请添加考试对象!");
  407. return Promise.reject();
  408. }
  409. let errorMsg = [];
  410. this.tableData.forEach((row) => {
  411. let errorFields = [];
  412. this.extendFields.forEach((field) => {
  413. if (!row.extends[field.code]) {
  414. errorFields.push(field.name);
  415. }
  416. });
  417. if (!row.backupCount) {
  418. errorFields.push("备份数量");
  419. }
  420. if (!row.printHouseId) {
  421. errorFields.push("印刷室");
  422. }
  423. if (errorFields.length) {
  424. errorMsg.push(
  425. `考试对象${row.className}中,${errorFields.join("、")}必须填写`
  426. );
  427. }
  428. });
  429. if (errorMsg.length) {
  430. this.$message.error(errorMsg.join("。"));
  431. return Promise.reject();
  432. }
  433. return Promise.resolve(true);
  434. },
  435. updateData() {
  436. const tableData = this.tableData.map((row) => {
  437. let nrow = { ...row };
  438. let extendFields = this.extendFields.map((field) => {
  439. let info = { ...field };
  440. info.value = row.extends[field.code];
  441. return info;
  442. });
  443. nrow.extendFields = JSON.stringify(extendFields);
  444. nrow.examStartTime = this.modalForm.examStartTime;
  445. nrow.examEndTime = this.modalForm.examEndTime;
  446. return nrow;
  447. });
  448. this.updateTaskInfo({
  449. infoPrintTask: {
  450. ...this.modalForm,
  451. list: tableData,
  452. },
  453. });
  454. },
  455. updatePackageInfos() {
  456. this.packageInfos.packageCount = this.tableData.length;
  457. this.packageInfos.studentCount = calcSum(
  458. this.tableData.map((item) => item.studentCount)
  459. );
  460. this.packageInfos.paperReleaseCount = this.packageInfos.studentCount;
  461. this.packageInfos.paperBackupCount = calcSum(
  462. this.tableData.map((item) => item.backupCount || 0)
  463. );
  464. this.packageInfos.paperCount =
  465. this.packageInfos.paperReleaseCount +
  466. this.packageInfos.paperBackupCount;
  467. },
  468. async getExtendFields() {
  469. const examRule = await examRuleDetail();
  470. this.extendFields = examRule.extendFields
  471. ? JSON.parse(examRule.extendFields)
  472. : [];
  473. this.extendFields = this.extendFields.filter((item) => item.enable);
  474. },
  475. async getPrintHouses() {
  476. this.printHouses = await listTaskPrintHouse();
  477. },
  478. timeChange() {
  479. if (!this.createDate || !this.createTime) {
  480. this.modalForm.examStartTime = null;
  481. this.modalForm.examEndTime = null;
  482. return;
  483. }
  484. const curDate = getTimeDatestamp(this.createDate);
  485. const timeDate = getTimeDatestamp(this.createTime[0]);
  486. this.modalForm.examStartTime = curDate + this.createTime[0] - timeDate;
  487. this.modalForm.examEndTime = curDate + this.createTime[1] - timeDate;
  488. },
  489. backupCountChange() {
  490. this.updatePackageInfos();
  491. },
  492. printHouseChange(row) {
  493. const curHouse = this.printHouses.find(
  494. (item) => item.printHouseId === row.printHouseId
  495. );
  496. if (curHouse) {
  497. row.printHouseName = curHouse.printHouseName;
  498. }
  499. },
  500. toAdd() {
  501. if (!this.infoExamTask.courseCode) {
  502. this.$message.error("请先选择课程");
  503. return;
  504. }
  505. const types = {
  506. TEACH_CLAZZ_STUDENT: this.checkPrivilege("button", "MyTeachCourse"),
  507. BASIC_CLAZZ_STUDENT: this.checkPrivilege("button", "StudentLibrary"),
  508. };
  509. this.disabledStudentIds = this.getTabelStudentIds();
  510. this.objectTypes = Object.keys(types).filter((k) => types[k]);
  511. this.showStudent = this.checkPrivilege("button", "SelectStudent");
  512. this.$refs.ModifyExamStudent.open();
  513. },
  514. getTabelStudentIds() {
  515. let ids = [];
  516. this.tableData.forEach((item) => {
  517. item.examTaskStudentObjectParamList.forEach((elem) => {
  518. ids.push(elem.id);
  519. });
  520. });
  521. return ids;
  522. },
  523. getInitTableRow() {
  524. let modalFormData = { ...this.modalForm };
  525. delete modalFormData.printHouseId;
  526. let data = {
  527. id: this.$randomCode(),
  528. examPlace: "",
  529. examRoom: "",
  530. classId: "",
  531. className: "",
  532. studentCount: "",
  533. printHouseId: "",
  534. printHouseName: "",
  535. extendFields: "",
  536. backupCount: 0,
  537. minBackupCount: 0,
  538. isSelectStudent: true,
  539. examTaskStudentObjectParamList: [],
  540. ...modalFormData,
  541. };
  542. let extendFieldModal = {};
  543. this.extendFields.forEach((field) => {
  544. extendFieldModal[field.code] = "";
  545. });
  546. data.extends = extendFieldModal;
  547. return data;
  548. },
  549. examStudentModified({ selectedStudents, isSelectStudent }) {
  550. if (this.IS_MODEL2) {
  551. this.model2ClassList = selectedStudents.map((item) => {
  552. return {
  553. clazzId: item.clazzId,
  554. clazzName: item.clazzName,
  555. };
  556. });
  557. this.model2ClassIds = this.model2ClassList.map((item) => item.clazzId);
  558. this.modalForm.classId = this.model2ClassIds.join();
  559. return;
  560. }
  561. if (this.studentUploaded) {
  562. this.tableData = [];
  563. this.studentUploaded = false;
  564. }
  565. let examTaskStudentObjectParamList = [];
  566. selectedStudents.forEach((item) => {
  567. examTaskStudentObjectParamList.push(...item.children);
  568. });
  569. let tableRow = this.$objAssign(this.getInitTableRow(), {
  570. classId: selectedStudents.map((item) => item.clazzId).join(),
  571. className: selectedStudents.map((item) => item.clazzName).join(),
  572. studentCount: examTaskStudentObjectParamList.length,
  573. examTaskStudentObjectParamList,
  574. isSelectStudent,
  575. ...this.getBackupCount(examTaskStudentObjectParamList.length),
  576. });
  577. this.tableData.push(tableRow);
  578. this.updatePackageInfos();
  579. },
  580. toDelete(index) {
  581. this.tableData.splice(index, 1);
  582. this.updatePackageInfos();
  583. if (!this.tableData.length) {
  584. this.$refs.ModifyExamStudent.clearSelectedExamObjectType();
  585. }
  586. },
  587. toViewStudent(row) {
  588. // console.log(row);
  589. this.examStudentList = row.examTaskStudentObjectParamList.map((item) => {
  590. return {
  591. id: item.id,
  592. studentName: item.studentName,
  593. studentCode: item.studentCode,
  594. className: item.basicClazzName,
  595. };
  596. });
  597. this.$refs.PreviewTaskStudent.open();
  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.$refs.ModifyExamStudent.clearTypeData();
  607. this.tableData = res.data.map((item) => {
  608. const initRow = this.getInitTableRow();
  609. let examTaskStudentObjectParamList = [];
  610. item.examTaskStudentObjectResultList.forEach((elem) => {
  611. elem.studentInfoList.forEach((std) => {
  612. examTaskStudentObjectParamList.push({
  613. ...std,
  614. studentClazzType: elem.studentClazzType,
  615. id: `${elem.clazzId}_${std.studentId}`,
  616. });
  617. });
  618. });
  619. let tableRow = this.$objAssign(initRow, {
  620. classId: item.examTaskStudentObjectResultList
  621. .map((item) => item.clazzId)
  622. .join(),
  623. className: item.examTaskStudentObjectResultList
  624. .map((item) => item.clazzName)
  625. .join(),
  626. examRoom: item.examRoom,
  627. examPlace: item.examPlace,
  628. studentCount: examTaskStudentObjectParamList.length,
  629. examTaskStudentObjectParamList,
  630. ...this.getBackupCount(examTaskStudentObjectParamList.length),
  631. });
  632. return tableRow;
  633. });
  634. this.updatePackageInfos();
  635. },
  636. // model2 select class
  637. toSelectClass() {
  638. if (!this.infoExamTask.courseCode) {
  639. this.$message.error("请先选择课程");
  640. return;
  641. }
  642. this.disabledStudentIds = [];
  643. this.objectTypes = ["BASIC_CLAZZ_STUDENT"];
  644. this.showStudent = false;
  645. this.$refs.ModifyExamStudent.open();
  646. },
  647. },
  648. };
  649. </script>