BatchAddExamTask.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <el-dialog
  3. class="batch-add-exam-task"
  4. :visible.sync="modalIsShow"
  5. title="批量新建命题任务"
  6. top="10vh"
  7. width="800px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="visibleChange"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. :model="modalForm"
  16. :rules="rules"
  17. label-position="top"
  18. >
  19. <el-form-item prop="batchNo" label="命题任务表:">
  20. <upload-file-view
  21. :upload-url="uploadExamTaskUrl"
  22. @upload-success="uploadExamTaskSuccess"
  23. ref="ExamTaskUploadFileView"
  24. v-if="modalIsShow"
  25. ></upload-file-view>
  26. <el-button
  27. type="success"
  28. icon="el-icon-download"
  29. style="margin-left:10px;"
  30. >
  31. <a :href="downloadUrl" download="命题任务导入模板.xlsx">模板下载</a>
  32. </el-button>
  33. </el-form-item>
  34. <el-form-item prop="startTime" label="命题时间:">
  35. <el-date-picker
  36. v-model="createTime"
  37. type="datetimerange"
  38. range-separator="至"
  39. start-placeholder="开始时间"
  40. end-placeholder="结束时间"
  41. value-format="timestamp"
  42. align="right"
  43. unlink-panels
  44. @change="dateChange"
  45. >
  46. </el-date-picker>
  47. </el-form-item>
  48. <el-form-item prop="cardRuleId" label="题卡规则:">
  49. <card-rule-select
  50. ref="CardRuleSelect"
  51. v-model.trim="modalForm.cardRuleId"
  52. placeholder="请选择"
  53. clearable
  54. ></card-rule-select>
  55. <p class="tips-info">
  56. 说明:若选择全部通卡,则命题老师只能选择通卡,若选择题卡规则,则专卡和通卡均可选择
  57. </p>
  58. </el-form-item>
  59. <el-form-item label="指派命题老师:">
  60. <el-table class="el-table--noback" :data="tasks" border>
  61. <el-table-column prop="courseName" label="课程(代码)">
  62. <span slot-scope="scope">
  63. {{ scope.row.courseName }}({{ scope.row.courseCode }})
  64. </span>
  65. </el-table-column>
  66. <el-table-column prop="paperNumber" label="试卷编号">
  67. <template slot-scope="scope">
  68. {{ scope.row.paperNumber | defaultFieldFilter }}
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="命题老师" width="180px">
  72. <template slot-scope="scope">
  73. <el-select
  74. v-model="scope.row.userId"
  75. size="small"
  76. style="width: 150px;"
  77. placeholder="请选择"
  78. clearable
  79. >
  80. <el-option
  81. v-for="user in scope.row.users"
  82. :key="user.id"
  83. :value="user.id"
  84. :label="user.name"
  85. ></el-option>
  86. </el-select>
  87. </template>
  88. </el-table-column>
  89. </el-table>
  90. </el-form-item>
  91. </el-form>
  92. <div slot="footer">
  93. <el-button type="primary" :disabled="isSubmit" @click="toSave"
  94. >确认</el-button
  95. >
  96. <el-button @click="cancel">取消</el-button>
  97. </div>
  98. </el-dialog>
  99. </template>
  100. <script>
  101. import { batchAddExamTask } from "../api";
  102. import UploadFileView from "@/components/UploadFileView";
  103. const initModalForm = {
  104. cardRuleId: "",
  105. startTime: "",
  106. endTime: "",
  107. batchNo: "",
  108. userIds: []
  109. };
  110. export default {
  111. name: "batch-add-exam-task",
  112. components: { UploadFileView },
  113. data() {
  114. return {
  115. modalIsShow: false,
  116. isSubmit: false,
  117. modalForm: { ...initModalForm },
  118. createTime: [],
  119. tasks: [],
  120. batchConfirmMessage: "",
  121. rules: {
  122. batchNo: [
  123. {
  124. required: true,
  125. message: "请上传命题任务表",
  126. trigger: "change"
  127. }
  128. ],
  129. startTime: [
  130. {
  131. required: true,
  132. message: "请设置命题时间",
  133. trigger: "change"
  134. }
  135. ],
  136. cardRuleId: [
  137. {
  138. required: true,
  139. message: "请选择题卡规则",
  140. trigger: "change"
  141. }
  142. ]
  143. },
  144. downloadUrl: "/temps/examTaskTemplate.xlsx",
  145. // import
  146. uploadExamTaskUrl: "/api/admin/exam/task/import"
  147. };
  148. },
  149. methods: {
  150. visibleChange() {
  151. this.modalForm = { ...initModalForm };
  152. this.tasks = [];
  153. this.createTime = [];
  154. this.batchConfirmMessage = "";
  155. this.$nextTick(() => {
  156. this.$refs.modalFormComp.clearValidate();
  157. });
  158. },
  159. cancel() {
  160. this.modalIsShow = false;
  161. },
  162. open() {
  163. this.modalIsShow = true;
  164. },
  165. dateChange() {
  166. if (this.createTime) {
  167. this.modalForm.startTime = this.createTime[0];
  168. this.modalForm.endTime = this.createTime[1];
  169. } else {
  170. this.modalForm.startTime = "";
  171. this.modalForm.endTime = "";
  172. }
  173. },
  174. toSave() {
  175. if (!this.batchConfirmMessage) {
  176. this.save();
  177. return;
  178. }
  179. this.$confirm(`${this.batchConfirmMessage}, 是否继续提交?`, "提示", {
  180. type: "warning"
  181. })
  182. .then(() => {
  183. this.save();
  184. })
  185. .catch(() => {});
  186. },
  187. async save() {
  188. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  189. if (!valid) return;
  190. if (this.isSubmit) return;
  191. this.isSubmit = true;
  192. let datas = {
  193. ...this.modalForm
  194. };
  195. datas.users = this.tasks.map(task => {
  196. return {
  197. courseCode: task.courseCode,
  198. courseName: task.courseName,
  199. paperNumber: task.paperNumber,
  200. specialty: task.specialty,
  201. userId: task.userId
  202. };
  203. });
  204. const data = await batchAddExamTask(datas).catch(() => {});
  205. this.isSubmit = false;
  206. if (!data) return;
  207. this.$message.success("保存成功!");
  208. this.$emit("modified");
  209. this.cancel();
  210. },
  211. // upload-handler
  212. // uplaodError(errorData) {
  213. // let message = errorData.message;
  214. // try {
  215. // message = JSON.parse(errorData.error);
  216. // message = message.map(item => item.excelErrorType).join(",");
  217. // } catch (msg) {
  218. // console.error(msg);
  219. // }
  220. // if (message) this.$notify.error({ title: "错误提示", message });
  221. // },
  222. uploadExamTaskSuccess(data) {
  223. this.$message.success("上传成功!");
  224. this.modalForm.batchNo = data.batchNo;
  225. this.batchConfirmMessage = data.errorMsg;
  226. this.tasks = data.tasks.map(item => {
  227. item.userId = item.users.length === 1 ? item.users[0].id : "";
  228. return item;
  229. });
  230. this.$refs.modalFormComp.validateField("batchNo");
  231. }
  232. }
  233. };
  234. </script>