bindDevice.vue
5.15 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
<template>
<el-dialog
:title="$t('dialog.deviceBind')"
class="manage-dialog bind-middle-dialog"
:visible.sync="bindVisible"
:close-on-click-modal="false"
@close="bindDialogClose">
<div class="mall-sel-box">
<el-select class="belong-mall-sel" v-model="belongMallVal" placeholder="选择所属门店">
<el-option v-for="(mallItem, mallIndex) in belongMallList" :label="mallItem.name" :value="mallItem.id" :key="mallIndex"></el-option>
</el-select>
</div>
<el-row class="search-box">
<el-col :span="20">
<el-input v-model="devSerialnum" class="search-inp" size="mini" placeholder="请输入设备序列号" clearable @keyup.enter.native="searchFn"></el-input>
</el-col>
<el-col :span="3" :offset="1">
<el-button type="primary" class="search-btn" plain size="mini" @click="searchFn">{{$t('button.search')}}</el-button>
</el-col>
</el-row>
<el-table
class="dev-table"
:data="devList"
style="width: 100%"
height="400"
:empty-text="noDataText"
@selection-change="handleSelectionChange">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column label="IP" prop="localIp" align="center"></el-table-column>
<el-table-column :label="$t('table.deviceNum')" prop="serialnum" align="center"></el-table-column>
</el-table>
<div slot="footer" class="dialog-footer">
<el-button type="primary" class="dialog-btn dialog-confirm-btn" :disabled="bindDisable" @click="bindDev">{{$t('button.binding')}}</el-button>
</div>
</el-dialog>
</template>
<script>
export default {
data() {
return {
bindVisible: false,
belongMallVal: '',
belongMallList: [],
devSerialnum: '',
devList: [],
bindDisable: false,
noDataText: '',
checkedDev: [],
}
},
methods: {
dialogInit() {
this.getDevMallList();
if(this.$Project == 'mall') {
this.getAllUnbindDev();
}
this.bindVisible = true;
},
getDevMallList() {
this.belongMallList = [];
this.belongMallVal = '';
// this.mallNoData = 'load';
this.$api.base.mall({
accountId: this.$cookie.get('accountId'),
// status: 1,
status_arr: '1,3'
// _t: Date.parse(new Date()) / 1000
},null,true)
.then((data) => {
let result = data.data;
if (result.data.length <= 0) {
// this.mallNoData = '数据为空';
// this.bindForm.mallId = result[0].id;
}
result.data.forEach((item, index) => {
if (index == 0) {
// this.belongMallVal = item.id;
}
// item.isCheck = false;
// item.className = 'gate-item';
})
this.belongMallList = result.data;
})
.catch((error) => { })
},
searchFn() {
this.getAllUnbindDev();
},
getAllUnbindDev() {
this.devList = [];
this.noDataText = 'load';
// 获取所有未绑定的设备
this.$api.management.getDevices({
accountId: this.$cookie.get('accountId'),
// mallId: this.mallValue,
// status: '',
serialnum: this.devSerialnum ? this.devSerialnum : null,
localIp: this.devSerialnum ? this.devSerialnum : null,
// mallId_null: true,
// _t: Date.parse(new Date()) / 1000
})
.then((data) => {
let result = data.data;
// console.log('unbind dev:', result)
if (result.data.list.length <= 0) {
this.noDataText = this.$t('echartsTitle.noData')
}
this.devList = result.data.list;
})
},
handleSelectionChange(val) {
this.checkedDev = val.map(item => {
return item.id;
})
},
bindDev() {
// console.log(this.checkedDev, this.curCheckMall)
if (this.checkedDev.length == 0) return;
if(!this.belongMallVal) {
this.$message({
showClose: true,
type: 'warning',
message: this.$t('message.selectMall')
})
return;
}
this.bindDisable = true;
this.$api.management.batchBindDevice({
mallId: this.belongMallVal,
deviceIds: this.checkedDev
})
.then((res) => {
let result = res.data;
// console.log('batch bind:', result)
if (result.code == 200) {
this.bindVisible = false;
this.$message({
showClose: true,
type: 'success',
message: this.$t('message.bindDevice')
})
this.$parent.getTableData();
} else {
this.$message({
showClose: true,
type: 'error',
message: this.$t('message.deviceFailed') + result.msg
})
this.bindDisable = false;
}
})
.catch(err => {
this.$message({
showClose: true,
type: 'error',
message: this.$t('message.deviceFailed') + err.message
})
this.bindDisable = false;
})
},
bindDialogClose() {
this.devSerialnum = '';
},
}
}
</script>
<style scoped>
.mall-sel-box {
padding: 0 0 10px;
}
.belong-mall-sel {
display: inline-block;
width: 100%;
}
.search-box {
margin-bottom: 10px;
}
</style>