CoursePaperDialog.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <el-dialog
  3. ref="dialog"
  4. title="编辑绑卷"
  5. width="800px"
  6. :visible.sync="visible"
  7. @close="closeDialog"
  8. >
  9. <el-form
  10. :model="form"
  11. ref="form"
  12. :rules="rules"
  13. label-position="right"
  14. label-width="120px"
  15. inline
  16. >
  17. <el-row>
  18. <el-form-item label="批次名称">
  19. <ExamSelect v-model="course.examId" disabled />
  20. </el-form-item>
  21. <el-form-item label="科目名称">
  22. <CourseSelect
  23. :examId="course.examId"
  24. v-model="course.courseCode"
  25. disabled
  26. />
  27. </el-form-item>
  28. </el-row>
  29. <el-row>
  30. <el-table :data="papers" stripe style="width: 100%;">
  31. <el-table-column width="42" />
  32. <el-table-column width="100" label="ID">
  33. <span slot-scope="scope">{{ scope.row.id }}</span>
  34. </el-table-column>
  35. <el-table-column label="试卷名称">
  36. <span slot-scope="scope">{{ scope.row.name }}</span>
  37. </el-table-column>
  38. <el-table-column width="100" label="分值">
  39. <span slot-scope="scope">{{ scope.row.totalScore }}</span>
  40. </el-table-column>
  41. <el-table-column width="170" label="抽卷几率">
  42. <span slot-scope="scope">
  43. <el-input-number
  44. v-model.trim="scope.row.weight"
  45. :min="0"
  46. :step="1"
  47. step-strictly
  48. :max="100"
  49. style="width: 50px;"
  50. :controls="false"
  51. >
  52. </el-input-number>
  53. %
  54. </span>
  55. </el-table-column>
  56. <el-table-column width="170" label="音频播放次数">
  57. <span slot-scope="scope">
  58. <el-input-number
  59. :min="1"
  60. :max="1000"
  61. v-model.trim="scope.row.audioPlayCount"
  62. ></el-input-number>
  63. </span>
  64. </el-table-column>
  65. </el-table>
  66. </el-row>
  67. <el-row>
  68. <el-form-item label="客观题小题乱序" prop="objectiveShuffle">
  69. <el-radio-group
  70. class="pull_right_sm"
  71. v-model="refreshCourse.objectiveShuffle"
  72. >
  73. <el-radio :label="1">启用</el-radio>
  74. <el-radio :label="0">禁用</el-radio>
  75. </el-radio-group>
  76. </el-form-item>
  77. </el-row>
  78. <el-row>
  79. <el-form-item label="客观题选项乱序" prop="optionShuffle">
  80. <el-radio-group
  81. class="pull_right_sm"
  82. v-model="refreshCourse.optionShuffle"
  83. >
  84. <el-radio :label="1">启用</el-radio>
  85. <el-radio :label="0">禁用</el-radio>
  86. </el-radio-group>
  87. </el-form-item>
  88. </el-row>
  89. <el-row class="d-flex justify-content-center">
  90. <el-button type="primary" @click="submitForm" :loading="loading">
  91. 保 存
  92. </el-button>
  93. <el-button @click="closeDialog">取 消</el-button>
  94. </el-row>
  95. </el-form>
  96. </el-dialog>
  97. </template>
  98. <script>
  99. import {
  100. searchCourses,
  101. searchPapers,
  102. saveCourse,
  103. savePapers,
  104. } from "@/api/examwork-course";
  105. export default {
  106. name: "CoursePaperDialog",
  107. props: {
  108. course: Object,
  109. },
  110. data() {
  111. return {
  112. visible: false,
  113. form: {},
  114. rules: {},
  115. refreshCourse: {},
  116. papers: [],
  117. loading: false,
  118. };
  119. },
  120. watch: {
  121. course: {
  122. immediate: true,
  123. handler() {
  124. this.refreshCourse = {};
  125. this.papers = [];
  126. this.initData();
  127. },
  128. },
  129. },
  130. methods: {
  131. async initData() {
  132. if (!this.course?.examId) return;
  133. const courseRes = await searchCourses({
  134. id: this.course.id,
  135. examId: this.course.examId,
  136. pageNumber: 1,
  137. pageSize: 1,
  138. });
  139. this.refreshCourse = courseRes?.data.data.records[0];
  140. const res = await searchPapers({
  141. examId: this.refreshCourse.examId,
  142. courseCode: this.refreshCourse.courseCode,
  143. pageNumber: this.currentPage,
  144. pageSize: this.pageSize,
  145. });
  146. this.papers = res?.data.data;
  147. },
  148. openDialog() {
  149. this.visible = true;
  150. },
  151. closeDialog() {
  152. this.visible = false;
  153. },
  154. async submitForm() {
  155. try {
  156. const totalWieght = this.papers
  157. .map((v) => v.weight)
  158. .reduce((p, c) => p + c);
  159. if (totalWieght !== 100) {
  160. this.$notify({
  161. type: "warning",
  162. title: `抽卷几率之和必须等于100,当前之和为${totalWieght}`,
  163. });
  164. return;
  165. }
  166. this.loading = true;
  167. await saveCourse({
  168. examId: this.refreshCourse.examId,
  169. courseCode: this.refreshCourse.courseCode,
  170. objectiveShuffle: this.refreshCourse.objectiveShuffle,
  171. optionShuffle: this.refreshCourse.optionShuffle,
  172. });
  173. const ps = [];
  174. for (const paper of this.papers) {
  175. ps.push({
  176. id: paper.id,
  177. weight: paper.weight,
  178. audioPlayCount: paper.audioPlayCount,
  179. });
  180. }
  181. await savePapers(ps);
  182. this.$emit("reload");
  183. this.$notify({ title: "保存成功", type: "success" });
  184. this.closeDialog();
  185. } catch (error) {
  186. console.log(error);
  187. this.initData();
  188. this.$notify({ title: "保存失败", type: "warning" });
  189. } finally {
  190. this.loading = false;
  191. }
  192. },
  193. },
  194. };
  195. </script>
  196. <style></style>