longyvfengyun
2024-08-14 a37c0febb90efd7aa25855f25cabf9ddc6a92c31
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
<template>
  <div class="main">
    <div class="tbl-data-body">
      <el-table stripe size="small" :data="switchInfo">
        <el-table-column
          v-for="header in table.headers"
          :key="header.prop"
          :prop="header.prop"
          :label="header.label"
          align="center"
        ></el-table-column>
        <el-table-column label="操作" width="100">
          <template slot-scope="scope">
            <el-button
              v-if="!scope.row.state1"
              type="primary"
              size="mini"
              :disabled="scope.row.control1"
              @click="switchControl(scope.row, 1)"
              >合闸</el-button
            >
            <el-button
              v-else
              type="danger"
              :disabled="scope.row.control1"
              size="mini"
              @click="switchControl(scope.row, 0)"
              >分闸</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
 
<script>
import { setDev6159Swtich } from "../js/realTime";
 
export default {
  name: "",
  props: {
    devId: {
      type: [String, Number],
      required: true,
    },
    switchInfo: {
      type: Array,
      required: true,
    },
  },
  data() {
    return {
      table: {
        headers: [
          {
            prop: "name",
            label: "开关名称",
          },
          {
            prop: "control",
            label: "控制方式",
          },
          {
            prop: "state",
            label: "状态",
          },
        ],
      },
      setTestFlag: false,
      DK11: false,
      DK12: false,
      DK13: true,
      DK14: false,
      DK15: false,
      DK16: false,
      DK17: false,
      DK18: true,
    };
  },
  components: {},
  methods: {
    getParams() {},
    switchControl(obj, state) {
      let loading = this.$layer.loading(1);
      setDev6159Swtich(this.devId, obj.ctrlName, !obj.state1 * 1)
        .then((res) => {
          let { code, data } = res.data;
          if (code && data) {
            // console.log(data);
            this.$layer.msg("操作成功");
          } else {
            this.$layer.msg("操作失败");
          }
          // 关闭等待框
          this.$layer.close(loading);
        })
        .catch((err) => {
          console.log(err);
          // 关闭等待框
          this.$layer.close(loading);
        });
    },
  },
 
  mounted() {},
};
</script>
 
<style scoped lang="less">
.main {
  width: 600px;
  padding: 20px;
  background: #f0f0f0;
  .switch-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr 2fr);
    gap: 6px 20px;
    place-content: center;
    place-items: center end;
    .name {
      font-size: 16px;
      font-weight: bold;
      color: #f7b33c;
      &::after {
        content: ":";
      }
    }
    .state {
      justify-self: start;
    }
  }
  .footer {
    padding-top: 20px;
    text-align: right;
    /deep/ .three-btn + .three-btn {
      margin-left: 0.8em;
    }
  }
}
</style>