EditComposition.vue 1.9 KB

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