EditExplain.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <div class="edit-explain">
  3. <el-form
  4. ref="modalFormComp"
  5. :model="modalForm"
  6. :rules="rules"
  7. :key="modalForm.id"
  8. label-width="100px"
  9. >
  10. <!-- <el-form-item prop="topicNo" label="大题序号:">
  11. <el-input-number
  12. v-model="modalForm.topicNo"
  13. :min="1"
  14. :max="99"
  15. :step="1"
  16. step-strictly
  17. :controls="false"
  18. ></el-input-number>
  19. </el-form-item> -->
  20. <el-form-item prop="topicName" label="题目名称:">
  21. <card-name-edit v-model="modalForm"></card-name-edit>
  22. </el-form-item>
  23. <el-form-item prop="startEnd" label="起止题号:">
  24. <el-input-number
  25. style="width: 40px"
  26. v-model="modalForm.startNumber"
  27. :min="0"
  28. :max="999"
  29. :step="1"
  30. step-strictly
  31. :controls="false"
  32. ></el-input-number>
  33. <span class="el-input-split"></span>
  34. <el-input-number
  35. style="width: 40px"
  36. v-model="modalForm.endNumber"
  37. :min="0"
  38. :max="999"
  39. :step="1"
  40. step-strictly
  41. :controls="false"
  42. ></el-input-number>
  43. </el-form-item>
  44. </el-form>
  45. </div>
  46. </template>
  47. <script>
  48. import CardNameEdit from "../../components/common/CardNameEdit.vue";
  49. const initModalForm = {
  50. id: "",
  51. topicNo: null,
  52. topicName: "",
  53. nameFontSize: "14px",
  54. nameFontWeight: 400,
  55. startNumber: 1,
  56. endNumber: 4,
  57. questionsCount: 4,
  58. };
  59. export default {
  60. name: "edit-explain",
  61. components: { CardNameEdit },
  62. props: {
  63. instance: {
  64. type: Object,
  65. default() {
  66. return {};
  67. },
  68. },
  69. },
  70. data() {
  71. const numberRangeValidater = (rule, value, callback) => {
  72. if (!this.modalForm.startNumber || !this.modalForm.endNumber) {
  73. return callback(new Error("请输入起止题号"));
  74. }
  75. if (this.modalForm.startNumber > this.modalForm.endNumber) {
  76. callback(new Error("开始题号不能大于结束题号"));
  77. } else {
  78. callback();
  79. }
  80. };
  81. return {
  82. modalForm: { ...initModalForm },
  83. rules: {
  84. topicNo: [
  85. {
  86. required: true,
  87. message: "请输入大题序号",
  88. trigger: "change",
  89. },
  90. ],
  91. topicName: [
  92. {
  93. required: true,
  94. message: "请输入题目名称",
  95. trigger: "change",
  96. },
  97. ],
  98. endNumber: [
  99. {
  100. required: true,
  101. message: "请输入起止题号",
  102. trigger: "change",
  103. },
  104. {
  105. type: "number",
  106. validator: numberRangeValidater,
  107. trigger: "change",
  108. },
  109. ],
  110. },
  111. };
  112. },
  113. mounted() {
  114. this.initData(this.instance);
  115. },
  116. methods: {
  117. initData(val) {
  118. const valInfo = val.parent || val;
  119. this.modalForm = { ...valInfo };
  120. this.modalForm.endNumber =
  121. this.modalForm.startNumber + this.modalForm.questionsCount - 1;
  122. },
  123. async submit() {
  124. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  125. if (!valid) return;
  126. this.modalForm.questionsCount =
  127. this.modalForm.endNumber - this.modalForm.startNumber + 1;
  128. this.modalForm.topicName = this.modalForm.topicName.trim();
  129. this.$emit("modified", this.modalForm);
  130. },
  131. },
  132. };
  133. </script>