ModifyTrainingPlan.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <template>
  2. <el-dialog
  3. :visible.sync="modalIsShow"
  4. :title="title"
  5. top="10vh"
  6. width="500px"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. @open="visibleChange"
  11. >
  12. <el-form
  13. ref="modalFormComp"
  14. :model="modalForm"
  15. :key="modalForm.id"
  16. :rules="rules"
  17. label-width="120px"
  18. >
  19. <el-form-item prop="name" label="培养方案名称:">
  20. <el-input
  21. v-model.trim="modalForm.name"
  22. placeholder="培养方案名称"
  23. clearable
  24. ></el-input>
  25. </el-form-item>
  26. <el-form-item prop="professionalId" label="所属专业:">
  27. <professional-select
  28. v-model="modalForm.professionalId"
  29. placeholder="所属专业"
  30. :org-id="userOrgId"
  31. ></professional-select>
  32. </el-form-item>
  33. </el-form>
  34. <div slot="footer">
  35. <el-button type="primary" :disabled="isSubmit" @click="submit"
  36. >确认</el-button
  37. >
  38. <el-button @click="cancel">取消</el-button>
  39. </div>
  40. </el-dialog>
  41. </template>
  42. <script>
  43. import { updateTrainingPlan } from "../../api";
  44. const initModalForm = {
  45. id: null,
  46. professionalId: "",
  47. name: "",
  48. };
  49. export default {
  50. name: "modify-training-plan",
  51. props: {
  52. instance: {
  53. type: Object,
  54. default() {
  55. return {};
  56. },
  57. },
  58. },
  59. data() {
  60. return {
  61. modalIsShow: false,
  62. isSubmit: false,
  63. userOrgId: this.$ls.get("orgId", ""),
  64. modalForm: { ...initModalForm },
  65. rules: {
  66. name: [
  67. { required: true, message: "请输入培养方案名称", trigger: "change" },
  68. {
  69. message: "培养方案名称不能超过30个字",
  70. max: 30,
  71. trigger: "change",
  72. },
  73. ],
  74. professionalId: [
  75. { required: true, message: "请选择专业", trigger: "change" },
  76. ],
  77. },
  78. };
  79. },
  80. computed: {
  81. isEdit() {
  82. return !!this.instance.id;
  83. },
  84. title() {
  85. return (this.isEdit ? "编辑" : "新增") + "培养方案";
  86. },
  87. },
  88. methods: {
  89. visibleChange() {
  90. this.modalForm = this.$objAssign(initModalForm, 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. const data = await updateTrainingPlan(this.modalForm).catch(() => {});
  104. this.isSubmit = false;
  105. if (!data) return;
  106. this.$message.success("修改成功!");
  107. this.$emit("modified");
  108. this.cancel();
  109. },
  110. },
  111. };
  112. </script>