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="80px">
7       <el-form-item label="类型名称" prop="pointtypename">
8         <el-input v-model="dataForm.pointtypename" placeholder="类型名称" maxlength="50" clearable :disabled="!!dataForm.id"></el-input>
9       </el-form-item>
10       <el-form-item label="编号" prop="pointtypeno">
11         <el-input v-model="dataForm.pointtypeno" placeholder="编号" maxlength="5" clearable :disabled="!!dataForm.id"></el-input>
12       </el-form-item>
13       <el-form-item label="描述" prop="descp">
14         <el-input v-model="dataForm.descp" placeholder="描述" maxlength="50" clearable></el-input>
15       </el-form-item>
16     </el-form>
17     <span slot="footer" class="dialog-footer">
18       <el-button @click="visible = false">取消</el-button>
19       <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
20     </span>
21   </el-dialog>
22 </template>
23
24 <script>
25   import { isInteger } from '@/utils/validate'
26   export default {
27     data () {
28       var validatePointtypeno = (rule, value, callback) => {
29         if (!isInteger(value)) {
30           callback(new Error('编号应该为整数'))
31         } else {
32           callback()
33         }
34       }
35       return {
36
37         visible: false,
38         roleList: [],
39         dataForm: {
40           id: 0,
41           pointtypename: '',
42           pointtypeno: '',
43           descp: ''
44         },
45         dataRule: {
46           pointtypename: [
47             { required: true, message: '类型名称不能为空', trigger: 'blur' }
48           ],
49           pointtypeno: [
50             { required: true, message: '编号不能为空', trigger: 'blur' },
51             { validator: validatePointtypeno, trigger: 'blur' }
52           ]
53         }
54       }
55     },
56     methods: {
57       init (id) {
58         this.dataForm.id = id || 0
59         this.visible = true
60         this.$nextTick(() => {
61           this.$refs['dataForm'].resetFields()
62         })
63         if (id) {
64           this.$http({
65             url: `/data/data/point-type/info/${this.dataForm.id}`,
66             method: 'get',
67             params: this.$http.adornParams()
68           }).then(({data}) => {
69             if (data && data.code === 0) {
70               this.dataForm.pointtypename = data.pointType.pointtypename
71               this.dataForm.pointtypeno = data.pointType.pointtypeno
72               this.dataForm.descp = data.pointType.descp
73             }
74           })
75         }
76       },
77       // 表单提交
78       dataFormSubmit () {
79         this.$refs['dataForm'].validate((valid) => {
80           if (valid) {
81             this.$http['post'](`/data/data/point-type/${!this.dataForm.id ? 'save' : 'update'}`, this.dataForm).then(({ data: res }) => {
82               if (res.code !== 0) {
83                 return this.$message.error(res.msg)
84               }
85               this.$message({
86                 message: this.$t('prompt.success'),
87                 type: 'success',
88                 duration: 500,
89                 onClose: () => {
90                   this.visible = false
91                   this.$emit('refreshDataList')
92                 }
93               })
94             }).catch(() => {})
95           }
96         })
97       }
98     }
99   }
100 </script>