UploadSamplePaperDialog.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <el-dialog
  3. class="upload-sample-paper-dialog"
  4. :visible.sync="modalIsShow"
  5. title="上传样卷或试卷结构文件"
  6. top="10vh"
  7. width="560px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @opened="visibleChange"
  12. >
  13. <div class="file-upload-body">
  14. <el-form
  15. ref="ModalForm"
  16. :model="modalForm"
  17. :rules="rules"
  18. label-width="85px"
  19. label-position="left"
  20. >
  21. <el-form-item prop="title" label="文件标题:">
  22. <el-input
  23. style="width:386px"
  24. v-model.trim="modalForm.title"
  25. placeholder="请输入文件标题"
  26. ></el-input>
  27. </el-form-item>
  28. <el-form-item prop="paperAttachmentId">
  29. <upload-button
  30. btn-icon="icon icon-upload"
  31. btn-type="default"
  32. btn-content="选择上传文件"
  33. :upload-url="uploadUrl"
  34. :format="format"
  35. :max-size="maxSize"
  36. :upload-data="uploadData"
  37. @upload-error="uplaodError"
  38. @upload-success="uploadSuccess"
  39. style="margin: 0;"
  40. ></upload-button>
  41. <span style="margin-left: 10px;"
  42. >上传的单个试卷文件大小不超过20M</span
  43. >
  44. </el-form-item>
  45. </el-form>
  46. </div>
  47. <div slot="footer" style="text-align: right;">
  48. <el-button type="primary" :disabled="isSubmit" @click="confirm"
  49. >确定</el-button
  50. >
  51. <el-button @click="cancel">返回</el-button>
  52. </div>
  53. </el-dialog>
  54. </template>
  55. <script>
  56. import UploadButton from "@/components/UploadButton";
  57. import { createCard, saveWaitTask } from "../api";
  58. export default {
  59. name: "upload-sample-paper-dialog",
  60. props: {
  61. data: {
  62. type: Object,
  63. default() {
  64. return {};
  65. }
  66. }
  67. },
  68. components: { UploadButton },
  69. data() {
  70. return {
  71. modalIsShow: false,
  72. modalForm: {
  73. title: "",
  74. cardSource: "2",
  75. paperAttachmentId: ""
  76. },
  77. rules: {
  78. title: [
  79. {
  80. required: true,
  81. message: "请输入文件标题",
  82. trigger: "change"
  83. }
  84. ],
  85. paperAttachmentId: [
  86. {
  87. required: true,
  88. message: "请上传样卷或试卷结构文件",
  89. trigger: "change"
  90. }
  91. ]
  92. },
  93. isSubmit: false,
  94. // upload
  95. format: [],
  96. uploadData: {
  97. schoolId: this.$ls.get("schoolId"),
  98. userId: this.$ls.get("user", { id: "" }).id
  99. },
  100. maxSize: 20 * 1024 * 1024,
  101. uploadUrl: "/api/print/basic/sys/saveAttachment"
  102. };
  103. },
  104. methods: {
  105. visibleChange() {
  106. this.modalForm.title = "";
  107. this.modalForm.cardSource = this.data.cardSource;
  108. this.modalForm.paperAttachmentId = "";
  109. },
  110. uplaodError(msg) {
  111. this.$message.error(msg);
  112. },
  113. uploadSuccess(res) {
  114. this.$message.success("上传成功!");
  115. this.modalForm.paperAttachmentId = res.data.id;
  116. this.$refs["ModalForm"].validateField("paperAttachmentId");
  117. },
  118. cancel() {
  119. this.modalIsShow = false;
  120. },
  121. open() {
  122. this.modalIsShow = true;
  123. },
  124. async confirm() {
  125. const valid = await this.$refs["ModalForm"].validate().catch(() => {});
  126. if (!valid) return;
  127. if (this.isSubmit) return;
  128. this.isSubmit = true;
  129. const datas = {
  130. tcPCard: this.modalForm
  131. };
  132. const data = await createCard(datas).catch(() => {});
  133. this.isSubmit = false;
  134. if (!data) return;
  135. // 自助创建时暂存任务
  136. if (this.data.taskId && this.data.cardSource === "2") {
  137. await saveWaitTask({
  138. tcPExamTaskDetail: {
  139. ...this.data,
  140. cardId: data.cardId,
  141. paperAttachmentId: this.modalForm.paperAttachmentId
  142. }
  143. });
  144. }
  145. this.$message.success("申请成功!");
  146. this.$emit("confirm");
  147. this.cancel();
  148. }
  149. }
  150. };
  151. </script>