123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- <template>
- <el-dialog
- class="merge-push-dialog"
- :visible.sync="modalIsShow"
- title="批量合并印刷任务"
- top="10vh"
- width="448px"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- append-to-body
- @open="visibleChange"
- >
- <div class="mb-4">
- <p class="tips-info">
- 1、此操作会将多个印刷计划合并,合并操作不可还原,是否继续合并操作?
- </p>
- <p class="tips-info">
- 2、如果确定需要合并,请填写合并后考试名称及对应考试ID,然后点击确定按钮。
- </p>
- </div>
- <div class="mb-4 tab-btns">
- <el-button
- v-for="(val, key) in EXAM_TYPE"
- :key="key"
- :type="examType == key ? 'primary' : 'default'"
- @click="selectMenu(key)"
- >{{ val }}</el-button
- >
- </div>
- <el-form
- v-if="examType === '0'"
- ref="modalFormComp"
- :model="modalForm"
- :rules="rules"
- label-position="top"
- >
- <el-form-item label="考试ID:">
- <el-input
- v-model.trim="modalForm.thirdRelateId"
- placeholder="请输入考试ID"
- clearable
- @input="thirdRelateIdChange"
- ></el-input>
- </el-form-item>
- <el-form-item label="考试名称:">
- <el-input
- v-model.trim="modalForm.thirdRelateName"
- placeholder="请输入考试名称"
- clearable
- :disabled="!canEditThirdRelateName"
- ></el-input>
- </el-form-item>
- <el-form-item prop="thirdRelate"></el-form-item>
- </el-form>
- <el-form
- v-else
- ref="modalFormComp"
- :model="modalForm"
- :rules="rules1"
- label-position="top"
- >
- <el-form-item prop="thirdRelateId" label="考试ID:">
- <el-select
- v-model="modalForm.thirdRelateId"
- placeholder="请选择"
- filterable
- style="width:100%"
- >
- <el-option
- v-for="(item, index) in exams"
- :key="index"
- :value="item.thirdRelateId"
- :label="item.thirdRelateName"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </el-form>
- <div slot="footer">
- <el-button type="primary" :disabled="isSubmit" @click="submit"
- >确认</el-button
- >
- <el-button @click="cancel">取消</el-button>
- </div>
- </el-dialog>
- </template>
- <script>
- import { printPlanMergePush, printPlanSyncExamList } from "../api";
- const initModalForm = {
- thirdRelateId: "",
- thirdRelateName: ""
- };
- export default {
- name: "merge-push-dialog",
- props: {
- ids: {
- type: Array,
- default() {
- return [];
- }
- }
- },
- data() {
- const thirdRelateValidator = (rule, value, callback) => {
- if (!this.modalForm.thirdRelateId && !this.modalForm.thirdRelateName) {
- return callback(new Error(`考试ID和名称至少填一项。`));
- }
- if (
- this.modalForm.thirdRelateId &&
- this.modalForm.thirdRelateId.length > 50
- ) {
- return callback(new Error("考试ID长度不能超过50"));
- }
- if (
- this.modalForm.thirdRelateName &&
- this.modalForm.thirdRelateName.length > 50
- ) {
- return callback(new Error("考试名称长度不能超过50"));
- }
- return callback();
- };
- return {
- modalIsShow: false,
- isSubmit: false,
- exams: [],
- canEditThirdRelateName: true,
- modalForm: { ...initModalForm },
- rules: {
- thirdRelate: [
- {
- required: true,
- validator: thirdRelateValidator,
- trigger: "change"
- }
- ]
- },
- rules1: {
- thirdRelateId: [
- {
- required: true,
- message: "请选择考试ID",
- trigger: "change"
- }
- ]
- },
- examType: "0",
- EXAM_TYPE: {
- 0: "未同步考试",
- 1: "已同步考试"
- }
- };
- },
- methods: {
- initData(val) {
- this.modalForm = { ...initModalForm };
- this.$nextTick(() => {
- this.$refs.modalFormComp.clearValidate();
- });
- },
- visibleChange() {
- this.initData(this.instance);
- this.getExamList();
- },
- async getExamList() {
- const data = await printPlanSyncExamList();
- this.exams = data || [];
- },
- thirdRelateIdChange() {
- const exam = this.exams.find(
- exam => this.modalForm.thirdRelateId === exam.thirdRelateId
- );
- if (!exam) {
- this.modalForm.thirdRelateName = "";
- this.canEditThirdRelateName = true;
- return;
- }
- this.modalForm.thirdRelateName = exam.thirdRelateName;
- this.canEditThirdRelateName = false;
- },
- selectMenu(val) {
- this.examType = val;
- this.modalForm = { ...initModalForm };
- },
- cancel() {
- this.modalIsShow = false;
- },
- open() {
- this.modalIsShow = true;
- },
- async submit() {
- const valid = await this.$refs.modalFormComp.validate().catch(() => {});
- if (!valid) return;
- if (this.isSubmit) return;
- this.isSubmit = true;
- const data = await printPlanMergePush({
- ...this.modalForm,
- list: this.ids
- }).catch(() => {
- this.isSubmit = false;
- });
- if (!data) return;
- this.isSubmit = false;
- this.$message.success("提交成功!");
- this.$emit("modified");
- this.cancel();
- }
- }
- };
- </script>
|