liuxiaolong
2019-05-06 d380e76ec9783bcd80eb42e495d6f8e1af0827b4
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
<template>
  <b-card no-body class="mx-4 mt-4 " style="height: 85vh;">
    <div class="px-4 py-4">
      <h4 class="font-weight-bold py-3 mb-2">
        <router-link to="/">
          <span class="font-weight-bold" style="color:#4E5155">布控任务 /</span>
        </router-link>
        <span class="text-muted font-weight-light">布控详情</span>
      </h4>
      <div class="flex-row-between">
        <div class="flex-row-left">
          <div class="flex-center">
            <div
              class="table-switch-btn active"
              :class="tabType==='map'?'active':''"
              @click="tabType='map'"
              v-show="tabType==='table' || tabType==='list'"
              >
              <i class="fas fa-map"></i>
            </div>
            <div
              class="table-switch-btn active"
              :class="tabType==='table'?'active':''"
              @click="tabType='table'"
              v-show="tabType==='map'"
              >
              <i class="fas fa-list-ul"></i>
            </div>
            <div>
              <span class="top-left">{{ctrolObj.name}}</span>
            </div>
            <div class="ml20">
              <span>状态:{{ctrolObj.status === 0?'未布控':'布控中'}}</span>
            </div>
            <div class="ml20">
              <span>对比阈值:{{ctrolObj.threshold}}</span>
            </div>
            <div class="ml20">
              <span>布控时间:</span>
              {{ctrolObj.startTime}} - {{ctrolObj.endTime}}
            </div>
          </div>
 
        </div>
        <div class="flex-row-right">
          <div
            class="table-switch-btn active"
            :class="tabType==='list'?'active':''"
            @click="tabType='list'"
            v-show="tabType==='table' || tabType==='map'"
            title="点击切换列表与视图模式"
          >
            <i class="fas fa-th-large"></i>
          </div>
          <div
            class="table-switch-btn active"
            :class="tabType==='table'?'active':''"
            @click="tabType='table'"
            v-show="tabType==='list'"
            >
            <i class="fas fa-list-ul"></i>
          </div>
          <el-button type="primary" @click.native="handleStopCtrlBatch">停止布控</el-button>
          <el-button type="info" @click.native="handleDelPersonBatch">删除此人</el-button>
        </div>
      </div>
      <div class="mt30">
        <!-- 布控列表 start -->
        <div v-show="tabType === 'table'">
          <detail-table
            :selectOpts="selectOpts"
            :selectVal="selectVal"
            :tableList="newTableList"
            :total="total"
            :activePage="activePage"
            :pageSize="pageSize"
            @sortChange="handleSortChange"
            @handleSelectionChange="handleSelectionChange"
            @stop="handleStopCtrl"
            @del="handleDelPerson"
          ></detail-table>
          <div class="pt15 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>
         <div v-if="tabType === 'map'" style="height:64vh">
 
            <div class="flex-center">
              <!-- 侧边栏按钮 start -->
              <div class="toggleOpen-btn open-tree bg-dark" :class="!isOpenTree?'isShow':''" v-if="!isOpenTree">
                <b-button variant="link" class="tree-btn" @click="isOpenTree = !isOpenTree">
                  <i class="ion ion-md-swap f20 text-white"></i>
                </b-button>
              </div>
              <div :style="isOpenTree?'width:25%;height:68vh':'width:0%;height:68vh'">
                <div
                  class="bg-white home-sidenav border-right"
                  :class="isOpenTree?'w-20':'w-0'"
                  style="height:68vh;"
                  >
                  <div class="pl-2 pr-2" style="min-width:200px">
                    <!-- 组织集合 start -->
                    <org-tree
                      ref="tree"
                      :isSearch="true"
                      :data="colonyData"
                      @currentNode="_currentNode"
                      :isOpen="true"
                      @toggleOpen="isOpenTree = !isOpenTree"
                    />
                    <!-- 组织集合 end -->
                  </div>
                </div>
              </div>
              <div :style="isOpenTree?'width:75%;height:68vh':'width:100%;height:68vh'">
                <view-map ref="map" :allDevices="allDevices"></view-map>
              </div>
            </div>
        </div>
        <div v-show="tabType === 'list'" class="overflow-auto" style="height:64vh">
          <!-- 布控列表 start -->
          <div class="px-4 py-4 person-list">
            <div class="row">
              <div
                class="col-lg-3 col-md-4 col-sm-6 pb-2"
                v-for="(item,index) in newTableList"
                :key="index"
              >
                <div class="person-list-item d-flex px-2 py-3 border">
                  <div class="person-list-item-check pr-2">
                    <el-checkbox v-model="item.checked" @change="checkboxChange"/>
                  </div>
                  <div class="person-list-item-img flex-center">
                    <httpImg :src="item.imgUrl" width="100px" height="100px" alt/>
                  </div>
                  <div class="person-list-item-info px-2">
                    <p class="mb-1" title="布控中">{{item.isControl}}</p>
                    <h6 class="mb-1 text-danger" title="吸毒人员">{{item.taskName}}</h6>
                    <p class="mb-1" title="张三/男/18岁">{{item.userInfo}}</p>
                    <div class="btns">
                      <span class="far fa-stop-circle" @click="handleStopCtrl(item)"></span>
                      <span class="ion ion-md-close" @click="handleDelPerson(item)"></span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <!-- 布控列表 end -->
 
        </div>
      </div>
    </div>
  </b-card>
</template>
<script>
import {
  Table,
  TableColumn,
  DatePicker,
  Select,
  Option,
  Row,
  Col,
  Button,
  Input,
  Checkbox
} from 'element-ui'
import ViewMap from '../../Home/components/mapDeviceList'
import orgTree from './deviceTree'
import detailTable from './detailTable'
import { getAllColonyNode } from '@/server/home.js'
import {getCtrlUserAlreadyList, stopCtrlAlready, delCtrlUserAlready} from '@/server/ctrl.js'
import {
  findScopeDetailByTaskId
} from '@/server/task.js'
 
export default {
  props: {
 
  },
  components: {
    elTable: Table,
    elTableColumn: TableColumn,
    elSelect: Select,
    elOption: Option,
    elInput: Input,
    elRow: Row,
    elCol: Col,
    elDatePicker: DatePicker,
    elButton: Button,
    ViewMap: ViewMap,
    orgTree: orgTree,
    detailTable: detailTable,
    elCheckbox: Checkbox
  },
  data() {
    return {
      userInfo: this.$store.getters.basicUserInfo,
      tabType: 'table',
      /** table数据 */
      newTableList: [],
      total: 10,
      pageSize: 10,
      activePage: 1,
      /** 排序字段 */
      sortName: '',
      sortType: 'desc',
      /** 地图上设备树是否展开 */
      isOpenTree: true,
      /** 树节点 */
      currentItem: {id: '0', type: '1', name: '集群设备'},
      /** 设备集群树数据 */
      colonyData: [],
      /** 地图上的所有设备集合 */
      allDevices: [],
      /** 布控状态数据源 */
      selectOpts: [
        {
          name: '布控状态',
          value: ''
        },
        {
          name: '未布控',
          value: '0'
        },
        {
          name: '布控中',
          value: '1'
        }
      ],
      selectVal: '',
      /** 表格跟列表转换 */
      tableTolist: 'table',
      /** 存储布控任务的对象 */
      ctrolObj: {},
      /** 勾选table中的 */
      checkIds: [],
      checkListIds: []
    }
  },
  computed: {
    orgId() {
      return this.$store.getters.basicUserInfo.orgId
    },
    userId() {
      return this.$store.getters.basicUserInfo.id
    }
  },
  methods: {
    /** 当排序发生改变的回调 */
    sortChange(column, prop, order) {
      console.log(column, prop, order, 'column, prop, order')
    },
    /** 获取序号 */
    snMethod(index) {
      return this.activePage > 1
        ? this.pageSize * (this.activePage - 1) + index + 1
        : index + 1
    },
    /** 地图上选择节点后回调 */
    _currentNode(data) {
      this.currentItem = data
      console.log(data, 'node---设备树')
      if (data) {
        this.selectDevice(data)
      }
    },
    /** 查询设备树 */
    async getAllColonyNode() {
      let res = await getAllColonyNode({ orgById: this.orgId })
      if (res) {
        this.colonyData = res
      }
    },
    // 排序
    handleSortChange(data) {
      console.log(data, '排序  sortChange')
      if (data) {
        if (data.prop === null) {
          this.sortType = 'desc'
          this.sortName = ''
        }
        if (data.order === 'descending') {
          this.sortType = 'desc'
          this.sortName = data.prop
        }
        if (data.order === 'ascending') {
          this.sortType = 'asc'
          this.sortName = data.prop
        }
        this.getCtrlUserAlreadyList(this.ctrolObj)
      }
    },
    // 布控select 选择
    handleSelectionChange(data) {
      console.log(data, '选择 handleSelectionChange')
      this.checkListIds = data.map(item => item.id)
    },
    checkboxChange(data) {
      const ids = this.newTableList
        .filter(item => item.checked)
        .map(item => item.id)
      this.handleTableCheck(ids)
      console.log(data, 'check', ids)
    },
    // 表格 check 事件
    handleTableCheck(ids) {
      console.log(ids, 'ids')
      this.checkListIds = [...ids]
    },
    // 停止布控
    handleStopCtrl({ id }) {
      this.checkIds = [id]
      this.stopCtrl(false)
    },
    // 批量停止布控
    handleStopCtrlBatch() {
      this.checkIds = [...this.checkListIds]
      this.stopCtrl(true)
    },
    async stopCtrlAlready() {
      const res = await stopCtrlAlready({
        ids: this.checkIds
      })
      return res
    },
    stopCtrl(isBatch) {
      this.$swal(
        {
          title: '确定停止布控吗?',
          text: isBatch
            ? '您所勾选的人员将会停止布控!'
            : '当前人员将会停止布控!',
          type: 'warning',
          showCancelButton: true,
          confirmButtonColor: '#DD6B55',
          cancelButtonText: '取消',
          confirmButtonText: '确定停止!',
          closeOnConfirm: false
        },
        async data => {
          if (!data) {
            return false
          }
          const res = await this.stopCtrlAlready()
          if (res && res.success) {
            this.$swal(
              '停止布控!',
              res.msg ? res.msg : '停止布控成功',
              'success'
            )
            // 成功后刷新
            this.getCtrlUserAlreadyList(this.ctrolObj)
          } else {
            this.$swal(
              '停止布控!',
              res.msg ? res.msg : '停止布控失败',
              'error'
            )
          }
        }
      )
    },
    // 删除此人
    handleDelPerson({ id }) {
      this.checkIds = [id]
      this.delPerson(false)
    },
    // 删除此人
    handleDelPersonBatch() {
      this.checkIds = [...this.checkListIds]
      this.delPerson(true)
    },
    async delCtrlUserAlready() {
      const list = this.checkIds.map(item => ({ id: item }))
      const res = await delCtrlUserAlready(list)
      console.log(res, 'delCtrlUserAlready()')
      return res
    },
    delPerson(isBatch) {
      this.$swal(
        {
          title: '确定删除布控吗?',
          text: isBatch
            ? '您所勾选的人员将会删除布控!'
            : '当前人员将会删除布控!',
          type: 'warning',
          showCancelButton: true,
          confirmButtonColor: '#DD6B55',
          cancelButtonText: '取消',
          confirmButtonText: '确定删除!',
          closeOnConfirm: false
        },
        async data => {
          if (!data) {
            return false
          }
          const res = await this.delCtrlUserAlready()
          if (res && res.success) {
            this.$swal(
              '删除布控!',
              res.msg ? res.msg : '删除布控成功',
              'success'
            )
            // 成功后刷新
            this.getCtrlUserAlreadyList(this.ctrolObj)
          } else {
            this.$swal(
              '删除布控!',
              res.msg ? res.msg : '删除布控失败',
              'error'
            )
          }
        }
      )
    },
    /* 检索事件 */
    handleSearch() {},
    /** 查询布控人员列表 */
    async getCtrlUserAlreadyList(data) {
      if (data) {
        let json = {
          isControl: this.selectVal,
          groupInformation: '',
          taskId: data.id,
          orderBy: this.sortName,
          sortType: this.sortType,
          start: this.pageSize * (this.activePage - 1),
          length: this.pageSize
        }
        let res = await getCtrlUserAlreadyList(json)
        if (res && res.success) {
          this.total = res.data.total
 
          this.newTableList = res.data.list.map(item => {
            // 处理布控状态 语义化
            for (let s of this.selectOpts) {
              if (item.isControl === s.value) {
                item.isControl = s.name
              }
            }
            // userInfo 拼接用户信息
            if (item.sex > -1) {
              item.sexName = item.sex ? '男' : '女'
            }
            const arr = ['username', 'sexName', 'idCard', 'mobile']
            let userInfo = ''
            for (let [index, name] of arr.entries()) {
              if (item[name]) {
                userInfo += item[name] + `${index !== arr.length - 1 ? '/' : ''}`
              }
            }
            let baseInfoName = ''
            for (let [index, name] of item.baseInfo.entries()) {
              if (name) {
                baseInfoName += name + `${index !== item.baseInfo.length - 1 ? '\n' : ''}`
              }
            }
            item.baseInfoName = baseInfoName
            item.userInfo = userInfo
            return item
          })
          console.log(this.newTableList, 'this.newTableList')
          this.newTableList.forEach(item => {
            this.$set(item, 'checked', false)
          })
        } else {
          this.$toast({
            type: 'error',
            message: '查询布控详情列表失败!'
          })
        }
      }
    },
    /** 查询任务的所在的设备 */
    async findDevices() {
      console.log(this.ctrolObj, 'this.ctrolObj  findDevices')
      let res = await findScopeDetailByTaskId({taskId: this.ctrolObj.id})
      console.log(res, 'res  findDevices')
      if (res && res.success) {
        /** 设置没有子节点的节点不可勾选 */
        const _setDisabled = data => {
          if (data.child && data.child !== null) {
            this.$set(data, 'isDevice', false)
            data.child.forEach(i => {
              _setDisabled(i)
            })
          } else {
            this.$set(data, 'isDevice', true)
          }
        }
        res.data.forEach((item) => {
          _setDisabled(item)
        })
        this.colonyData = res.data
        this.getDevicesToMap()
      }
    },
    /** 获取所有节点的集合 */
    getTreeNode(obj, arr) {
      arr.push(obj)
      if (obj.child && obj.child.length !== 0) {
        obj.child.forEach((item, index) => {
          this.getTreeNode(item, arr)
        })
      }
    },
    /** 筛选所选设备树节点中的设备,传给地图 */
    getDevicesToMap() {
      let devices = []
      this.colonyData.forEach(item => {
        this.getTreeNode(item, devices)
      })
      devices = devices.filter((item) => {
        return item.isDevice
      })
      this.allDevices = devices
      console.log(this.allDevices, 'devices')
    },
    /** 地图上的选择某个设备 */
    selectDevice(data) {
      if (data) {
        this.$refs.map.setActive(data)
      }
    },
    /** 取消高亮 */
    cancelActive() {
      this.$refs.map.cancelActive()
    }
 
  },
  created() {
    if (this.$route.query.rowData) {
      console.log(this.$route.query.rowData, 'this.$route.query.rowData')
      this.ctrolObj = this.$route.query.rowData
      this.getCtrlUserAlreadyList(this.ctrolObj)
      console.log(this.ctrolObj, 'this.ctrolObj')
      this.findDevices()
    }
    if (this.$route.query.isMap) {
      this.tabType = 'map'
    }
  }
}
</script>
<style lang="scss" scoped>
.table-switch-btn {
  height: 40px;
  line-height: 30px;
  font-size: 30px;
  padding: 5px 8px;
  color: #ccc;
  cursor: pointer;
  &.active {
    color: #35bde7;
  }
}
.top-left{
  color: red;
}
.el-button--primary {
  color: #fff;
  background-color: #35bde7;
  border-color: #35bde7;
}
.el-table--border, .el-table--group {
    border: 1px solid #ebeef5;
}
.home-sidenav {
  transition: all 0.5s;
  overflow: hidden;
}
.w-20 {
  width: 100%;
}
.w-80 {
  width: 80%;
}
.w-0 {
  width: 0%;
}
.open-tree{
  position: absolute;
  left: 5px;
  z-index: 500;
}
.person-list {
  .person-list-item {
    overflow: auto;
    .person-list-item-check {
      display: flex;
      align-items: center;
    }
    .person-list-item-img {
      flex: 1 1 auto;
      text-align: center;
    }
    .person-list-item-info {
      flex: 1 1 auto;
      h6 {
        font-size: 16px;
        font-weight: 900;
      }
      h6,
      p {
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin: 0 auto;
      }
      p.visibility {
        visibility: hidden;
      }
      p.none {
        display: none;
      }
      .btns {
        max-width: 100px;
        margin: 0 auto;
      }
      .btns span {
        padding: 0 2px;
        font-size: 15px;
        cursor: pointer;
        color: #35bde7;
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
      }
    }
    .person-list-item-close{
      float: right;
    }
  }
}
</style>