houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog
3     :title="!dataForm.id ? '新增' : '修改'"
4     :close-on-click-modal="false"
5     :visible.sync="visible">
6     <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
7       <el-form-item label="分组名称" prop="groupName">
8         <el-input v-model="dataForm.groupName" placeholder="分组名称"></el-input>
9       </el-form-item>
10       <el-form-item label="分组描述" prop="groupDesc">
11         <el-input v-model="dataForm.groupDesc" placeholder="分组描述"></el-input>
12       </el-form-item>
13     </el-form>
14     <span slot="footer" class="dialog-footer">
15       <el-button @click="visible = false">取消</el-button>
16       <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
17     </span>
18   </el-dialog>
19 </template>
20
21 <script>
22   export default {
23     data () {
24       return {
25         visible: false,
26         loading: false,
27         dataForm: {
28           id: '',
29           groupName: '',
30           groupDesc: ''
31         },
32         dataRule: {
33           groupName: [
34             { required: true, message: '分组名称不能为空', trigger: 'blur' }
35           ]
36         }
37       }
38     },
39     methods: {
40       init (id) {
41         this.dataForm.id = id || 0
42         this.visible = true
43         this.$nextTick(() => {
44           this.$refs['dataForm'].resetFields()
45           if (this.dataForm.id) {
46             this.getInfo()
47           }
48         })
49       },
50       // 获取信息
51       getInfo() {
52         this.$http.get(`/data/api-gateway/group/info/${this.dataForm.id}`).then(({data: res}) => {
53           if (res.code !== 0) {
54             return this.$message.error(res.msg)
55           }
56           this.dataForm = {
57             ...this.dataForm,
58             ...res.data
59           }
60         }).catch(() => {
61         })
62       },
63       // 表单提交
64       dataFormSubmit () {
65         this.$refs['dataForm'].validate((valid) => {
66           if (!valid) {
67             return false
68           }
69           this.loading = true
70           this.$http['post'](`/data/api-gateway/group/${!this.dataForm.id ? 'add' : 'update'}`, this.dataForm).then(({data: res}) => {
71             this.loading = false
72             if (res.code !== 0) {
73               return this.$message.error(res.msg)
74             }
75             this.$message({
76               message: this.$t('prompt.success'),
77               type: 'success',
78               duration: 500,
79               onClose: () => {
80                 this.visible = false
81                 this.$emit('refreshDataList')
82               }
83             })
84           }).catch(() => {
85           })
86         })
87       }
88     }
89   }
90 </script>