ModifyExamConfigDetail.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. <template>
  2. <el-dialog
  3. class="modify-exam-config-detail"
  4. :visible.sync="modalIsShow"
  5. top="0"
  6. width="800px"
  7. title="考试配置"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @opened="dialogOpened"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. label-width="140px"
  16. :rules="rules"
  17. :model="modalForm"
  18. >
  19. <el-form-item label="是否启用入库审核:" required>
  20. <el-switch v-model="modalForm.review" inactive-color="#dcdfe6">
  21. </el-switch>
  22. </el-form-item>
  23. <el-form-item v-if="modalForm.review" label="强制审核内容:" required>
  24. <el-checkbox-group v-model="modalForm.auditContent">
  25. <el-checkbox
  26. v-for="(val, key) in PRINT_CONTENT_TYPE"
  27. :key="key"
  28. :label="key"
  29. >{{ val }}</el-checkbox
  30. >
  31. </el-checkbox-group>
  32. </el-form-item>
  33. <el-form-item label="提交印刷方式:" required>
  34. <el-radio-group v-model="modalForm.printMethod">
  35. <el-radio
  36. v-for="(val, key) in CONFIRM_PRINT_TYPE"
  37. :key="key"
  38. :label="key"
  39. >{{ val }}</el-radio
  40. >
  41. </el-radio-group>
  42. </el-form-item>
  43. <el-form-item prop="cardRuleId" label="题卡规则:">
  44. <card-rule-select
  45. ref="CardRuleSelect"
  46. v-model.trim="modalForm.cardRuleId"
  47. placeholder="请选择"
  48. clearable
  49. ></card-rule-select>
  50. <div class="tips-info">
  51. <p>说明:</p>
  52. <p>
  53. 1、若选择全部通卡,则命题老师只能选择通卡,若选择题卡规则,则专卡和通卡均可选择
  54. </p>
  55. <p>
  56. 2、若选择题卡规则,命题老师在该考试下自主创建题卡时,版头样式及版头内容为该规则对应样式及版头。
  57. </p>
  58. </div>
  59. </el-form-item>
  60. <div class="part-box">
  61. <div class="config-title">
  62. <h4>试卷&题卡印品:</h4>
  63. <el-checkbox
  64. v-show="infoShow"
  65. v-model="allSelected"
  66. label="全选"
  67. @change="selectAll"
  68. ></el-checkbox>
  69. </div>
  70. <el-form-item prop="printContent" label="试卷、题卡:">
  71. <el-checkbox-group
  72. v-model="modalForm.printContent"
  73. @change="() => checkSelectAll()"
  74. >
  75. <el-checkbox
  76. v-for="(val, key) in PRINT_CONTENT_TYPE"
  77. :key="key"
  78. :label="key"
  79. >{{ val }}</el-checkbox
  80. >
  81. </el-checkbox-group>
  82. </el-form-item>
  83. <el-form-item
  84. v-if="modalForm.printContent.length"
  85. prop="backupMethod"
  86. label="备用数量:"
  87. >
  88. <el-select
  89. v-model="modalForm.backupMethod"
  90. class="mr-2"
  91. size="small"
  92. placeholder="请选择"
  93. >
  94. <el-option
  95. v-for="(val, key) in PAPER_BACKUP_TYPE"
  96. :key="key"
  97. :value="key"
  98. :label="val"
  99. ></el-option>
  100. </el-select>
  101. <exam-backup-edit v-model="modalForm.backupCount"></exam-backup-edit>
  102. </el-form-item>
  103. <el-form-item
  104. v-show="infoShow"
  105. v-if="contentIncludesPaper"
  106. prop="drawRule"
  107. label="抽卷规则:"
  108. >
  109. <el-radio-group v-model="modalForm.drawRule">
  110. <el-radio
  111. v-for="(val, key) in DRAW_RULE_TYPE"
  112. :label="key"
  113. :key="key"
  114. >{{ val }}</el-radio
  115. >
  116. </el-radio-group>
  117. <div class="tips-info">
  118. <p>说明:</p>
  119. <p>
  120. 1.只抽取一次:不同印刷计划下,同一试卷编号下的卷型只能被抽取一次;
  121. </p>
  122. <p>
  123. 2.可反复抽取:不同印刷计划下,同一试卷编号下的卷型可重复抽取,系统默认优先抽取未曝光卷型。
  124. </p>
  125. </div>
  126. </el-form-item>
  127. </div>
  128. <div class="part-box" v-show="infoShow">
  129. <div class="config-title">
  130. <h4>其他印品:</h4>
  131. </div>
  132. <el-form-item
  133. v-for="(item, index) in modalForm.variableContent"
  134. :key="item.type"
  135. :label="`${TEMPLATE_CLASSIFY[item.type]}:`"
  136. :prop="`variableContent.${index}.templateId`"
  137. :rules="{
  138. required: false,
  139. validator: templateValidator,
  140. trigger: 'change',
  141. }"
  142. :required="!!item.templateId.length"
  143. >
  144. <el-checkbox-group
  145. v-model="item.templateId"
  146. @change="(vals) => tempChange(vals, `variableContent.${index}`)"
  147. >
  148. <el-checkbox
  149. v-for="temp in templateSources[item.type]"
  150. :label="temp.id"
  151. :key="temp.id"
  152. >{{ temp.name }}</el-checkbox
  153. >
  154. </el-checkbox-group>
  155. <div v-if="item.templateId.length">
  156. <el-select
  157. v-model="item.backupMethod"
  158. class="mr-2"
  159. size="small"
  160. placeholder="请选择"
  161. >
  162. <el-option
  163. v-for="(val, key) in PRINT_BACKUP_TYPE"
  164. :key="key"
  165. :value="key"
  166. :label="val"
  167. ></el-option>
  168. </el-select>
  169. <el-input-number
  170. class="mr-1"
  171. v-model="item.backupCount"
  172. size="small"
  173. :min="0"
  174. :max="200"
  175. :step="1"
  176. step-strictly
  177. :controls="false"
  178. style="width: 60px"
  179. ></el-input-number>
  180. <span>份</span>
  181. </div>
  182. </el-form-item>
  183. <!-- <h4 class="part-box-tips">普通印品:</h4> -->
  184. <el-form-item
  185. v-for="(item, index) in modalForm.ordinaryContent"
  186. :key="item.type"
  187. :label="`${TEMPLATE_CLASSIFY[item.type]}:`"
  188. :prop="`ordinaryContent.${index}.templateId`"
  189. :rules="{
  190. required: false,
  191. validator: templateValidator,
  192. trigger: 'change',
  193. }"
  194. :required="!!item.templateId.length"
  195. >
  196. <el-checkbox-group
  197. v-model="item.templateId"
  198. @change="(vals) => tempChange(vals, `ordinaryContent.${index}`)"
  199. >
  200. <el-checkbox
  201. v-for="temp in templateSources[item.type]"
  202. :label="temp.id"
  203. :key="temp.id"
  204. >{{ temp.name }}</el-checkbox
  205. >
  206. </el-checkbox-group>
  207. <div v-if="item.templateId.length">
  208. <el-select
  209. v-model="item.backupMethod"
  210. class="mr-2"
  211. size="small"
  212. placeholder="请选择"
  213. >
  214. <el-option
  215. v-for="(val, key) in PRINT_BACKUP_TYPE"
  216. :key="key"
  217. :value="key"
  218. :label="val"
  219. ></el-option>
  220. </el-select>
  221. <el-input-number
  222. class="mr-1"
  223. v-model="item.backupCount"
  224. size="small"
  225. :min="0"
  226. :max="200"
  227. :step="1"
  228. step-strictly
  229. :controls="false"
  230. style="width: 60px"
  231. ></el-input-number>
  232. <span>份</span>
  233. </div>
  234. </el-form-item>
  235. </div>
  236. <el-form-item prop="selectedPrint"></el-form-item>
  237. <div class="part-box">
  238. <div class="config-title">
  239. <h4>输出印品配置:</h4>
  240. </div>
  241. <el-form-item prop="pdfTypes" label="输出文件类型:">
  242. <el-checkbox-group v-model="modalForm.pdfTypes">
  243. <el-checkbox
  244. v-for="(val, key) in EXAM_PDF_TYPE"
  245. :label="val"
  246. :key="key"
  247. >
  248. {{ val }}
  249. </el-checkbox>
  250. </el-checkbox-group>
  251. </el-form-item>
  252. </div>
  253. </el-form>
  254. <div slot="footer">
  255. <el-button type="primary" :disabled="isSubmit" @click="submit"
  256. >确认</el-button
  257. >
  258. <el-button @click="cancel">取消</el-button>
  259. </div>
  260. </el-dialog>
  261. </template>
  262. <script>
  263. import {
  264. PRINT_CONTENT_TYPE,
  265. DRAW_RULE_TYPE,
  266. PRINT_BACKUP_TYPE,
  267. PAPER_BACKUP_TYPE,
  268. TEMPLATE_CLASSIFY,
  269. CONFIRM_PRINT_TYPE,
  270. EXAM_PDF_TYPE,
  271. } from "@/constants/enumerate";
  272. import { deepCopy } from "@/plugins/utils";
  273. import { examConfigQuery, updateExamConfig } from "../api";
  274. import { printPlanTemplateList } from "../../print/api";
  275. import ExamBackupEdit from "./ExamBackupEdit.vue";
  276. const initModalForm = {
  277. id: null,
  278. examId: null,
  279. review: true,
  280. auditContent: [],
  281. printMethod: "AUTO",
  282. cardRuleId: "",
  283. printContent: [],
  284. backupMethod: "ROOM",
  285. backupCount: 1,
  286. drawRule: "ONE",
  287. pdfTypes: [],
  288. variableContent: [
  289. {
  290. type: "SIGN",
  291. templateId: [],
  292. oldTemplateId: [],
  293. backupMethod: "ROOM",
  294. backupCount: 1,
  295. },
  296. {
  297. type: "PACKAGE",
  298. templateId: [],
  299. oldTemplateId: [],
  300. backupMethod: "ROOM",
  301. backupCount: 1,
  302. },
  303. ],
  304. ordinaryContent: [
  305. {
  306. type: "CHECK_IN",
  307. templateId: [],
  308. oldTemplateId: [],
  309. backupMethod: "ROOM",
  310. backupCount: 1,
  311. },
  312. ],
  313. };
  314. export default {
  315. name: "modify-exam-config-detail",
  316. components: { ExamBackupEdit },
  317. props: {
  318. exam: {
  319. type: Object,
  320. default() {
  321. return {};
  322. },
  323. },
  324. },
  325. computed: {
  326. contentIncludesPaper() {
  327. return this.modalForm.printContent.includes("PAPER");
  328. },
  329. },
  330. data() {
  331. const printContentValidator = (rule, value, callback) => {
  332. if (!this.modalForm.printContent.length) {
  333. return callback(new Error("请选择试卷、题卡"));
  334. }
  335. callback();
  336. };
  337. const backupMethodValidator = (rule, value, callback) => {
  338. if (!this.modalForm.printContent.length) {
  339. return callback();
  340. }
  341. if (!value) {
  342. return callback(new Error("请选择备份方式"));
  343. }
  344. if (!this.modalForm.backupCount && this.modalForm.backupCount !== 0) {
  345. return callback(new Error("请输入备份数量"));
  346. }
  347. callback();
  348. };
  349. const selectedPrintValidator = (rule, value, callback) => {
  350. const printInfo = [
  351. ...this.modalForm.variableContent,
  352. ...this.modalForm.ordinaryContent,
  353. ];
  354. const hasPrintInfo = printInfo.some((item) => item.templateId.length);
  355. if (hasPrintInfo || this.modalForm.printContent.length) {
  356. callback();
  357. } else {
  358. callback(new Error("必须选择一项印品"));
  359. }
  360. };
  361. const pdfTypesValidator = (rule, value, callback) => {
  362. if (!value.length) {
  363. return callback(new Error("请选择输出文件类型"));
  364. }
  365. callback();
  366. };
  367. return {
  368. modalIsShow: false,
  369. isSubmit: false,
  370. modalForm: deepCopy(initModalForm),
  371. PRINT_CONTENT_TYPE,
  372. DRAW_RULE_TYPE,
  373. PRINT_BACKUP_TYPE,
  374. PAPER_BACKUP_TYPE,
  375. CONFIRM_PRINT_TYPE,
  376. TEMPLATE_CLASSIFY,
  377. EXAM_PDF_TYPE,
  378. variableContent: [],
  379. ordinaryContent: [],
  380. templateSources: {},
  381. oldPrintContent: [],
  382. allSelected: false,
  383. infoShow: true,
  384. rules: {
  385. cardRuleId: [
  386. {
  387. required: true,
  388. message: "请选择题卡规则",
  389. trigger: "change",
  390. },
  391. ],
  392. printContent: [
  393. {
  394. required: true,
  395. validator: printContentValidator,
  396. trigger: "change",
  397. },
  398. ],
  399. backupMethod: [
  400. {
  401. required: true,
  402. validator: backupMethodValidator,
  403. trigger: "change",
  404. },
  405. ],
  406. drawRule: [
  407. {
  408. required: true,
  409. message: "请选择抽卷规则",
  410. trigger: "change",
  411. },
  412. ],
  413. selectedPrint: [
  414. {
  415. required: false,
  416. validator: selectedPrintValidator,
  417. trigger: "change",
  418. },
  419. ],
  420. pdfTypes: [
  421. {
  422. required: true,
  423. validator: pdfTypesValidator,
  424. trigger: "change",
  425. },
  426. ],
  427. },
  428. };
  429. },
  430. mounted() {
  431. this.getTemplates();
  432. },
  433. methods: {
  434. async dialogOpened() {
  435. const data = await examConfigQuery({
  436. examId: this.exam.id,
  437. pageNumber: 1,
  438. pageSize: 10,
  439. });
  440. let val = data.records[0] || {};
  441. val.examId = this.exam.id;
  442. this.initData(val);
  443. },
  444. cancel() {
  445. this.modalIsShow = false;
  446. },
  447. open() {
  448. this.modalIsShow = true;
  449. },
  450. async getTemplates() {
  451. const data = await printPlanTemplateList();
  452. const templateSources = {};
  453. const templates = [...data.variable, ...data.ordinary];
  454. templates.forEach((item) => {
  455. templateSources[item.type] = item.template;
  456. });
  457. this.templateSources = templateSources;
  458. },
  459. initData(val) {
  460. if (val.id) {
  461. this.modalForm = this.$objAssign(deepCopy(initModalForm), val);
  462. const transformInfo = (item) => {
  463. const templateIds = item.templateId ? [item.templateId] : [];
  464. return {
  465. type: item.type,
  466. templateId: templateIds,
  467. oldTemplateId: templateIds,
  468. backupMethod: item.backupMethod,
  469. backupCount: item.backupCount,
  470. };
  471. };
  472. const initModalFormContent = deepCopy(initModalForm);
  473. const variableContent = JSON.parse(val.variableContent);
  474. const variableContentTypes = variableContent.map((item) => item.type);
  475. this.modalForm.variableContent = [];
  476. initModalFormContent.variableContent.forEach((item) => {
  477. if (variableContentTypes.includes(item.type)) {
  478. const vitem = variableContent.find(
  479. (cont) => cont.type === item.type
  480. );
  481. this.modalForm.variableContent.push(transformInfo(vitem));
  482. return;
  483. }
  484. if (this.templateSources[item.type]) {
  485. this.modalForm.variableContent.push(item);
  486. return;
  487. }
  488. });
  489. const ordinaryContent = JSON.parse(val.ordinaryContent);
  490. const ordinaryContentTypes = ordinaryContent.map((item) => item.type);
  491. this.modalForm.ordinaryContent = [];
  492. initModalFormContent.ordinaryContent.forEach((item) => {
  493. if (ordinaryContentTypes.includes(item.type)) {
  494. const vitem = ordinaryContent.find(
  495. (cont) => cont.type === item.type
  496. );
  497. this.modalForm.ordinaryContent.push(transformInfo(vitem));
  498. return;
  499. }
  500. if (this.templateSources[item.type]) {
  501. this.modalForm.ordinaryContent.push(item);
  502. return;
  503. }
  504. });
  505. this.modalForm.printContent = JSON.parse(val.printContent || "[]");
  506. this.modalForm.auditContent = JSON.parse(val.auditContent || "[]");
  507. this.modalForm.pdfTypes = JSON.parse(val.pdfTypes || "[]");
  508. } else {
  509. let modalForm = this.$objAssign(deepCopy(initModalForm), val);
  510. modalForm.variableContent = modalForm.variableContent.filter(
  511. (item) => this.templateSources[item.type]
  512. );
  513. modalForm.ordinaryContent = modalForm.ordinaryContent.filter(
  514. (item) => this.templateSources[item.type]
  515. );
  516. this.modalForm = modalForm;
  517. }
  518. if (!this.checkHasSelect()) {
  519. this.allSelected = true;
  520. this.selectAll(this.allSelected);
  521. } else {
  522. this.checkSelectAll();
  523. }
  524. },
  525. getData() {
  526. let data = deepCopy(this.modalForm);
  527. const transformInfo = (item) => {
  528. const templateId = item.templateId.join();
  529. const template = this.templateSources[item.type].find(
  530. (temp) => temp.id === templateId
  531. );
  532. return {
  533. type: item.type,
  534. templateId,
  535. attachmentId: template && template.attachmentId,
  536. backupMethod: item.backupMethod,
  537. backupCount: item.backupCount,
  538. };
  539. };
  540. data.printContent = JSON.stringify(this.modalForm.printContent);
  541. data.auditContent = JSON.stringify(this.modalForm.auditContent);
  542. data.variableContent = JSON.stringify(
  543. this.modalForm.variableContent.map(transformInfo)
  544. );
  545. data.ordinaryContent = JSON.stringify(
  546. this.modalForm.ordinaryContent.map(transformInfo)
  547. );
  548. return data;
  549. },
  550. selectAll(selected) {
  551. if (selected) {
  552. this.modalForm.printContent = Object.keys(this.PRINT_CONTENT_TYPE);
  553. this.modalForm.variableContent.forEach((item) => {
  554. if (item.templateId && item.templateId.length) return;
  555. const source = this.templateSources[item.type][0];
  556. item.templateId = source && [source.id];
  557. item.oldTemplateId = source && [source.id];
  558. });
  559. this.modalForm.ordinaryContent.forEach((item) => {
  560. if (item.templateId && item.templateId.length) return;
  561. const source = this.templateSources[item.type][0];
  562. item.templateId = source && [source.id];
  563. item.oldTemplateId = source && [source.id];
  564. });
  565. } else {
  566. this.modalForm.printContent = [];
  567. this.modalForm.variableContent.forEach((item) => {
  568. item.templateId = [];
  569. item.oldTemplateId = [];
  570. });
  571. this.modalForm.ordinaryContent.forEach((item) => {
  572. item.templateId = [];
  573. item.oldTemplateId = [];
  574. });
  575. }
  576. },
  577. checkSelectAll() {
  578. const vNotSelected = this.modalForm.variableContent.some(
  579. (item) => !item.templateId.length
  580. );
  581. const oNotSelected = this.modalForm.ordinaryContent.some(
  582. (item) => !item.templateId.length
  583. );
  584. const pNotSelected =
  585. this.modalForm.printContent.length <
  586. Object.keys(this.PRINT_CONTENT_TYPE).length;
  587. const selecteds = [vNotSelected, oNotSelected, pNotSelected];
  588. this.allSelected = !selecteds.some((item) => item);
  589. },
  590. checkHasSelect() {
  591. const vSelected = this.modalForm.variableContent.some(
  592. (item) => item.templateId.length
  593. );
  594. const oSelected = this.modalForm.ordinaryContent.some(
  595. (item) => item.templateId.length
  596. );
  597. const pSelected = !!this.modalForm.printContent.length;
  598. const selecteds = [vSelected, oSelected, pSelected];
  599. return selecteds.some((item) => item);
  600. },
  601. templateValidator(rule, value, callback) {
  602. const [field, index] = rule.field.split(".");
  603. const val = this.modalForm[field][index];
  604. if (val.templateId.length) {
  605. if (!val.backupMethod) {
  606. return callback(new Error("请选择备份方式"));
  607. }
  608. if (!val.backupCount) {
  609. return callback(new Error("请输入备份数量"));
  610. }
  611. callback();
  612. } else {
  613. callback();
  614. }
  615. },
  616. tempChange(vals, name) {
  617. const [field, index] = name.split(".");
  618. const info = this.modalForm[field][index];
  619. const newVals = vals.filter((item) => !info.oldTemplateId.includes(item));
  620. info.templateId = newVals;
  621. info.oldTemplateId = newVals;
  622. this.checkSelectAll();
  623. this.$refs.modalFormComp.validateField("selectedPrint");
  624. },
  625. async submit() {
  626. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  627. if (!valid) return;
  628. if (this.isSubmit) return;
  629. this.isSubmit = true;
  630. let datas = this.getData();
  631. const data = await updateExamConfig(datas).catch(() => {
  632. this.isSubmit = false;
  633. });
  634. if (!data) return;
  635. this.isSubmit = false;
  636. this.$message.success("编辑成功!");
  637. this.$emit("modified");
  638. this.cancel();
  639. },
  640. },
  641. };
  642. </script>