electricityConsumptionAnalysis.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <template>
  2. <view>
  3. <u-navbar title="能耗分析" title-color="#101010"></u-navbar>
  4. <u-select v-model="tabsFrom.show1" mode="mutil-column-auto"
  5. :default-value ="tabsFrom.show1Index" child-name="childList"
  6. :list="mainList" value-name="id" label-name="name"
  7. @columnChange="columnChange"
  8. :title="title"
  9. @confirm="selector1confirm"></u-select>
  10. <view class="background">
  11. <!-- 选择电表 -->
  12. <view class="unit">
  13. <view class="title">
  14. 选择查询设备
  15. </view>
  16. <view class="value" @click="tabsFrom.show1=true">
  17. <view class="text">
  18. {{tabsFrom.show1Text}}
  19. </view>
  20. <view class="icon">
  21. <u-icon name="arrow-down" color="#999999" size="32" ></u-icon>
  22. </view>
  23. </view>
  24. </view>
  25. <view class="main" v-show="info&&info.hourKwhList&&info.hourKwhList.length">
  26. <view class="title">
  27. <view class="icon">
  28. </view>
  29. <view class="text" v-if="meterType==0">
  30. 各时段平均用电量 (度)
  31. </view>
  32. <view class="text" v-if="meterType==1">
  33. 各时段平均用水量 (m³)
  34. </view>
  35. <view class="check-all" @click="clickbar">
  36. 查看全部<u-icon name="arrow-right" size="24" color="#838383"></u-icon>
  37. </view>
  38. </view>
  39. <view class="tips" v-if="meterType==0">
  40. <view>{{info.timeSlot}}</view>
  41. <view>日平均用电量:{{info.dayKwh}}度</view>
  42. </view>
  43. <view class="tips" v-if="meterType==1">
  44. <view>{{info.hourStartTime}} 至 {{info.hourEndTime}}</view>
  45. <view>日平均用水量:{{info.totalConsumption}}m³</view>
  46. </view>
  47. <!-- 图表 -->
  48. <view class="chart">
  49. <view id="barEcharts" style="min-height:440rpx;">
  50. </view>
  51. </view>
  52. <!-- 备注 -->
  53. <view class="remark" v-if="meterType==0">
  54. <p>备注说明:</p>
  55. 电表设备的各时段平均用电量,采集自设备上一个【不断电状态核准周期】内的每日各时段用电量平均值。以此平均用电量数据基准,作为智能停电节省电费的数据支撑。
  56. </view>
  57. <view class="remark" v-if="meterType==1">
  58. <p>备注说明:</p>
  59. 水表设备的各时段平均用水量,采集自设备上一个【数据核准周期】内的每日各时段用水量平均值。以此平均用水量数据基准,作为智能停水节水的数据支撑。
  60. </view>
  61. </view>
  62. <view class="main2" v-show="info&&!info.hourKwhList">
  63. <u-divider :isnone="true" nonetext="选择设备" style="margin-top: 20rpx;"
  64. border-color="#CFD2D5">已经到底了</u-divider>
  65. </view>
  66. <view class="main2" v-show="info&&info.hourKwhList&&info.hourKwhList.length==0">
  67. <u-divider :isnone="true" nonetext="暂无数据" style="margin-top: 20rpx;"
  68. border-color="#CFD2D5">已经到底了</u-divider>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. import * as echarts from 'echarts';
  75. import * as API_energyManage from '@/apis/pagejs/energyManage.js'
  76. import * as API_water from '@/apis/pagejs/water.js'
  77. import * as API from '@/apis/pagejs/meterTimer.js'
  78. export default {
  79. data() {
  80. return {
  81. timeShow:false,
  82. title:"",
  83. meterId :"",
  84. info:{},
  85. params: {
  86. year: true,
  87. month: true,
  88. day: false,
  89. hour: false,
  90. minute: false,
  91. second: false
  92. },
  93. tabsFrom: {
  94. show1: false,
  95. show1Index: [],
  96. show2Index: '',
  97. show2: false,
  98. show1Text: "选择设备",
  99. show2Text: "全部时间",
  100. selector1: [
  101. ]
  102. },
  103. meterType:0,//0电表1水表
  104. myChart: null,
  105. companyList:null,
  106. meterList:null,
  107. waterList:null,
  108. mainList:null,
  109. }
  110. },
  111. onLoad(op) {
  112. uni.showLoading({
  113. title: "加载中",
  114. mask: true,
  115. })
  116. this.getHaveMeterList()
  117. this.getCompanyInfoList()
  118. },
  119. methods: {
  120. columnChange(e){
  121. if(this.waterList&&this.waterList.length){
  122. this.title=e[3].label
  123. }else{
  124. this.title=e[2].label
  125. }
  126. },
  127. callback2(){
  128. var companyList=JSON.parse(JSON.stringify(this.companyList))
  129. companyList.forEach((item)=>{
  130. item.childList.forEach((info)=>{
  131. info.childList=[]
  132. })
  133. })
  134. this.waterList.forEach((meter)=>{
  135. companyList.forEach((item)=>{
  136. item.childList.forEach((info)=>{
  137. if(meter.parkId==info.id){
  138. info.childList.push(meter)
  139. }
  140. })
  141. })
  142. })
  143. this.mainList=[
  144. {
  145. id:"1",name:"电表",i:0,childList:[
  146. ...this.companyList
  147. ]
  148. },
  149. {
  150. id:"2",name:"水表",i:1,childList:[
  151. ...companyList
  152. ]
  153. }
  154. ];
  155. },
  156. callback(){
  157. if(this.companyList&&this.meterList){
  158. uni.hideLoading();
  159. }
  160. if(this.companyList.length&&this.meterList.length){
  161. this.companyList.forEach((item)=>{
  162. item.childList.forEach((info)=>{
  163. info.childList=[]
  164. })
  165. })
  166. this.meterList.forEach((meter)=>{
  167. this.companyList.forEach((item)=>{
  168. item.childList.forEach((info)=>{
  169. if(meter.parkId==info.id){
  170. info.childList.push(meter)
  171. }
  172. })
  173. })
  174. })
  175. this.mainList=[...this.companyList]
  176. this.getHaveMeterListWater()
  177. }
  178. },
  179. getCompanyInfoList() {
  180. API_energyManage.deviceCompanyList().then((response) => {
  181. //uni.hideLoading();
  182. var list = response.data.companyInfoList;
  183. this.companyList=list
  184. this.callback()
  185. }).catch(error => {
  186. uni.showToast({
  187. title: error,
  188. icon: "none"
  189. })
  190. })
  191. },
  192. getInfo2(){
  193. uni.showLoading({
  194. title: "加载中",
  195. mask: true,
  196. })
  197. API_water.meterHourConsumption({
  198. meterId:this.meterId
  199. }).then((response) => {
  200. uni.hideLoading();
  201. this.info=response.data
  202. this.info.hourKwhList=[]
  203. for(var i in this.info.hourMap){
  204. this.info.hourKwhList.push({
  205. hour:i,
  206. obj:this.info.hourMap[i]
  207. })
  208. }
  209. if(this.myChart){
  210. this.myChart.clear();
  211. }
  212. if(this.info&&this.info.hourKwhList&&this.info.hourKwhList.length){
  213. this.$nextTick(()=>{
  214. this.getBarChartsWater()
  215. })
  216. }
  217. }).catch(error => {
  218. uni.showToast({
  219. title: error,
  220. icon: "none"
  221. })
  222. })
  223. },
  224. getInfo(){
  225. uni.showLoading({
  226. title: "加载中",
  227. mask: true,
  228. })
  229. API.meterHourKwhList({
  230. meterId:this.meterId
  231. }).then((response) => {
  232. uni.hideLoading();
  233. this.info=response.data
  234. if(this.myChart){
  235. this.myChart.clear();
  236. }
  237. if(this.info&&this.info.hourKwhList&&this.info.hourKwhList.length){
  238. this.$nextTick(()=>{
  239. this.getBarCharts()
  240. })
  241. }
  242. }).catch(error => {
  243. uni.showToast({
  244. title: error,
  245. icon: "none"
  246. })
  247. })
  248. },
  249. getBarChartsWater() {
  250. if (!this.myChart) {
  251. this.myChart = echarts.init(document.getElementById('barEcharts'), null, {
  252. // width: uni.upx2px(700),
  253. height: uni.upx2px(480)
  254. });
  255. }
  256. var data1 = [];
  257. var data2 = [];
  258. var data3 = [];
  259. var data4 = [];
  260. var list=this.info.hourKwhList;
  261. for (var i in list) {
  262. var obj=list[i]
  263. data1.push(obj.hour+'时')
  264. data2.push(obj.obj.consumptionAverage)
  265. data3.push(obj.obj.workConsumptionAverage)
  266. data4.push(obj.obj.restConsumptionAverage)
  267. // sumQuantity+=list[i]
  268. }
  269. var option = {
  270. tooltip: {
  271. trigger: 'axis',
  272. axisPointer: {
  273. type: 'shadow'
  274. },
  275. },
  276. legend: {
  277. },
  278. grid: {
  279. top: 40,
  280. left: 5,
  281. right: 10,
  282. bottom: 20,
  283. containLabel: true
  284. },
  285. xAxis: {
  286. type: 'category',
  287. data: data1,
  288. axisLabel: {
  289. rotate: 40,
  290. interval: 0,
  291. textStyle: {
  292. color: "#333"
  293. },
  294. },
  295. },
  296. yAxis: {
  297. type: 'value',
  298. },
  299. series: [{
  300. name: '全部',
  301. data: data2,
  302. type: 'bar',
  303. barGap:"0%",
  304. label: {
  305. show: true,
  306. position: 'top',
  307. color: '#5C7BD9'
  308. },
  309. itemStyle: {
  310. color: '#387aea' // 设置所有柱子的颜色为'#4FE773'
  311. }
  312. },
  313. {
  314. label: {
  315. show: true,
  316. position: 'top',
  317. color: '#5C7BD9'
  318. },
  319. name: '工作日',
  320. data: data3,
  321. type: 'bar',
  322. itemStyle: {
  323. color: '#8db7f4' // 设置所有柱子的颜色为'#4FE773'
  324. }
  325. },
  326. {
  327. label: {
  328. show: true,
  329. position: 'top',
  330. color: '#5C7BD9'
  331. },
  332. name: '非工作日',
  333. data: data4,
  334. type: 'bar',
  335. itemStyle: {
  336. color: '#6a9df1' // 设置所有柱子的颜色为'#4FE773'
  337. }
  338. }
  339. ]
  340. }
  341. console.log(option)
  342. this.myChart.setOption(option);
  343. // // 监听点击事件
  344. // this.myChart.off('click',this.clickbar);
  345. // // 监听点击事件
  346. // this.myChart.on('click',this.clickbar);
  347. },
  348. clickbar() {
  349. uni.navigateTo({
  350. url:`/pages/platformRevenueStatistics/daypartingStatisticsWater?meterId=${this.meterId}&title=${this.tabsFrom.show1Text}&queryStartDate=${this.info.hourStartTime}&queryEndDate=${this.info.hourEndTime}`
  351. })
  352. },
  353. getBarCharts() {
  354. if (!this.myChart) {
  355. this.myChart = echarts.init(document.getElementById('barEcharts'), null, {
  356. // width: uni.upx2px(700),
  357. height: uni.upx2px(480)
  358. });
  359. }
  360. var data1 = [];
  361. var data2 = [];
  362. var list=this.info.hourKwhList;
  363. for (var i in list) {
  364. var obj=list[i]
  365. data1.push(obj.hour+'时')
  366. data2.push(obj.kwh)
  367. // sumQuantity+=list[i]
  368. }
  369. var option = {
  370. tooltip: {
  371. trigger: 'axis',
  372. axisPointer: {
  373. type: 'shadow'
  374. },
  375. },
  376. grid: {
  377. top: 40,
  378. left: 5,
  379. right: 10,
  380. bottom: 20,
  381. containLabel: true
  382. },
  383. xAxis: {
  384. type: 'category',
  385. data: data1,
  386. },
  387. yAxis: {
  388. type: 'value',
  389. },
  390. series: [{
  391. name: '合计',
  392. data: data2,
  393. type: 'bar',
  394. markPoint: {
  395. data: [
  396. {type: 'max', name: '最大值'},
  397. {type: 'min', name: '最小值'}
  398. // 或者使用具体的坐标(如果数据中有多个相同的最大值或最小值)
  399. // {coord: [maxIndex, maxVal], name: '最大值'},
  400. // {coord: [minIndex, minVal], name: '最小值'}
  401. ]
  402. }
  403. }]
  404. }
  405. console.log(option)
  406. this.myChart.setOption(option);
  407. },
  408. selector1confirm(e) {
  409. console.log(e)
  410. var index = [e[0].i,e[1].i,e[2].i]
  411. var eObj={}
  412. if(this.waterList&&this.waterList.length){
  413. index = [e[0].i,e[1].i,e[2].i,e[3].i]
  414. eObj=e[3]
  415. this.meterType = e[0].i
  416. }else{
  417. eObj=e[2]
  418. }
  419. if(eObj.value){
  420. this.tabsFrom.show1Text =eObj.label
  421. this.meterId = eObj.value
  422. this.tabsFrom.show1Index = index
  423. if(this.meterType==0){
  424. this.getInfo()
  425. }else{
  426. this.getInfo2()
  427. }
  428. }else{
  429. uni.showToast({
  430. title: "未选择设备",
  431. icon: "none"
  432. })
  433. }
  434. },
  435. getHaveMeterListWater(){
  436. var data = {
  437. queryForm:"property",
  438. };
  439. API_water.haveMeterList(data).then((response) => {
  440. //var MeterList=response.data.switchRecordList.data
  441. //this.meterList = response.data.remoteReadingMeterList;
  442. var meterList = response.data.waterMeterList;
  443. meterList=meterList.sort((item1,item2)=>{
  444. if(item1.sortNo==item2.sortNo){
  445. return item1.level>item2.level?1:-1
  446. }
  447. return item1.sortNo>item2.sortNo?1:-1
  448. })
  449. this.waterList=meterList
  450. this.callback2()
  451. }).catch(error => {
  452. uni.showToast({
  453. title: error,
  454. icon: "none"
  455. })
  456. })
  457. },
  458. getHaveMeterList(){
  459. var data = {
  460. queryForm:"property",
  461. };
  462. API.haveMeterList(data).then((response) => {
  463. //var MeterList=response.data.switchRecordList.data
  464. //this.meterList = response.data.remoteReadingMeterList;
  465. var meterList = response.data.remoteReadingMeterList;
  466. meterList=meterList.sort((item1,item2)=>{
  467. if(item1.sortNo==item2.sortNo){
  468. return item1.level>item2.level?1:-1
  469. }
  470. return item1.sortNo>item2.sortNo?1:-1
  471. })
  472. this.meterList=meterList
  473. this.callback()
  474. }).catch(error => {
  475. uni.showToast({
  476. title: error,
  477. icon: "none"
  478. })
  479. })
  480. },
  481. }
  482. }
  483. </script>
  484. <style>
  485. page{
  486. padding-bottom: 100px;
  487. }
  488. </style>
  489. <style lang="scss" scoped>
  490. .background {
  491. background: linear-gradient(180deg, rgba(22,119,255,1) 0%,rgba(22,119,255,0) 100%);
  492. padding: 32rpx 0;
  493. height: 720rpx;
  494. .unit {
  495. background-color: #fff;
  496. margin: 0 32rpx;
  497. border-radius: 8px;
  498. padding: 32rpx;
  499. .title {
  500. color: rgba(153, 153, 153, 1);
  501. }
  502. .value {
  503. color: rgba(51, 51, 51, 1);
  504. font-size: 40rpx;
  505. margin-top: 16rpx;
  506. display: flex;
  507. align-items: center;
  508. justify-content: space-between;
  509. font-weight: bold;
  510. }
  511. }
  512. .main2{
  513. background-color: #fff;
  514. border-radius: 8px;
  515. padding: 32rpx ;
  516. margin: 32rpx;
  517. }
  518. .main{
  519. background-color: #fff;
  520. border-radius: 8px;
  521. padding: 32rpx ;
  522. margin: 32rpx;
  523. .tips{
  524. display: flex;
  525. justify-content: space-around;
  526. color: rgba(119,119,119,1);
  527. font-size: 24rpx;
  528. }
  529. .title{
  530. display: flex;
  531. align-items: center;
  532. margin-bottom: 20px;
  533. .icon{
  534. width: 36rpx;
  535. height: 36rpx;
  536. background-color: #b6d4ff;
  537. border: 6px solid #1677ff;
  538. border-radius: 100px;
  539. }
  540. .text{
  541. color: #333333;
  542. font-size: 36rpx;
  543. margin-left: 16rpx;
  544. font-weight: bold;
  545. }
  546. .date{
  547. margin-left: auto;
  548. border: 1px solid #bbbbbb;
  549. border-radius: 4px;
  550. padding: 4px;
  551. font-size: 12px;
  552. text{
  553. margin-right: 8rpx;
  554. }
  555. }
  556. }
  557. // 图标
  558. .chart{
  559. img{
  560. width: 100%;
  561. height: 440rpx;
  562. }
  563. }
  564. }
  565. .total{
  566. color: rgba(51,51,51,1);
  567. text-align: center;
  568. font-weight: bold;
  569. }
  570. // 备注
  571. .remark {
  572. padding: 40rpx 24rpx;
  573. margin-top: 24rpx;
  574. border-radius: 8px;
  575. background-color: rgba(242, 244, 246, 1);
  576. color: rgba(16, 16, 16, 1);
  577. font-size: 24rpx;
  578. line-height: 34rpx;
  579. }
  580. }
  581. .check-all {
  582. margin-left: auto;
  583. color: rgba(131, 131, 131, 1);
  584. font-size: 24rpx;
  585. }
  586. </style>