houzhongjian
2024-07-23 8501060c4f921d1e744c477e4dc08eb47b52693c
提交 | 用户 | 时间
850106 1 <template>
H 2   <el-dialog :visible.sync="visible" :title="!dataForm.id ? $t('add') : $t('update')" :close-on-click-modal="false"
3              :close-on-press-escape="false">
4     <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmitHandle()"
5              :label-width="$i18n.locale === 'en-US' ? '120px' : '80px'">
6       <el-row>
7         <el-col :span="12">
8           <el-form-item label="设备ID" prop="deviceCode">
9             <el-input v-model="dataForm.deviceId" placeholder="设备编号"></el-input>
10           </el-form-item>
11         </el-col>
12         <el-col :span="12">
13           <el-form-item label="设备编号" prop="deviceCode">
14             <el-input v-model="dataForm.deviceCode" placeholder="设备编号"></el-input>
15           </el-form-item>
16         </el-col>
17       </el-row>
18       <el-row>
19         <el-col :span="12">
20           <el-form-item label="设备名称" prop="deviceName">
21             <el-input v-model="dataForm.deviceName" placeholder="设备名称"></el-input>
22           </el-form-item>
23         </el-col>
24         <el-col :span="12">
25           <el-form-item label="所属车间" prop="workshop">
26             <el-input v-model="dataForm.workshop" placeholder="所属车间"></el-input>
27           </el-form-item>
28         </el-col>
29       </el-row>
30     </el-form>
31     <template slot="footer">
32       <el-button @click="visible = false">{{ $t('cancel') }}</el-button>
33       <el-button type="primary" @click="dataFormSubmitHandle()">{{ $t('confirm') }}</el-button>
34     </template>
35   </el-dialog>
36 </template>
37
38 <script>
39 import debounce from 'lodash/debounce'
40
41 export default {
42   data() {
43     return {
44       visible: false,
45       dataForm: {
46         id: '',
47         deviceId: '',
48         deviceCode: '',
49         deviceName: '',
50         workshop: '',
51       }
52     }
53   },
54   computed: {
55     dataRule() {
56       return {
57         deviceId: [
58           {required: true, message: this.$t('validate.required'), trigger: 'blur'}
59         ],
60         deviceCode: [
61           {required: true, message: this.$t('validate.required'), trigger: 'blur'}
62         ],
63         deviceName: [
64           {required: true, message: this.$t('validate.required'), trigger: 'blur'}
65         ]
66       }
67     }
68   },
69   methods: {
70     init() {
71       this.visible = true
72       this.$nextTick(() => {
73         this.$refs['dataForm'].resetFields()
74         if (this.dataForm.id) {
75           this.getInfo()
76         }
77       })
78     },
79     // 获取信息
80     getInfo() {
81       this.$http.get(`/iailab-ntt-model/device/device-account/${this.dataForm.id}`).then(({data: res}) => {
82         if (res.code !== 0) {
83           return this.$message.error(res.msg)
84         }
85         this.dataForm = {
86           ...this.dataForm,
87           ...res.data
88         }
89       }).catch(() => {
90       })
91     },
92     // 表单提交
93     dataFormSubmitHandle: debounce(function () {
94       this.$refs['dataForm'].validate((valid) => {
95         if (!valid) {
96           return false
97         }
98         this.$http[!this.dataForm.id ? 'post' : 'put']('/iailab-ntt-model/device/device-account/', this.dataForm).then(({data: res}) => {
99           if (res.code !== 0) {
100             return this.$message.error(res.msg)
101           }
102           this.$message({
103             message: this.$t('prompt.success'),
104             type: 'success',
105             duration: 500,
106             onClose: () => {
107               this.visible = false
108               this.$emit('refreshDataList')
109             }
110           })
111         }).catch(() => {
112         })
113       })
114     }, 1000, {'leading': true, 'trailing': false})
115   }
116 }
117 </script>