ModifySemester.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <el-dialog
  3. class="modify-semester"
  4. :visible.sync="modalIsShow"
  5. :title="title"
  6. top="10vh"
  7. width="600px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="visibleChange"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. :model="modalForm"
  16. :rules="rules"
  17. label-width="100px"
  18. >
  19. <el-form-item prop="semesterName" label="学期名称:">
  20. <el-input
  21. v-model.trim="modalForm.semesterName"
  22. placeholder="请输入学期名称"
  23. clearable
  24. ></el-input>
  25. <p class="tips-info">示例:2021~2022第一学期/上学期</p>
  26. </el-form-item>
  27. </el-form>
  28. <div slot="footer">
  29. <el-button type="primary" :disabled="isSubmit" @click="submit"
  30. >确认</el-button
  31. >
  32. <el-button @click="cancel">取消</el-button>
  33. </div>
  34. </el-dialog>
  35. </template>
  36. <script>
  37. import { updateSemester } from "../api";
  38. const initModalForm = {
  39. id: null,
  40. semesterName: "",
  41. };
  42. export default {
  43. name: "modify-semester",
  44. props: {
  45. instance: {
  46. type: Object,
  47. default() {
  48. return {};
  49. },
  50. },
  51. },
  52. computed: {
  53. isEdit() {
  54. return !!this.instance.id;
  55. },
  56. title() {
  57. return (this.isEdit ? "编辑" : "新增") + "学年学期";
  58. },
  59. },
  60. data() {
  61. return {
  62. modalIsShow: false,
  63. isSubmit: false,
  64. modalForm: { ...initModalForm },
  65. rules: {
  66. semesterName: [
  67. {
  68. required: true,
  69. message: "请输入学期名称",
  70. trigger: "change",
  71. },
  72. {
  73. message: "学期名称不能超过100个字",
  74. max: 100,
  75. trigger: "change",
  76. },
  77. ],
  78. },
  79. };
  80. },
  81. methods: {
  82. initData(val) {
  83. if (val.id) {
  84. this.modalForm = this.$objAssign(initModalForm, val);
  85. } else {
  86. this.modalForm = { ...initModalForm };
  87. }
  88. },
  89. visibleChange() {
  90. this.initData(this.instance);
  91. },
  92. cancel() {
  93. this.modalIsShow = false;
  94. },
  95. open() {
  96. this.modalIsShow = true;
  97. },
  98. async submit() {
  99. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  100. if (!valid) return;
  101. if (this.isSubmit) return;
  102. this.isSubmit = true;
  103. let datas = { ...this.modalForm };
  104. const data = await updateSemester(datas).catch(() => {});
  105. this.isSubmit = false;
  106. if (!data) return;
  107. this.$message.success(this.title + "成功!");
  108. this.$emit("modified");
  109. this.cancel();
  110. },
  111. },
  112. };
  113. </script>