he wei
2024-09-21 70edda3b00f2528a473c28ec5a50b739ed160f0f
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
<template>
  <div class="alarm-on-off-manage">
    <el-transfer
      v-model="value"
      :data="data"
      filterable
      class="transfer-width320"
      :titles="['已关闭告警', '已开启告警']"
      :button-texts="['移除', '添加']"
      @change="handleChange"></el-transfer>
  </div>
</template>
 
<script>
import {changeOnOff, powerSourceManage} from "@/views/alarmMager/js/power";
 
export default {
  name: "alarmOnOffManage",
  props: {
    id: {
      type: [String, Number],
      default: 0
    }
  },
  data() {
    return {
      data: [],
      value: [],
    }
  },
  methods:{
    searchData() {
      powerSourceManage(this.id).then(res=>{
        let rs = res.data;
        let list = [];
        if(rs.code === 1) {
          list = rs.data;
        }
        this.formatData(list);
      }).catch(error=>{
        console.log(error);
        this.formatData([]);
      });
    },
    formatData(list) {
      let value = [];
      let data = [];
      list.map(item=>{
        if(item.alarmEnNode) {
          value.push(item.alarmId);
        }
        item.key = item.alarmId;
        item.label = item.alarmName;
        data.push({...item});
      });
      this.value = value;
      this.data = data;
    },
    handleChange(list, type, values) {
      // 根据类型确定事件
      switch (type) {
        case "left":
          this.remove(values);
          break;
        case "right":
          this.add(values);
          break;
      }
    },
    add(list) {
      let changeList = this.getChangeList(this.data, list);
      changeOnOff(changeList, true).then((res)=>{
        let rs = res.data;
        if(rs.code === 1) {
          this.$message.success("启用告警成功");
          this.$emit('success', true);
        }else {
          this.$message.error("启用告警失败");
        }
        this.searchData();
      }).catch(error=>{
        this.searchData();
      });
    },
    remove(list) {
      let changeList = this.getChangeList(this.data, list);
      changeOnOff(changeList, false).then((res)=>{
        let rs = res.data;
        if(rs.code === 1) {
          this.$message.success("移除告警成功");
          this.$emit('success', true);
        }else {
          this.$message.error("移除告警失败");
        }
        this.searchData();
      }).catch(error=>{
        this.searchData();
      });
    },
    getChangeList(data, list) {
      let result = [];
      for(let i=0; i<list.length;i++) {
        let value = list[i];
        for(let j=0;j<data.length; j++) {
          let item = data[j];
          if(item.alarmId == value) {
            result.push({...item});
            break;
          }
        }
      }
      return result;
    }
  },
  mounted() {
    this.searchData();
  }
}
</script>
 
<style scoped>
.alarm-on-off-manage {
  width: 960px;
  height: 600px;
  background-color: #024d5f;
  padding-top: 16px;
  padding-bottom: 16px;
}
</style>