储能智慧云小程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

index.js 11KB

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