BatchAddExamTask.vue 7.4 KB

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