WaitTaskDetail.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. <template>
  2. <div class="wait-task-detail task-detail">
  3. <div class="task-title">
  4. <h2>
  5. <span>考试名称: {{ task.examName }} </span>
  6. <span>科目名称:{{ task.courseName }}</span>
  7. </h2>
  8. <div class="task-title-infos">
  9. <el-checkbox v-model="pTypeEnable" @change="pTypeEnableChange"
  10. >启用{{ paperTypeFieldContent }}卷</el-checkbox
  11. >
  12. </div>
  13. </div>
  14. <div class="task-body">
  15. <table class="table">
  16. <tr>
  17. <th>试卷类型</th>
  18. <th>试卷文件</th>
  19. <th>答题卡</th>
  20. </tr>
  21. <tr v-for="(attachment, index) in curPaperAttachments" :key="index">
  22. <td>{{ attachment.name }}卷</td>
  23. <td class="td-link">
  24. <span @click="toUpload(attachment)" title="点击上传试卷">
  25. <i
  26. :class="[
  27. 'icon',
  28. attachment.attachmentId ? 'icon-files-act' : 'icon-files'
  29. ]"
  30. ></i
  31. >{{
  32. attachment.attachmentId
  33. ? attachment.filename
  34. : "点击上传试卷文件"
  35. }}
  36. </span>
  37. </td>
  38. <td
  39. class="td-link"
  40. :rowspan="pTypeEnable ? curPaperAttachments.length : 1"
  41. v-if="index === 0"
  42. >
  43. <span @click="toCreateCard"
  44. ><i class="icon icon-plus-act"></i>{{ cardTodoName }}</span
  45. >
  46. </td>
  47. </tr>
  48. </table>
  49. <div class="task-action">
  50. <el-button type="primary" style="width:105px;" @click="toSubmit"
  51. >确认提交</el-button
  52. >
  53. <el-button style="width:88px;" @click="toSave">暂存</el-button>
  54. <el-button @click="goback" style="width:88px;">取消</el-button>
  55. </div>
  56. </div>
  57. <!-- upload-paper-dialog -->
  58. <upload-paper-dialog
  59. :paper-attachment="curAttachment"
  60. @confirm="uploadConfirm"
  61. ref="UploadPaperDialog"
  62. ></upload-paper-dialog>
  63. <!-- card-option-dialog -->
  64. <card-option-dialog
  65. :data="task"
  66. ref="CardOptionDialog"
  67. @confirm="cardConfirm"
  68. ></card-option-dialog>
  69. </div>
  70. </template>
  71. <script>
  72. import { waitTaskDetail, saveWaitTask, submitWaitTask } from "../api";
  73. import UploadPaperDialog from "../components/UploadPaperDialog";
  74. import CardOptionDialog from "../components/CardOptionDialog";
  75. export default {
  76. name: "wait-task-detail",
  77. components: {
  78. UploadPaperDialog,
  79. CardOptionDialog
  80. },
  81. data() {
  82. return {
  83. taskId: this.$route.params.taskId,
  84. PAPER_TYPE_FIELDS: ["A", "B"],
  85. task: {
  86. id: "",
  87. taskId: "",
  88. enablePaperType: "A",
  89. paperAttachmentId: "",
  90. cardId: "",
  91. cardSource: "",
  92. refCardId: ""
  93. },
  94. pTypeEnable: false,
  95. paperAttachments: [],
  96. curPaperAttachments: [],
  97. curAttachment: {}
  98. };
  99. },
  100. computed: {
  101. paperTypeFieldContent() {
  102. return this.PAPER_TYPE_FIELDS.join("/");
  103. },
  104. cardTodoName() {
  105. let name = "创建答题卡";
  106. if (this.task.cardId) {
  107. if (this.task.cardSource === 0) {
  108. name = "选择题卡";
  109. } else if (this.task.cardSource === 1) {
  110. name = "编辑题卡";
  111. } else {
  112. // 已经审核的题卡可以自行编辑,未审核的题卡只能查看
  113. name = this.task.auditingStatus ? "编辑题卡" : "查看题卡";
  114. }
  115. }
  116. return name;
  117. }
  118. },
  119. mounted() {
  120. this.getData();
  121. },
  122. methods: {
  123. async getData() {
  124. const data = await waitTaskDetail(this.taskId);
  125. const nameCode = data.courseNameCode.split(/\(|\)/);
  126. this.task = Object.assign(this.task, data, {
  127. courseName: nameCode[0],
  128. courseCode: nameCode[1]
  129. });
  130. this.pTypeEnable =
  131. this.task.enablePaperType &&
  132. this.task.enablePaperType.split(",").length > 1;
  133. this.parsePaperAttachment();
  134. this.pTypeEnableChange(this.pTypeEnable);
  135. this.task.enablePaperType = this.getEnablePaperType();
  136. },
  137. parsePaperAttachment() {
  138. const paperAttachment =
  139. this.task.paperAttachmentId && JSON.parse(this.task.paperAttachmentId);
  140. const papers = paperAttachment && paperAttachment.paper;
  141. let paperDict = {};
  142. if (papers) {
  143. papers.map(paper => {
  144. paperDict[paper.name] = paper;
  145. });
  146. }
  147. this.paperAttachments = this.PAPER_TYPE_FIELDS.map(paperType => {
  148. const paperInfo = paperDict[paperType];
  149. let paper = {
  150. attachmentId: "",
  151. name: paperType
  152. };
  153. return paperInfo ? Object.assign({}, paper, paperInfo) : paper;
  154. });
  155. },
  156. pTypeEnableChange(val) {
  157. this.curPaperAttachments = val
  158. ? this.paperAttachments
  159. : [this.paperAttachments[0]];
  160. },
  161. toUpload(attachment) {
  162. this.curAttachment = { ...attachment };
  163. this.$refs.UploadPaperDialog.open();
  164. },
  165. uploadConfirm(attachment) {
  166. this.curAttachment = Object.assign(this.curAttachment, attachment);
  167. const index = this.paperAttachments.findIndex(
  168. item => item.name === attachment.name
  169. );
  170. this.paperAttachments.splice(index, 1, { ...this.curAttachment });
  171. this.pTypeEnableChange(this.pTypeEnable);
  172. },
  173. toCreateCard() {
  174. if (this.task.cardId) {
  175. if (this.task.cardSource === 0) {
  176. this.$refs.CardOptionDialog.open();
  177. } else if (this.task.cardSource === 1) {
  178. this.$router.push({
  179. name: "CardDesign",
  180. params: {
  181. cardId: this.task.cardId
  182. }
  183. });
  184. } else {
  185. if (this.task.auditingStatus) {
  186. this.$router.push({
  187. name: "CardDesign",
  188. params: {
  189. cardId: this.task.cardId
  190. }
  191. });
  192. } else {
  193. window.open(`/#/card/preview/${this.task.cardId}/view`);
  194. }
  195. }
  196. return;
  197. }
  198. this.$refs.CardOptionDialog.open();
  199. },
  200. cardConfirm(options) {
  201. this.task = Object.assign(this.task, options);
  202. },
  203. getEnablePaperType() {
  204. return this.curPaperAttachments.map(item => item.name).join(",");
  205. },
  206. getTaskData() {
  207. let datas = { ...this.task };
  208. datas.taskId = this.taskId;
  209. datas.paperAttachmentId = JSON.stringify({
  210. paper: this.curPaperAttachments
  211. });
  212. datas.enablePaperType = this.getEnablePaperType();
  213. return { tcPExamTaskDetail: datas };
  214. },
  215. checkDataValid() {
  216. const attachmentValid = !this.curPaperAttachments.some(
  217. item => !item.attachmentId
  218. );
  219. if (!attachmentValid) {
  220. this.$message.error("请完成试卷文件上传!");
  221. return;
  222. }
  223. if (!this.task.cardId) {
  224. this.$message.error("请选择题卡创建方式!");
  225. return;
  226. }
  227. return true;
  228. },
  229. toSubmit() {
  230. this.$confirm(
  231. "任务确定提交后,则不可更改试卷及答题卡内容,确定提交该任务?",
  232. "提示",
  233. {
  234. confirmButtonText: "确定",
  235. cancelButtonText: "取消",
  236. type: "warning"
  237. }
  238. ).then(async () => {
  239. if (!this.checkDataValid()) return;
  240. await submitWaitTask(this.getTaskData());
  241. this.$message.success("提交成功!");
  242. this.goback();
  243. });
  244. },
  245. async toSave() {
  246. await saveWaitTask(this.getTaskData());
  247. this.$message.success("保存成功!");
  248. this.goback();
  249. }
  250. }
  251. };
  252. </script>