TopicTaskModify.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <div class="topic-task-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="examId" label="考试名称:">
  11. <el-select
  12. v-model="modalForm.examId"
  13. style="width: 439px;"
  14. placeholder="请选择"
  15. @change="examChange"
  16. clearable
  17. v-if="!isEdit"
  18. >
  19. <el-option
  20. v-for="item in exams"
  21. :key="item.id"
  22. :value="item.id"
  23. :label="item.name"
  24. ></el-option>
  25. </el-select>
  26. <el-input
  27. v-model.trim="modalForm.examName"
  28. style="width: 439px;"
  29. readonly
  30. v-else
  31. ></el-input>
  32. </el-form-item>
  33. <el-form-item prop="courseCode" label="科目:">
  34. <el-select
  35. v-model="modalForm.courseCode"
  36. style="width: 439px;"
  37. placeholder="请选择"
  38. @change="courseChange"
  39. clearable
  40. v-if="!isEdit"
  41. >
  42. <el-option
  43. v-for="item in courses"
  44. :key="item.courseCode"
  45. :value="item.courseCode"
  46. :label="item.courseName"
  47. ></el-option>
  48. </el-select>
  49. <el-input
  50. v-model.trim="modalForm.courseName"
  51. style="width: 439px;"
  52. readonly
  53. v-else
  54. ></el-input>
  55. </el-form-item>
  56. <el-form-item label="考试开始时间:">
  57. <el-input
  58. v-model.trim="modalForm.beginTime"
  59. style="width: 439px;"
  60. readonly
  61. ></el-input>
  62. </el-form-item>
  63. <el-form-item prop="questionTeacherId" label="命题老师:">
  64. <el-select
  65. v-model="modalForm.questionTeacherId"
  66. style="width: 439px;"
  67. placeholder="请选择"
  68. clearable
  69. >
  70. <el-option
  71. v-for="item in teachers"
  72. :key="item.id"
  73. :value="item.id"
  74. :label="item.name"
  75. ></el-option>
  76. </el-select>
  77. </el-form-item>
  78. <el-form-item>
  79. <el-button type="primary" :disabled="isSubmit" @click="save"
  80. >保存</el-button
  81. >
  82. <el-button @click="goback">返回</el-button>
  83. </el-form-item>
  84. </el-form>
  85. </div>
  86. </template>
  87. <script>
  88. import {
  89. updateTopicTask,
  90. topicTaskDetail,
  91. topicTaskExamList,
  92. topicTaskExamCourseList,
  93. topicTaskExamTeacherList
  94. } from "../api";
  95. export default {
  96. name: "topic-task-modify",
  97. data() {
  98. return {
  99. taskId: this.$route.params.taskId,
  100. modalForm: {
  101. examId: "",
  102. examName: "",
  103. courseCode: "",
  104. courseName: "",
  105. beginTime: "",
  106. questionTeacherId: ""
  107. },
  108. curExam: {},
  109. rules: {
  110. examId: [
  111. {
  112. required: true,
  113. message: "请选择考试",
  114. trigger: "change"
  115. }
  116. ],
  117. courseCode: [
  118. {
  119. required: true,
  120. message: "请选择科目",
  121. trigger: "change"
  122. }
  123. ],
  124. questionTeacherId: [
  125. {
  126. required: true,
  127. message: "请选择命题老师",
  128. trigger: "change"
  129. }
  130. ]
  131. },
  132. exams: [],
  133. courses: [],
  134. teachers: [],
  135. isSubmit: false
  136. };
  137. },
  138. computed: {
  139. isEdit() {
  140. return !!this.taskId;
  141. }
  142. },
  143. mounted() {
  144. this.initData();
  145. },
  146. methods: {
  147. async initData() {
  148. if (this.isEdit) {
  149. await this.getTaskDetail();
  150. this.getTeachers();
  151. } else {
  152. this.getExams();
  153. }
  154. },
  155. async getTaskDetail() {
  156. const data = await topicTaskDetail(this.taskId);
  157. this.modalForm = this.$objAssign(this.modalForm, data);
  158. },
  159. async getExams() {
  160. const data = await topicTaskExamList();
  161. this.exams = data.map(item => {
  162. return {
  163. id: item.id,
  164. name: item.examName,
  165. beginTime: item.beginTime
  166. };
  167. });
  168. },
  169. async getCourses() {
  170. this.courses = await topicTaskExamCourseList(this.modalForm.examId);
  171. },
  172. async getTeachers() {
  173. this.teachers = await topicTaskExamTeacherList(this.modalForm.courseCode);
  174. },
  175. examChange() {
  176. this.modalForm.courseCode = "";
  177. this.modalForm.questionTeacherId = "";
  178. this.courses = [];
  179. this.teachers = [];
  180. if (!this.modalForm.examId) {
  181. this.curExam = {};
  182. return;
  183. }
  184. this.curExam = this.exams.find(item => item.id === this.modalForm.examId);
  185. this.modalForm.beginTime = this.curExam.beginTime;
  186. this.getCourses();
  187. },
  188. courseChange() {
  189. this.modalForm.questionTeacherId = "";
  190. this.teachers = [];
  191. if (!this.modalForm.courseCode) return;
  192. this.getTeachers();
  193. },
  194. async save() {
  195. const valid = await this.$refs["ModalForm"].validate().catch(() => {});
  196. if (!valid) return;
  197. if (this.isSubmit) return;
  198. this.isSubmit = true;
  199. const datas = {
  200. ...this.modalForm
  201. };
  202. if (this.isEdit) {
  203. datas.taskId = this.taskId;
  204. } else {
  205. const curCourse = this.courses.find(
  206. item => item.courseCode === datas.courseCode
  207. );
  208. datas.courseName = curCourse.courseName;
  209. }
  210. const data = await updateTopicTask(datas).catch(() => {});
  211. this.isSubmit = false;
  212. if (!data) return;
  213. this.$message.success("保存成功!");
  214. this.goback();
  215. }
  216. }
  217. };
  218. </script>