CreateExamAndPrintTask.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. <template>
  2. <el-dialog
  3. class="create-exam-and-print-task"
  4. :visible.sync="modalIsShow"
  5. :close-on-click-modal="false"
  6. :close-on-press-escape="false"
  7. :show-close="false"
  8. append-to-body
  9. fullscreen
  10. @open="visibleChange"
  11. >
  12. <div slot="title">
  13. <span class="el-dialog__title">新增命题申请</span>
  14. </div>
  15. <el-steps
  16. class="apply-step"
  17. :active="current"
  18. align-center
  19. finish-status="success"
  20. >
  21. <el-step v-for="step in steps" :key="step.name" :title="step.title">
  22. </el-step>
  23. </el-steps>
  24. <div class="apply-body" v-if="dataReady">
  25. <component
  26. :is="currentComponent"
  27. :ref="currentComponent"
  28. :datas="infos"
  29. @next-step="toNext"
  30. @on-ready="compReady"
  31. @data-change="dataChange"
  32. ></component>
  33. </div>
  34. <div class="text-center">
  35. <el-button
  36. v-if="!isFirstStep"
  37. type="primary"
  38. :disabled="loading"
  39. @click="prevStep"
  40. >上一步</el-button
  41. >
  42. <el-button
  43. v-if="isLastStep"
  44. type="success"
  45. :disabled="loading"
  46. @click="nextStep"
  47. >确认提交</el-button
  48. >
  49. <el-button v-else type="primary" @click="nextStep" :disabled="loading"
  50. >下一步</el-button
  51. >
  52. <el-button @click="cancel">取消</el-button>
  53. </div>
  54. <div slot="footer"></div>
  55. </el-dialog>
  56. </template>
  57. <script>
  58. import { examRuleDetail } from "../../../base/api";
  59. import { teacherSubmitTaskApply } from "../../api";
  60. import { printPlanTemplateList } from "../../../print/api";
  61. import InfoPrintPlan from "./InfoPrintPlan";
  62. import InfoExamTask from "./InfoExamTask";
  63. import InfoPrintTask from "./InfoPrintTask";
  64. import { COMMON_CARD_RULE_ID } from "@/constants/enumerate";
  65. import { deepCopy } from "@/plugins/utils";
  66. const STEPS_LIST = [
  67. {
  68. name: "exam-task",
  69. title: "命题信息"
  70. },
  71. {
  72. name: "print-plan",
  73. title: "备卷印品信息"
  74. },
  75. {
  76. name: "print-task",
  77. title: "考务信息"
  78. }
  79. ];
  80. const initExamTask = {
  81. courseCode: "",
  82. courseName: "",
  83. paperNumber: "",
  84. cardRuleId: COMMON_CARD_RULE_ID,
  85. teachingRoomId: "",
  86. teacherName: "",
  87. paperName: ""
  88. };
  89. const initExamTaskDetail = {
  90. operateType: "STAGE",
  91. paperType: "A",
  92. cardId: "",
  93. paperAttachmentIds: "[]",
  94. paperConfirmAttachmentIds: "[]",
  95. drawCount: 2,
  96. remark: "",
  97. makeMethod: "SELECT",
  98. // 题卡状态
  99. status: "",
  100. // 考务规则
  101. review: false,
  102. includePaper: false,
  103. customCard: false
  104. };
  105. const initPrintPlan = {
  106. name: "",
  107. examStartTime: "",
  108. examEndTime: "",
  109. printContent: [],
  110. backupMethod: "ROOM",
  111. backupCount: 1,
  112. drawRule: "ONE",
  113. templateSources: {},
  114. variableContent: [
  115. {
  116. type: "SIGN",
  117. templateId: "",
  118. oldTemplateId: "",
  119. backupMethod: "ROOM",
  120. backupCount: 1
  121. },
  122. {
  123. type: "PACKAGE",
  124. templateId: "",
  125. oldTemplateId: "",
  126. backupMethod: "ROOM",
  127. backupCount: 1
  128. }
  129. ],
  130. ordinaryContent: [
  131. {
  132. type: "CHECK_IN",
  133. templateId: "",
  134. oldTemplateId: "",
  135. backupMethod: "ROOM",
  136. backupCount: 1
  137. }
  138. ]
  139. };
  140. const initPrintTask = {
  141. examStartTime: "",
  142. examEndTime: "",
  143. paperNumber: "",
  144. courseName: "",
  145. courseCode: "",
  146. list: []
  147. };
  148. export default {
  149. name: "create-exam-and-print-task",
  150. components: { InfoPrintPlan, InfoExamTask, InfoPrintTask },
  151. data() {
  152. return {
  153. modalIsShow: false,
  154. needReview: false,
  155. examRule: {},
  156. infos: {},
  157. templateSources: {},
  158. // step
  159. steps: STEPS_LIST,
  160. current: 0,
  161. loading: false,
  162. dataReady: false
  163. };
  164. },
  165. computed: {
  166. currentComponent() {
  167. return `info-${this.steps[this.current].name}`;
  168. },
  169. isFirstStep() {
  170. return this.current === 0;
  171. },
  172. isLastStep() {
  173. return this.current === this.lastStep;
  174. },
  175. lastStep() {
  176. return this.steps.length - 1;
  177. }
  178. },
  179. methods: {
  180. async getExamRule() {
  181. const examRule = await examRuleDetail();
  182. this.examRule = examRule || {};
  183. this.needReview = examRule && examRule.review;
  184. },
  185. async getTemplates() {
  186. const data = await printPlanTemplateList();
  187. const templateSources = {};
  188. const templates = [...data.variable, ...data.ordinary];
  189. templates.forEach(item => {
  190. templateSources[item.type] = item.template;
  191. });
  192. this.templateSources = templateSources;
  193. },
  194. async initData() {
  195. await this.getExamRule();
  196. await this.getTemplates();
  197. const examTaskDetail = Object.assign({}, initExamTaskDetail, {
  198. includePaper: this.examRule.includePaper,
  199. review: this.examRule.review,
  200. customCard: this.examRule.customCard
  201. });
  202. // printPlan
  203. let printPlan = deepCopy(initPrintPlan);
  204. printPlan.variableContent = printPlan.variableContent.filter(
  205. item => this.templateSources[item.type]
  206. );
  207. printPlan.ordinaryContent = printPlan.ordinaryContent.filter(
  208. item => this.templateSources[item.type]
  209. );
  210. printPlan.templateSources = this.templateSources;
  211. this.infos = {
  212. examTask: { ...initExamTask },
  213. examTaskDetail,
  214. printPlan,
  215. printTask: { ...initPrintTask }
  216. };
  217. this.dataReady = true;
  218. },
  219. visibleChange() {
  220. this.dataReady = false;
  221. this.current = 0;
  222. this.loading = false;
  223. this.initData();
  224. },
  225. prevStep() {
  226. if (this.isFirstStep) return;
  227. this.$refs[this.currentComponent].updateData();
  228. this.current -= 1;
  229. },
  230. nextStep() {
  231. this.loading = true;
  232. this.$refs[this.currentComponent].checkData();
  233. },
  234. toNext() {
  235. if (this.isLastStep) {
  236. this.submit();
  237. } else {
  238. this.current += 1;
  239. }
  240. },
  241. dataChange(data) {
  242. console.log(data);
  243. Object.entries(data).forEach(([key, val]) => {
  244. this.infos[key] = Object.assign(this.infos[key], val);
  245. });
  246. },
  247. compReady(type = false) {
  248. this.loading = type;
  249. },
  250. async cancel() {
  251. const result = await this.$confirm("确定取消该任务?", "提示", {
  252. type: "warning"
  253. }).catch(() => {});
  254. if (result !== "confirm") return;
  255. this.close();
  256. },
  257. close() {
  258. this.modalIsShow = false;
  259. },
  260. open() {
  261. this.modalIsShow = true;
  262. },
  263. async submit() {
  264. const result = await this.$confirm("确定提交该任务?", "提示", {
  265. type: "warning"
  266. }).catch(() => {});
  267. if (result !== "confirm") {
  268. this.loading = false;
  269. return;
  270. }
  271. let examPrintPlan = deepCopy(this.infos.printPlan);
  272. delete examPrintPlan.templateSources;
  273. examPrintPlan.variableContent = JSON.stringify(
  274. examPrintPlan.variableContent
  275. );
  276. examPrintPlan.ordinaryContent = JSON.stringify(
  277. examPrintPlan.ordinaryContent
  278. );
  279. const examTaskContent = {
  280. examTask: this.infos.examTask,
  281. examTaskDetail: this.infos.examTaskDetail,
  282. examPrintPlan,
  283. examDetail: this.infos.printTask
  284. };
  285. const data = await teacherSubmitTaskApply({
  286. examTaskContent: JSON.stringify(examTaskContent)
  287. }).catch(() => {});
  288. this.loading = false;
  289. if (!data) return;
  290. this.$message.success("提交成功!");
  291. this.close();
  292. this.$emit("modified");
  293. }
  294. }
  295. };
  296. </script>