EditExplain.vue 3.1 KB

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