EditComposition.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="edit-composition">
  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. <el-input
  22. v-model="modalForm.topicName"
  23. type="textarea"
  24. :autosize="{ minRows: 2, maxRows: 5 }"
  25. resize="none"
  26. placeholder="请输入题目名称"
  27. clearable
  28. maxlength="100"
  29. show-word-limit
  30. ></el-input>
  31. </el-form-item>
  32. </el-form>
  33. </div>
  34. </template>
  35. <script>
  36. const initModalForm = {
  37. id: "",
  38. topicNo: null,
  39. topicName: "",
  40. };
  41. export default {
  42. name: "edit-composition",
  43. props: {
  44. instance: {
  45. type: Object,
  46. default() {
  47. return {};
  48. },
  49. },
  50. },
  51. data() {
  52. return {
  53. modalForm: { ...initModalForm },
  54. rules: {
  55. topicNo: [
  56. {
  57. required: true,
  58. message: "请输入大题序号",
  59. trigger: "change",
  60. },
  61. ],
  62. topicName: [
  63. {
  64. required: true,
  65. message: "请输入题目名称",
  66. trigger: "change",
  67. },
  68. ],
  69. },
  70. };
  71. },
  72. mounted() {
  73. this.initData(this.instance);
  74. },
  75. methods: {
  76. initData(val) {
  77. const valInfo = val.parent || val;
  78. this.modalForm = { ...valInfo };
  79. },
  80. async submit() {
  81. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  82. if (!valid) return;
  83. this.modalForm.topicName = this.modalForm.topicName.trim();
  84. this.$emit("modified", this.modalForm);
  85. },
  86. },
  87. };
  88. </script>