ModifyDetailStruct.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. <template>
  2. <el-dialog
  3. :title="dTitle"
  4. :visible.sync="modalIsShow"
  5. width="520px"
  6. :modal="true"
  7. append-to-body
  8. custom-class="side-dialog"
  9. @open="visibleChange"
  10. >
  11. <el-form
  12. ref="modalFormComp"
  13. :model="modalForm"
  14. :rules="rules"
  15. label-width="90px"
  16. >
  17. <el-form-item label="大题名称" prop="detailName">
  18. <el-input
  19. v-model="modalForm.detailName"
  20. class="dialog-input-width"
  21. placeholder="请输入题型名称"
  22. ></el-input>
  23. </el-form-item>
  24. <el-form-item label="大题描述" prop="description">
  25. <v-editor
  26. v-model="modalForm.description"
  27. placeholder="请输入大题描述"
  28. :enable-formula="false"
  29. ></v-editor>
  30. </el-form-item>
  31. <template v-if="!onlyName">
  32. <el-form-item label="题型" prop="sourceDetailId">
  33. <source-detail-select
  34. v-model="modalForm"
  35. :course-id="modalForm.courseId"
  36. ></source-detail-select>
  37. </el-form-item>
  38. <el-form-item label="每题分值" prop="scorePerQuestion">
  39. <el-input-number
  40. v-model="modalForm.scorePerQuestion"
  41. class="align-left"
  42. placeholder="请输入每题分值"
  43. :step="0.1"
  44. :min="0.1"
  45. :max="999"
  46. :controls="false"
  47. :precision="1"
  48. step-strictly
  49. ></el-input-number>
  50. </el-form-item>
  51. </template>
  52. <template v-if="showSelective && !isAdd">
  53. <el-form-item label="是否选做题">
  54. <el-radio-group
  55. v-model="modalForm.selective"
  56. @change="selectiveChange"
  57. >
  58. <el-radio :label="true">是</el-radio>
  59. <el-radio :label="false">否</el-radio>
  60. </el-radio-group>
  61. </el-form-item>
  62. <el-form-item
  63. v-if="modalForm.selective"
  64. label="选做题数"
  65. prop="selectiveCount"
  66. >
  67. <el-input-number
  68. v-model="modalForm.selectiveCount"
  69. class="align-left"
  70. placeholder="请输入选做题数"
  71. :step="1"
  72. :min="1"
  73. :max="999"
  74. :controls="false"
  75. :precision="0"
  76. step-strictly
  77. ></el-input-number>
  78. </el-form-item>
  79. <el-form-item
  80. v-if="modalForm.selective"
  81. label="取分规则"
  82. prop="selectiveRule"
  83. >
  84. <el-select v-model="modalForm.selectiveRule">
  85. <el-option
  86. v-for="(val, key) in SELECTIVE_RULE_TYPE"
  87. :key="key"
  88. :label="val"
  89. :value="key"
  90. ></el-option>
  91. </el-select>
  92. </el-form-item>
  93. </template>
  94. </el-form>
  95. <div slot="footer">
  96. <el-button type="primary" @click="confirm">保存</el-button>
  97. <el-button type="danger" plain @click="cancel">返回</el-button>
  98. </div>
  99. </el-dialog>
  100. </template>
  101. <script>
  102. import { randomCode } from "@/plugins/utils";
  103. import { debounce } from "lodash";
  104. import { SELECTIVE_RULE_TYPE } from "@/constants/constants";
  105. const initModalForm = {
  106. id: null,
  107. detailName: "",
  108. courseId: "",
  109. description: { sections: [] },
  110. questionType: null,
  111. sourceDetailId: null,
  112. scorePerQuestion: 1,
  113. selective: false,
  114. selectiveCount: null,
  115. selectiveRule: "",
  116. };
  117. export default {
  118. name: "ModifyDetailStruct",
  119. props: {
  120. detail: {
  121. type: Object,
  122. default() {
  123. return {};
  124. },
  125. },
  126. onlyName: {
  127. type: Boolean,
  128. default: false,
  129. },
  130. showSelective: {
  131. type: Boolean,
  132. default: false,
  133. },
  134. },
  135. computed: {
  136. isAdd() {
  137. return !Object.keys(this.detail).length;
  138. },
  139. dTitle() {
  140. return this.isAdd ? "新增大题" : "大题信息";
  141. },
  142. },
  143. data() {
  144. return {
  145. modalIsShow: false,
  146. SELECTIVE_RULE_TYPE,
  147. modalForm: { ...initModalForm },
  148. rules: {
  149. detailName: [
  150. {
  151. required: true,
  152. message: "请输入大题名称",
  153. trigger: "change",
  154. },
  155. ],
  156. sourceDetailId: [
  157. {
  158. required: true,
  159. message: "请选择题型",
  160. trigger: "change",
  161. },
  162. ],
  163. scorePerQuestion: [
  164. {
  165. required: true,
  166. message: "请输入每题分值",
  167. trigger: "change",
  168. },
  169. ],
  170. selectiveCount: [
  171. {
  172. required: true,
  173. message: "请输入选做题数",
  174. trigger: "blur",
  175. },
  176. ],
  177. selectiveRule: [
  178. {
  179. required: true,
  180. message: "请选择取分规则",
  181. trigger: "change",
  182. },
  183. ],
  184. },
  185. };
  186. },
  187. methods: {
  188. visibleChange() {
  189. this.modalForm = this.$objAssign(initModalForm, this.detail);
  190. },
  191. cancel() {
  192. this.modalIsShow = false;
  193. },
  194. open() {
  195. this.modalIsShow = true;
  196. },
  197. selectiveChange() {
  198. this.modalForm.selectiveRule = "";
  199. this.modalForm.selectiveCount = undefined;
  200. },
  201. confirm: debounce(
  202. async function () {
  203. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  204. if (!valid) return;
  205. let data = { ...this.modalForm };
  206. if (!data.id) data.id = randomCode();
  207. this.$emit("modified", data, this.isAdd);
  208. this.cancel();
  209. },
  210. 1000,
  211. { leading: true, trailing: false }
  212. ),
  213. },
  214. };
  215. </script>