ExamModify.vue 7.7 KB

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