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
<template>
  <div class="module-wrapper">
    <el-row :gutter="layout.gutter" class="full-height">
      <el-col :span="layout.left" class="full-height">
        <layout-box no-bg>
          <div class="layout-content">
            <flex-box title="节约电费统计折线图" size="mini">
              <div slot="tools">
                <el-input class="flex-box-input" size="mini" v-model="priceRatio">
                  <template slot="prepend">电价系数</template>
                </el-input>
                <el-select v-model="timeNum" size="mini">
                  <el-option
                      v-for="(item, key) in timeNums" :key="'key'+key"
                      :label="item.label" :value="item.value"></el-option>
                </el-select>
                <el-button size="mini" type="primary" @click="getPeakPrice">查询</el-button>
                <el-button size="mini" type="success" @click="exportExcel">导出</el-button>
              </div>
              <dot-line ref="priceDotLine" :show-area="true"></dot-line>
            </flex-box>
          </div>
        </layout-box>
      </el-col>
      <el-col :span="layout.right" class="full-height">
        <layout-box no-bg>
          <div class="layout-content">
            <div class="layout-content-top">
              <flex-box title="电价分布图" size="mini">
                <ele-price-bar ref="elePriceBar"></ele-price-bar>
              </flex-box>
            </div>
            <div class="layout-content-bottom">
              <flex-box title="节约电费统计数据" size="mini">
                <el-table
                  stripe
                  size="small"
                  :data="tblData"
                  height="100%">
                  <el-table-column
                      prop="num"
                      align="center"
                      label="编号"
                      width="80">
                  </el-table-column>
                  <el-table-column
                      prop="date"
                      align="center"
                      label="日期">
                  </el-table-column>
                  <el-table-column
                      prop="price"
                      align="center"
                      label="节约电费(度/元)">
                  </el-table-column>
                </el-table>
              </flex-box>
            </div>
          </div>
        </layout-box>
      </el-col>
    </el-row>
    <form
        :action="exportInfo.action" method="post"
        ref="all_picture" enctype="multipart/form-data">
      <input type="hidden" id="exPageName" name="pageName" value="ePrice" />
      <input type="hidden" name="ePriceAnalysisPic" ref="ePriceAnalysisPic" value="" />
      <input type="hidden" name="ePriceDistributeMapPic" ref="ePriceDistributeMapPic" value="" />
      <input type="hidden" name="ePriceAnalysisData" ref="ePriceAnalysisData" value="" />
    </form>
  </div>
</template>
 
<script>
import FlexBox from "@/components/FlexBox";
import LayoutBox from "@/pages/dataTest/components/layout-box";
import ElePriceBar from "@/components/chart/elePriceBar";
import DotLine from "@/components/chart/line/dotLine";
import {formatSeconds} from "@/assets/js/tools";
import getItemByKey from "@/assets/js/tools/getItemByKey";
export default {
  name: "elePriceTpl",
  props: {
    name: {
      type: String,
      default: "",
    },
    devId: {
      type: [String, Number],
      default: 0,
    },
    batt: {
      type: Object,
      default() {
        return {}
      }
    },
  },
  components: {
    DotLine,
    ElePriceBar,
    LayoutBox,
    FlexBox
  },
  data() {
    let baseURL = this.$axios.defaults.baseURL;
    baseURL = baseURL ? baseURL : "";
    return {
      flag: "elePrice",
      layout: {
        gutter: 16,
        left: 15,
        right: 9,
      },
      priceRatio: 1,
      timeNum: 1,
      timeNums: [
        {
          key: 1,
          value: 1,
          num: 1, // 按月统计
          label: '最近7天',
          days: 7,
        },
        {
          key: 2,
          value: 2,
          num: 1, // 按月统计
          label: '最近30天',
          days: 30,
        },
        {
          key: 3,
          value: 3,
          num: 1, // 按月统计
          label: '最近3个月',
          days: 30*3,
        },
        {
          key: 4,
          value: 4,
          num: 1, // 按月统计
          label: '最近6个月',
          days: 30*6,
        },
        {
          key: 5,
          value: 5,
          num: 3,   // 按年统计
          label: "最近1年",
          days: 365,
        }
      ],
      tblData: [],
      exportInfo: {
        action: baseURL + "EchartPictureDowload.servlet",
        ePriceAnalysisPic: "",
        ePriceDistributeMapPic: "",
        ePriceAnalysisData: {
          num: 1,
          tmp_starttime: "2021-10-14",
          ele_price: 0,
        },
      }
    }
  },
  watch: {
    name() {
      this.searchData();
    },
    devId() {
      this.priceRatio = this.batt.priceFactor?this.batt.priceFactor:0;
      this.searchData();
    }
  },
  methods: {
    resize() {
      this.$nextTick(()=>{
        this.$refs.elePriceBar.resize();
        this.$refs.priceDotLine.resize();
      });
    },
    searchData() {
      //console.log(this.batt);
    },
    getPeakPrice() { // 统计削峰填谷价格
      let priceRatio = this.priceRatio;
      let reg = /^[0-9]+.?[0-9]*$/;
      if(!reg.test(priceRatio)) {
        this.$layer.msg("电价系数必须为数字");
        return;
      }
 
      let batt = this.batt;
      let timeNum = getItemByKey(this.timeNum, this.timeNums);
      let num = timeNum.num;
      let recordTime1 = new Date().format("yyyy-MM-dd");
      let recordTime = new Date(new Date().getTime()-timeNum.days*24*3600*1000).format("yyyy-MM-dd");
      // 构造查询条件
      let searchParams = {
        BattGroupId: batt.BattGroupId,
        num: num,
        record_time: recordTime,
        record_time1: recordTime1,
        priceFactor: priceRatio,
      };
      // 查询后台
      this.$apis.dcdc.getPeakPrice(searchParams).then(res=>{
        let rs = JSON.parse(res.data.result);
        let data = [];
        if(rs.code == 1) {
          data = rs.data;
        }else {
          this.$layer.msg(rs.msg);
        }
        let formatData = this.getFormatData(data, num, priceRatio);
        this.tblData = formatData.xData.map((item,key)=> {
            let price = formatData.yData[key];
            return {
              num: key+1,
              date: item,
              price:price,
            }
        }).reverse().map((item,key)=>{
          item.num = key+1;
          return item;
        });
        this.$refs.priceDotLine.setData(formatData);
      }).catch(error => {
        let formatData = this.getFormatData([], num);
        this.$refs.priceDotLine.setData(formatData);
      });
    },
    getFormatData(data, type, ratio) {
      let xData = [];
      let yData = [];
      ratio = ratio?ratio:1;
      data.map(item=>{
        let times = item.perid_Time.split(" ");
        let time = times[0];
        switch (type) {
          case 1:
            time = new Date(time).format("yyyy-MM-dd");
            break;
          case 3:
            time = new Date(time).format("yyyy-MM");
            break;
        }
        xData.push(time);
        yData.push((item.price*ratio).toHold(4));
      });
      return {
        xData,
        yData
      }
    },
    searchElePrices() {
      let batt = this.batt;
      let loading = this.$layer.loading();
      // 查询电价
      this.$apis.dcdc
        .searchElePrices(batt.tmp_id)
        .then((res) => {
          // 关闭弹出框
          this.$layer.close(loading);
 
          let rs = JSON.parse(res.data.result);
          let data = [];
          if (rs.code == 1) {
            data = rs.data;
          }
          let barData = data.map((child) => {
            return {
              value: [
                "2022-10-01 " + child.tmp_starttime,
                "2022-10-01 " + child.tmp_stoptime,
                child.ele_price,
                "电费",
              ],
              itemStyle: {
                color: "#49A1FA",
              },
            };
          });
 
          // 设置电价的图表
          this.$refs.elePriceBar.setData({
            title: "",
            data: barData,
          });
        })
        .catch((error) => {
          // 关闭弹出框
          this.$layer.close(loading);
        });
    },
    // 导出报表
    exportExcel() {
      if (this.tblData.length == 0) {
        this.$layer.msg('暂无数据导出!');
        return false;
      }
 
      // 格式化导出数据
      let tblData = this.tblData.map(item=>{
        let tmp = {
          num: item.num,
          analysisDate: item.date,
          ele_price: item.price
        };
        return tmp;
      });
      // 表格数据
      this.$refs.ePriceAnalysisData.value = JSON.stringify(tblData);
      // 电价分布图
      this.$refs.ePriceDistributeMapPic.value = this.$refs.elePriceBar.getDataURL();
      // 电价分析图
      this.$refs.ePriceAnalysisPic.value = this.$refs.priceDotLine.getDataURL();
 
      // 提交表单
      this.$refs.all_picture.submit();
    }
  },
  computed: {
 
  },
  mounted() {
    // 设置电价系数
    this.priceRatio = this.batt.priceFactor?this.batt.priceFactor:0;
    // 信息修改
    this.searchData();
    this.getPeakPrice();
    this.searchElePrices();
  },
  beforeDestroy() {
  }
}
</script>
 
<style scoped>
.module-wrapper {
  width: 100%;
  height: 100%;
  box-sizing: border-box;
}
.layout-content {
  box-sizing: border-box;
  padding: 12px 16px 16px 16px;
  height: 100%;
}
.layout-content-top,
.layout-content-bottom {
  box-sizing: border-box;
  height: 50%;
}
.layout-content-top {
  padding-bottom: 8px;
}
.layout-content-bottom {
  padding-top: 8px;
}
.layout-price-bar,
.layout-cap-line {
  box-sizing: border-box;
}
.layout-price-bar {
  height: 40%;
}
.layout-cap-line {
  height: 60%;
}
.flex-box-input {
  width: 150px;
  margin-right: 8px;
}
</style>