储能智慧云小程序
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

index.js 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  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. filed:'month',
  63. format:'YYYY-MM'
  64. },
  65. /**
  66. * 生命周期函数--监听页面加载
  67. */
  68. onLoad(options) {
  69. console.log(options);
  70. this.setData({
  71. uuid:options.uuid
  72. })
  73. // let base64imgages =util.Background_base64('https://esos-iot.bjdexn.cn/wx_images/bj.png')
  74. this.setData({
  75. img_path:'https://esos-iot.bjdexn.cn/wx_images/bj.png',
  76. value:[new Date(util.getdataTime('7')).getTime(),new Date(util.getdataTime('当日')).getTime()],
  77. valueitem:util.getdataTime('7'),
  78. })
  79. console.log(util.getdataTime('365'));
  80. // this.ecComponent = this.selectComponent('#mychart_line1');
  81. this.ecline = this.selectComponent('#mychart_line2');
  82. this.getlineMonth()
  83. },
  84. // 返回上一级
  85. onIconTap(){
  86. wx.navigateBack({
  87. delta: 1
  88. });
  89. },
  90. onlabel(e){
  91. this.setData({
  92. labelindex:e.target.dataset.index
  93. })
  94. if (this.data.labelindex==1) {
  95. this.setData({
  96. echartstype:'bar',
  97. valueitem:util.getdataTime('7'),
  98. value:util.getdataTime('7'),
  99. format:'YYYY-MM',
  100. filed:'month',
  101. })
  102. if (this.data.tapindex==0) {
  103. this.getlineMonth();
  104. }else{
  105. this.Powertrend();
  106. }
  107. }else if(this.data.labelindex==2){
  108. this.setData({
  109. echartstype:'bar',
  110. valueitem:util.getdataTime('365'),
  111. value:util.getdataTime('365'),
  112. filed:'year',
  113. format:'YYYY'
  114. })
  115. if (this.data.tapindex==0) {
  116. this.getlineMonth();
  117. }else{
  118. this.Powertrend();
  119. }
  120. } else if(this.data.labelindex==3){
  121. this.setData({
  122. echartstype:'bar',
  123. filed:''
  124. })
  125. if (this.data.tapindex==0) {
  126. this.getlineMonth();
  127. }else{
  128. this.Powertrend();
  129. }
  130. }
  131. },
  132. handleCalendar() {
  133. this.setData({
  134. visible: true,
  135. rangetype:'range'
  136. })
  137. },
  138. // 选择时间
  139. bindclose(){
  140. this.setData({
  141. visible: false
  142. })
  143. },
  144. handleConfirm(e) {
  145. console.log(e.detail.value);
  146. this.setData({
  147. valueitem:e.detail.value,
  148. })
  149. if (this.data.tapindex==0) {
  150. this.getlineMonth();
  151. }else{
  152. this.Powertrend();
  153. }
  154. },
  155. // 电量
  156. getlineMonth(){
  157. let filed = ''
  158. if (this.data.labelindex==1) {
  159. filed = 'day'
  160. }else if(this.data.labelindex==2){
  161. filed ='Month'
  162. }else{
  163. filed ='year'
  164. this.setData({
  165. valueitem:''
  166. })
  167. }
  168. let data={
  169. page:1,
  170. rows:10000,
  171. starttime:this.data.valueitem,
  172. filed:filed,
  173. filter:'5c465aaa-b65e-463f-a9ae-a338a630a4c1_delta,469dc1cc-e5ad-492f-a350-f7bc473d55ee_delta',
  174. uuid:wx.getStorageSync('station').id
  175. }
  176. api.request(`/api/va/hisdata/hour/datas`, 'get',data )
  177. .then((res) => {
  178. let list = res.data.list;
  179. let chargeTotal ='';
  180. let dischargeTotal ='';
  181. chargeTotal = list.map(item => parseFloat(item["5c465aaa-b65e-463f-a9ae-a338a630a4c1_delta"]/1000).toFixed(2));
  182. dischargeTotal = list.map(item => parseFloat(item["469dc1cc-e5ad-492f-a350-f7bc473d55ee_delta"]/1000).toFixed(2));
  183. let ymdlist = ''
  184. if(this.data.labelindex==1){
  185. ymdlist = list.map(item => item.recordtime.slice(-2));
  186. }else{
  187. ymdlist = list.map(item => item.recordtime);
  188. }
  189. this.setData({
  190. // Electricitylevel: res.data,
  191. chargeTotal: chargeTotal,
  192. dischargeTotal: dischargeTotal,
  193. ymdlist: ymdlist,
  194. });
  195. this.initChart_right()
  196. })
  197. .catch((err) => {
  198. console.error('请求失败:', err);
  199. // 在这里处理请求失败的情况
  200. });
  201. },
  202. Powertrend(){
  203. let filed = ''
  204. if (this.data.labelindex==1) {
  205. filed = 'day'
  206. }else if(this.data.labelindex==2){
  207. filed ='Month'
  208. }else{
  209. filed ='year'
  210. this.setData({
  211. valueitem:''
  212. })
  213. }
  214. let data={
  215. page:1,
  216. rows:10000,
  217. starttime:this.data.valueitem,
  218. filed:filed,
  219. filter:'a0acf8cf-7d12-49af-97d9-1a2e630c4bfe_delta',
  220. uuid:wx.getStorageSync('station').id
  221. }
  222. api.request(`/api/va/hisdata/hour/datas`, 'get',data)
  223. .then((res) => {
  224. let list = res.data.list;
  225. console.log(list);
  226. let chargeTotal = ''
  227. chargeTotal = list.map(item =>
  228. parseFloat(item["a0acf8cf-7d12-49af-97d9-1a2e630c4bfe_delta"]/1000).toFixed(2)
  229. );
  230. // let dischargeTotal = list.storedPower.map(item => item.totalActivePower);
  231. let ymdlist = ''
  232. if(this.data.labelindex==1){
  233. ymdlist = list.map(item => item.recordtime.slice(-2));
  234. }else{
  235. ymdlist = list.map(item => item.recordtime);
  236. }
  237. this.setData({
  238. // Electricitylevel: res.data,
  239. chargeTotal: chargeTotal,
  240. // dischargeTotal: dischargeTotal,
  241. ymdlist: ymdlist,
  242. });
  243. this.initChart_right()
  244. })
  245. .catch((err) => {
  246. console.error('请求失败:', err);
  247. // 在这里处理请求失败的情况
  248. });
  249. },
  250. // 切换标签
  251. onTabsChange(event) {
  252. this.setData({
  253. tapindex:event.detail.value,
  254. // labelindex:1,
  255. // filed:'month',
  256. // format:'YYYY-MM',
  257. // valueitem:util.getdataTime('7'),
  258. // value:util.getdataTime('7'),
  259. })
  260. if (this.data.tapindex==0) {
  261. this.getlineMonth();
  262. }else{
  263. this.Powertrend();
  264. }
  265. },
  266. /**
  267. * 生命周期函数--监听页面初次渲染完成
  268. */
  269. onReady() {
  270. },
  271. /**
  272. * 生命周期函数--监听页面显示
  273. */
  274. onShow() {
  275. },
  276. /**
  277. * 生命周期函数--监听页面隐藏
  278. */
  279. onHide() {
  280. },
  281. /**
  282. * 生命周期函数--监听页面卸载
  283. */
  284. onUnload() {
  285. },
  286. /**
  287. * 页面相关事件处理函数--监听用户下拉动作
  288. */
  289. onPullDownRefresh() {
  290. },
  291. /**
  292. * 页面上拉触底事件的处理函数
  293. */
  294. onReachBottom() {
  295. },
  296. /**
  297. * 用户点击右上角分享
  298. */
  299. onShareAppMessage() {
  300. },
  301. initChart_right: function () {
  302. var unitName = '';
  303. if (this.data.tapindex==0) {
  304. if (this.data.labelindex==1) {
  305. unitName = '电量(MWh/日)'
  306. } else if(this.data.labelindex==2) {
  307. unitName = '电量(MWh/月)'
  308. }else{
  309. unitName = '电量(MWh/年)'
  310. }
  311. }else if(this.data.tapindex==1){
  312. if (this.data.labelindex==1) {
  313. unitName = '收益(千元/日)';
  314. }else if(this.data.labelindex==2){
  315. unitName = '收益(千元/月)';
  316. }else{
  317. unitName = '收益(千元/年)';
  318. }
  319. }
  320. let _this = this;
  321. this.ecline.init((canvas, width, height, dpr) => {
  322. const chart = echarts.init(canvas, null, {
  323. width: width,
  324. height: height,
  325. devicePixelRatio: dpr
  326. });
  327. canvas.setChart(chart);
  328. var option = {
  329. title: {
  330. subtext: unitName,
  331. textStyle: {
  332. color: 'rgba(0, 0, 0, 0)',
  333. }
  334. },
  335. grid: {
  336. left: '1%',
  337. top: '14%',
  338. right: '1%',
  339. bottom: '20%',
  340. containLabel: true
  341. },
  342. xAxis: {
  343. type: 'category',
  344. data: _this.data.ymdlist,
  345. axisTick: {
  346. show: false
  347. },
  348. barWidth: 20,
  349. axisLabel: {
  350. interval: 0 // 设置为0以显示所有坐标点
  351. },
  352. },
  353. yAxis: {
  354. // name: unitName,
  355. x: 'center',
  356. type: 'value',
  357. axisTick: {
  358. show: false
  359. },
  360. splitLine: {
  361. show: false
  362. }
  363. },
  364. dataZoom: {
  365. type: 'inside',
  366. start: 0,
  367. end: 50
  368. },
  369. // dataZoom: {
  370. // type: 'slider',
  371. // start: 0,
  372. // end: 50,
  373. // handleSize:0,
  374. // show:false
  375. // },
  376. series: [{
  377. type:"bar",
  378. barMaxWidth: 20,
  379. smooth: true,
  380. label: {
  381. show: true,
  382. position: 'top',
  383. color:'#222'
  384. },
  385. showSymbol: false,
  386. data: _this.data.chargeTotal,
  387. itemStyle: {
  388. color: 'rgba(60, 158, 250, 1)',
  389. barBorderRadius: [4, 4, 0, 0] // 设置柱状图的圆角半径为5
  390. },
  391. areaStyle: {
  392. color: 'rgba(60, 158, 250, 1)',
  393. }
  394. }
  395. // ,{
  396. // name: viewname[1],
  397. // type: _this.data.echartstype,
  398. // smooth: true,
  399. // showSymbol: false,
  400. // barMaxWidth: 20,
  401. // data: _this.data.dischargeTotal,
  402. // itemStyle: {
  403. // color: 'rgba(77, 240, 150, 1)',
  404. // barBorderRadius: [5, 5, 0, 0]
  405. // },
  406. // areaStyle: {
  407. // color: 'rgba(77, 240, 150, 1)',
  408. // }
  409. // }
  410. ]
  411. };
  412. chart.setOption(option);
  413. return chart;
  414. })
  415. },
  416. })