ModifyExamConfigDetail.vue 20 KB

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