ModifyExamConfigDetail.vue 18 KB

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