MergePushDialog.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <el-dialog
  3. class="merge-push-dialog"
  4. :visible.sync="modalIsShow"
  5. title="批量合并印刷任务"
  6. top="10vh"
  7. width="448px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="visibleChange"
  12. >
  13. <div class="mb-4">
  14. <p class="tips-info">
  15. 1、此操作会将多个印刷计划合并,合并操作不可还原,是否继续合并操作?
  16. </p>
  17. <p class="tips-info">
  18. 2、如果确定需要合并,请填写合并后考试名称及对应考试ID,然后点击确定按钮。
  19. </p>
  20. </div>
  21. <div class="mb-4 tab-btns">
  22. <el-button
  23. v-for="(val, key) in EXAM_TYPE"
  24. :key="key"
  25. :type="examType == key ? 'primary' : 'default'"
  26. @click="selectMenu(key)"
  27. >{{ val }}</el-button
  28. >
  29. </div>
  30. <el-form
  31. v-if="examType === '0'"
  32. ref="modalFormComp"
  33. :model="modalForm"
  34. :rules="rules"
  35. label-position="top"
  36. >
  37. <el-form-item label="考试ID:">
  38. <el-input
  39. v-model.trim="modalForm.thirdRelateId"
  40. placeholder="请输入考试ID"
  41. clearable
  42. @input="thirdRelateIdChange"
  43. ></el-input>
  44. </el-form-item>
  45. <el-form-item label="考试名称:">
  46. <el-input
  47. v-model.trim="modalForm.thirdRelateName"
  48. placeholder="请输入考试名称"
  49. clearable
  50. :disabled="!canEditThirdRelateName"
  51. ></el-input>
  52. </el-form-item>
  53. <el-form-item prop="thirdRelate"></el-form-item>
  54. </el-form>
  55. <el-form
  56. v-else
  57. ref="modalFormComp"
  58. :model="modalForm"
  59. :rules="rules1"
  60. label-position="top"
  61. >
  62. <el-form-item prop="thirdRelateId" label="考试ID:">
  63. <el-select
  64. v-model="modalForm.thirdRelateId"
  65. placeholder="请选择"
  66. filterable
  67. style="width:100%"
  68. >
  69. <el-option
  70. v-for="(item, index) in exams"
  71. :key="index"
  72. :value="item.thirdRelateId"
  73. :label="item.thirdRelateName"
  74. >
  75. </el-option>
  76. </el-select>
  77. </el-form-item>
  78. </el-form>
  79. <div slot="footer">
  80. <el-button type="primary" :disabled="isSubmit" @click="submit"
  81. >确认</el-button
  82. >
  83. <el-button @click="cancel">取消</el-button>
  84. </div>
  85. </el-dialog>
  86. </template>
  87. <script>
  88. import { printPlanMergePush, printPlanSyncExamList } from "../api";
  89. const initModalForm = {
  90. thirdRelateId: "",
  91. thirdRelateName: ""
  92. };
  93. export default {
  94. name: "merge-push-dialog",
  95. props: {
  96. ids: {
  97. type: Array,
  98. default() {
  99. return [];
  100. }
  101. }
  102. },
  103. data() {
  104. const thirdRelateValidator = (rule, value, callback) => {
  105. if (!this.modalForm.thirdRelateId && !this.modalForm.thirdRelateName) {
  106. return callback(new Error(`考试ID和名称至少填一项。`));
  107. }
  108. if (
  109. this.modalForm.thirdRelateId &&
  110. this.modalForm.thirdRelateId.length > 50
  111. ) {
  112. return callback(new Error("考试ID长度不能超过50"));
  113. }
  114. if (
  115. this.modalForm.thirdRelateName &&
  116. this.modalForm.thirdRelateName.length > 50
  117. ) {
  118. return callback(new Error("考试名称长度不能超过50"));
  119. }
  120. return callback();
  121. };
  122. return {
  123. modalIsShow: false,
  124. isSubmit: false,
  125. exams: [],
  126. canEditThirdRelateName: true,
  127. modalForm: { ...initModalForm },
  128. rules: {
  129. thirdRelate: [
  130. {
  131. required: true,
  132. validator: thirdRelateValidator,
  133. trigger: "change"
  134. }
  135. ]
  136. },
  137. rules1: {
  138. thirdRelateId: [
  139. {
  140. required: true,
  141. message: "请选择考试ID",
  142. trigger: "change"
  143. }
  144. ]
  145. },
  146. examType: "0",
  147. EXAM_TYPE: {
  148. 0: "未同步考试",
  149. 1: "已同步考试"
  150. }
  151. };
  152. },
  153. methods: {
  154. initData(val) {
  155. this.modalForm = { ...initModalForm };
  156. this.$nextTick(() => {
  157. this.$refs.modalFormComp.clearValidate();
  158. });
  159. },
  160. visibleChange() {
  161. this.initData(this.instance);
  162. this.getExamList();
  163. },
  164. async getExamList() {
  165. const data = await printPlanSyncExamList();
  166. this.exams = data || [];
  167. },
  168. thirdRelateIdChange() {
  169. const exam = this.exams.find(
  170. exam => this.modalForm.thirdRelateId === exam.thirdRelateId
  171. );
  172. if (!exam) {
  173. this.modalForm.thirdRelateName = "";
  174. this.canEditThirdRelateName = true;
  175. return;
  176. }
  177. this.modalForm.thirdRelateName = exam.thirdRelateName;
  178. this.canEditThirdRelateName = false;
  179. },
  180. selectMenu(val) {
  181. this.examType = val;
  182. this.modalForm = { ...initModalForm };
  183. },
  184. cancel() {
  185. this.modalIsShow = false;
  186. },
  187. open() {
  188. this.modalIsShow = true;
  189. },
  190. async submit() {
  191. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  192. if (!valid) return;
  193. if (this.isSubmit) return;
  194. this.isSubmit = true;
  195. const data = await printPlanMergePush({
  196. ...this.modalForm,
  197. list: this.ids
  198. }).catch(() => {
  199. this.isSubmit = false;
  200. });
  201. if (!data) return;
  202. this.isSubmit = false;
  203. this.$message.success("提交成功!");
  204. this.$emit("modified");
  205. this.cancel();
  206. }
  207. }
  208. };
  209. </script>