electricityConsumptionAnalysis.vue 15 KB

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