deviceList.vue
9.69 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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
<template>
<v-layout>
<template slot="breadcrumb">
<el-breadcrumb-item>设备管理</el-breadcrumb-item>
<el-breadcrumb-item>设备管理</el-breadcrumb-item>
</template>
<template slot="main">
<div class="ibox">
<!-- 表单查询 -->
<el-form :inline="true" ref="form" :model="form" >
<el-form-item label="创建时间">
<el-date-picker
v-model="form.dateRange"
value-format="yyyy-MM-dd"
size="small"
type="daterange"
range-separator="至"
start-placeholder="开始日期"
end-placeholder="结束日期">
</el-date-picker>
</el-form-item>
<el-form-item label="厂商">
<contractor-select
defaultValue=""
@contractorChange="(contractor)=>form.contractor=contractor">
</contractor-select>
</el-form-item>
<el-form-item label="分类">
<device-type-cascade
:id="form.classifyId"
:init="false"
@onTypeChange="(id)=>form.classifyId=id"
></device-type-cascade>
</el-form-item>
<el-form-item label="状态">
<el-select v-model="form.status" placeholder="请选择" size="small" style="width:100px;">
<el-option label="全部" value=""></el-option>
<el-option label="启用" :value="1"></el-option>
<el-option label="停用" :value="0"></el-option>
</el-select>
</el-form-item>
<el-form-item label="是否有源">
<el-select v-model="form.source" placeholder="请选择" size="small" style="width:100px;">
<el-option label="全部" value=""></el-option>
<el-option label="有源" :value="1"></el-option>
<el-option label="无源" :value="0"></el-option>
</el-select>
</el-form-item>
<el-form-item>
<el-input placeholder="请输入对应条件值" v-model.trim="form.queryTerm" size="small" class="input-with-select" clearable>
<el-select v-model="form.queryType" slot="prepend" style="width:130px;" placeholder="请选择" size="small">
<el-option label="设备名称" value="name"></el-option>
<!-- <el-option label="设备型号" value="deviceType"></el-option> -->
</el-select>
</el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="onSubmit" size="small">查询</el-button>
</el-form-item>
</el-form>
<!-- 表单查询 /-->
</div>
<div class="ibox">
<div class="ibox-title">
<h3 class="pull-left">设备管理</h3>
<el-button
type="primary"
plain size="small"
class="pull-right ibox-ctrl"
@click="addDevice">
添加设备
</el-button>
</div>
<div class="ibox-content">
<el-table
:data="tableData"
border
size="small"
v-loading="loading"
@selection-change="selectChange"
style="width: 100%">
<!-- <el-table-column fixed type="selection" width="40" align="center"></el-table-column> -->
<el-table-column fixed type="index" label="序号" :index="getIndex" align="center" width="70"></el-table-column>
<el-table-column fixed prop="id" label="设备编号" min-width="100" align="center"></el-table-column>
<el-table-column prop="name" label="设备名称" min-width="160" align="center"></el-table-column>
<el-table-column prop="classifyName" label="分类" min-width="180" align="center"></el-table-column>
<el-table-column prop="contractor" label="厂商" min-width="160" align="center"></el-table-column>
<el-table-column prop="source" label="是否有源" min-width="100" align="center">
<template slot-scope="scope">
<span v-show="scope.row.source===1">有源</span>
<span v-show="scope.row.source===0">无源</span>
</template>
</el-table-column>
<el-table-column prop="status" label="状态" min-width="100" align="center">
<template slot-scope="scope">
<span v-show="scope.row.status===1">启用</span>
<span v-show="scope.row.status===0">停用</span>
</template>
</el-table-column>
<el-table-column prop="createUser" label="创建人" min-width="100" align="center"></el-table-column>
<el-table-column prop="createTime" label="创建时间" min-width="160" align="center"></el-table-column>
<el-table-column fixed="right" label="操作" min-width="160" align="center">
<template slot-scope="scope">
<el-button v-if="scope.row.status===0" @click="toggleDeviceStatus(scope.row.id, '开启')" type="text" size="medium">开启</el-button>
<el-button v-if="scope.row.status===1" @click="toggleDeviceStatus(scope.row.id, '关闭')" type="text" size="medium">关闭</el-button>
<el-button @click="editDevice(scope.row.id)" type="text" size="medium">编辑</el-button>
<el-button @click="checkDevice(scope.row.id)" type="text" size="medium">查看</el-button>
</template>
</el-table-column>
</el-table>
<div class="table-page-wrap">
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[10, 20, 30, 40]"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="total">
</el-pagination>
</div>
</div>
</div>
<!-- 添加设备弹框 -->
<device-modal
:deviceModalVisible="deviceModalVisible"
:id="deviceId"
:isReadMode="isReadMode"
@onDeviceModalChange="(isOpen)=>deviceModalVisible = isOpen"
@onRefreshList="getData">
</device-modal>
<!-- 批量导入弹框 /-->
</template>
</v-layout>
</template>
<script>
import vDateRange from 'components/DateRange.vue'
import {exportExcel} from 'utils'
import {services} from '../../api'
import deviceModal from './deviceModal.vue'
import deviceTypeCascade from './DeviceTypeCascade.vue'
import contractorSelect from './ContractorSelect.vue'
const DEVICE_SERVICE = services.device;
export default{
data(){
return {
loading: true,
currentPage: 1,
pageSize: 10,
total: 0,
tableData: [],
form: {
dateRange: [],
contractor: '',
classifyId: '',
queryType: 'name',
queryTerm: '',
status: '',
source: ''
},
selectedIds: [],
deviceId: '',
isReadMode: false,
deviceModalVisible: false
}
},
created(){
this.getData();
},
computed: {
},
methods: {
getIndex(index){
return (this.currentPage-1)*this.pageSize+index+1;
},
getData(curr=this.currentPage, size=this.pageSize){
this.loading = true;
let params = this.getParams();
params.currentPage = curr;
params.pageSize = size;
DEVICE_SERVICE.getDeviceList(params).then((response)=>{
if(Array.isArray(response.data)){
this.tableData = response.data;
this.total = response.recordsTotal;
}else{
this.tableData = [];
this.total = 0;
}
this.loading = false;
}).catch((error) => console.log(error))
},
getParams(){
const form = this.form;
const params = {}
if(form.dateRange && form.dateRange.length){
params.sTime = moment(form.dateRange[0]).startOf('day').format('YYYY-MM-DD HH:mm:ss')
params.eTime = moment(form.dateRange[1]).endOf('day').format('YYYY-MM-DD HH:mm:ss')
}
if(form.classifyId !== ''){
params.classifyId = form.classifyId
}
if(form.contractor){
params.contractor = form.contractor;
}
if(typeof form.status === 'number'){
params.status = form.status
}
if(typeof form.source === 'number'){
params.source = form.source
}
const queryTerm = form.queryTerm;
if(queryTerm && form.queryType){
params[form.queryType] = queryTerm
}
return params;
},
selectChange(selection){
this.selectedIds = [];
selection.map((obj)=>{
this.selectedIds.push(obj.id)
});
},
checkDevice(id){
this.deviceModalVisible = true
this.deviceId = id
this.isReadMode = true
},
editDevice(id){
this.deviceModalVisible = true
this.deviceId = id
this.isReadMode = false
},
addDevice(){
this.deviceModalVisible = true
this.deviceId = ''
this.isReadMode = false
},
toggleDeviceStatus(id, info){
this.$confirm(`确定要${info}该设备吗?`, '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
DEVICE_SERVICE.swichDeviceById({id}).then((res) => {
if(res.returnCode == 0){
this.getData()
}
})
})
},
handleSizeChange(val) {
this.pageSize = val;
this.getData(this.currentPage,this.pageSize)
},
handleCurrentChange(val) {
this.currentPage = val;
this.getData(val)
},
onSubmit(){
this.currentPage = 1;
this.pageSize = 10;
this.getData();
},
exportExcel(){
const url = 'device/deviceManage/exportDeviceManageList';
if(this.selectedIds.length){
exportExcel(url, {idList: this.selectedIds.join(',')})
}else{
exportExcel(url, this.getParams())
}
}
},
components:{
vDateRange,
deviceModal,
contractorSelect,
deviceTypeCascade
}
}
</script>
<style lang="scss">
</style>