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     append-to-body>
7     <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="100px">
8       <el-row :gutter="20">
9         <el-col :span="12">
10           <el-form-item label="编号" prop="clockCode">
11             <el-input v-model="dataForm.clockCode" placeholder="编号"></el-input>
12           </el-form-item>
13         </el-col>
14         <el-col :span="12">
15           <el-form-item label="名称" prop="clockName">
16             <el-input v-model="dataForm.clockName" placeholder="名称"></el-input>
17           </el-form-item>
18         </el-col>
19       </el-row>
20       <el-row :gutter="20">
21         <el-col :span="12">
22           <el-form-item label="类别" prop="clockType">
23             <dict-select-tag v-model="dataForm.clockType" placeholder="类别" dictCode="clock-type" />
24           </el-form-item>
25         </el-col>
26         <el-col :span="12">
27           <el-form-item label="状态" prop="status">
28             <dict-select-tag v-model="dataForm.status" placeholder="状态" dictCode="enable" />
29           </el-form-item>
30         </el-col>
31       </el-row>
32       <el-row :gutter="20">
33         <el-col :span="24">
34           <el-form-item label="描述" prop="description">
35             <el-input v-model="dataForm.description" placeholder="描述"></el-input>
36           </el-form-item>
37         </el-col>
38       </el-row>
39     </el-form>
40     <span slot="footer" class="dialog-footer">
41       <el-button :loading="loading" @click="visible = false">取消</el-button>
42       <el-button :loading="loading" type="primary" @click="dataFormSubmit()">确定</el-button>
43     </span>
44   </el-dialog>
45 </template>
46
47 <script>
48   import DictSelectTag from '@/components/dict/dict-select-tag'
49   export default {
50     components: {
51       DictSelectTag
52     },
53     data () {
54       return {
55         loading: false,
56         visible: false,
57         dataForm: {
58           id: '',
59           clockCode: '',
60           clockName: '',
61           clockType: '',
62           status: '1',
63           description: ''
64         },
65         dataRule: {
66           clockCode: [
67             { required: true, message: '编号不能为空', trigger: 'blur' }
68           ],
69           clockName: [
70             { required: true, message: '名称不能为空', trigger: 'blur' }
71           ],
72           clockType: [
73             { required: true, message: '类别不能为空', trigger: 'blur' }
74           ]
75         }
76       }
77     },
78     methods: {
79       init (id, dictId) {
80         this.dataForm.id = id || 0
81         this.dataForm.dictId = dictId
82         this.visible = true
83         this.$nextTick(() => {
84           this.$refs['dataForm'].resetFields()
85           if (this.dataForm.id) {
86             this.$http({
87               url: `/data/index-data/clock/info/${this.dataForm.id}`,
88               method: 'get',
89               params: this.$http.adornParams()
90             }).then(({code, data}) => {
91               if (data && code === 0) {
92                 this.dataForm.clockCode = data.clockCode
93                 this.dataForm.clockName = data.clockName
94                 this.dataForm.clockType = data.clockType
95                 this.dataForm.status = data.status
96                 this.dataForm.description = data.description
97               }
98             })
99           }
100         })
101       },
102       // 表单提交
103       dataFormSubmit () {
104         this.$refs['dataForm'].validate((valid) => {
105           if (valid) {
106             this.loading = true
107             this.$http['post'](`/data/index-data/clock/${!this.dataForm.id ? 'add' : 'update'}`, this.dataForm).then(({ data: res }) => {
108               this.loading = false
109               if (res.code !== 0) {
110                 return this.$message.error(res.msg)
111               }
112               this.$message({
113                 message: this.$t('prompt.success'),
114                 type: 'success',
115                 duration: 500,
116                 onClose: () => {
117                   this.visible = false
118                   this.$emit('refreshDataList')
119                 }
120               })
121             }).catch(() => {this.loading = false})
122           }
123         })
124       }
125     }
126   }
127 </script>
128 <style>
129   .el-select {
130     width:100%
131   }
132   .el-input-group__append {
133     padding: 0 5px 0 5px
134   }
135   .el-input-group__prepend {
136     padding: 0 5px 0 5px
137   }
138 </style>