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
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
<template>
  <div class="params-container">
    <el-form ref="ruleForm" size="mini" label-position="top" :model="params" :rules="rules" class="params-dialog">
      <el-form-item label="电池组名称">
        <el-input v-model="otherParams.groupName" readonly></el-input>
      </el-form-item>
      <div class="table-layout">
        <div class="table-row">
          <div class="table-cell pr16">
            <el-form-item label="设备ID">
              <el-input v-model="params.dev_id" readonly></el-input>
            </el-form-item>
          </div>
          <div class="table-cell">
            <el-form-item label="除硫/养护">
              <el-select v-model="op_cmd" placeholder="请选择">
                <el-option v-for="item in testType" :key="item.value" :label="item.label"
                           :value="item.value"></el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
        <div class="table-row">
          <div class="table-cell pr16">
            <el-form-item label="标称容量">
              <el-input v-model="params.STDCap" readonly></el-input>
            </el-form-item>
          </div>
          <div class="table-cell">
            <el-form-item label="模块编号">
              <el-select v-model="params.GroupNum" placeholder="请选择" @change="changeGroupNum">
                <el-option :value="1">1</el-option>
                <el-option :value="2">2</el-option>
                <el-option :value="3">3</el-option>
                <el-option :value="4">4</el-option>
                <el-option :value="5">5</el-option>
              </el-select>
            </el-form-item>
          </div>
        </div>
        <div class="table-row">
          <div class="table-cell pr16">
            <el-form-item label="浮充电压(0~90V)" prop="FloatVol">
              <el-input v-model="params.FloatVol"></el-input>
            </el-form-item>
          </div>
          <div class="table-cell">
            <el-form-item label="除硫强度(0~30)" prop="Strength">
              <el-input v-model="params.Strength"></el-input>
            </el-form-item>
          </div>
        </div>
        <div class="table-row">
          <div class="table-cell pr16">
            <el-form-item label="养护强度(0~30)" prop="YHStrength">
              <el-input v-model="params.YHStrength"></el-input>
            </el-form-item>
          </div>
          <div class="table-cell">
            <el-form-item label="除硫天数(0~999天)" prop="TimeLong">
              <el-input v-model="params.TimeLong"></el-input>
            </el-form-item>
          </div>
        </div>
      </div>
      <div class="form-footer">
        <three-btn :disabled="!startTestFlag" @click="confirmStart">启动</three-btn>
        <three-btn @click="readFromDev">读取</three-btn>
        <three-btn :disabled="!setTestFlag" @click="submitFrom">设定</three-btn>
      </div>
    </el-form>
  </div>
</template>
 
<script>
import {
  const_curing
} from '@/assets/js/const'
import {
  testVal
} from '../../assets/js/tools'
 
export default {
  name: "CuringParams",
  props: {
    batt: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    let cmd = const_curing.cmd;
    let testType = const_curing.testType;
    let rules = const_curing.dischargeRules;
    return {
      loading: 0,
      cmd: cmd,
      op_cmd: testType[0].value,
      testType: testType,
      startTestFlag: false, // 启动测试的状态
      setTestFlag: false, // 设置参数的状态
      params: {
        dev_id: 0,
        GroupNum: 1, // 电池组号
        STDCap: 0, // 标称容量
        FloatVol: 0, // 浮充电压
        Strength: 0, // 除硫强度
        YHStrength: 0, // 养护强度
        TimeLong: 0 // 除硫天数
      },
      allData: {
        FloatVol_five: 0,
        FloatVol_four: 0,
        FloatVol_one: 0,
        FloatVol_three: 0,
        FloatVol_two: 0,
        GroupNum: 1,
        STDCap_five: 0,
        STDCap_four: 0,
        STDCap_one: 0,
        STDCap_three: 0,
        STDCap_two: 0,
        Strength_five: 0,
        Strength_four: 0,
        Strength_one: 0,
        Strength_three: 0,
        Strength_two: 0,
        TimeLong_five: 0,
        TimeLong_four: 0,
        TimeLong_one: 0,
        TimeLong_three: 0,
        TimeLong_two: 0,
        YHStrength_five: 0,
        YHStrength_four: 0,
        YHStrength_one: 0,
        YHStrength_three: 0,
        YHStrength_two: 0,
        dev_id: 0,
        num: 0,
        op_cmd: 0,
        test_cmd: 0,
      },
      rules: {
        FloatVol: [{
          validator(rule, value, callback) {
            testVal(rule, value, callback, rules.FloatVol)
          },
          trigger: 'change'
        }],
        Strength: [{
          validator(rule, value, callback) {
            testVal(rule, value, callback, rules.Strength)
          },
          trigger: 'change'
        }],
        YHStrength: [{
          validator(rule, value, callback) {
            testVal(rule, value, callback, rules.YHStrength)
          },
          trigger: 'change'
        }],
        TimeLong: [{
          validator(rule, value, callback) {
            testVal(rule, value, callback, rules.TimeLong)
          },
          trigger: 'change'
        }],
      },
    }
  },
  methods: {
    init() {
      // 界面参数
      this.params = {
        dev_id: 0,
        GroupNum: 1, // 电池组号
        STDCap: 0, // 标称容量
        FloatVol: 0, // 浮充电压
        Strength: 0, // 除硫强度
        YHStrength: 0, // 养护强度
        TimeLong: 0 // 除硫天数
      };
 
      // 提交数据库的参数
      this.allData = {
        FloatVol_five: 0,
        FloatVol_four: 0,
        FloatVol_one: 0,
        FloatVol_three: 0,
        FloatVol_two: 0,
        GroupNum: 1,
        STDCap_five: 0,
        STDCap_four: 0,
        STDCap_one: 0,
        STDCap_three: 0,
        STDCap_two: 0,
        Strength_five: 0,
        Strength_four: 0,
        Strength_one: 0,
        Strength_three: 0,
        Strength_two: 0,
        TimeLong_five: 0,
        TimeLong_four: 0,
        TimeLong_one: 0,
        TimeLong_three: 0,
        TimeLong_two: 0,
        YHStrength_five: 0,
        YHStrength_four: 0,
        YHStrength_one: 0,
        YHStrength_three: 0,
        YHStrength_two: 0,
        dev_id: 0,
        num: 0,
        op_cmd: 0,
        test_cmd: 0,
      };
    },
    changeGroupNum() { // 改变某块编号
      let groupNum = this.getCuringGroupNum(this.params.GroupNum);
      Object.keys(this.allData).forEach(key => {
        if (key.indexOf(groupNum) != -1) {
          Object.keys(this.params).forEach(jkey => {
            if ((jkey + groupNum) == key) {
              this.params[jkey] = this.allData[key];
            }
          });
        }
      });
    },
    readFromDB(loading) { // 从数据库中读取养护除硫参数
      let batt = this.batt;
      this.init(); // 初始化信息
      if (loading) {
        // 开启等待框
        this.loading = this.$layer.loading(1);
      }
      // 查询后台
      this.$apis.curing.readFromDB(batt.FBSDeviceId).then(res => {
        let rs = JSON.parse(res.data.result);
        // 查询成功执行
        if (rs.code === 1) {
          // 从读取设备执行后执行
          if (!loading) {
            // this.startTestFlag = true;   // 启动测试的状态
            this.setTestFlag = true; // 设置参数的状态
            // 提示读取参数状态
            this.$layer.msg(rs.msg);
          }
          let data = rs.data[0];
          this.allData = data;
          let groupNum = this.getCuringGroupNum(data.GroupNum);
          Object.keys(this.params).forEach(key => {
            if (key == 'dev_id') {
              this.params[key] = data[key];
            } else if (key == 'GroupNum') {
              if (loading) {
                if (data[key] == 0) {
                  this.params[key] = data[key] + 1;
                } else {
                  this.params[key] = data[key];
                }
              }
            } else {
              this.params[key] = data[key + groupNum];
            }
          });
        } else {
          this.$layer.msg(rs.msg);
        }
 
        // 关闭等待框
        this.$layer.close(this.loading);
      }).catch(error => {
        // 关闭等待框
        this.$layer.close(this.loading);
      });
    },
    readFromDev() { // 从设备上获取数据,写入数据库
      let batt = this.batt;
      // 开启等待框
      this.loading = this.$layer.loading(1);
      // 查询后台
      this.$apis.curing.readFromDev(batt.FBSDeviceId, batt.GroupIndexInFBSDevice).then(res => {
        let rs = JSON.parse(res.data.result);
        if (rs.code == 1) {
          this.readFromDB();
        } else {
          // 关闭等待框
          this.$layer.close(this.loading);
          this.$layer.msg(rs.msg);
        }
      }).catch(error => {
        // 关闭等待框
        this.$layer.close(this.loading);
      });
    },
    getCuringGroupNum(group) {
      let groupNum = null;
      group = Number(group);
      switch (group) {
        case 0:
        case 1:
          groupNum = '_one';
          break;
        case 2:
          groupNum = '_two';
          break;
        case 3:
          groupNum = '_three';
          break;
        case 4:
          groupNum = '_four';
          break;
        case 5:
          groupNum = '_five';
          break;
      }
      return groupNum;
    },
    submitFrom() {
      this.$refs.ruleForm.validate((valid) => {
        // 校验通过
        if (valid) {
          // 设置参数
          this.setParams();
        } else {
          this.$layer.msg('存在校验未通过的数据!');
          return false;
        }
      });
    },
    setParams() {
      let params = this.getSetParams();
      // 开启等待框
      this.loading = this.$layer.loading(1);
      this.$apis.curing.setParams(params).then((res) => {
        let rs = JSON.parse(res.data.result);
        if (rs.code == 1) {
          // 关闭等待框
          this.$layer.close(this.loading);
          this.$layer.msg(rs.msg);
          this.startTestFlag=true;
        } else {
          // 关闭等待框
          this.$layer.close(this.loading);
          this.$layer.msg(rs.msg);
        }
      }).catch((err) => {
        // 关闭等待框
        this.$layer.close(this.loading);
        this.$layer.msg('设置失败!');
      })
    },
    getSetParams() {
      let params = this.params;
      let groupNum = this.getCuringGroupNum(params.GroupNum);
      for (let key in params) {
        if (key !== "dev_id" && key !== "GroupNum") {
          let realKey = key + groupNum;
          this.allData[realKey] = Number(params[key]);
        }
      }
      this.allData.BattGroupNum = this.batt.GroupIndexInFBSDevice;
      this.allData.GroupNum = this.params.GroupNum;
      return this.allData;
    },
    confirmStart() {
      this.$confirm('确定启动养护除硫', '系统提示', {
        type: 'error',
        iconClass:"el-icon-question",
      }).then(()=>{
        // 启动测试
        this.start();
      }).catch(()=>{})
    },
    start() {
      let batt = this.batt;
      // 请求后台启动养护处理
      let loading = this.$layer.loading();
      this.$apis.curing.start( this.op_cmd, batt.FBSDeviceId, this.params.GroupNum, batt.GroupIndexInFBSDevice).then(res=>{
        let rs = JSON.parse(res.data.result);
        if(rs.code == 1) {
          this.$layer.msg("启动成功");
        }else {
          this.$layer.msg("启动失败");
        }
        // 关闭等待框
        this.$layer.close(loading);
      }).catch(error=>{
        // 关闭等待框
        this.$layer.close(loading);
      });
    },
  },
  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.readFromDev(true);
  }
}
</script>
 
<style scoped>
.params-container {
  padding: 8px;
  background-color: #ececec;
}
 
.form-footer {
  margin-top: 16px;
  margin-bottom: 16px;
  text-align: right;
}
 
.form-footer .three-btn {
  margin-left: 12px;
}
</style>