EditComposition.vue 1.9 KB

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