zhangzengfei
2023-08-30 b2d0ac2db80c08783fd848933230618cc30d76a2
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
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
<template>
  <div class="sub-account" v-if="!isShowAdd">
    <div class="search">
      <div class="left">
        <div class="id">
          点位名称/企业编码/场景
          <el-input v-model="inputText" placeholder="请输入" clearable></el-input>
        </div>
      </div>
 
      <div class="right">
        <div class="button searchBtn" @click="checkCamerasList(1)">搜索</div>
      </div>
    </div>
    <div class="btns">
      <div class="button add" @click="addPoint">
        <span class="iconfont">&#xe614;</span>
        <span>添加点位</span>
      </div>
    </div>
    <div class="switchBox">
      <span style="margin-right:10px">开启上报</span>
      <el-switch v-model="value1" active-color="#0065ff" @change="changeAll($event)"> </el-switch>
    </div>
    <div class="table-area">
      <el-table
        v-loading="tbLoading"
        id="pointTable"
        ref="pointTable"
        :data="dataList"
        :fit="true"
        :default-sort="{ prop: 'companyCode', order: 'ascending' }"
      >
        <el-table-column prop="cameraName" label="点位名称" width="130px" show-overflow-tooltip></el-table-column>
        <el-table-column
          prop="channelCode"
          label="报警通道编码"
          min-width="250px"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column prop="companyCode" label="企业编码" width="150px" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ scope.row.companyCode | fillCompanyCode(companyCodeOptions) }}
          </template>
        </el-table-column>
        <el-table-column prop="scenes" label="推送场景" min-width="100px" show-overflow-tooltip></el-table-column>
        <el-table-column prop="updatedAt" label="推送时间" width="100px" show-overflow-tooltip>
          <template slot-scope="scope">{{ scope.row.startTime }}-{{ scope.row.endTime }}</template>
        </el-table-column>
        <el-table-column prop="Enable" label="开关" width="60px" show-overflow-tooltip>
          <template slot-scope="scope">
            <el-switch v-model="scope.row.enable" @change="changeSwitch($event, scope.row)" active-color="#0065ff">
            </el-switch>
          </template>
        </el-table-column>
 
        <el-table-column label="操作" align="center" width="100px">
          <template slot-scope="scope">
            <span class="iconfont option" @click="editCameras(scope.row)">编辑</span>
            <span class="iconfont option" style="color:red" @click="delCameras(scope.row)">删除</span>
          </template>
        </el-table-column>
      </el-table>
      <div>
        <el-pagination
          @current-change="refrash"
          @size-change="handleSizeChange"
          :current-page="page"
          :page-size="size"
          layout="total, sizes, prev, pager, next, jumper"
          :page-sizes="[5, 10, 15, 20, 25]"
          :total="total"
          background
        ></el-pagination>
      </div>
    </div>
  </div>
  <div class="sub-account" v-else-if="isShowAdd">
    <div class="head-name" style="margin-bottom:20px">编辑点位</div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      :label-position="'left'"
      ref="ruleForm"
      label-width="120px"
      class="add-ruleForm"
    >
      <el-form-item label="点位名称" prop="CameraName">
        <el-select filterable style="width: 350px" v-model="ruleForm.CameraName" placeholder="请选择">
          <el-option v-for="item in cameraOptions" :key="item.id" :label="item.name" :value="item.name"> </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="报警通道编码" prop="ChannelCode">
        <el-input v-model="ruleForm.ChannelCode" placeholder="请输入报警通道编码" style="width: 350px"></el-input>
      </el-form-item>
      <el-form-item label="企业编码" prop="CompanyCode">
        <el-select style="width: 350px" v-model="ruleForm.CompanyCode" placeholder="请选择">
          <el-option v-for="item in companyCodeOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="推送场景" prop="Sceneslist">
        <el-select multiple style="width: 350px" v-model="ruleForm.Sceneslist" filterable placeholder="请选择">
          <el-option v-for="item in scene_nameOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="推送时间" required>
        <el-col :span="12" style="width: 175px">
          <el-form-item prop="StartTime">
            <el-time-select
              style="width: 175px"
              placeholder="起始时间"
              v-model="ruleForm.StartTime"
              :picker-options="{
                start: '00:00',
                step: '00:30',
                end: ruleForm.EndTime ? ruleForm.EndTime : '24:00',
                maxTime: ruleForm.EndTime
              }"
            >
            </el-time-select>
          </el-form-item>
        </el-col>
        <el-col :span="12" style="width: 175px">
          <el-form-item prop="EndTime">
            <el-time-select
              style="width: 175px"
              placeholder="结束时间"
              v-model="ruleForm.EndTime"
              :picker-options="{
                start: ruleForm.StartTime ? ruleForm.StartTime : '00:00',
                step: '00:30',
                end: '24:00',
                minTime: ruleForm.StartTime
              }"
            >
            </el-time-select>
          </el-form-item>
        </el-col>
      </el-form-item>
    </el-form>
    <div class="right">
      <div class="button searchBtn" @click="save">保存</div>
      <div class="button resetBtn" @click="resetUser">重置</div>
      <div class="button resetBtn" style="margin-left:20px" @click="goback">返回</div>
    </div>
  </div>
</template>
 
<script>
import { getLocalCameraTree } from "@/api/area"
import { getClusterDevList } from "@/api/clusterManage"
import { camerasList, camerasCreate, camerasConfig, camerasSwitch, camerasUpdate, camerasDelete } from "@/api/report"
import { traverse } from "./point/point"
import "./point/point.scss"
 
export default {
  filters: {
    fillCompanyCode(key, opts) {
      let obj = opts.find((t) => t.value == key)
      return obj ? obj.label : key
    }
  },
  data() {
    return {
      tbLoading: false,
      activeColor: "",
      inactiveColor: "#f0f3f5",
      value1: false,
      query: {},
      inputText: "", //输入框内容
      cameraOptions: [],
      scene_nameOptions: [],
      isShowAdd: false, //是否展示新增弹窗
      ruleForm: {
        CameraName: "", // 摄像机名称
        ChannelCode: "", // 报警通道编号
        CompanyCode: "", // 所属企业编号
        Scenes: "", // 推送场景
        Sceneslist: [], // 推送场景
        StartTime: "", // 开始时间
        EndTime: "", // 结束时间
 
        CameraId: "", // 摄像机id
        Level: "",
        Enable: false,
        createdAt: "",
        updatedAt: "",
        id: ""
      },
      dataList: [],
      tip: 1, // 区分保存还是编辑 但是现在没有编辑
      rules: {
        CameraName: [{ required: true, message: "请选择点位名称", trigger: "change" }],
        ChannelCode: [{ required: true, message: "请输入报警通道编码", trigger: "blur" }],
        CompanyCode: [{ required: true, message: "请输入企业编码", trigger: "blur" }],
        Sceneslist: [{ type: "array", required: true, message: "请选择推送场景", trigger: "change" }],
        StartTime: [{ type: "string", required: true, message: "请选择开始时间", trigger: "change" }],
        EndTime: [{ type: "string", required: true, message: "请选择结束时间", trigger: "change" }]
      },
      page: 1,
      size: 20, //分页相关
      total: 0, //总数
      companyCodeOptions: [
        {
          value: "370300010",
          label: "370300010/汇丰"
        },
        {
          value: "370300450",
          label: "370300450/海益"
        },
        {
          value: "370300440",
          label: "370300440/金汇丰"
        },
        {
          value: "370300480",
          label: "370300480/中汇"
        },
        {
          value: "370380545",
          label: "370380545/锦汇"
        }
      ]
    }
  },
  async created() {
    let query = { pageIndex: this.page, pageSize: this.size, keyword: this.inputText }
    this.query = query
    let res = await camerasList(query)
    this.dataList = res.data
    this.total = res.total
    this.scene_nameOptions = this.Constants.sceneNameOptions
    this.pageInit()
  },
 
  methods: {
    async changeAll(val) {
      let enable
      val ? (enable = 1) : (enable = 0)
      let rsp = await camerasSwitch({ enable: enable })
      if (rsp && rsp.success) {
        this.$message({
          type: "success",
          message: "成功!"
        })
        // this.checkCamerasList()
      }
    },
    changeSwitch(val, row) {
      let params = {
        CameraName: row.cameraName,
        ChannelCode: row.channelCode,
        CompanyCode: row.companyCode,
        Scenes: row.scenes,
        StartTime: row.startTime,
        EndTime: row.endTime,
        CameraId: row.cameraId, //
        Level: row.level,
        Enable: val,
        createdAt: row.createdAt,
        updatedAt: row.updatedAt,
        id: row.id
      }
      camerasUpdate(params).then((res) => {
        if (res && res.success) {
          this.$message({
            type: "success",
            message: res.msg
          })
        }
      })
    },
    editCameras(row) {
      this.tip = 2
      this.isShowAdd = true
      this.resetUser()
      this.ruleForm.StartTime = row.startTime
      this.ruleForm.EndTime = row.endTime
      this.ruleForm.CameraName = row.cameraName
      this.ruleForm.ChannelCode = row.channelCode
      this.ruleForm.CompanyCode = row.companyCode
      this.ruleForm.Sceneslist = row.scenes.split(",")
 
      this.ruleForm.Level = row.level
      this.ruleForm.Enable = row.enable
      this.ruleForm.createdAt = row.createdAt
      this.ruleForm.updatedAt = row.updatedAt
      this.ruleForm.id = row.id
    },
    async pageInit() {
      // 进入页面前的初始化
      let res = await camerasConfig()
      // 总开关
      if (res && res.success) {
        res.data.enable === 0 ? (this.value1 = false) : (this.value1 = true)
      }
      let clusterId = ""
      let clusterReq = await getClusterDevList()
      // 查询
      if (clusterReq && clusterReq.success) {
        if (clusterReq.data.clusterList.length > 0) {
          clusterId = clusterReq.data.clusterList[0].cluster_id
        }
      }
      let camereReq = await getLocalCameraTree({ clusterId: clusterId })
      // 这个是 添加时的点位 是从摄像机页面 来的
      let array = []
      this.cameraOptions = traverse(camereReq.data.treeMenu, array)
    },
    addPoint() {
      this.isShowAdd = true
      this.tip = 1
      this.resetUser()
    }, //y
    save() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          if (this.tip !== 1) {
            // tip1 是添加 其他是编辑
            let obj = this.cameraOptions.find((item) => item.name === this.ruleForm.CameraName)
            let params = {
              CameraName: this.ruleForm.CameraName,
              ChannelCode: this.ruleForm.ChannelCode,
              CompanyCode: this.ruleForm.CompanyCode,
              Scenes: this.ruleForm.Sceneslist.toString(),
              StartTime: this.ruleForm.StartTime,
              EndTime: this.ruleForm.EndTime,
              CameraId: obj.id, //
              Level: this.ruleForm.Level,
              Enable: this.ruleForm.Enable,
              createdAt: this.ruleForm.createdAt,
              updatedAt: this.ruleForm.updatedAt,
              id: this.ruleForm.id
            }
            //  编辑
            camerasUpdate(params).then((res) => {
              if (res && res.success) {
                this.$message({
                  type: "success",
                  message: res.msg
                })
                this.goback()
                this.checkCamerasList()
              }
            })
          } else {
            let obj = this.cameraOptions.find((item) => item.name === this.ruleForm.CameraName)
            let params = {
              CameraName: this.ruleForm.CameraName,
              ChannelCode: this.ruleForm.ChannelCode,
              CompanyCode: this.ruleForm.CompanyCode,
              Scenes: this.ruleForm.Sceneslist.toString(),
              StartTime: this.ruleForm.StartTime,
              EndTime: this.ruleForm.EndTime,
              CameraId: obj.id, //
              Level: this.ruleForm.Level,
              Enable: this.ruleForm.Enable
            }
            // 新建
            camerasCreate(params).then((res) => {
              if (res && res.success) {
                this.$message({
                  type: "success",
                  message: res.msg
                })
                this.goback()
                this.checkCamerasList()
              }
            })
          }
        } else {
          return false
        }
      })
    },
    handleSizeChange(size) {
      this.size = size
      this.checkCamerasList(1)
    },
    //分页功能
    refrash(page) {
      this.page = page
      this.checkCamerasList(1)
    },
    delCameras(row) {
      this.$confirm("确认要删除该点位吗, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(async () => {
        let rsp = await camerasDelete({ id: row.id })
        if (rsp && rsp.success) {
          this.$message({
            type: "success",
            message: "删除成功!"
          })
        }
        this.checkCamerasList()
      })
    },
    async checkCamerasList(val) {
      this.tbLoading = true
      if (val === 1) {
        let query = { pageIndex: this.page, pageSize: this.size, keyword: this.inputText }
        this.query = query
        let res = await camerasList(query)
        this.dataList = res.data
        this.total = res.total
      } else {
        let res = await camerasList(this.query)
        this.dataList = res.data
        this.total = res.total
      }
 
      setTimeout(() => {
        this.tbLoading = false
      }, 300)
    },
    resetUser() {
      // this.ruleForm. = {
      this.ruleForm.CameraName = ""
      this.ruleForm.ChannelCode = ""
      this.ruleForm.CompanyCode = ""
      this.ruleForm.Sceneslist = []
      this.ruleForm.StartTime = ""
      this.ruleForm.EndTime = ""
    },
    goback() {
      this.isShowAdd = false
    }
  }
}
</script>
 
<style scoped lang="scss">
.sub-account {
  padding: 20px;
  .head-name {
    font-weight: 700;
    font-size: 16px;
    line-height: 22px;
    color: #3d3d3d;
    border-left: 4px solid #0065ff;
    padding-left: 10px;
  }
  .add-title {
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    line-height: 22px;
    color: #3d3d3d;
    margin-bottom: 30px;
    .iconfont {
      margin-right: 10px;
    }
  }
  .add-ruleForm::v-deep {
    .el-input__inner {
      color: #3d3d3d;
      border-radius: 4px;
      border-color: #c0c5cc;
      height: 32px;
      line-height: 32px;
      border-color: #c0c5cc;
    }
    .user-tree {
      .el-form-item__label:before {
        content: "*";
        color: #f52323;
        margin-right: 4px;
      }
      .el-form-item__content {
        display: flex;
        .tree-box {
          .t {
            height: 32px;
            background: #f0f5fa;
            border-radius: 3px 3px 0px 0px;
            line-height: 32px;
            text-align: center;
            border-bottom: 1px solid #c0c5cc;
          }
          width: 336px;
          height: 480px;
          border: 1px solid #c0c5cc;
          margin-right: 20px;
          box-sizing: border-box;
        }
      }
    }
  }
  .searchBtn {
    width: 50px;
    height: 25px;
    line-height: 25px;
    font-size: 14px;
    text-align: center;
    color: #fff;
    background: #0065ff;
    margin-right: 20px;
  }
  .right {
    display: flex;
  }
  .resetBtn {
    width: 50px;
    height: 25px;
    line-height: 25px;
    font-size: 14px;
    text-align: center;
    color: #0065ff;
    box-sizing: border-box;
    border: 1px solid #0065ff;
  }
  .search {
    display: flex;
    font-size: 14px;
    border-bottom: 1px solid #e9ebee;
    margin-top: 30px;
    padding-bottom: 20px;
    .left,
    .right,
    .id,
    .time,
    .cluster {
      display: flex;
      align-items: center;
      .el-select {
        width: auto;
      }
    }
 
    .id .el-input ::v-deep {
      width: 200px;
    }
 
    .cluster::v-deep .el-input {
      width: 300px;
 
      margin-left: 10px;
      margin-right: 20px;
      .el-input__icon {
        line-height: 32px;
      }
      input {
        border-radius: 0;
 
        &::-webkit-input-placeholder {
          color: #999;
        }
 
        &:focus {
          border-color: #0065ff;
        }
      }
    }
 
    .el-input ::v-deep {
      width: 200px;
      margin-left: 10px;
      margin-right: 20px;
      height: 32px;
      line-height: 32px;
      input {
        border-radius: 0;
        height: 32px;
        line-height: 32px;
        &::-webkit-input-placeholder {
          color: #999;
        }
 
        &:focus {
          border-color: #0065ff;
        }
      }
    }
 
    .el-date-editor {
      width: 318px;
      height: 40px;
      margin-left: 10px;
      margin-right: 20px;
      border-radius: 0;
 
      &::-webkit-input-placeholder {
        color: #999;
      }
 
      &.is-active {
        border-color: #0065ff;
      }
    }
  }
 
  .btns {
    display: flex;
    margin: 20px 0;
    text-align: center;
    justify-content: space-between;
 
    .add {
      margin-right: 20px;
      width: 126px;
      height: 32px;
      background: #0065ff;
      color: #fff;
      span {
        margin-right: 5px;
        line-height: 32px;
        font-size: 14px;
      }
    }
 
    .export {
      width: 126px;
      height: 32px;
      border: 1px solid #0065ff;
      color: #0065ff;
      box-sizing: border-box;
      span {
        margin-right: 5px;
        line-height: 32px;
        font-size: 14px;
      }
    }
  }
  .switchBox {
    display: flex;
    align-items: center;
    float: right;
    position: absolute;
    right: 20px;
    top: 130px;
    font-size: 14px;
  }
  .el-table ::v-deep {
    background-color: rgb(233, 235, 238);
    padding: 1px;
 
    &::after {
      display: none;
    }
 
    td.index .cell {
      padding-left: 16px;
      padding-right: 4px;
    }
 
    .has-gutter tr th {
      background: #f0f3f5;
      font-size: 16px;
      color: #3d3d3d;
      font-weight: 700;
    }
 
    td .cell {
      color: #3d3d3d;
    }
 
    tr:hover > td.el-table__cell {
      background-color: #fff;
    }
 
    .el-table__row--striped .el-table__cell {
      background-color: #f0f5fa !important;
    }
    tr:hover > td.el-table__cell {
      background-color: #fff;
    }
 
    .el-table__row--striped .el-table__cell {
      background-color: #f0f5fa !important;
    }
 
    .status {
      color: #ff4b33;
 
      &.green {
        color: #36b24a;
      }
    }
 
    .option {
      margin-right: 10px;
      font-size: 14px;
      color: rgb(0, 101, 255);
      cursor: pointer;
    }
  }
 
  .el-pagination ::v-deep {
    margin-top: 30px;
    text-align: center;
    height: 24px;
    .el-pagination__sizes {
      margin-right: 0;
    }
 
    button {
      margin: 0;
      background-color: #fff;
      border: 1px solid #c0c5cc;
      border-radius: 2px;
    }
 
    .number {
      background-color: #fff;
 
      &:not(.disabled):hover {
        color: #0065ff;
      }
 
      &:not(.disabled).active {
        background-color: #0065ff;
        color: #fff;
      }
    }
 
    .el-input .el-input__inner {
      padding-left: 0;
 
      &:hover,
      &:focus {
        border-color: #0065ff;
      }
    }
  }
 
  .el-select ::v-deep {
    .el-select__tags-text {
      color: #3d3d3d;
    }
  }
}
</style>
 
<style>
/* .el-switch__core {
  height: 32px !important;
}
.el-switch__core::after {
  height: 30px !important;
  width: 30px !important;
} */
.el-date-table td.start-date span,
.el-date-table td.end-date span {
  background-color: #0065ff;
}
 
.el-button--text span {
  color: #0065ff;
}
 
.el-button.is-plain:hover,
.el-button.is-plain:focus {
  color: #0065ff;
  border-color: #0065ff;
}
 
/* .el-switch__core {
  width: 40px !important;
  height: 20px;
}
.el-switch__core::after {
  width: 16px;
  height: 16px;
  margin-top: -1px;
}
.el-switch.is-checked .el-switch__core::after {
  margin-left: -17px;
} */
</style>