EditExplain.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. explainHeight: 250,
  59. };
  60. export default {
  61. name: "edit-explain",
  62. components: { CardNameEdit },
  63. props: {
  64. instance: {
  65. type: Object,
  66. default() {
  67. return {};
  68. },
  69. },
  70. },
  71. data() {
  72. const numberRangeValidater = (rule, value, callback) => {
  73. if (!this.modalForm.startNumber || !this.modalForm.endNumber) {
  74. return callback(new Error("请输入起止题号"));
  75. }
  76. if (this.modalForm.startNumber > this.modalForm.endNumber) {
  77. callback(new Error("开始题号不能大于结束题号"));
  78. } else {
  79. callback();
  80. }
  81. };
  82. return {
  83. modalForm: { ...initModalForm },
  84. rules: {
  85. topicNo: [
  86. {
  87. required: true,
  88. message: "请输入大题序号",
  89. trigger: "change",
  90. },
  91. ],
  92. topicName: [
  93. {
  94. required: true,
  95. message: "请输入题目名称",
  96. trigger: "change",
  97. },
  98. ],
  99. endNumber: [
  100. {
  101. required: true,
  102. message: "请输入起止题号",
  103. trigger: "change",
  104. },
  105. {
  106. type: "number",
  107. validator: numberRangeValidater,
  108. trigger: "change",
  109. },
  110. ],
  111. },
  112. };
  113. },
  114. mounted() {
  115. this.initData(this.instance);
  116. },
  117. methods: {
  118. initData(val) {
  119. const valInfo = val.parent || val;
  120. this.modalForm = { ...valInfo };
  121. this.modalForm.endNumber =
  122. this.modalForm.startNumber + this.modalForm.questionsCount - 1;
  123. },
  124. async submit() {
  125. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  126. if (!valid) return;
  127. this.modalForm.questionsCount =
  128. this.modalForm.endNumber - this.modalForm.startNumber + 1;
  129. this.modalForm.topicName = this.modalForm.topicName.trim();
  130. this.$emit("modified", this.modalForm);
  131. },
  132. },
  133. };
  134. </script>