ModifyTaskPaper.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425
  1. <template>
  2. <div class="modify-task-paper">
  3. <el-dialog
  4. class="task-detail"
  5. :visible.sync="modalIsShow"
  6. :title="title"
  7. top="10vh"
  8. width="900px"
  9. :close-on-click-modal="false"
  10. :close-on-press-escape="false"
  11. append-to-body
  12. @open="visibleChange"
  13. >
  14. <div class="part-box part-box-pad part-box-border">
  15. <el-form class="form-info" label-width="100px">
  16. <el-row>
  17. <el-col :span="12">
  18. <el-form-item label="试卷编号:">
  19. <span>{{ instance.paperNumber }}</span>
  20. </el-form-item>
  21. </el-col>
  22. <el-col :span="12">
  23. <el-form-item label="课程(代码):">
  24. <span>
  25. {{ instance.courseName }}({{ instance.courseCode }})
  26. </span>
  27. </el-form-item>
  28. </el-col>
  29. </el-row>
  30. <el-row>
  31. <el-col :span="12">
  32. <el-form-item label="卷型:">
  33. <span>{{ instance.paperType }}</span>
  34. </el-form-item>
  35. </el-col>
  36. <el-col :span="12">
  37. <el-form-item label="命题老师:">
  38. <span>{{ instance.userName }}</span>
  39. </el-form-item>
  40. </el-col>
  41. </el-row>
  42. <el-row>
  43. <el-col :span="12">
  44. <el-form-item label="已曝光:">
  45. <span>{{
  46. instance.exposedPaperType | defaultFieldFilter
  47. }}</span>
  48. </el-form-item>
  49. </el-col>
  50. <el-col :span="12">
  51. <el-form-item label="未曝光:">
  52. <span>{{
  53. instance.unexposedPaperType | defaultFieldFilter
  54. }}</span>
  55. </el-form-item>
  56. </el-col>
  57. </el-row>
  58. </el-form>
  59. </div>
  60. <div class="part-box part-box-pad part-box-border">
  61. <div v-if="IS_EDIT" class="mb-2 text-right">
  62. <el-button
  63. type="primary"
  64. icon="el-icon-circle-plus-outline"
  65. @click="addAtachment"
  66. >增加卷型</el-button
  67. >
  68. </div>
  69. <table class="table">
  70. <tr>
  71. <th>试卷类型</th>
  72. <th>试卷文件</th>
  73. <th>答题卡</th>
  74. <th v-if="IS_EDIT">操作</th>
  75. </tr>
  76. <tr v-for="(attachment, index) in paperAttachments" :key="index">
  77. <td>{{ attachment.name }}卷</td>
  78. <td class="td-link">
  79. <span
  80. v-if="attachment.editable && IS_EDIT"
  81. @click="toUpload(attachment)"
  82. title="点击上传试卷"
  83. >
  84. <i
  85. :class="[
  86. 'icon',
  87. attachment.attachmentId ? 'icon-files-act' : 'icon-files'
  88. ]"
  89. ></i
  90. >{{
  91. attachment.attachmentId
  92. ? attachment.filename
  93. : "点击上传试卷文件"
  94. }}
  95. </span>
  96. <span
  97. v-else
  98. @click="downloadPaper(attachment)"
  99. title="点击查看试卷"
  100. >
  101. <i
  102. class="icon icon-download-act"
  103. v-if="attachment.attachmentId"
  104. ></i>
  105. <i>{{ attachment.filename }}</i>
  106. </span>
  107. </td>
  108. <td
  109. class="td-link"
  110. :rowspan="paperAttachments.length"
  111. v-if="index === 0"
  112. >
  113. <span v-if="CAN_EDIT_CARD" @click="toCreateOrViewCard"
  114. ><i class="icon icon-plus-act"></i>{{ cardTodoName }}</span
  115. >
  116. <span v-else @click="toViewCard">
  117. <i class="icon icon-circle-right"></i>
  118. <i>查看题卡</i>
  119. </span>
  120. </td>
  121. <td v-if="IS_EDIT">
  122. <el-button
  123. v-if="attachment.editable"
  124. class="btn-primary"
  125. type="text"
  126. icon="icon icon-delete"
  127. title="删除"
  128. @click="deleteAttachment(index)"
  129. ></el-button>
  130. </td>
  131. </tr>
  132. </table>
  133. </div>
  134. <div slot="footer">
  135. <el-button
  136. v-if="IS_EDIT"
  137. type="primary"
  138. :disabled="isSubmit"
  139. @click="submit"
  140. >确认提交</el-button
  141. >
  142. <el-button @click="cancel">取消</el-button>
  143. </div>
  144. </el-dialog>
  145. <!-- upload-paper-dialog -->
  146. <upload-paper-dialog
  147. :paper-attachment="curAttachment"
  148. :upload-type="curUploadType"
  149. @confirm="uploadConfirm"
  150. ref="UploadPaperDialog"
  151. ></upload-paper-dialog>
  152. <!-- card-option-dialog -->
  153. <card-option-dialog
  154. ref="CardOptionDialog"
  155. :data="curTaskApply"
  156. @confirm="cardConfirm"
  157. ></card-option-dialog>
  158. </div>
  159. </template>
  160. <script>
  161. import UploadPaperDialog from "./UploadPaperDialog";
  162. import CardOptionDialog from "./CardOptionDialog";
  163. import { taskApplyDetail, taskPaperApplyEdit } from "../api";
  164. import { attachmentPreview } from "../../login/api";
  165. import { examRuleDetail } from "../../base/api";
  166. const initTaskApply = {
  167. examTaskId: "",
  168. paperType: "A",
  169. paperAttachmentIds: "",
  170. cardId: "",
  171. cardRuleId: "",
  172. makeMethod: "",
  173. courseCode: "",
  174. courseName: "",
  175. // 题卡状态
  176. status: "",
  177. // 考务规则
  178. includePaper: false,
  179. customCard: false
  180. };
  181. export default {
  182. name: "preview-task-paper",
  183. components: { UploadPaperDialog, CardOptionDialog },
  184. props: {
  185. instance: {
  186. type: Object,
  187. default() {
  188. return {};
  189. }
  190. },
  191. editType: {
  192. type: String,
  193. default: "PREVIEW",
  194. validator: val => ["EDIT", "PREVIEW"].includes(val)
  195. }
  196. },
  197. computed: {
  198. title() {
  199. const names = {
  200. EDIT: "申请编辑卷库",
  201. PREVIEW: "卷库详情"
  202. };
  203. return names[this.editType];
  204. },
  205. IS_PREVIEW() {
  206. return this.editType === "PREVIEW";
  207. },
  208. IS_EDIT() {
  209. return this.editType === "EDIT";
  210. },
  211. CAN_EDIT_CARD() {
  212. return this.editType === "EDIT" && !this.instance.exposedPaperType;
  213. },
  214. cardTodoName() {
  215. let name = "查看题卡";
  216. if (this.CAN_EDIT_CARD) {
  217. if (this.curTaskApply.makeMethod === "SELECT") {
  218. name = "选择题卡";
  219. } else {
  220. name = "编辑题卡";
  221. }
  222. }
  223. return name;
  224. }
  225. },
  226. data() {
  227. return {
  228. isSubmit: false,
  229. modalIsShow: false,
  230. curTaskApply: { ...initTaskApply },
  231. paperAttachments: [],
  232. paperConfirmAttachments: [],
  233. curAttachment: {},
  234. curUploadType: "paper",
  235. abc: "abcdefghijklmnopqrstuvwxyz".toUpperCase(),
  236. includePaper: false
  237. };
  238. },
  239. created() {
  240. this.getExamRule();
  241. },
  242. methods: {
  243. async getExamRule() {
  244. const examRule = await examRuleDetail();
  245. this.includePaper = examRule && examRule.includePaper;
  246. },
  247. async visibleChange() {
  248. const data = await taskApplyDetail(this.instance.id);
  249. this.curTaskApply = this.$objAssign(initTaskApply, data || {});
  250. this.curTaskApply.courseCode = this.instance.courseCode;
  251. this.curTaskApply.courseName = this.instance.courseName;
  252. this.curTaskApply.cardRuleId = this.instance.cardRuleId;
  253. this.curTaskApply.includePaper = this.includePaper;
  254. this.paperAttachments = data.paperAttachmentIds
  255. ? JSON.parse(data.paperAttachmentIds)
  256. : [];
  257. const exposedPaperType = this.instance.exposedPaperType || "";
  258. this.paperAttachments.forEach(paper => {
  259. paper.editable = !exposedPaperType.includes(paper.name);
  260. });
  261. },
  262. cancel() {
  263. this.modalIsShow = false;
  264. },
  265. open() {
  266. this.modalIsShow = true;
  267. },
  268. addAtachment() {
  269. if (this.paperAttachments.length >= this.abc.length) return;
  270. const paperType = this.paperAttachments.map(item => item.name);
  271. const name = this.abc.split("").find(code => !paperType.includes(code));
  272. const newAttachment = {
  273. name,
  274. attachmentId: "",
  275. filename: "",
  276. pages: 0,
  277. editable: true
  278. };
  279. this.paperAttachments.push(newAttachment);
  280. this.paperAttachments.sort((a, b) => (a.name < b.name ? -1 : 1));
  281. },
  282. deleteAttachment(index) {
  283. if (this.paperAttachments.length <= 1) {
  284. this.$message.error("试卷类型数量不得少于1");
  285. return;
  286. }
  287. this.paperAttachments.splice(index, 1);
  288. },
  289. toUpload(attachment) {
  290. this.curUploadType = "paper";
  291. this.curAttachment = {
  292. ...attachment
  293. };
  294. this.$refs.UploadPaperDialog.open();
  295. },
  296. uploadConfirm(attachment, uploadType) {
  297. if (uploadType === "paper") {
  298. const index = this.paperAttachments.findIndex(
  299. item => item.name === attachment.name
  300. );
  301. this.paperAttachments.splice(index, 1, { ...attachment });
  302. }
  303. },
  304. async downloadPaper(attachment) {
  305. if (!attachment.attachmentId) return;
  306. const data = await attachmentPreview(attachment.attachmentId);
  307. window.open(data.url);
  308. },
  309. toViewCard() {
  310. window.open(
  311. this.getRouterPath({
  312. name: "CardPreview",
  313. params: {
  314. cardId: this.curTaskApply.cardId,
  315. viewType: "view"
  316. }
  317. })
  318. );
  319. },
  320. toEditCard() {
  321. this.cachePrepareTcpCard();
  322. this.$router.push({
  323. name: "CardDesign",
  324. params: {
  325. cardId: this.curTaskApply.cardId
  326. }
  327. });
  328. },
  329. cachePrepareTcpCard() {
  330. this.$ls.set("prepareTcPCard", {
  331. examTaskId: this.curTaskApply.examTaskId,
  332. courseCode: this.curTaskApply.courseCode,
  333. courseName: this.curTaskApply.courseName,
  334. makeMethod: this.curTaskApply.makeMethod,
  335. cardRuleId: this.curTaskApply.cardRuleId,
  336. paperType: this.paperAttachments.map(item => item.name).join(",")
  337. });
  338. },
  339. async toCreateOrViewCard() {
  340. this.task = this.getTaskData();
  341. if (this.CAN_EDIT_CARD) {
  342. if (this.curTaskApply.makeMethod === "SELECT") {
  343. this.$refs.CardOptionDialog.open();
  344. } else {
  345. this.toEditCard();
  346. }
  347. } else {
  348. this.toViewCard();
  349. }
  350. },
  351. cardConfirm(data) {
  352. this.curTaskApply = this.$objAssign(this.curTaskApply, data);
  353. },
  354. getTaskData() {
  355. let data = { ...this.curTaskApply };
  356. return data;
  357. },
  358. checkDataValid() {
  359. // 校验试卷类型是否连续
  360. const lastPaperName = this.paperAttachments.slice(-1)[0].name;
  361. const paperLength = this.abc.indexOf(lastPaperName) + 1;
  362. if (this.paperAttachments.length !== paperLength) {
  363. this.$message.error("请保持试卷类型连续!");
  364. return;
  365. }
  366. const attachmentValid = !this.paperAttachments.some(
  367. item => !item.attachmentId
  368. );
  369. // 设置了入库强制包含试卷时,校验试卷是否上传。
  370. if (this.curTaskApply.includePaper && !attachmentValid) {
  371. this.$message.error("请完成试卷文件上传!");
  372. return;
  373. }
  374. if (!this.curTaskApply.cardId) {
  375. this.$message.error("请选择题卡创建方式!");
  376. return;
  377. }
  378. if (
  379. this.curTaskApply.makeMethod !== "SELECT" &&
  380. this.curTaskApply.status !== "SUBMIT"
  381. ) {
  382. this.$message.error("请先提交题卡!");
  383. return;
  384. }
  385. return true;
  386. },
  387. async submit() {
  388. if (!this.checkDataValid()) return;
  389. this.$confirm("确定要提交申请修改当前任务吗?", "提示", {
  390. type: "warning"
  391. })
  392. .then(async () => {
  393. const datas = {
  394. examTaskId: this.curTaskApply.examTaskId,
  395. cardId: this.curTaskApply.cardId,
  396. paperType: this.paperAttachments.map(item => item.name).join(","),
  397. paperAttachmentIds: JSON.stringify(this.paperAttachments, (k, v) =>
  398. k === "editable" || k === "url" ? undefined : v
  399. )
  400. };
  401. const data = await taskPaperApplyEdit(datas).catch(() => {});
  402. if (!data) return;
  403. this.$message.success("提交成功!");
  404. this.$emit("modified");
  405. this.cancel();
  406. })
  407. .catch(() => {});
  408. }
  409. }
  410. };
  411. </script>