| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- import * as echarts from '../../ec-canvas/echarts';
- import * as liquidFill from '../../ec-canvas/echarts-liquidfill.min';
- const util = require('../../utils/util.js')
- const api = require('../../api/index.js');
- const moment = require('moment');
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- // 状态栏高度
- statusBarHeight: wx.getStorageSync('statusBarHeight'),
- // 导航栏高度
- navBarHeight: wx.getStorageSync('navBarHeight'),
- // 导航栏和状态栏高度
- navStatusBarHeight: wx.getStorageSync('navStatusBarHeight'),
- // 胶囊
- menu:wx.getStorageSync('menu'),
- mode: '',
- datetimeVisible: false,
- datetime: new Date('2021-12-23').getTime(),
- datetimeText: '',
- img_path:'',
- tapindex:0,
- labelindex:1,
- visible: false,
- ec: {
- lazyLoad: true
- },
- ech: {
- lazyLoad: true
- },
- value:[],
- valueitem:'',
- minDate: new Date(2022, 1, 1).getTime(),
- maxDate: new Date(util.getdataTime('当日')).getTime(),
- format(day) {
- const { date } = day;
- const year = date.getFullYear();
- const month = date.getMonth() + 1;
- const curDate = date.getDate();
- if (year== moment().format('YYYY')) {
- if(month== moment().format('MM')){
- if(curDate== moment().format('DD')){
- day.suffix = '今日';
- }
- }
- }
- return day;
- },
- Electricitylevel:[],
- chargeTotal:[],
- dischargeTotal:[],
- ymdlist:[],
- echartstype:'bar',
- unm:0,
- current:0,
- rangetype:'',
- uuid:'',
- chargeTotaldatas:[],
- ymdlistdatas:[]
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- console.log(options);
- this.setData({
- uuid:options.uuid
- })
- // let base64imgages =util.Background_base64('https://esos-iot.bjdexn.cn/wx_images/bj.png')
- this.setData({
- img_path:'https://esos-iot.bjdexn.cn/wx_images/bj.png',
- value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
- valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
-
- })
- // this.ecComponent = this.selectComponent('#mychart_line1');
- this.ecline = this.selectComponent('#mychart_line2');
- this.getlineMonth()
- },
-
- // 返回上一级
- onIconTap(){
- wx.navigateBack({
- delta: 1
- });
- },
- // 切换标签
- ontop(e){
- // console.log(e);
- this.setData({
- tapindex:e.detail.current
- })
- console.log(this.data.tapindex);
-
- if (this.data.tapindex==0) {
- // this.ecComponent = this.selectComponent('#mychart_line1');
- this.ecline = this.selectComponent('#mychart_line2');
- this.setData({
- labelindex:1,
- value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
- valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
- echartstype:'bar'
- })
- this.getlineMonth();
- }else if(this.data.tapindex==1){
- this.ecline = this.selectComponent('#mychart_line2');
- this.setData({
- valueitem:util.getdataTime('当日'),
- value:new Date(util.getdataTime('当日')).getTime(),
- echartstype:'line'
- })
- this.Powertrend();
- }
-
- },
- onlabel(e){
- this.setData({
- labelindex:e.target.dataset.index
- })
- if (this.data.tapindex==0) {
- if (this.data.labelindex==1) {
- this.setData({
- echartstype:'bar',
- value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
- valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
-
- })
- }else if(this.data.labelindex==2){
-
- this.setData({
- echartstype:'line',
- value:[new Date(util.getdataTime(31)).getTime(),new Date(util.getdataTime('当日')).getTime()],
- valueitem:`${util.getdataTime(31)} - ${util.getdataTime('当日')}`,
- })
- }
- this.getlineMonth();
- }else if(this.data.tapindex==1){
- this.ecline = this.selectComponent('#mychart_line2');
- this.setData({
- valueitem:util.getdataTime('当日'),
- echartstype:'line'
- })
- this.Powertrend();
- }else if(this.data.tapindex==2){
- if (this.data.labelindex==1) {
- this.setData({
- echartstype:'bar',
- value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
- valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
- })
- } else{
-
- this.setData({
- echartstype:'line',
- value:[new Date(util.getdataTime(365)).getTime(),new Date(util.getdataTime('当日')).getTime()],
- valueitem:`${util.getdataTime(365)} - ${util.getdataTime('当日')}`,
- })
- }
- this.electrictime();
-
- }
-
- },
- // 上一天
- Lastday(){
- this.data.unm++
- this.setData({
- unm:this.data.unm
- })
- this.ecline = this.selectComponent('#mychart_line2');
- this.setData({
- valueitem:util.CumulativeTime(this.data.unm),
- echartstype:'line'
- })
- this.Powertrend();
- },
- handleCalendar() {
- if (this.data.tapindex==1) {
- this.setData({
- visible: true,
- rangetype:'single'
- })
- }else{
- this.setData({
- visible: true,
- rangetype:'range'
- })
- }
-
- },
- // 下一天
- dayfollowing(){
- if (this.data.unm==0) {
- return wx.showToast({
- title: '不可超出当前时间',
- icon: 'none',
- });
- }
- this.data.unm--
- this.setData({
- unm:this.data.unm
- })
- this.ecline = this.selectComponent('#mychart_line2');
- this.setData({
- valueitem:util.CumulativeTime(this.data.unm),
- echartstype:'line'
- })
- this.Powertrend();
- },
- // 时间区间范围
- bindclose(){
- this.setData({
- visible: false
- })
- },
- handleConfirm(e) {
- console.log(e);
- let formattedTime =[]
- if (this.data.tapindex==1) {
- formattedTime.push(moment(e.detail.value).format('YYYY-MM-DD'));
- this.setData({
- visible: false,
- valueitem:`${formattedTime[0]}`,
- value:e.detail.value
- });
- this.Powertrend();
- }else{
- if (e.detail.value.length==0) {
- e.detail.value.forEach(ts => {
- formattedTime.push(moment(ts).format('YYYY-MM-DD'));
- });
- this.setData({
- visible: false,
- valueitem:`${formattedTime[0]} - ${util.getdataTime('当日')}`,
- value:e.detail.value
- });
- }else{
- e.detail.value.forEach(ts => {
- formattedTime.push(moment(ts).format('YYYY-MM-DD'));
- });
- this.setData({
- visible: false,
- valueitem:`${formattedTime[0]} - ${formattedTime[1]}`,
- value:e.detail.value
- });
- }
- if (this.data.tapindex==1) {
- this.getlineMonth()
- }else{
- this.electrictime()
-
- }
- }
- },
- // 电量
- getlineMonth(){
- let data={
- page:1,
- rows:10000,
- starttime:moment(this.data.value[0]).format('YYYY-MM-DD')+' 00:00:00',
- stoptime:moment(this.data.value[1]).format('YYYY-MM-DD')+' 00:00:00',
- // starttime:'2024-07-29 00:00:00',
- // stoptime:'2024-07-30 00:00:00',
- filter:'5c465aaa-b65e-463f-a9ae-a338a630a4c1_delta,469dc1cc-e5ad-492f-a350-f7bc473d55ee_delta',
- uuid:this.data.uuid
- }
- let daymonth = ''
- if (this.data.labelindex==1) {
- daymonth = 'day'
- }else if(this.data.labelindex==2){
- daymonth = 'month'
-
- }else if(this.data.labelindex==3){
- daymonth = 'year'
-
- }
- api.request(`/api/v1/hisdata/hour/datas`, 'get',data )
- .then((res) => {
- let list = res.data.list;
- let chargeTotal = list.map(item => item["5c465aaa-b65e-463f-a9ae-a338a630a4c1_delta"]);
- let dischargeTotal = list.map(item => item["469dc1cc-e5ad-492f-a350-f7bc473d55ee_delta"]);
- let ymdlist = list.map(item => item.recordtime.slice(5, 11));
- this.setData({
- // Electricitylevel: res.data,
- chargeTotal: chargeTotal,
- dischargeTotal: dischargeTotal,
- ymdlist: ymdlist,
- });
- // this.initChartright()
- this.initChart_right()
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
- });
- },
- // 收益
- Powertrend(){
- let data={
- page:1,
- rows:10000,
- starttime:moment(this.data.value[0]).format('YYYY-MM-DD') + "00:00:00",
- stoptime:moment(this.data.value[1]).format('YYYY-MM-DD') + "00:00:00",
- // starttime:'2024-07-29 00:00:00',
- // stoptime:'2024-07-30 00:00:00',
- filter:'a0acf8cf-7d12-49af-97d9-1a2e630c4bfe_delta',
- uuid:this.data.uuid
- }
-
- api.request(`/api/v1/hisdata/hour/datas`, 'get',data)
- .then((res) => {
- let list = res.data.list;
- console.log(list);
- let chargeTotal = list.map(item => item["a0acf8cf-7d12-49af-97d9-1a2e630c4bfe_delta"]);
- // let dischargeTotal = list.storedPower.map(item => item.totalActivePower);
- let ymdlist = list.map(item => item.recordtime.slice(12, 16));
- this.setData({
- // Electricitylevel: res.data,
- chargeTotaldatas: chargeTotal,
- // dischargeTotal: dischargeTotal,
- ymdlistdatas: ymdlist,
- });
-
- this.initChart_rightshoyi()
- })
- .catch((err) => {
- console.error('请求失败:', err);
- // 在这里处理请求失败的情况
-
-
- });
- },
-
- onTabsChange(event) {
- this.setData({
- tapindex:event.detail.value
- })
- },
-
-
- onStickyScroll(event) {
- console.log(event.detail);
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady() {
-
- },
-
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
-
- },
-
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide() {
-
- },
-
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload() {
-
- },
-
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh() {
-
- },
-
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom() {
-
- },
-
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage() {
-
- },
- initChartright: function(){
- let _this = this
- this.ecComponent.init((canvas, width, height, dpr)=> {
-
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- canvas.setChart(chart);
-
- var option = {
- legend:[ {
- right: '0', // 图例水平居中
- bottom: '35%',
- itemHeight:8,
- itemWidth:8,
- icon:"circle",
- formatter: function (name) {
- return name + _this.data.Electricitylevel.total.sumdischargeTotal+' kwh'; // 在名称和单位之间添加空格间距
- },
- data:[
- {name: '累计充电'},
- ]
- },{
- right: '0', // 图例水平居中
- bottom: '50%',
- itemHeight:8,
- itemWidth:8,
- icon:"circle",
- formatter: function (name) {
- return name + _this.data.Electricitylevel.total.sumchargeTotal + ' kwh'; // 在名称和单位之间添加空格间距
- },
- data:[
- {name: '累计放电'},
- ]
- }],
- tooltip: {
- trigger: 'item'
- },
- series: [{
- type: 'pie',
- radius: ['40%', '60%'],
- center: ['20%', '50%'],
- avoidLabelOverlap: false,
- label: {
- show: false,
- position: 'center'
- },
- emphasis: {
- label: {
- show: true,
- fontSize: 0,
- fontWeight: 'bold'
- }
- },
- labelLine: {
- show: false
- },
- data: [{
- value: _this.data.Electricitylevel.total.sumchargeTotal,
- name: '累计充电',
- itemStyle: { color: '#4DF096' }
- }, {
- value: _this.data.Electricitylevel.total.sumdischargeTotal,
- name: '累计放电',
- itemStyle: { color: '#3C9EFA' }
- }
- ]
- }]
- };
-
- chart.setOption(option);
- return chart;
- })},
- initChart_right: function () {
- var unitName = '';
- var viewname = ['充电量','放电量'];
- if (this.data.tapindex==0) {
- unitName = 'kWh';
- viewname = ['充电量','放电量'];
- }else if(this.data.tapindex==1){
- unitName = 'kW';
- viewname = ['收益'];
-
- }
- let _this = this
- this.ecline.init((canvas, width, height, dpr)=> {
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- canvas.setChart(chart);
- var option = {
- legend: { bottom: '0%'},
- grid: {
- left:'3%',
- top:'20%',
- right:'1%',
- bottom:'20%',
- containLabel: true
- },
- tooltip: {
- show: true,
- trigger: 'axis'
- },
- xAxis: {
- type: 'category',
- data:_this.data.ymdlist,
- // show: false,
- axisTick: {
- show: false // 这里设置x轴的刻度线不显示
- },
-
- barWidth: 10 // 设置柱状图的宽度
- },
- yAxis: {
- name:unitName,
- x: 'center',
- type: 'value',
- axisTick: {
- show: false // 这里设置x轴的刻度线不显示
- },
-
- splitLine: {
- show: false // 这里设置x轴的刻度线不显示
- },
-
- // show: false
- },
- series: [{
- name: viewname[0],
- type: _this.data.echartstype,
- barMaxWidth: 20,// 设置柱状图的宽度
- smooth: true,
- showSymbol: false,
- data:_this.data.chargeTotal,
- itemStyle: {
- color: 'rgba(60, 158, 250, 0.5)' // 设置数据点颜色为蓝色(使用十六进制表示法)
- },
- areaStyle: {
- color: 'rgba(60, 158, 250, 0.3)' // 设置区域填充颜色
- }
- },{
- name: viewname[1],
- type: _this.data.echartstype,
- smooth: true,
- showSymbol: false,
- barMaxWidth: 20,// 设置柱状图的宽度
- data: _this.data.dischargeTotal,
- itemStyle: {
- color: 'rgba(77, 240, 150, 0.5)' // 设置数据点颜色为绿色(使用十六进制表示法)
- },
- areaStyle: {
- color: 'rgba(77, 240, 150, 0.3)' // 设置区域填充颜色为半透明的绿色
- }
- } ]
- };
-
- chart.setOption(option);
- return chart;
- })},
- initChart_rightshoyi: function () {
- var unitName = '元';
- var viewname = ['收益'];
-
- let _this = this
- this.ecline.init((canvas, width, height, dpr)=> {
- const chart = echarts.init(canvas, null, {
- width: width,
- height: height,
- devicePixelRatio: dpr // new
- });
- canvas.setChart(chart);
- var option = {
- legend: { bottom: '0%'},
- grid: {
- left:'2%',
- top:'20%',
- right:'1%',
- bottom:'20%',
- containLabel: true
- },
- tooltip: {
- show: true,
- trigger: 'axis'
- },
- xAxis: {
- type: 'category',
- data:_this.data.ymdlistdatas,
- // show: false,
- axisTick: {
- show: false // 这里设置x轴的刻度线不显示
- },
-
- barWidth: 10 // 设置柱状图的宽度
- },
- yAxis: {
- name:unitName,
- x: 'center',
- type: 'value',
- axisTick: {
- show: false // 这里设置x轴的刻度线不显示
- },
-
- splitLine: {
- show: false // 这里设置x轴的刻度线不显示
- },
-
- // show: false
- },
- series: [{
- name: viewname[0],
- type: _this.data.echartstype,
- barMaxWidth: 20,// 设置柱状图的宽度
- smooth: true,
- showSymbol: false,
- data:_this.data.chargeTotaldatas,
- itemStyle: {
- color: 'rgba(60, 158, 250, 0.5)' // 设置数据点颜色为蓝色(使用十六进制表示法)
- },
- areaStyle: {
- color: 'rgba(60, 158, 250, 0.3)' // 设置区域填充颜色
- }
- } ]
- };
-
- chart.setOption(option);
- return chart;
- })}
- })
|