zhangjie 4 lat temu
rodzic
commit
3e9b52e250

+ 3 - 0
src/modules/exam/api.js

@@ -90,6 +90,9 @@ export const taskPaperListPage = datas => {
 export const ableTaskPaper = ({ id, enable }) => {
   return $post("/api/admin/exam/task/paper_enable", { id, enable });
 };
+export const taskPaperApplyEdit = datas => {
+  return $post("/api/admin/exam/task/paper_update", datas);
+};
 export const downloadPaper = examTaskId => {
   return $postParam(
     "/api/admin/exam/task/paper_download",

+ 10 - 10
src/modules/exam/components/ApplyContent.vue

@@ -44,7 +44,10 @@
               @click="downloadPaper(attachment)"
               title="点击查看试卷"
             >
-              <i class="icon icon-download-act"></i>
+              <i
+                class="icon icon-download-act"
+                v-if="attachment.attachmentId"
+              ></i>
               <i>{{ attachment.filename }}</i>
             </span>
           </td>
@@ -177,7 +180,6 @@
     <card-option-dialog
       ref="CardOptionDialog"
       :data="task"
-      :exam-rule="examRule"
       @upload-sample-over="initData"
       @draft-task="silentSave"
       @confirm="cardConfirm"
@@ -232,12 +234,6 @@ export default {
       type: String,
       default: "APPLY",
       validator: val => ["APPLY", "PREVIEW", "AUDIT"].includes(val)
-    },
-    examRule: {
-      type: Object,
-      default() {
-        return {};
-      }
     }
   },
   data() {
@@ -407,6 +403,7 @@ export default {
       this.$emit("cancel");
     },
     async downloadPaper(attachment) {
+      if (!attachment.attachmentId) return;
       const data = await attachmentPreview(attachment.attachmentId);
       window.open(data.url);
     },
@@ -416,9 +413,12 @@ export default {
     getTaskData() {
       let data = { ...this.curTaskApply };
       data.paperType = this.paperAttachments.map(item => item.name).join(",");
-      data.paperAttachmentIds = JSON.stringify(this.paperAttachments);
+      data.paperAttachmentIds = JSON.stringify(this.paperAttachments, (k, v) =>
+        k === "url" ? undefined : v
+      );
       data.paperConfirmAttachmentIds = JSON.stringify(
-        this.paperConfirmAttachments
+        this.paperConfirmAttachments,
+        (k, v) => (k === "url" ? undefined : v)
       );
       return data;
     },

+ 0 - 1
src/modules/exam/components/ModifyTaskApply.vue

@@ -106,7 +106,6 @@
         ref="ApplyContent"
         :exam-task="modalForm"
         :edit-type="editType"
-        :exam-rule="examRule"
         @cancel="cancel"
         @modified="modified"
       ></apply-content>

+ 264 - 67
src/modules/exam/components/ModifyTaskPaper.vue

@@ -1,62 +1,145 @@
 <template>
-  <el-dialog
-    class="modify-task-paper task-detail"
-    :visible.sync="modalIsShow"
-    :title="title"
-    top="10vh"
-    width="900px"
-    :close-on-click-modal="false"
-    :close-on-press-escape="false"
-    append-to-body
-    @open="visibleChange"
-  >
-    <div class="part-box part-box-pad part-box-border">
-      <div v-if="IS_EDIT" class="mb-2 text-right">
+  <div class="modify-task-paper">
+    <el-dialog
+      class="task-detail"
+      :visible.sync="modalIsShow"
+      :title="title"
+      top="10vh"
+      width="900px"
+      :close-on-click-modal="false"
+      :close-on-press-escape="false"
+      append-to-body
+      @open="visibleChange"
+    >
+      <div class="part-box part-box-pad part-box-border">
+        <div v-if="IS_EDIT" class="mb-2 text-right">
+          <el-button
+            type="primary"
+            icon="el-icon-circle-plus-outline"
+            @click="addAtachment"
+            >增加卷型</el-button
+          >
+        </div>
+        <table class="table">
+          <tr>
+            <th>试卷类型</th>
+            <th>试卷文件</th>
+            <th>答题卡</th>
+            <th v-if="IS_EDIT">操作</th>
+          </tr>
+          <tr v-for="(attachment, index) in paperAttachments" :key="index">
+            <td>{{ attachment.name }}卷</td>
+            <td class="td-link">
+              <span
+                v-if="attachment.editable && IS_EDIT"
+                @click="toUpload(attachment)"
+                title="点击上传试卷"
+              >
+                <i
+                  :class="[
+                    'icon',
+                    attachment.attachmentId ? 'icon-files-act' : 'icon-files'
+                  ]"
+                ></i
+                >{{
+                  attachment.attachmentId
+                    ? attachment.filename
+                    : "点击上传试卷文件"
+                }}
+              </span>
+              <span
+                v-else
+                @click="downloadPaper(attachment)"
+                title="点击查看试卷"
+              >
+                <i
+                  class="icon icon-download-act"
+                  v-if="attachment.attachmentId"
+                ></i>
+                <i>{{ attachment.filename }}</i>
+              </span>
+            </td>
+            <td
+              class="td-link"
+              :rowspan="paperAttachments.length"
+              v-if="index === 0"
+            >
+              <span v-if="CAN_EDIT_CARD" @click="toCreateOrViewCard"
+                ><i class="icon icon-plus-act"></i>{{ cardTodoName }}</span
+              >
+              <span v-else @click="toViewCard">
+                <i class="icon icon-circle-right"></i>
+                <i>查看题卡</i>
+              </span>
+            </td>
+            <td v-if="IS_EDIT">
+              <el-button
+                v-if="attachment.editable"
+                class="btn-table-icon"
+                type="text"
+                icon="icon icon-delete"
+                title="删除"
+                @click="deleteAttachment(index)"
+              ></el-button>
+            </td>
+          </tr>
+        </table>
+      </div>
+
+      <div slot="footer">
         <el-button
+          v-if="IS_EDIT"
           type="primary"
-          icon="el-icon-circle-plus-outline"
-          @click="addAtachment"
-          >增加卷型</el-button
+          :disabled="isSubmit"
+          @click="submit"
+          >确认提交</el-button
         >
+        <el-button type="danger" @click="cancel" plain>取消</el-button>
       </div>
-      <table class="table">
-        <tr>
-          <th>试卷类型</th>
-          <th>试卷文件</th>
-          <th>答题卡</th>
-        </tr>
-        <tr v-for="(attachment, index) in paperAttachments" :key="index">
-          <td>{{ attachment.name }}卷</td>
-          <td class="td-link">
-            <span @click="downloadPaper(attachment)" title="点击下载试卷">
-              <i class="icon icon-download-act"></i>
-              <i>{{ attachment.filename }}</i>
-            </span>
-          </td>
-          <td
-            class="td-link"
-            :rowspan="paperAttachments.length"
-            v-if="index === 0"
-          >
-            <span @click="toViewCard">
-              <i class="icon icon-circle-right"></i>
-              <i>查看题卡</i>
-            </span>
-          </td>
-        </tr>
-      </table>
-    </div>
+    </el-dialog>
 
-    <div slot="footer"></div>
-  </el-dialog>
+    <!-- upload-paper-dialog -->
+    <upload-paper-dialog
+      :paper-attachment="curAttachment"
+      :upload-type="curUploadType"
+      @confirm="uploadConfirm"
+      ref="UploadPaperDialog"
+    ></upload-paper-dialog>
+    <!-- card-option-dialog -->
+    <card-option-dialog
+      ref="CardOptionDialog"
+      :data="curTaskApply"
+      @confirm="cardConfirm"
+    ></card-option-dialog>
+  </div>
 </template>
 
 <script>
-import { taskApplyDetail } from "../api";
+import UploadPaperDialog from "./UploadPaperDialog";
+import CardOptionDialog from "./CardOptionDialog";
+import { taskApplyDetail, taskPaperApplyEdit } from "../api";
 import { attachmentPreview } from "../../login/api";
+import { examRuleDetail } from "../../base/api";
+
+const initTaskApply = {
+  examTaskId: "",
+  paperType: "A",
+  paperAttachmentIds: "",
+  cardId: "",
+  cardRuleId: "",
+  makeMethod: "",
+  courseCode: "",
+  courseName: "",
+  // 题卡状态
+  status: "",
+  // 考务规则 TODO:
+  includePaper: false,
+  customCard: false
+};
 
 export default {
   name: "preview-task-paper",
+  components: { UploadPaperDialog, CardOptionDialog },
   props: {
     instance: {
       type: Object,
@@ -73,7 +156,7 @@ export default {
   computed: {
     title() {
       const names = {
-        EDIT: "编辑卷库",
+        EDIT: "申请编辑卷库",
         PREVIEW: "卷库详情"
       };
       return names[this.editType];
@@ -86,22 +169,54 @@ export default {
     },
     CAN_EDIT_CARD() {
       return this.editType === "EDIT" && !this.instance.exposedPaperType;
+    },
+    cardTodoName() {
+      let name = "查看题卡";
+      if (this.CAN_EDIT_CARD) {
+        if (this.curTaskApply.makeMethod === "SELECT") {
+          name = "选择题卡";
+        } else {
+          name = "编辑题卡";
+        }
+      }
+      return name;
     }
   },
   data() {
     return {
+      isSubmit: false,
       modalIsShow: false,
-      cardId: "",
-      paperAttachments: []
+      curTaskApply: { ...initTaskApply },
+      paperAttachments: [],
+      paperConfirmAttachments: [],
+      curAttachment: {},
+      curUploadType: "paper",
+      abc: "abcdefghijklmnopqrstuvwxyz".toUpperCase(),
+      includePaper: false
     };
   },
+  created() {
+    this.getExamRule();
+  },
   methods: {
+    async getExamRule() {
+      const examRule = await examRuleDetail();
+      this.includePaper = examRule && examRule.includePaper;
+    },
     async visibleChange() {
       const data = await taskApplyDetail(this.instance.id);
-      this.cardId = data.cardId;
+      this.curTaskApply = this.$objAssign(initTaskApply, data || {});
+      this.curTaskApply.courseCode = this.instance.courseCode;
+      this.curTaskApply.courseName = this.instance.courseName;
+      this.curTaskApply.cardRuleId = this.instance.cardRuleId;
+      this.curTaskApply.includePaper = this.includePaper;
       this.paperAttachments = data.paperAttachmentIds
         ? JSON.parse(data.paperAttachmentIds)
         : [];
+      const exposedPaperType = this.instance.exposedPaperType || "";
+      this.paperAttachments.forEach(paper => {
+        paper.editable = !exposedPaperType.includes(paper.name);
+      });
     },
     cancel() {
       this.modalIsShow = false;
@@ -110,15 +225,21 @@ export default {
       this.modalIsShow = true;
     },
     addAtachment() {
-      if (this.paperAttachments.length >= this.attachmentLimitCount) return;
+      if (this.paperAttachments.length >= this.abc.length) return;
+
+      const paperType = this.paperAttachments.map(item => item.name);
+      const name = this.abc.split("").find(code => !paperType.includes(code));
 
       const newAttachment = {
-        name: this.abc[this.paperAttachments.length],
+        name,
         attachmentId: "",
         filename: "",
-        pages: 0
+        pages: 0,
+        editable: true
       };
       this.paperAttachments.push(newAttachment);
+
+      this.paperAttachments.sort((a, b) => (a.name < b.name ? -1 : 1));
     },
     deleteAttachment(index) {
       if (this.paperAttachments.length <= 1) {
@@ -126,9 +247,6 @@ export default {
         return;
       }
       this.paperAttachments.splice(index, 1);
-      this.paperAttachments.forEach((item, itemIndex) => {
-        item.name = this.abc[itemIndex];
-      });
     },
     toUpload(attachment) {
       this.curUploadType = "paper";
@@ -137,25 +255,16 @@ export default {
       };
       this.$refs.UploadPaperDialog.open();
     },
-    toUploadPaperConfirm() {
-      if (this.paperConfirmAttachments.length >= 4) return;
-      this.curUploadType = "paperConfirm";
-      this.curAttachment = {
-        ...this.paperConfirmAttachmentId
-      };
-      this.$refs.UploadPaperDialog.open();
-    },
     uploadConfirm(attachment, uploadType) {
       if (uploadType === "paper") {
         const index = this.paperAttachments.findIndex(
           item => item.name === attachment.name
         );
         this.paperAttachments.splice(index, 1, { ...attachment });
-      } else {
-        this.paperConfirmAttachments.push(attachment);
       }
     },
     async downloadPaper(attachment) {
+      if (!attachment.attachmentId) return;
       const data = await attachmentPreview(attachment.attachmentId);
       window.open(data.url);
     },
@@ -164,11 +273,99 @@ export default {
         this.getRouterPath({
           name: "CardPreview",
           params: {
-            cardId: this.cardId,
+            cardId: this.curTaskApply.cardId,
             viewType: "view"
           }
         })
       );
+    },
+    toEditCard() {
+      this.cachePrepareTcpCard();
+      this.$router.push({
+        name: "CardDesign",
+        params: {
+          cardId: this.curTaskApply.cardId
+        }
+      });
+    },
+    cachePrepareTcpCard() {
+      this.$ls.set("prepareTcPCard", {
+        examTaskId: this.curTaskApply.examTaskId,
+        courseCode: this.curTaskApply.courseCode,
+        courseName: this.curTaskApply.courseName,
+        makeMethod: this.curTaskApply.makeMethod,
+        cardRuleId: this.curTaskApply.cardRuleId,
+        paperType: this.paperAttachments.map(item => item.name).join(",")
+      });
+    },
+    async toCreateOrViewCard() {
+      this.task = this.getTaskData();
+      if (this.CAN_EDIT_CARD) {
+        if (this.curTaskApply.makeMethod === "SELECT") {
+          this.$refs.CardOptionDialog.open();
+        } else {
+          this.toEditCard();
+        }
+      } else {
+        this.toViewCard();
+      }
+    },
+    cardConfirm(data) {
+      this.curTaskApply = this.$objAssign(this.curTaskApply, data);
+    },
+    getTaskData() {
+      let data = { ...this.curTaskApply };
+
+      return data;
+    },
+    checkDataValid() {
+      const attachmentValid = !this.paperAttachments.some(
+        item => !item.attachmentId
+      );
+      // 设置了入库强制包含试卷时,校验试卷是否上传。
+      if (this.curTaskApply.includePaper && !attachmentValid) {
+        this.$message.error("请完成试卷文件上传!");
+        return;
+      }
+
+      if (!this.curTaskApply.cardId) {
+        this.$message.error("请选择题卡创建方式!");
+        return;
+      }
+
+      if (
+        this.curTaskApply.makeMethod !== "SELECT" &&
+        this.curTaskApply.status !== "SUBMIT"
+      ) {
+        this.$message.error("请先提交题卡!");
+        return;
+      }
+      return true;
+    },
+    async submit() {
+      if (!this.checkDataValid()) return;
+
+      this.$confirm("确定要提交申请修改当前任务吗?", "提示", {
+        cancelButtonClass: "el-button--danger is-plain",
+        confirmButtonClass: "el-button--primary",
+        type: "warning"
+      })
+        .then(async () => {
+          const datas = {
+            examTaskId: this.curTaskApply.examTaskId,
+            cardId: this.curTaskApply.cardId,
+            paperType: this.paperAttachments.map(item => item.name).join(","),
+            paperAttachmentIds: JSON.stringify(this.paperAttachments, (k, v) =>
+              k === "editable" || k === "url" ? undefined : v
+            )
+          };
+          const data = await taskPaperApplyEdit(datas).catch(() => {});
+          if (!data) return;
+          this.$message.success("提交成功!");
+          this.$emit("modified");
+          this.cancel();
+        })
+        .catch(() => {});
     }
   }
 };

+ 2 - 1
src/modules/exam/views/TaskPaperManage.vue

@@ -104,7 +104,7 @@
               title="查看"
             ></el-button>
             <el-button
-              v-if="!scope.row.auditStatus && !scope.row.reviewStatus"
+              v-if="IS_QUESTION_TEACHER"
               class="btn-table-icon"
               type="text"
               icon="icon icon-edit"
@@ -153,6 +153,7 @@
       :instance="curPaper"
       :edit-type="editType"
       ref="ModifyTaskPaper"
+      @modified="getList"
     ></modify-task-paper>
   </div>
 </template>