addDevice.vue
7.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
<template>
<el-dialog :title="$t('dialog.addDevice')" class="manage-dialog" :visible.sync="addDialogVisible"
:close-on-click-modal="false" @open="dialogOpen(addForm)" @close="addDialogClose">
<el-form :model="addForm" status-icon :rules="rules" ref="addForm">
<el-form-item :label="$t('dialog.number')" prop="serialnum">
<el-input v-model="addForm.serialnum"></el-input>
<i class="error-tip">*</i>
</el-form-item>
<el-form-item :label="$t('dialog.deviceName')" prop="name">
<el-input v-model="addForm.name"></el-input>
</el-form-item>
<el-form-item :label="$t('table.channelNum')" prop="channelCount">
<el-input v-model="addForm.channelCount"></el-input>
</el-form-item>
<el-form-item :label="$t('dialog.Mac')" prop="mac">
<el-input v-model="addForm.mac"></el-input>
</el-form-item>
<el-form-item :label="$t('table.state')" prop="status">
<el-select class="manage-sel" v-model="addForm.status" :placeholder="$t('pholder.state')">
<el-option :label="$t('pholder.stateA')" :value="1"></el-option>
<el-option :label="$t('pholder.stateB')" :value="0"></el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('table.localIP')" prop="localIp">
<el-input v-model="addForm.localIp"></el-input>
</el-form-item>
<el-form-item :label="$t('table.extranet')" prop="wanIp">
<el-input v-model="addForm.wanIp"></el-input>
</el-form-item>
<el-form-item :label="$t('dialog.swVersion')" prop="software">
<el-input v-model="addForm.software"></el-input>
</el-form-item>
<el-form-item :label="$t('dialog.hwVersion')" prop="hardware">
<el-input v-model="addForm.hardware"></el-input>
</el-form-item>
<el-form-item :label="$t('table.bloc')" prop="accountId">
<el-select class="manage-sel" v-model="addForm.accountId" filterable :placeholder="$t('pholder.select')"
@change="changeAddAccount" :no-data-text="$t('pholder.nodata')">
<el-option v-for="item in accountList" :key="item.id" :label="item.name" :value="item.id">
</el-option>
</el-select>
<i class="error-tip">*</i>
</el-form-item>
<el-form-item :label="$t('table.square')" prop="mallId">
<el-select class="manage-sel" v-model="addForm.mallId" filterable :placeholder="$t('pholder.select')"
:no-data-text="$t('pholder.nodata')">
<el-option v-for="item in mallList" :key="item.id" :label="item.name" :value="item.id">
</el-option>
</el-select>
<i class="error-tip">*</i>
</el-form-item>
<!-- <el-form-item label="描述">
<el-input type="textarea" v-model="addForm.intro"></el-input>
</el-form-item> -->
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="addDialogVisible = false" class="dialog-btn">{{ $t('dialog.cancel') }}</el-button>
<el-button type="primary" @click="addSubmit('addForm')" class="dialog-btn dialog-confirm-btn">
{{ $t('dialog.confirm') }}</el-button>
</div>
</el-dialog>
</template>
<script>
export default {
data() {
var validatorSerialnum = (rule, value, callback) => {
// if (value === '') {
// return callback(new Error('请输入设备序列号'));
// } else
if (!value) {
return callback(new Error('请输入设备序列号'));
}
this.$api.management.deviceList({
serialnum: value,
// _t: Date.parse(new Date()) / 1000
})
.then((res) => {
if (res.data.data.length > 0) {
if (res.data.data[0].mallId) {
callback();
} else {
return callback(new Error('该设备序列号已绑定, 请重新输入'));
}
} else {
callback();
}
})
.catch((error) => {})
};
return {
addDialogVisible: false,
accountList: [],
mallList: [],
addForm: {
serialnum: '',
name: '',
channelCount: '',
mac: '',
status: null,
localIp: '',
wanIp: '',
software: '',
hardware: '',
accountId: '',
mallId: ''
},
rules: {
serialnum: [{
required: true,
message: '请输入设备序列号',
trigger: 'blur'
}],
accountId: [{
required: true,
message: '请选择集团',
trigger: 'change'
}],
mallId: [{
required: true,
message: '请选择门店',
trigger: 'change'
}]
},
curMallId: null,
}
},
created() {},
methods: {
dialogInit(mall_id) {
this.curMallId = mall_id;
this.addDialogVisible = true;
},
dialogOpen(formDatas) {
this.getAccountList();
},
getAccountList() {
this.accountList = [];
this.$api.base.account({
// _t: Date.parse(new Date()) / 1000
})
.then((data) => {
let result = data.data;
result.data.forEach(item => {
if (item.id == this.$cookie.get('accountId')) {
this.addForm.accountId = item.id;
}
})
this.accountList = result.data;
this.getMallList(this.addForm.accountId);
})
.catch((error) => {})
},
changeAddAccount(val) {
this.getMallList(val)
},
getMallList(accountId) {
this.mallList = [];
this.addForm.mallId = '';
if (!accountId) return;
this.$api.base.mall({
accountId: accountId,
// status: 1,
status_arr: '1,3'
// _t: Date.parse(new Date()) / 1000
}, null, true)
.then((data) => {
let result = data.data;
result.data.forEach(item => {
if (item.id == this.curMallId) {
this.addForm.mallId = item.id;
}
})
this.mallList = result.data;
if (this.mallList.length > 0) {
if (!this.curMallId) {
this.addForm.mallId = this.mallList[0].id;
}
// this.editForm.mallId = this.mallList[0].id;
// this.getFloorList(this.addForm.mallId)
}
})
.catch((error) => {})
},
addSubmit(formName) {
this.$refs[formName].validate((valid) => {
if (valid) {
// this.addForm.accountId = this.$cookie.get('accountId');
this.addForm.createUser = this.$cookie.get('userId');
this.addForm.modifyUser = this.$cookie.get('userId');
this.$api.management.addDevice(this.addForm)
.then((data) => {
this.addDialogVisible = false;
this.$parent.getTableData();
})
.catch((error) => {})
} else {
return false;
}
});
},
addDialogClose() {
this.$refs.addForm.resetFields();
},
}
}
</script>