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
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
<template>
  <div class="params-container">
    <el-form
      ref="ruleForm"
      size="mini"
      label-position="left"
      :model="params"
      :rules="rules"
      class="params-dialog bg-white">
      <el-form-item label="装置名称">
        <el-input v-model="otherParams.groupName" readonly></el-input>
      </el-form-item>
      <el-row :gutter="layout.gutter">
        <el-col :span="layout.span">
          <el-form-item label="KM1:">
            <el-switch
              :disabled="!info.kmState1"
              v-model="params.km1Switch"
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-text="开关闭合"
              inactive-text="开关断开"
              :active-value="1"
              :inactive-value="2">
            </el-switch>
          </el-form-item>
        </el-col>
        <el-col :span="layout.span">
          <el-form-item label="KM2:">
            <el-switch
              :disabled="!info.kmState2"
              v-model="params.km2Switch"
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-text="开关闭合"
              inactive-text="开关断开"
              :active-value="1"
              :inactive-value="2">
            </el-switch>
          </el-form-item>
        </el-col>
        <el-col :span="layout.span">
          <el-form-item label="KM3:">
            <el-switch
              :disabled="!info.kmState3"
              v-model="params.km3Switch"
              active-color="#13ce66"
              inactive-color="#ff4949"
              active-text="开关闭合"
              inactive-text="开关断开"
              :active-value="1"
              :inactive-value="2">
            </el-switch>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="form-footer">
        <three-btn @click="confirmSetParams">设置</three-btn>
      </div>
    </el-form>
  </div>
</template>
 
<script>
import {checkUserPwd} from "@/views/login/js/api";
import {update61851} from "@/views/dataTest/js/realTime";
 
export default {
  name: "SwitchControlSet",
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    batt: {
      type: Object,
      default() {
        return {};
      }
    },
    info: {
      type: Object,
      default() {
        return {};
      }
    },
  },
  data() {
    return {
      layout: {
        gutter: 16,
        span: 24,
      },
      setTestFlag: false,   // 设置参数按钮的状态
      params: {
        opCmd: 0x82,
        devId: "",
        km1Switch: 0,
        km2Switch: 0,
        km3Switch: 0
      },
      rules: {},
      switchState: {
        switch1: false,
        switch2: false,
        switch3: false
      }
    }
  },
  methods: {
    initParams() {
      let batt = this.batt;
      let info = this.info;
      this.params.devId = batt.fbsdeviceId;
      this.params.km1Switch = info.kmState1 === 0?2:info.kmState1;
      this.params.km2Switch = info.kmState2 === 0?2:info.kmState2;
      this.params.km3Switch = info.kmState3 === 0?2:info.kmState3;
    },
    getParams() {
      let batt = this.batt;
      let info = this.info;
      this.params.devId = batt.fbsdeviceId;
      let params = {...this.params};
      params.km1Switch = info.kmState1 === 0?0:this.params.km1Switch===2?0:1;
      params.km2Switch = info.kmState2 === 0?0:this.params.km2Switch===2?0:1;
      params.km3Switch = info.kmState3 === 0?0:this.params.km3Switch===2?0:1;
      return params;
    },
    confirmSetParams() {
      this.$layer.prompt(
        {
          title: "输入设置口令,并确认",
          formType: 2,
          area: ["300px", "180px"],
        },
        (pass, index) => {
          // 请求后台校验密码
          checkUserPwd(pass).then((res) => {
            res = res.data;
            if (res.code) {
              // 关闭弹出框
              this.$layer.close(index);
              // 启动测试
              this.setParams();
            } else {
              this.$layer.msg("启动口令错误!");
            }
          }).catch((error) => {
            console.log(error);
            this.$layer.msg("网络请求异常");
          });
        });
    },
    setParams() {
      let params = this.getParams();
      let loading = this.$layer.loading();
      update61851(params).then(res=>{
        this.$layer.close(loading);
        let rs = res.data;
        if(rs.code && rs.data) {
          this.$message.success("设置成功");
        }else {
          this.$message.warning("设置失败");
        }
      }).catch(error=>{
        this.$layer.close(loading);
        this.$message.error("后台接口请求失败");
        console.log(error);
      });
    },
    close() {
      this.$emit("update:visible", false);
    },
  },
  computed: {
    otherParams() {
      let batt = this.batt;
      let groupInfo =
        "单体数量:" +
        this.batt.monCount +
        ";电压(V):" +
        this.batt.monVolStd +
        ";容量(AH):" +
        this.batt.monCapStd;
      return {
        groupName: batt.stationName + "-" + batt.battGroupName,
        fbsdeviceId: batt.fbsdeviceId,
        groupInfo: groupInfo,
        groupIndexInFBSDevice: this.batt.groupIndexInFBSDevice + 1,
      };
    },
  },
  mounted() {
    this.initParams();
  }
}
</script>
 
<style scoped>
.params-container {
  width: 340px;
  background-color: #ececec;
}
.form-footer {
  margin-top: 16px;
  margin-bottom: 16px;
  text-align: right;
}
 
.form-footer .three-btn {
  margin-left: 12px;
}
</style>