储能智慧云小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. import * as echarts from '../../ec-canvas/echarts';
  2. import * as liquidFill from '../../ec-canvas/echarts-liquidfill.min';
  3. const util = require('../../utils/util.js')
  4. const api = require('../../api/index.js');
  5. const moment = require('moment');
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. // 状态栏高度
  12. statusBarHeight: wx.getStorageSync('statusBarHeight'),
  13. // 导航栏高度
  14. navBarHeight: wx.getStorageSync('navBarHeight'),
  15. // 导航栏和状态栏高度
  16. navStatusBarHeight: wx.getStorageSync('navStatusBarHeight'),
  17. // 胶囊
  18. menu:wx.getStorageSync('menu'),
  19. mode: '',
  20. datetimeVisible: false,
  21. datetime: new Date('2021-12-23').getTime(),
  22. datetimeText: '',
  23. img_path:'',
  24. tapindex:0,
  25. labelindex:1,
  26. visible: false,
  27. ec: {
  28. lazyLoad: true
  29. },
  30. ech: {
  31. lazyLoad: true
  32. },
  33. value:[],
  34. valueitem:'',
  35. minDate: new Date(2022, 1, 1).getTime(),
  36. maxDate: new Date(util.getdataTime('当日')).getTime(),
  37. format(day) {
  38. const { date } = day;
  39. const year = date.getFullYear();
  40. const month = date.getMonth() + 1;
  41. const curDate = date.getDate();
  42. if (year== moment().format('YYYY')) {
  43. if(month== moment().format('MM')){
  44. if(curDate== moment().format('DD')){
  45. day.suffix = '今日';
  46. }
  47. }
  48. }
  49. return day;
  50. },
  51. Electricitylevel:[],
  52. chargeTotal:[],
  53. dischargeTotal:[],
  54. ymdlist:[],
  55. echartstype:'bar',
  56. unm:0,
  57. current:0,
  58. rangetype:'',
  59. uuid:'',
  60. chargeTotaldatas:[],
  61. ymdlistdatas:[]
  62. },
  63. /**
  64. * 生命周期函数--监听页面加载
  65. */
  66. onLoad(options) {
  67. console.log(options);
  68. this.setData({
  69. uuid:options.uuid
  70. })
  71. // let base64imgages =util.Background_base64('https://esos-iot.bjdexn.cn/wx_images/bj.png')
  72. this.setData({
  73. img_path:'https://esos-iot.bjdexn.cn/wx_images/bj.png',
  74. value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
  75. valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
  76. })
  77. // this.ecComponent = this.selectComponent('#mychart_line1');
  78. this.ecline = this.selectComponent('#mychart_line2');
  79. this.getlineMonth()
  80. },
  81. // 返回上一级
  82. onIconTap(){
  83. wx.navigateBack({
  84. delta: 1
  85. });
  86. },
  87. // 切换标签
  88. ontop(e){
  89. // console.log(e);
  90. this.setData({
  91. tapindex:e.detail.current
  92. })
  93. console.log(this.data.tapindex);
  94. if (this.data.tapindex==0) {
  95. // this.ecComponent = this.selectComponent('#mychart_line1');
  96. this.ecline = this.selectComponent('#mychart_line2');
  97. this.setData({
  98. labelindex:1,
  99. value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
  100. valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
  101. echartstype:'bar'
  102. })
  103. this.getlineMonth();
  104. }else if(this.data.tapindex==1){
  105. this.ecline = this.selectComponent('#mychart_line2');
  106. this.setData({
  107. valueitem:util.getdataTime('当日'),
  108. value:new Date(util.getdataTime('当日')).getTime(),
  109. echartstype:'line'
  110. })
  111. this.Powertrend();
  112. }
  113. },
  114. onlabel(e){
  115. this.setData({
  116. labelindex:e.target.dataset.index
  117. })
  118. if (this.data.tapindex==0) {
  119. if (this.data.labelindex==1) {
  120. this.setData({
  121. echartstype:'bar',
  122. value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
  123. valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
  124. })
  125. }else if(this.data.labelindex==2){
  126. this.setData({
  127. echartstype:'line',
  128. value:[new Date(util.getdataTime(31)).getTime(),new Date(util.getdataTime('当日')).getTime()],
  129. valueitem:`${util.getdataTime(31)} - ${util.getdataTime('当日')}`,
  130. })
  131. }
  132. this.getlineMonth();
  133. }else if(this.data.tapindex==1){
  134. this.ecline = this.selectComponent('#mychart_line2');
  135. this.setData({
  136. valueitem:util.getdataTime('当日'),
  137. echartstype:'line'
  138. })
  139. this.Powertrend();
  140. }else if(this.data.tapindex==2){
  141. if (this.data.labelindex==1) {
  142. this.setData({
  143. echartstype:'bar',
  144. value:[new Date(util.getdataTime('当日')).getTime(),new Date(util.getdataTime('当日')).getTime()],
  145. valueitem:`${util.getdataTime('当日')} - ${util.getdataTime('当日')}`,
  146. })
  147. } else{
  148. this.setData({
  149. echartstype:'line',
  150. value:[new Date(util.getdataTime(365)).getTime(),new Date(util.getdataTime('当日')).getTime()],
  151. valueitem:`${util.getdataTime(365)} - ${util.getdataTime('当日')}`,
  152. })
  153. }
  154. this.electrictime();
  155. }
  156. },
  157. // 上一天
  158. Lastday(){
  159. this.data.unm++
  160. this.setData({
  161. unm:this.data.unm
  162. })
  163. this.ecline = this.selectComponent('#mychart_line2');
  164. this.setData({
  165. valueitem:util.CumulativeTime(this.data.unm),
  166. echartstype:'line'
  167. })
  168. this.Powertrend();
  169. },
  170. handleCalendar() {
  171. if (this.data.tapindex==1) {
  172. this.setData({
  173. visible: true,
  174. rangetype:'single'
  175. })
  176. }else{
  177. this.setData({
  178. visible: true,
  179. rangetype:'range'
  180. })
  181. }
  182. },
  183. // 下一天
  184. dayfollowing(){
  185. if (this.data.unm==0) {
  186. return wx.showToast({
  187. title: '不可超出当前时间',
  188. icon: 'none',
  189. });
  190. }
  191. this.data.unm--
  192. this.setData({
  193. unm:this.data.unm
  194. })
  195. this.ecline = this.selectComponent('#mychart_line2');
  196. this.setData({
  197. valueitem:util.CumulativeTime(this.data.unm),
  198. echartstype:'line'
  199. })
  200. this.Powertrend();
  201. },
  202. // 时间区间范围
  203. bindclose(){
  204. this.setData({
  205. visible: false
  206. })
  207. },
  208. handleConfirm(e) {
  209. console.log(e);
  210. let formattedTime =[]
  211. if (this.data.tapindex==1) {
  212. formattedTime.push(moment(e.detail.value).format('YYYY-MM-DD'));
  213. this.setData({
  214. visible: false,
  215. valueitem:`${formattedTime[0]}`,
  216. value:e.detail.value
  217. });
  218. this.Powertrend();
  219. }else{
  220. if (e.detail.value.length==0) {
  221. e.detail.value.forEach(ts => {
  222. formattedTime.push(moment(ts).format('YYYY-MM-DD'));
  223. });
  224. this.setData({
  225. visible: false,
  226. valueitem:`${formattedTime[0]} - ${util.getdataTime('当日')}`,
  227. value:e.detail.value
  228. });
  229. }else{
  230. e.detail.value.forEach(ts => {
  231. formattedTime.push(moment(ts).format('YYYY-MM-DD'));
  232. });
  233. this.setData({
  234. visible: false,
  235. valueitem:`${formattedTime[0]} - ${formattedTime[1]}`,
  236. value:e.detail.value
  237. });
  238. }
  239. if (this.data.tapindex==1) {
  240. this.getlineMonth()
  241. }else{
  242. this.electrictime()
  243. }
  244. }
  245. },
  246. // 电量
  247. getlineMonth(){
  248. let data={
  249. page:1,
  250. rows:10000,
  251. starttime:moment(this.data.value[0]).format('YYYY-MM-DD')+' 00:00:00',
  252. stoptime:moment(this.data.value[1]).format('YYYY-MM-DD')+' 00:00:00',
  253. // starttime:'2024-07-29 00:00:00',
  254. // stoptime:'2024-07-30 00:00:00',
  255. filter:'5c465aaa-b65e-463f-a9ae-a338a630a4c1_delta,469dc1cc-e5ad-492f-a350-f7bc473d55ee_delta',
  256. uuid:this.data.uuid
  257. }
  258. let daymonth = ''
  259. if (this.data.labelindex==1) {
  260. daymonth = 'day'
  261. }else if(this.data.labelindex==2){
  262. daymonth = 'month'
  263. }else if(this.data.labelindex==3){
  264. daymonth = 'year'
  265. }
  266. api.request(`/api/v1/hisdata/hour/datas`, 'get',data )
  267. .then((res) => {
  268. let list = res.data.list;
  269. let chargeTotal = list.map(item => item["5c465aaa-b65e-463f-a9ae-a338a630a4c1_delta"]);
  270. let dischargeTotal = list.map(item => item["469dc1cc-e5ad-492f-a350-f7bc473d55ee_delta"]);
  271. let ymdlist = list.map(item => item.recordtime.slice(5, 11));
  272. this.setData({
  273. // Electricitylevel: res.data,
  274. chargeTotal: chargeTotal,
  275. dischargeTotal: dischargeTotal,
  276. ymdlist: ymdlist,
  277. });
  278. // this.initChartright()
  279. this.initChart_right()
  280. })
  281. .catch((err) => {
  282. console.error('请求失败:', err);
  283. // 在这里处理请求失败的情况
  284. });
  285. },
  286. // 收益
  287. Powertrend(){
  288. let data={
  289. page:1,
  290. rows:10000,
  291. starttime:moment(this.data.value[0]).format('YYYY-MM-DD') + "00:00:00",
  292. stoptime:moment(this.data.value[1]).format('YYYY-MM-DD') + "00:00:00",
  293. // starttime:'2024-07-29 00:00:00',
  294. // stoptime:'2024-07-30 00:00:00',
  295. filter:'a0acf8cf-7d12-49af-97d9-1a2e630c4bfe_delta',
  296. uuid:this.data.uuid
  297. }
  298. api.request(`/api/v1/hisdata/hour/datas`, 'get',data)
  299. .then((res) => {
  300. let list = res.data.list;
  301. console.log(list);
  302. let chargeTotal = list.map(item => item["a0acf8cf-7d12-49af-97d9-1a2e630c4bfe_delta"]);
  303. // let dischargeTotal = list.storedPower.map(item => item.totalActivePower);
  304. let ymdlist = list.map(item => item.recordtime.slice(12, 16));
  305. this.setData({
  306. // Electricitylevel: res.data,
  307. chargeTotaldatas: chargeTotal,
  308. // dischargeTotal: dischargeTotal,
  309. ymdlistdatas: ymdlist,
  310. });
  311. this.initChart_rightshoyi()
  312. })
  313. .catch((err) => {
  314. console.error('请求失败:', err);
  315. // 在这里处理请求失败的情况
  316. });
  317. },
  318. onTabsChange(event) {
  319. this.setData({
  320. tapindex:event.detail.value
  321. })
  322. },
  323. onStickyScroll(event) {
  324. console.log(event.detail);
  325. },
  326. /**
  327. * 生命周期函数--监听页面初次渲染完成
  328. */
  329. onReady() {
  330. },
  331. /**
  332. * 生命周期函数--监听页面显示
  333. */
  334. onShow() {
  335. },
  336. /**
  337. * 生命周期函数--监听页面隐藏
  338. */
  339. onHide() {
  340. },
  341. /**
  342. * 生命周期函数--监听页面卸载
  343. */
  344. onUnload() {
  345. },
  346. /**
  347. * 页面相关事件处理函数--监听用户下拉动作
  348. */
  349. onPullDownRefresh() {
  350. },
  351. /**
  352. * 页面上拉触底事件的处理函数
  353. */
  354. onReachBottom() {
  355. },
  356. /**
  357. * 用户点击右上角分享
  358. */
  359. onShareAppMessage() {
  360. },
  361. initChartright: function(){
  362. let _this = this
  363. this.ecComponent.init((canvas, width, height, dpr)=> {
  364. const chart = echarts.init(canvas, null, {
  365. width: width,
  366. height: height,
  367. devicePixelRatio: dpr // new
  368. });
  369. canvas.setChart(chart);
  370. var option = {
  371. legend:[ {
  372. right: '0', // 图例水平居中
  373. bottom: '35%',
  374. itemHeight:8,
  375. itemWidth:8,
  376. icon:"circle",
  377. formatter: function (name) {
  378. return name + _this.data.Electricitylevel.total.sumdischargeTotal+' kwh'; // 在名称和单位之间添加空格间距
  379. },
  380. data:[
  381. {name: '累计充电'},
  382. ]
  383. },{
  384. right: '0', // 图例水平居中
  385. bottom: '50%',
  386. itemHeight:8,
  387. itemWidth:8,
  388. icon:"circle",
  389. formatter: function (name) {
  390. return name + _this.data.Electricitylevel.total.sumchargeTotal + ' kwh'; // 在名称和单位之间添加空格间距
  391. },
  392. data:[
  393. {name: '累计放电'},
  394. ]
  395. }],
  396. tooltip: {
  397. trigger: 'item'
  398. },
  399. series: [{
  400. type: 'pie',
  401. radius: ['40%', '60%'],
  402. center: ['20%', '50%'],
  403. avoidLabelOverlap: false,
  404. label: {
  405. show: false,
  406. position: 'center'
  407. },
  408. emphasis: {
  409. label: {
  410. show: true,
  411. fontSize: 0,
  412. fontWeight: 'bold'
  413. }
  414. },
  415. labelLine: {
  416. show: false
  417. },
  418. data: [{
  419. value: _this.data.Electricitylevel.total.sumchargeTotal,
  420. name: '累计充电',
  421. itemStyle: { color: '#4DF096' }
  422. }, {
  423. value: _this.data.Electricitylevel.total.sumdischargeTotal,
  424. name: '累计放电',
  425. itemStyle: { color: '#3C9EFA' }
  426. }
  427. ]
  428. }]
  429. };
  430. chart.setOption(option);
  431. return chart;
  432. })},
  433. initChart_right: function () {
  434. var unitName = '';
  435. var viewname = ['充电量','放电量'];
  436. if (this.data.tapindex==0) {
  437. unitName = 'kWh';
  438. viewname = ['充电量','放电量'];
  439. }else if(this.data.tapindex==1){
  440. unitName = 'kW';
  441. viewname = ['收益'];
  442. }
  443. let _this = this
  444. this.ecline.init((canvas, width, height, dpr)=> {
  445. const chart = echarts.init(canvas, null, {
  446. width: width,
  447. height: height,
  448. devicePixelRatio: dpr // new
  449. });
  450. canvas.setChart(chart);
  451. var option = {
  452. legend: { bottom: '0%'},
  453. grid: {
  454. left:'3%',
  455. top:'20%',
  456. right:'1%',
  457. bottom:'20%',
  458. containLabel: true
  459. },
  460. tooltip: {
  461. show: true,
  462. trigger: 'axis'
  463. },
  464. xAxis: {
  465. type: 'category',
  466. data:_this.data.ymdlist,
  467. // show: false,
  468. axisTick: {
  469. show: false // 这里设置x轴的刻度线不显示
  470. },
  471. barWidth: 10 // 设置柱状图的宽度
  472. },
  473. yAxis: {
  474. name:unitName,
  475. x: 'center',
  476. type: 'value',
  477. axisTick: {
  478. show: false // 这里设置x轴的刻度线不显示
  479. },
  480. splitLine: {
  481. show: false // 这里设置x轴的刻度线不显示
  482. },
  483. // show: false
  484. },
  485. series: [{
  486. name: viewname[0],
  487. type: _this.data.echartstype,
  488. barMaxWidth: 20,// 设置柱状图的宽度
  489. smooth: true,
  490. showSymbol: false,
  491. data:_this.data.chargeTotal,
  492. itemStyle: {
  493. color: 'rgba(60, 158, 250, 0.5)' // 设置数据点颜色为蓝色(使用十六进制表示法)
  494. },
  495. areaStyle: {
  496. color: 'rgba(60, 158, 250, 0.3)' // 设置区域填充颜色
  497. }
  498. },{
  499. name: viewname[1],
  500. type: _this.data.echartstype,
  501. smooth: true,
  502. showSymbol: false,
  503. barMaxWidth: 20,// 设置柱状图的宽度
  504. data: _this.data.dischargeTotal,
  505. itemStyle: {
  506. color: 'rgba(77, 240, 150, 0.5)' // 设置数据点颜色为绿色(使用十六进制表示法)
  507. },
  508. areaStyle: {
  509. color: 'rgba(77, 240, 150, 0.3)' // 设置区域填充颜色为半透明的绿色
  510. }
  511. } ]
  512. };
  513. chart.setOption(option);
  514. return chart;
  515. })},
  516. initChart_rightshoyi: function () {
  517. var unitName = '元';
  518. var viewname = ['收益'];
  519. let _this = this
  520. this.ecline.init((canvas, width, height, dpr)=> {
  521. const chart = echarts.init(canvas, null, {
  522. width: width,
  523. height: height,
  524. devicePixelRatio: dpr // new
  525. });
  526. canvas.setChart(chart);
  527. var option = {
  528. legend: { bottom: '0%'},
  529. grid: {
  530. left:'2%',
  531. top:'20%',
  532. right:'1%',
  533. bottom:'20%',
  534. containLabel: true
  535. },
  536. tooltip: {
  537. show: true,
  538. trigger: 'axis'
  539. },
  540. xAxis: {
  541. type: 'category',
  542. data:_this.data.ymdlistdatas,
  543. // show: false,
  544. axisTick: {
  545. show: false // 这里设置x轴的刻度线不显示
  546. },
  547. barWidth: 10 // 设置柱状图的宽度
  548. },
  549. yAxis: {
  550. name:unitName,
  551. x: 'center',
  552. type: 'value',
  553. axisTick: {
  554. show: false // 这里设置x轴的刻度线不显示
  555. },
  556. splitLine: {
  557. show: false // 这里设置x轴的刻度线不显示
  558. },
  559. // show: false
  560. },
  561. series: [{
  562. name: viewname[0],
  563. type: _this.data.echartstype,
  564. barMaxWidth: 20,// 设置柱状图的宽度
  565. smooth: true,
  566. showSymbol: false,
  567. data:_this.data.chargeTotaldatas,
  568. itemStyle: {
  569. color: 'rgba(60, 158, 250, 0.5)' // 设置数据点颜色为蓝色(使用十六进制表示法)
  570. },
  571. areaStyle: {
  572. color: 'rgba(60, 158, 250, 0.3)' // 设置区域填充颜色
  573. }
  574. } ]
  575. };
  576. chart.setOption(option);
  577. return chart;
  578. })}
  579. })