ModifyOrganization.vue 3.8 KB

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