ExamModify.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <div class="exam-modify part-box part-box-border part-box-pad">
  3. <el-form
  4. ref="ModalForm"
  5. :model="modalForm"
  6. :rules="rules"
  7. label-width="180px"
  8. style="min-width:800px;"
  9. >
  10. <el-form-item prop="examName" label="考试名称:">
  11. <el-input
  12. style="width: 439px;"
  13. v-model.trim="modalForm.examName"
  14. placeholder="请输入考试名称"
  15. clearable
  16. ></el-input>
  17. </el-form-item>
  18. <el-form-item prop="examCodeTemp" label="考务文件:">
  19. <upload-file-view
  20. :upload-url="uploadUrl"
  21. @upload-error="uplaodError"
  22. @upload-success="uploadSuccess"
  23. ref="UploadFileView"
  24. ></upload-file-view>
  25. <el-button @click="toPreview" style="margin-left:16px;">预览</el-button>
  26. </el-form-item>
  27. <el-form-item label="考试开始时间:">
  28. <p class="form-item-content">{{ modalForm.beginTime }}</p>
  29. </el-form-item>
  30. <el-form-item prop="printTime" label="打印时间:">
  31. <el-date-picker
  32. v-model="modalForm.printTime"
  33. type="datetime"
  34. value-format="yyyy-MM-dd HH:mm:ss"
  35. placeholder="请选择日期"
  36. >
  37. </el-date-picker>
  38. </el-form-item>
  39. <el-form-item prop="backup" label="备用方式:">
  40. <el-radio-group v-model="modalForm.backup">
  41. <el-radio
  42. v-for="(val, key) in RESERVE_TYPE"
  43. :key="key"
  44. :label="key"
  45. >{{ val }}</el-radio
  46. >
  47. </el-radio-group>
  48. </el-form-item>
  49. <el-form-item prop="backupCard" label="备用各科试卷题卡份数:">
  50. <el-input-number
  51. style="width:220px;"
  52. v-model="modalForm.backupCard"
  53. :min="1"
  54. :max="1000"
  55. :step="1"
  56. step-strictly
  57. :controls="false"
  58. ></el-input-number>
  59. </el-form-item>
  60. <el-form-item prop="teacher" label="指派命题老师:">
  61. <el-table :data="courses" style="width: 420px;" border stripe>
  62. <el-table-column
  63. width="154"
  64. prop="courseName"
  65. label="科目"
  66. ></el-table-column>
  67. <el-table-column label="命题老师">
  68. <template slot-scope="scope">
  69. <el-select
  70. v-model="scope.row.teacherId"
  71. size="small"
  72. style="width: 156px;"
  73. placeholder="请选择"
  74. >
  75. <el-option
  76. v-for="user in scope.row.users"
  77. :key="user.id"
  78. :value="user.id"
  79. :label="user.name"
  80. ></el-option>
  81. </el-select>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. </el-form-item>
  86. <el-form-item>
  87. <el-button type="primary" :disabled="isSubmit" @click="save"
  88. >保存</el-button
  89. >
  90. <el-button @click="goback">返回</el-button>
  91. </el-form-item>
  92. </el-form>
  93. <!-- business-data -->
  94. <business-data
  95. :exam-code="modalForm.examCodeTemp"
  96. ref="BusinessData"
  97. ></business-data>
  98. </div>
  99. </template>
  100. <script>
  101. import { RESERVE_TYPE } from "@/constants/enumerate";
  102. import { uploadExam, examDetail } from "../api";
  103. import BusinessData from "../components/BusinessData";
  104. import UploadFileView from "../components/UploadFileView";
  105. export default {
  106. name: "exam-modify",
  107. components: { BusinessData, UploadFileView },
  108. data() {
  109. const printTimeValidator = (rule, value, callback) => {
  110. if (!this.checkDateRangeValid(value, this.modalForm.beginTime)) {
  111. callback(new Error("打印时间不能为空,且不得晚于考试开始时间"));
  112. } else {
  113. callback();
  114. }
  115. };
  116. const teacherValidator = (rule, value, callback) => {
  117. if (!this.checkTeacherSelected()) {
  118. callback(new Error("请选择各科目的命题老师"));
  119. } else {
  120. callback();
  121. }
  122. };
  123. return {
  124. examId: this.$route.params.examId,
  125. modalForm: {
  126. examName: "",
  127. beginTime: "",
  128. printTime: "",
  129. backup: "0",
  130. backupCard: "",
  131. examCodeTemp: "",
  132. attachmentId: ""
  133. },
  134. rules: {
  135. examName: [
  136. {
  137. required: true,
  138. message: "请输入考试名称",
  139. trigger: "change"
  140. }
  141. ],
  142. examCode: [
  143. {
  144. required: true,
  145. message: "请上传考务文件",
  146. trigger: "change"
  147. }
  148. ],
  149. printTime: [
  150. {
  151. required: true,
  152. validator: printTimeValidator,
  153. trigger: "change"
  154. }
  155. ],
  156. backup: [
  157. {
  158. required: true,
  159. message: "请选择备用方式",
  160. trigger: "change"
  161. }
  162. ],
  163. backupCard: [
  164. {
  165. required: true,
  166. message: "请输入备用各科试卷题卡份数",
  167. trigger: "change"
  168. }
  169. ],
  170. teacher: [
  171. {
  172. required: true,
  173. validator: teacherValidator
  174. }
  175. ]
  176. },
  177. RESERVE_TYPE,
  178. courses: [],
  179. isSubmit: false,
  180. // import
  181. uploadUrl: "/api/print/exam/exam/impExamData"
  182. };
  183. },
  184. computed: {
  185. isEdit() {
  186. return !!this.examId;
  187. }
  188. },
  189. mounted() {
  190. if (this.isEdit) {
  191. this.getExamDetail();
  192. }
  193. },
  194. methods: {
  195. async getExamDetail() {
  196. const data = await examDetail(this.examId);
  197. this.modalForm = Object.assign({}, this.modalForm, data.tcPExam);
  198. this.modalForm.backup += "";
  199. this.courses = data.userCourses;
  200. this.$refs.UploadFileView.setAttachmentName(
  201. `${data.tcPAttachment.name}${data.tcPAttachment.type}`
  202. );
  203. },
  204. checkDateRangeValid(startTime, endTime) {
  205. if (startTime && endTime) {
  206. var st = new Date(startTime.replace(/-/g, "/")).getTime();
  207. var et = new Date(endTime.replace(/-/g, "/")).getTime();
  208. return st < et;
  209. }
  210. return;
  211. },
  212. checkTeacherSelected() {
  213. return !this.courses.some(course => !course.teacherId);
  214. },
  215. async save() {
  216. const valid = await this.$refs["ModalForm"].validate().catch(() => {});
  217. if (!valid) return;
  218. if (this.isSubmit) return;
  219. this.isSubmit = true;
  220. const datas = {
  221. tcPExam: this.modalForm,
  222. tcPExamCourseUsers: this.courses.map(course => {
  223. return {
  224. courseName: course.courseName,
  225. courseCode: course.courseCode,
  226. userId: course.teacherId
  227. };
  228. })
  229. };
  230. const data = await uploadExam(datas).catch(() => {});
  231. this.isSubmit = false;
  232. if (!data) return;
  233. this.$message.success("保存成功!");
  234. this.goback();
  235. },
  236. toPreview() {
  237. if (!this.modalForm.examCodeTemp) {
  238. this.$message.error("请先上传考务文件!");
  239. return;
  240. }
  241. this.$refs.BusinessData.open();
  242. },
  243. // upload-handler
  244. uplaodError(msg) {
  245. this.$message.error(msg);
  246. },
  247. uploadSuccess(res) {
  248. this.$message.success("上传成功!");
  249. const data = res.data;
  250. this.modalForm.beginTime = data.startTime;
  251. this.modalForm.examCodeTemp = data.examCode;
  252. this.modalForm.attachmentId = data.attachmentId;
  253. this.$refs["ModalForm"].validateField("examCodeTemp");
  254. this.courses = data.userCourses.map(item => {
  255. item.teacherId = "";
  256. return item;
  257. });
  258. }
  259. }
  260. };
  261. </script>