ModifyPrintPlan.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. <template>
  2. <el-dialog
  3. class="modify-print-plan"
  4. :visible.sync="modalIsShow"
  5. :title="title"
  6. top="10px"
  7. width="700px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="visibleChange"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. label-width="110px"
  16. :rules="rules"
  17. :model="modalForm"
  18. >
  19. <div class="part-box part-box-pad part-box-border">
  20. <h4 class="part-box-tips">基本信息:</h4>
  21. <el-form-item prop="name" label="印刷计划名称:">
  22. <el-input
  23. v-model.trim="modalForm.name"
  24. clearable
  25. placeholder="请输入"
  26. :disabled="!editable"
  27. ></el-input>
  28. </el-form-item>
  29. <el-form-item prop="examStartTime" label="考试时间:">
  30. <el-date-picker
  31. v-model="createTime"
  32. type="datetimerange"
  33. range-separator="至"
  34. start-placeholder="开始日期"
  35. end-placeholder="结束日期"
  36. value-format="timestamp"
  37. align="right"
  38. unlink-panels
  39. :disabled="!editable"
  40. @change="dateChange"
  41. >
  42. </el-date-picker>
  43. </el-form-item>
  44. </div>
  45. <div class="part-box part-box-pad part-box-border">
  46. <h4 class="part-box-tips">试卷&题卡印品:</h4>
  47. <el-form-item prop="printContent" label="试卷、题卡:">
  48. <el-checkbox-group
  49. v-model="modalForm.printContent"
  50. :disabled="!editable"
  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. prop="backupMethod"
  62. label="试卷备份方式:"
  63. :required="!!modalForm.printContent.length"
  64. >
  65. <el-select
  66. v-model="modalForm.backupMethod"
  67. class="mr-2"
  68. size="small"
  69. placeholder="请选择"
  70. :disabled="!editable"
  71. >
  72. <el-option
  73. v-for="(val, key) in PAPER_BACKUP_TYPE"
  74. :key="key"
  75. :value="key"
  76. :label="val"
  77. ></el-option>
  78. </el-select>
  79. <el-input-number
  80. class="mr-1"
  81. v-model="modalForm.backupCount"
  82. size="small"
  83. :min="1"
  84. :max="200"
  85. :step="1"
  86. step-strictly
  87. :controls="false"
  88. :disabled="!editable"
  89. ></el-input-number>
  90. <span>份</span>
  91. </el-form-item>
  92. <el-form-item
  93. prop="drawRule"
  94. label="抽卷规则:"
  95. :required="!!modalForm.printContent.length"
  96. >
  97. <el-radio-group v-model="modalForm.drawRule" :disabled="!editable">
  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. <p class="tips-info">
  106. 1.只抽取一次:不同印刷计划下,同一试卷编号下的卷型只能被抽取一次;
  107. </p>
  108. <p class="tips-info">
  109. 2.可反复抽取:不同印刷计划下,同一试卷编号下的卷型可重复抽取,系统默认优先抽取未曝光卷型。
  110. </p>
  111. </el-form-item>
  112. </div>
  113. <div class="part-box part-box-pad part-box-border">
  114. <h4 class="part-box-tips">变量印品:</h4>
  115. <el-form-item
  116. v-for="(item, index) in modalForm.variableContent"
  117. :key="item.type"
  118. :label="`${TEMPLATE_CLASSIFY[item.type]}:`"
  119. :prop="`variableContent.${index}.templateId`"
  120. :rules="{
  121. required: false,
  122. validator: templateValidator,
  123. trigger: 'change'
  124. }"
  125. :required="!!item.templateId.length"
  126. >
  127. <el-checkbox-group
  128. v-model="item.templateId"
  129. :disabled="!editable"
  130. @change="vals => tempChange(vals, `variableContent.${index}`)"
  131. >
  132. <el-checkbox
  133. v-for="temp in templateSources[item.type]"
  134. :label="temp.id"
  135. :key="temp.id"
  136. >{{ temp.name }}</el-checkbox
  137. >
  138. </el-checkbox-group>
  139. <el-select
  140. v-model="item.backupMethod"
  141. class="mr-2"
  142. size="small"
  143. placeholder="请选择"
  144. :disabled="!editable"
  145. >
  146. <el-option
  147. v-for="(val, key) in PRINT_BACKUP_TYPE"
  148. :key="key"
  149. :value="key"
  150. :label="val"
  151. ></el-option>
  152. </el-select>
  153. <el-input-number
  154. v-model="item.backupCount"
  155. class="mr-1"
  156. size="small"
  157. :min="1"
  158. :max="200"
  159. :step="1"
  160. step-strictly
  161. :controls="false"
  162. :disabled="!editable"
  163. ></el-input-number>
  164. <span>份</span>
  165. </el-form-item>
  166. </div>
  167. <div class="part-box part-box-pad part-box-border">
  168. <h4 class="part-box-tips">普通印品:</h4>
  169. <el-form-item
  170. v-for="(item, index) in modalForm.ordinaryContent"
  171. :key="item.type"
  172. :label="`${TEMPLATE_CLASSIFY[item.type]}:`"
  173. label-width="130px"
  174. :prop="`ordinaryContent.${index}.templateId`"
  175. :rules="{
  176. required: false,
  177. validator: templateValidator,
  178. trigger: 'change'
  179. }"
  180. :required="!!item.templateId.length"
  181. >
  182. <el-checkbox-group
  183. v-model="item.templateId"
  184. :disabled="!editable"
  185. @change="vals => tempChange(vals, `ordinaryContent.${index}`)"
  186. >
  187. <el-checkbox
  188. v-for="temp in templateSources[item.type]"
  189. :label="temp.id"
  190. :key="temp.id"
  191. >{{ temp.name }}</el-checkbox
  192. >
  193. </el-checkbox-group>
  194. <el-select
  195. v-model="item.backupMethod"
  196. class="mr-2"
  197. size="small"
  198. placeholder="请选择"
  199. :disabled="!editable"
  200. >
  201. <el-option
  202. v-for="(val, key) in PRINT_BACKUP_TYPE"
  203. :key="key"
  204. :value="key"
  205. :label="val"
  206. ></el-option>
  207. </el-select>
  208. <el-input-number
  209. v-model="item.backupCount"
  210. class="mr-1"
  211. size="small"
  212. :min="1"
  213. :max="200"
  214. :step="1"
  215. step-strictly
  216. :controls="false"
  217. :disabled="!editable"
  218. ></el-input-number>
  219. <span>份</span>
  220. </el-form-item>
  221. </div>
  222. <el-form-item prop="selectedPrint"></el-form-item>
  223. </el-form>
  224. <div slot="footer">
  225. <el-button
  226. v-if="editable"
  227. type="primary"
  228. :disabled="isSubmit"
  229. @click="submit"
  230. >确认</el-button
  231. >
  232. <el-button type="danger" @click="cancel" plain>取消</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. } from "@/constants/enumerate";
  244. // import { deepCopy } from "@/plugins/utils";
  245. import { updatePrintPlan, printPlanTemplateList } from "../api";
  246. const initModalForm = {
  247. id: null,
  248. name: "",
  249. examStartTime: "",
  250. examEndTime: "",
  251. printContent: [],
  252. backupMethod: "PLACE",
  253. backupCount: 1,
  254. drawRule: "ONE",
  255. variableContent: [
  256. {
  257. type: "SIGN",
  258. templateId: [],
  259. oldTemplateId: [],
  260. backupMethod: "ROOM",
  261. backupCount: 1
  262. },
  263. {
  264. type: "PACKAGE",
  265. templateId: [],
  266. oldTemplateId: [],
  267. backupMethod: "STUDENT",
  268. backupCount: 1
  269. }
  270. ],
  271. ordinaryContent: [
  272. {
  273. type: "CHECK_IN",
  274. templateId: [],
  275. oldTemplateId: [],
  276. backupMethod: "ROOM",
  277. backupCount: 1
  278. }
  279. ]
  280. };
  281. export default {
  282. name: "modify-print-plan",
  283. props: {
  284. instance: {
  285. type: Object,
  286. default() {
  287. return {};
  288. }
  289. },
  290. editType: {
  291. type: String,
  292. default: "ADD",
  293. validator: val => ["ADD", "PREVIEW", "EDIT"].includes(val)
  294. }
  295. },
  296. computed: {
  297. isEdit() {
  298. return !!this.instance.id;
  299. },
  300. title() {
  301. const names = {
  302. ADD: "新增印刷计划",
  303. PREVIEW: "印刷计划详情",
  304. EDIT: "编辑印刷计划"
  305. };
  306. return names[this.editType];
  307. },
  308. editable() {
  309. return this.editType !== "PREVIEW";
  310. }
  311. },
  312. data() {
  313. const printContentValidator = (rule, value, callback) => {
  314. if (value.includes("PAPER") && !value.includes("CARD")) {
  315. callback(new Error("选择了试卷,同时必须选择题卡"));
  316. } else {
  317. callback();
  318. }
  319. };
  320. const backupMethodValidator = (rule, value, callback) => {
  321. if (!this.modalForm.printContent.length) {
  322. return callback();
  323. }
  324. if (!value) {
  325. return callback(new Error("请选择备份方式"));
  326. }
  327. if (!this.modalForm.backupCount) {
  328. return callback(new Error("请输入备份数量"));
  329. }
  330. callback();
  331. };
  332. const selectedPrintValidator = (rule, value, callback) => {
  333. const printInfo = [
  334. ...this.modalForm.variableContent,
  335. ...this.modalForm.ordinaryContent
  336. ];
  337. const hasPrintInfo = printInfo.some(item => item.templateId.length);
  338. if (hasPrintInfo || this.modalForm.printContent.length) {
  339. callback();
  340. } else {
  341. callback(new Error("必须选择一项印品"));
  342. }
  343. };
  344. return {
  345. modalIsShow: false,
  346. isSubmit: false,
  347. modalForm: { ...initModalForm },
  348. createTime: [],
  349. PRINT_CONTENT_TYPE,
  350. DRAW_RULE_TYPE,
  351. PRINT_BACKUP_TYPE,
  352. PAPER_BACKUP_TYPE,
  353. TEMPLATE_CLASSIFY,
  354. variableContent: [],
  355. ordinaryContent: [],
  356. templateSources: {},
  357. rules: {
  358. name: [
  359. {
  360. required: true,
  361. message: "请输入印刷计划名称,长度不要超过100个字符",
  362. max: 100,
  363. trigger: "change"
  364. }
  365. ],
  366. examStartTime: [
  367. {
  368. required: true,
  369. message: "请设置考试时间",
  370. trigger: "change"
  371. }
  372. ],
  373. printContent: [
  374. {
  375. required: false,
  376. validator: printContentValidator,
  377. trigger: "change"
  378. }
  379. ],
  380. backupMethod: [
  381. {
  382. required: false,
  383. validator: backupMethodValidator,
  384. trigger: "change"
  385. }
  386. ],
  387. drawRule: [
  388. {
  389. required: false,
  390. message: "请选择抽卷规则",
  391. trigger: "change"
  392. }
  393. ],
  394. selectedPrint: [
  395. {
  396. required: false,
  397. validator: selectedPrintValidator,
  398. trigger: "change"
  399. }
  400. ]
  401. }
  402. };
  403. },
  404. mounted() {
  405. this.getTemplates();
  406. },
  407. methods: {
  408. async getTemplates() {
  409. const data = await printPlanTemplateList();
  410. const templateSources = {};
  411. const templates = [...data.variable, ...data.ordinary];
  412. templates.forEach(item => {
  413. templateSources[item.type] = item.template;
  414. });
  415. this.templateSources = templateSources;
  416. },
  417. templateValidator(rule, value, callback) {
  418. const [field, index] = rule.field.split(".");
  419. const val = this.modalForm[field][index];
  420. if (val.templateId.length) {
  421. if (!val.backupMethod) {
  422. return callback(new Error("请选择备份方式"));
  423. }
  424. if (!val.backupCount) {
  425. return callback(new Error("请输入备份数量"));
  426. }
  427. callback();
  428. } else {
  429. callback();
  430. }
  431. },
  432. tempChange(vals, name) {
  433. const [field, index] = name.split(".");
  434. const info = this.modalForm[field][index];
  435. const newVals = vals.filter(item => !info.oldTemplateId.includes(item));
  436. info.templateId = newVals;
  437. info.oldTemplateId = newVals;
  438. this.$refs.modalFormComp.validateField("selectedPrint");
  439. },
  440. initData(val) {
  441. if (val.id) {
  442. this.createTime = [val.examStartTime, val.examEndTime];
  443. this.modalForm = this.$objAssign(initModalForm, val);
  444. const transformInfo = item => {
  445. return {
  446. type: item.type,
  447. templateId: [item.templateId],
  448. oldTemplateId: [item.templateId],
  449. backupMethod: item.backupMethod,
  450. backupCount: item.backupCount
  451. };
  452. };
  453. this.modalForm.variableContent = val.variableContent.map(transformInfo);
  454. this.modalForm.ordinaryContent = val.ordinaryContent.map(transformInfo);
  455. this.modalForm.printContent = val.printContent
  456. ? val.printContent.split(",")
  457. : [];
  458. } else {
  459. this.modalForm = { ...initModalForm };
  460. this.createTime = [];
  461. }
  462. },
  463. visibleChange() {
  464. this.initData(this.instance);
  465. this.$nextTick(() => {
  466. this.$refs.modalFormComp.clearValidate();
  467. });
  468. },
  469. cancel() {
  470. this.modalIsShow = false;
  471. },
  472. open() {
  473. this.modalIsShow = true;
  474. },
  475. dateChange() {
  476. if (this.createTime) {
  477. this.modalForm.examStartTime = this.createTime[0];
  478. this.modalForm.examEndTime = this.createTime[1];
  479. } else {
  480. this.modalForm.examStartTime = "";
  481. this.modalForm.examEndTime = "";
  482. }
  483. },
  484. async submit() {
  485. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  486. if (!valid) return;
  487. if (this.isSubmit) return;
  488. this.isSubmit = true;
  489. const datas = { ...this.modalForm };
  490. const transformInfo = item => {
  491. return {
  492. type: item.type,
  493. templateId: item.templateId.join(),
  494. backupMethod: item.backupMethod,
  495. backupCount: item.backupCount
  496. };
  497. };
  498. datas.variableContent = JSON.stringify(
  499. this.modalForm.variableContent.map(transformInfo)
  500. );
  501. datas.ordinaryContent = JSON.stringify(
  502. this.modalForm.ordinaryContent.map(transformInfo)
  503. );
  504. const data = await updatePrintPlan(datas).catch(() => {});
  505. this.isSubmit = false;
  506. if (!data) return;
  507. this.$message.success("保存成功!");
  508. this.$emit("modified");
  509. this.cancel();
  510. }
  511. }
  512. };
  513. </script>