liuxiaolong
2019-05-06 19e47fa0e48ac76a951bbfaa0a3e95211567f5a1
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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
<template>
  <div class="clients-wrapper" style="position: initial;" :class="{'clients-sidebox-open': sideboxOpened}">
    <div class="clients-content clients-scroll container-p-x container-p-y overflow-y">
      <!-- Header -->
      <h4 class="d-flex flex-wrap justify-content-between align-items-center font-weight-bold pt-2 mb-2">
        <div class="mb-2">设备管理</div>
        <div class="mb-2" style="max-width: 200px;">
          <fButton
            type="warning"
            @click.native="()=>{$router.push({path:'/device/add'})}"
            authority="sys:device:add"
          >
            <span class="fas fa-plus pr10"></span>
            添加设备
          </fButton>
      </div>
    </h4>
      <!-- / Header -->
 
      <!-- 设备列表 -->
      <b-card no-body>
          <!-- 检索 start -->
          <b-card-header header-tag="h4" class="media flex-wrap align-items-center py-4">
            <b-button-group class="mr10">
              <b-button
                v-for="iteam in newDeviceTypeDicts"
                :key="iteam.id"
                :variant="deviceType===iteam.value?'primary':'outline-primary'"
                @click="deviceType=iteam.value;_initData()"
                >
              {{iteam.lable}}
              </b-button>
            </b-button-group>
            <b-form-select style="max-width: 10rem;" v-model="authorizationSystem" @change="(e)=>{authorizationSystem = e;_initData()}" text-field="lable" :options="newSysDicts" class="mr10"/>
            <b-input
              placeholder="请输入IP地址、设备名称或位置描述..."
              autocomplete="off"
              style="max-width: 20rem;"
              class="mr10"
              v-model="searchName"
              @keyup.enter.native="handleSearch"
            />
            <b-btn variant="primary" class="mr10" @click="handleSearch"><span class="fs fas-search"></span>搜索</b-btn>
          </b-card-header>
          <!-- 检索 end -->
          <div class="pl20 pr20 pt10 pb30">
            <Table
              :data="newTableList"
              highlight-current-row
              @current-change="checkDeviceInfo"
              ref="leftTable"
            >
              <TableColumn
                type="index"
                prop="index"
                label="序号"
                :index="snMethod"
                width="50"
              />
              <TableColumn
                label="类型"
                prop="type"
                width="50">
                <template slot-scope="scope">
                  <img :src="'/static/img/map/'+scope.row.icon+'.png'" width="30" height="30" :onerror="noneImg" :alt="scope.row.icon">
                </template>
              </TableColumn>
              <TableColumn
                label="设备名称"
                prop="deviceName"
              />
              <TableColumn
                label="IP地址"
                prop="ip"
              />
              <TableColumn
                label="位置描述"
                prop="description"
              />
              <TableColumn
                label="授权系统"
                prop="authorizationSystemName"
              />
              <TableColumn
                label="操作"
                width="180"
              >
                <template slot-scope="scope">
                  <div @click.stop>
                  <fButton
                    type="link"
                    style="padding:2px;"
                    @click.native="handleDel(scope.row.id)"
                    authority="sys:device:delete"
                  >
                    删除
                  </fButton>
                  <fButton
                    type="link"
                    style="padding:2px;"
                    authority="sys:device:update"
                    @click.native.self="$router.push({path:'/device/add',query:{id:scope.row.id}})"
                  >
                    编辑
                  </fButton>
                  </div>
                </template>
              </TableColumn>
            </Table>
            <div class="pt20 pb20">
              <b-pagination class="justify-content-center justify-content-sm-end m-0"
                v-if="total"
                v-model="activePage"
                :total-rows="total"
                :per-page="pageSize"
              />
            </div>
          </div>
        </b-card>
      <!-- / 设备列表 -->
    </div>
    <!-- 详细信息栏 -->
    <div class="clients-sidebox">
      <a @click.prevent="closeSidebox" href="#" class="clients-sidebox-close setCloseBtn text-muted text-xlarge font-weight-light">
        <i class="fa fa-angle-double-right"></i>
      </a>
      <perfect-scrollbar  :options="{ suppressScrollX: true, wheelPropagation: true }" class="clients-scroll  pl20 pr20">
        <h5 class="pt30">设备属性 </h5>
        <b-card no-body class="pt30 pl20 pr20 pb20">
          <el-collapse v-model="activeCollapse"  >
            <el-collapse-item title="概况" name="basic">
              <b-form-group horizontal label-class="text-sm-right pt-0"  :label-cols="5" label="IP地址:"><div>{{deviceInfo&&deviceInfo.ip}}</div></b-form-group>
              <b-form-group horizontal label-class="text-sm-right pt-0" :label-cols="5" label="端口号:"><div>{{deviceInfo&&deviceInfo.port}}</div></b-form-group>
            </el-collapse-item>
            <el-collapse-item title="维修记录" name="repair">
              <div class="text-center">暂无数据</div>
            </el-collapse-item>
          </el-collapse>
        </b-card>
      </perfect-scrollbar>
    </div>
    <!-- / 详细信息栏 -->
  </div>
 
</template>
<!-- Page -->
<style src="@/vendor/styles/pages/clients.scss" lang="scss"></style>
<style>
.setCloseBtn {
  right: 10px;
  left: auto;
  top: 1.5rem;
}
</style>
 
<script>
import { Table, TableColumn, Collapse, CollapseItem } from 'element-ui'
import PerfectScrollbar from '@/vendor/libs/perfect-scrollbar/PerfectScrollbar'
import {
  getDeviceList,
  delDevice,
  getDeviceInfo
} from '@/server/deviceManagement.js'
import { getDeviceType, getSysList } from '@/server/common.js'
 
export default {
  name: 'deviceManagement',
  metaInfo: {
    title: '设备管理'
  },
  data() {
    return {
      noneImg: 'this.src="' + require('@/assets/img/noneImg.png') + '"',
      userInfo: this.$store.getters.basicUserInfo,
 
      deviceType: '',
      deviceTypeDicts: [],
      authorizationSystem: '',
      sysDicts: [],
 
      searchName: '',
      tableList: [],
      total: 0,
      pageSize: 10,
      activePage: 1,
 
      /* 右侧侧边栏 */
      sideboxOpened: false,
      activeCollapse: 'basic',
      deviceInfo: null
    }
  },
  computed: {
    newSysDicts() {
      return [{ value: '', lable: '全部' }, ...this.sysDicts]
    },
    newDeviceTypeDicts() {
      return [{ value: '', lable: '全部' }, ...this.deviceTypeDicts]
    },
    newTableList() {
      let sysDicts = this.sysDicts
      let list = this.tableList.map(iteam => {
        if (iteam.authorizationSystem) {
          let arr = iteam.authorizationSystem.replace(/^,+|,+$/g, '').split(',')
          let strName = ''
          for (let val of arr) {
            for (let sysIteam of sysDicts) {
              if (sysIteam.value === val) {
                strName +=
                  strName === '' ? sysIteam.lable : ',' + sysIteam.lable
              }
            }
          }
          iteam.authorizationSystemName = strName
          return iteam
        }
      })
      return list
    }
  },
  methods: {
    // 关闭侧边栏
    closeSidebox() {
      this.sideboxOpened = false
      /* 取消选择 */
      this.$refs.leftTable.setCurrentRow(null)
    },
    snMethod(index) {
      return this.activePage > 1
        ? this.pageSize * (this.activePage - 1) + index + 1
        : index + 1
    },
    async getSysDicts() {
      let res = await getSysList({
        orgId: this.userInfo.orgId,
        userId: this.userInfo.id,
        tags: 'device'
      })
      if (res && !res.error) {
        this.sysDicts = res
      }
    },
    async getDeviceTypeDicts() {
      let res = await getDeviceType({ orgId: this.userInfo.orgId })
      if (res) {
        this.deviceTypeDicts = res
      }
    },
    /* 设备列表初始化 */
    async _initData() {
      let res = await getDeviceList({
        orgId: this.userInfo.orgId,
        length: this.pageSize,
        start: this.pageSize * (this.activePage - 1),
        searchName: this.searchName,
        deviceType: this.deviceType,
        authorizationSystem: this.authorizationSystem
      })
      if (res) {
        this.tableList = res.data
        this.total = res.total
      }
    },
    /* 获取设备信息 */
    async getDeviceInfo(id) {
      let res = await getDeviceInfo({ orgId: this.userInfo.orgId, id })
      if (res) {
        this.deviceInfo = res
        /* 打开侧边栏 */
        this.sideboxOpened = true
      } else {
        this.$notify({
          group: 'foo',
          type: 'warn',
          title: '抱歉,这条数据有错误',
          text: '这条数据有错误,请联系管理员'
        })
      }
    },
    // 搜索
    handleSearch() {
      this._initData()
    },
    // 删除
    handleDel(id) {
      this.$swal(
        {
          title: '确定删除吗?',
          type: 'warning',
          showCancelButton: true,
          allowOutsideClick: true,
          confirmButtonText: '确定删除!',
          cancelButtonText: '取消删除!',
          closeOnConfirm: true
        },
        async () => {
          let res = await delDevice({
            orgId: this.userInfo.orgId,
            id
          })
          if (res && res.success) {
            // this.$swal(
            //   '删除成功',
            //   `${res.msg ? res.msg : ''}`,
            //   'success'
            // )
            this.$toast({
              type: 'success',
              message: '删除成功'
            })
            this._initData()
          } else {
            // this.$swal('删除失败', `${res.msg ? res.msg : ''}`, 'error')
            this.$toast({
              type: 'error',
              message: '删除失败'
            })
          }
        }
      )
    },
    // 查看设备详情
    checkDeviceInfo(row) {
      if (row && row.id) {
        this.getDeviceInfo(row.id)
      }
    }
  },
  watch: {
    activePage(val, oldVal) {
      if (val !== oldVal) {
        this.activePage = val
        this._initData()
      }
    }
  },
  created() {
    /* 查询字典 */
    this.getSysDicts()
    this.getDeviceTypeDicts()
    /* 查询列表 */
    this._initData()
  },
  components: {
    Table,
    TableColumn,
    elCollapse: Collapse,
    elCollapseItem: CollapseItem,
    PerfectScrollbar
  }
}
</script>