longyvfengyun
2023-12-25 d8d792a6842832e8f6af6604274c438b25053afe
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
<template>
  <div class="params-container">
    <el-form
      ref="ruleForm"
      size="mini"
      label-position="top"
      :model="params"
      :rules="rules"
      class="params-dialog bg-white"
    >
      <el-form-item label="机房名称" prop="StationName">
        <el-input
          placeholder="请输入机房名称"
          v-model="batt.StationName"
          readonly="readonly"
        >
        </el-input>
      </el-form-item>
      <el-row :gutter="layout.gutter">
        <el-col :span="layout.span" v-if="isSuperUser">
          <el-form-item label="均衡类型">
            <el-select v-model="junhengStyle">
              <el-option label="单充" :value="0"></el-option>
              <el-option label="可充可放" :value="1"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="layout.span">
          <el-form-item :label="junHengEnabledLabel" prop="junHengVol">
            <el-input v-model="params.junHengVol"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="layout.span">
          <el-form-item label="均衡停止电压阀值(0~20)" prop="junHengStVol">
            <el-input v-model="params.junHengStVol"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="layout.span">
          <el-form-item label="均衡停止电流阀值(0~5)" prop="junHengStCurr">
            <el-input v-model="params.junHengStCurr"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <div class="form-footer">
        <three-btn @click="getParams(true)">读取</three-btn>
        <three-btn :disabled="!setTestFlag" @click="submitFrom">设定</three-btn>
      </div>
    </el-form>
  </div>
</template>
 
<script>
import { testVal } from "@/assets/js/tools";
import { const_system } from "@/assets/js/const";
 
export default {
  props: {
    batt: {
      type: Object,
      default() {
        return {};
      },
    },
    visible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    let cmd = const_system.balanceControl.cmd;
    let rules = const_system.rules;
    let max = (this.batt.MonVolStd * 1.1).toFixed(1);
    rules.junHengVol.max = max;
    rules.junHengVol.msg = "取值范围0~" + max + "V(保留三位小数)";
    this.junHengEnabledLabel = "均衡电压(0~" + max + "V)";
    let isSuperUser = sessionStorage.getItem("userId") == "1002" ? true : false;
    return {
      isSuperUser: isSuperUser,
      high: 32768,
      cmd: cmd,
      setTestFlag: false, // 设置参数的状态
      layout: {
        span: 12,
        gutter: 16,
      },
      params: {
        op_cmd: 0,
        junHengEnabled: 0, // 均衡功能启用状态(0:禁用)
        junHengVol: 0, // 均衡电压
        junHengStVol: 0, // 均衡停止电压阀值
        junHengStCurr: 0, // 均衡停止电流阀值
      },
      junhengStyle: 0,
      junHengEnabledLabel: "",
      rules: {
        junHengVol: [
          {
            validator(rule, value, callback) {
              testVal(rule, value, callback, rules.junHengVol);
            },
            trigger: "change",
          },
        ],
        junHengStVol: [
          {
            validator(rule, value, callback) {
              testVal(rule, value, callback, rules.junHengStVol);
            },
            trigger: "change",
          },
        ],
        junHengStCurr: [
          {
            validator(rule, value, callback) {
              testVal(rule, value, callback, rules.junHengStCurr);
            },
            trigger: "change",
          },
        ],
      },
    };
  },
  watch: {
    junhengStyle(n) {
      this.changeJunHengRange(n);
    },
  },
  methods: {
    // 初始化参数
    initParams() {
      this.params = {
        op_cmd: 0,
        junHengEnabled: 0, // 均衡功能启用状态(0:禁用)
        junHengVol: 0, // 均衡电压值
        junHengStVol: 0, // 均衡停止电压阀值
        junHengStCurr: 0, // 均衡停止电流阀值
      };
    },
    // 读取参数
    getParams(showLoad) {
      // 定义等待框
      let loading;
      if (showLoad) {
        loading = this.$layer.loading(1);
      }
 
      // 查询后台
      this.$apis.system.balanceControl
        .getParams({
          op_cmd: this.cmd.get,
          dev_id: this.batt.FBSDeviceId,
        })
        .then((res) => {
          let rs = JSON.parse(res.data.result);
          if (rs.code == 1) {
            let data = rs.data[0];
            // 遍历参数属性并赋值
            for (let key in this.params) {
              if (key == "junHengVol") {
                // 可充可放模式
                if (data.junHengEnabled * 1000 > this.high) {
                  this.params.junHengVol =
                    (data.junHengEnabled * 1000 - this.high) / 1000;
                  this.junhengStyle = 1;
                } else {
                  this.params.junHengVol = data.junHengEnabled;
                  this.junhengStyle = 0;
                }
              } else {
                let value = data[key];
                this.params[key] = value;
              }
            }
 
            // 设置的命令和dev_id
            this.params.num = this.cmd.set;
            this.params.dev_id = this.batt.FBSDeviceId;
            this.$layer.msg("读取成功!");
            // 设置按钮可点击
            this.setTestFlag = true;
          } else {
            // 初始化参数
            this.initParams();
            // 设置按钮不可点击
            this.setTestFlag = false;
            this.$layer.msg("读取失败!");
          }
 
          // 关闭等待框
          this.$layer.close(loading);
        })
        .catch((error) => {
          console.log(error);
          // 初始化参数
          this.initParams();
          // 设置按钮不可点击
          this.setTestFlag = false;
          // 关闭等待框
          this.$layer.close(loading);
          this.$layer.msg("读取失败,读取请求异常!");
        });
    },
    // 提交表单设置参数
    submitFrom() {
      this.$refs.ruleForm.validate((valid) => {
        // 校验通过
        if (valid) {
          // 设置参数
          this.setParams();
        } else {
          this.$layer.msg("存在校验未通过的数据!");
          return false;
        }
      });
    },
    // 设置参数
    setParams() {
      let params = {};
      let isSuperUser = this.isSuperUser;
      // 遍历参数属性并赋值
      for (let key in this.params) {
        let value = this.params[key];
        params[key] = value;
      }
 
      // 可充可放模式且必须为超级用户
      if (this.junhengStyle && isSuperUser) {
        params.junHengEnabled = (params.junHengVol * 1000 + this.high) / 1000;
      } else {
        params.junHengEnabled = params.junHengVol;
      }
 
      // 设置命令
      params.op_cmd = this.cmd.set;
      // 等待框
      let loading = this.$layer.loading(1);
      // 请求后台
      this.$apis.system.balanceControl
        .setParams(params)
        .then((res) => {
          let rs = JSON.parse(res.data.result);
          if (rs.code == 1) {
            // 启动按钮可点击
            this.startTestFlag = true;
            // 提示信息
            this.$layer.msg("设置成功");
          } else {
            // 启动按钮不可点击
            this.startTestFlag = false;
            // 提示信息
            this.$layer.msg("设置失败!");
          }
          // 关闭等待框
          this.$layer.close(loading);
        })
        .catch((error) => {
          console.log(error);
          // 关闭等待框
          this.$layer.close(loading);
          // 启动按钮不可点击
          this.startTestFlag = false;
          // 提示信息
          this.$layer.msg("设置失败,设置请求异常!");
        });
    },
    changeJunHengRange(type) {
      let rules = const_system.rules;
      let isSuperUser = this.isSuperUser;
      if (type && isSuperUser) {
        rules.junHengVol.max = 30;
        rules.junHengVol.msg = "取值范围0~" + 30 + "V(保留三位小数)";
        this.junHengEnabledLabel = "均衡电压(0~" + 30 + "V)";
      } else {
        let max = (this.batt.MonVolStd * 1.1).toFixed(1);
        rules.junHengVol.max = max;
        rules.junHengVol.msg = "取值范围0~" + max + "V(保留三位小数)";
        this.junHengEnabledLabel = "均衡电压(0~" + max + "V)";
      }
 
      this.rules.junHengVol = [
        {
          validator(rule, value, callback) {
            testVal(rule, value, callback, rules.junHengVol);
          },
          trigger: "change",
        },
      ];
      // 清除提示
      this.$refs.ruleForm.clearValidate();
    },
  },
  mounted() {
    // 获取参数
    this.getParams(true);
    this.changeJunHengRange(0);
  },
  beforeDestroy() {},
};
</script>
 
<style scoped>
.params-container {
  width: 700px;
  background-color: #ffffff;
}
.table-layout {
  margin-top: 16px;
}
.bg-white .table-cell {
  color: #000000;
}
</style>