ModifyOrganization.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <template>
  2. <el-dialog
  3. class="modify-organization"
  4. :visible.sync="modalIsShow"
  5. :title="title"
  6. top="10vh"
  7. width="448px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @opened="visibleChange"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. :model="modalForm"
  16. :rules="rules"
  17. label-position="top"
  18. >
  19. <el-form-item label="上级机构:">
  20. <el-input v-model.trim="modalForm.parentName" disabled></el-input>
  21. </el-form-item>
  22. <el-form-item prop="name" label="机构名称:">
  23. <el-input
  24. v-model.trim="modalForm.name"
  25. placeholder="请输入机构名称"
  26. clearable
  27. ></el-input>
  28. </el-form-item>
  29. <el-form-item prop="type" label="机构类型:">
  30. <el-select
  31. v-model="modalForm.type"
  32. style="width: 100%;"
  33. placeholder="请选择"
  34. clearable
  35. >
  36. <el-option
  37. v-for="item in orgTypes"
  38. :key="item.type"
  39. :value="item.type"
  40. :label="item.name"
  41. ></el-option>
  42. </el-select>
  43. </el-form-item>
  44. <!-- <el-form-item label="启用/禁用:">
  45. <el-switch
  46. v-model="modalForm.enable"
  47. inactive-color="#dcdfe6"
  48. >
  49. </el-switch>
  50. </el-form-item> -->
  51. </el-form>
  52. <div slot="footer">
  53. <el-button type="primary" :disabled="isSubmit" @click="submit"
  54. >确认</el-button
  55. >
  56. <el-button @click="cancel">取消</el-button>
  57. </div>
  58. </el-dialog>
  59. </template>
  60. <script>
  61. import { updateOrganization } from "../api";
  62. const initModalForm = {
  63. id: null,
  64. name: "",
  65. type: "",
  66. parentId: null,
  67. parentName: "",
  68. enable: true
  69. };
  70. export default {
  71. name: "modify-organization",
  72. props: {
  73. instance: {
  74. type: Object,
  75. default() {
  76. return {};
  77. }
  78. },
  79. orgTypes: {
  80. type: Array,
  81. default() {
  82. return [];
  83. }
  84. }
  85. },
  86. computed: {
  87. isEdit() {
  88. return !!this.instance.id;
  89. },
  90. title() {
  91. return (this.isEdit ? "编辑" : "新增") + "机构";
  92. }
  93. },
  94. data() {
  95. return {
  96. modalIsShow: false,
  97. isSubmit: false,
  98. modalForm: {},
  99. rules: {
  100. name: [
  101. {
  102. required: true,
  103. pattern: /^[0-9a-zA-Z\u4E00-\u9FA5]{1,30}$/,
  104. message: "机构名称只能输入汉字、数字和字母,长度不能超过30",
  105. trigger: "change"
  106. }
  107. ],
  108. type: [
  109. {
  110. required: true,
  111. message: "请选择机构类型",
  112. trigger: "change"
  113. }
  114. ]
  115. }
  116. };
  117. },
  118. methods: {
  119. initData(val) {
  120. this.modalForm = this.$objAssign(initModalForm, val);
  121. },
  122. visibleChange() {
  123. this.initData(this.instance);
  124. this.$nextTick(() => {
  125. this.$refs.modalFormComp.clearValidate();
  126. });
  127. },
  128. cancel() {
  129. this.modalIsShow = false;
  130. },
  131. open() {
  132. this.modalIsShow = true;
  133. },
  134. async submit() {
  135. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  136. if (!valid) return;
  137. if (this.isSubmit) return;
  138. this.isSubmit = true;
  139. const datas = { ...this.modalForm };
  140. const data = await updateOrganization(datas).catch(() => {});
  141. this.isSubmit = false;
  142. if (!data) return;
  143. this.$emit("confirm", this.modalForm);
  144. this.cancel();
  145. }
  146. }
  147. };
  148. </script>