123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- <template>
- <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">
- <el-form class="form-info" label-width="100px">
- <el-row>
- <el-col :span="12">
- <el-form-item label="试卷编号:">
- <span>{{ instance.paperNumber }}</span>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="课程(代码):">
- <span>
- {{ instance.courseName }}({{ instance.courseCode }})
- </span>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="12">
- <el-form-item label="卷型:">
- <span>{{ instance.paperType }}</span>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="命题老师:">
- <span>{{ instance.userName }}</span>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row>
- <el-col :span="12">
- <el-form-item label="已曝光:">
- <span>{{
- instance.exposedPaperType | defaultFieldFilter
- }}</span>
- </el-form-item>
- </el-col>
- <el-col :span="12">
- <el-form-item label="未曝光:">
- <span>{{
- instance.unexposedPaperType | defaultFieldFilter
- }}</span>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- </div>
- <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-primary"
- 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"
- :disabled="isSubmit"
- @click="submit"
- >确认提交</el-button
- >
- <el-button @click="cancel">取消</el-button>
- </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 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: "",
- // 考务规则
- includePaper: false,
- customCard: false
- };
- export default {
- name: "preview-task-paper",
- components: { UploadPaperDialog, CardOptionDialog },
- props: {
- instance: {
- type: Object,
- default() {
- return {};
- }
- },
- editType: {
- type: String,
- default: "PREVIEW",
- validator: val => ["EDIT", "PREVIEW"].includes(val)
- }
- },
- computed: {
- title() {
- const names = {
- EDIT: "申请编辑卷库",
- PREVIEW: "卷库详情"
- };
- return names[this.editType];
- },
- IS_PREVIEW() {
- return this.editType === "PREVIEW";
- },
- IS_EDIT() {
- return this.editType === "EDIT";
- },
- 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,
- 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.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;
- },
- open() {
- this.modalIsShow = true;
- },
- addAtachment() {
- 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,
- attachmentId: "",
- filename: "",
- 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) {
- this.$message.error("试卷类型数量不得少于1");
- return;
- }
- this.paperAttachments.splice(index, 1);
- },
- toUpload(attachment) {
- this.curUploadType = "paper";
- this.curAttachment = {
- ...attachment
- };
- 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 });
- }
- },
- async downloadPaper(attachment) {
- if (!attachment.attachmentId) return;
- const data = await attachmentPreview(attachment.attachmentId);
- window.open(data.url);
- },
- toViewCard() {
- window.open(
- this.getRouterPath({
- name: "CardPreview",
- params: {
- 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 lastPaperName = this.paperAttachments.slice(-1)[0].name;
- const paperLength = this.abc.indexOf(lastPaperName) + 1;
- if (this.paperAttachments.length !== paperLength) {
- this.$message.error("请保持试卷类型连续!");
- return;
- }
- 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("确定要提交申请修改当前任务吗?", "提示", {
- 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(() => {});
- }
- }
- };
- </script>
|