inleft
2022-08-26 4adb0063ef324e235218cc73eea63e39a6e8e59f
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="confirmLoading">
11       <a-form :form="form">
12         <a-form-item
13           style="display: none;"
14           :labelCol="labelCol"
15           :wrapperCol="wrapperCol"
16           has-feedback
17         >
18           <a-input v-decorator="['typeId']" />
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="['value', {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-input placeholder="请输入唯一编码" v-decorator="['code', {rules: [{required: true, message: '请输入唯一编码!'}]}]" />
37         </a-form-item>
38
39         <a-form-item
40           :labelCol="labelCol"
41           :wrapperCol="wrapperCol"
42           label="排序"
43         >
44           <a-input-number placeholder="请输入排序" style="width: 100%" v-decorator="['sort', { initialValue: 100 }]" :min="1" :max="1000" />
45         </a-form-item>
46
47         <a-form-item
48           label="备注"
49           :labelCol="labelCol"
50           :wrapperCol="wrapperCol"
51           has-feedback
52         >
53           <a-textarea :rows="4" placeholder="请输入备注" v-decorator="['remark']"></a-textarea>
54         </a-form-item>
55
56       </a-form>
57
58     </a-spin>
59   </a-modal>
60 </template>
61
62 <script>
63   import { sysDictDataAdd } from '@/api/modular/system/dictDataManage'
64   export default {
65     data () {
66       return {
67         labelCol: {
68           xs: { span: 24 },
69           sm: { span: 5 }
70         },
71         wrapperCol: {
72           xs: { span: 24 },
73           sm: { span: 15 }
74         },
75         visible: false,
76         confirmLoading: false,
77         form: this.$form.createForm(this)
78       }
79     },
80     methods: {
81       // 初始化方法
82       add (record) {
83         this.visible = true
84         // 增加上级类型ID
85         setTimeout(() => {
86           this.form.setFieldsValue(
87             {
88               typeId: record
89             }
90           )
91         }, 100)
92       },
93
94       handleSubmit () {
95         const { form: { validateFields } } = this
96         this.confirmLoading = true
97         validateFields((errors, values) => {
98           if (!errors) {
99             sysDictDataAdd(values).then((res) => {
100               if (res.success) {
101                 this.$message.success('新增成功')
102                 this.visible = false
103                 this.confirmLoading = false
104                 this.$emit('ok', values)
105                 this.form.resetFields()
106               } else {
107                 this.$message.error('新增失败:' + res.message)
108               }
109             }).finally((res) => {
110               this.confirmLoading = false
111             })
112           } else {
113             this.confirmLoading = false
114           }
115         })
116       },
117       handleCancel () {
118         this.form.resetFields()
119         this.visible = false
120       }
121     }
122   }
123 </script>