inleft
2022-03-01 88f419df77ade235ea5e5e24be204842a24b7b33
commit | author | age
9bcb19 1 <template>
I 2   <a-modal
3     title="新增机构"
4     :width="900"
5     :visible="visible"
6     :confirmLoading="confirmLoading"
7     @ok="handleSubmit"
8     @cancel="handleCancel"
9   >
10     <a-spin :spinning="formLoading">
11       <a-form :form="form">
12         <a-form-item
13           label="机构名称"
14           :labelCol="labelCol"
15           :wrapperCol="wrapperCol"
16           has-feedback
17         >
18           <a-input placeholder="请输入机构名称" v-decorator="['name', {rules: [{required: true, message: '请输入机构名称!'}]}]" />
19         </a-form-item>
20
21         <a-form-item
22           label="唯一编码"
23           :labelCol="labelCol"
24           :wrapperCol="wrapperCol"
25           has-feedback
26         >
27           <a-input placeholder="请输入唯一编码" v-decorator="['code', {rules: [{required: true, message: '请输入唯一编码!'}]}]" />
28         </a-form-item>
29
30         <a-form-item
31           label="上级机构"
32           :labelCol="labelCol"
33           :wrapperCol="wrapperCol"
34           has-feedback
35         >
36           <a-tree-select
37             v-decorator="['pid', {rules: [{ required: true, message: '请选择上级机构!' }]}]"
38             style="width: 100%"
39             :dropdownStyle="{ maxHeight: '300px', overflow: 'auto' }"
40             :treeData="orgTree"
41             placeholder="请选择上级机构"
42             treeDefaultExpandAll
43           >
44             <span slot="title" slot-scope="{ id }">{{ id }}
45             </span>
46           </a-tree-select>
47         </a-form-item>
48
49         <a-form-item
50           :labelCol="labelCol"
51           :wrapperCol="wrapperCol"
52           label="排序"
53         >
54           <a-input-number placeholder="请输入排序" style="width: 100%" v-decorator="['sort', { initialValue: 100 }]" :min="1" :max="1000" />
55         </a-form-item>
56
57         <a-form-item
58           label="备注"
59           :labelCol="labelCol"
60           :wrapperCol="wrapperCol"
61           has-feedback
62         >
63           <a-textarea :rows="4" placeholder="请输入备注" v-decorator="['remark']"></a-textarea>
64         </a-form-item>
65
66       </a-form>
67
68     </a-spin>
69   </a-modal>
70 </template>
71
72 <script>
73   import store from '@/store'
74   import { sysOrgAdd, getOrgTree } from '@/api/modular/system/orgManage'
75   export default {
76     data () {
77       return {
78         labelCol: {
79           xs: { span: 24 },
80           sm: { span: 5 }
81         },
82         wrapperCol: {
83           xs: { span: 24 },
84           sm: { span: 15 }
85         },
86         orgTree: [],
87         visible: false,
88         confirmLoading: false,
89         formLoading: true,
90         form: this.$form.createForm(this)
91       }
92     },
93     methods: {
94       // 初始化方法
95       add () {
96         this.visible = true
97         this.getOrgTree()
98       },
99
100       /**
101        * 获取机构树,并加载于表单中
102        */
103       getOrgTree () {
104         getOrgTree().then((res) => {
105           this.formLoading = false
106           if (!res.success) {
107             this.orgTree = []
108             return
109           }
110           const admintype = store.getters.admintype
111           // eslint-disable-next-line eqeqeq
112           if (admintype == '1') {
113             this.orgTree = [{
114               'id': '-1',
115               'parentId': '0',
116               'title': '顶级',
117               'value': '0',
118               'pid': '0',
119               'children': res.data
120             }]
121           } else {
122             this.orgTree = res.data
123           }
124         })
125       },
126
127       handleSubmit () {
128         const { form: { validateFields } } = this
129         this.confirmLoading = true
130         validateFields((errors, values) => {
131           if (!errors) {
132             sysOrgAdd(values).then((res) => {
133               if (res.success) {
134                 this.$message.success('新增成功')
135                 this.visible = false
136                 this.confirmLoading = false
137                 this.$emit('ok', values)
138                 this.form.resetFields()
139               } else {
140                 this.$message.error('新增失败:' + res.message)
141               }
142             }).finally((res) => {
143               this.confirmLoading = false
144             })
145           } else {
146             this.confirmLoading = false
147           }
148         })
149       },
150       handleCancel () {
151         this.form.resetFields()
152         this.visible = false
153       }
154     }
155   }
156 </script>