electronicMonitoring.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. <template>
  2. <view>
  3. <view class="background">
  4. <u-picker v-model="tabsFrom.show1" mode="selector" :range="tabsFrom.selector1" range-key="label" @confirm="selector1confirm" ></u-picker>
  5. <u-picker-select title="日期选择" v-model="tabsFrom.show2"
  6. :defaultTime="tabsFrom.show2Index" :endYear="endYear"
  7. mode="time" :params="params" :noselect="false" @confirm="selector2confirm" @reset="selector2reset" ></u-picker-select>
  8. <u-navbar :background="background"
  9. @titleCk="titleCk" :title-icon="electricityMeterList.length>1?'arrow-down':''"
  10. back-icon-color="#fff" :title="title" title-color="#fff">
  11. <view class="u-nav-slot" slot="right" @click="tabsFrom.show2=true,params.day=true">
  12. <image class="img" src="@/assets/img/riLine-calendar-todo-line 1.svg" mode=""></image>
  13. </view>
  14. </u-navbar>
  15. <!-- 日期 -->
  16. <view class="date-box">
  17. <view class="item" v-for="(item,i) in topDate"
  18. :class="{
  19. 'item-today':item.queryDate==FormData.queryDate
  20. }"
  21. @click="queryDate(item.queryDate,true)"
  22. :key="i">
  23. <view class="date">
  24. {{item.num}}
  25. </view>
  26. <view class="week">
  27. {{item.week}}
  28. </view>
  29. <view class="dot" v-if="item.today==0">
  30. </view>
  31. </view>
  32. <view class="item item-today" v-if="0">
  33. <view class="date">
  34. 26
  35. </view>
  36. <view class="week ">
  37. 今天
  38. </view>
  39. <view class="dot">
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <!-- 用电量 -->
  45. <view class="electricity-consumption">
  46. <view class="title">
  47. 用电量统计(kW·h)
  48. </view>
  49. <view class="degree">
  50. <view class="item">
  51. <view class="item-text">
  52. 百万
  53. </view>
  54. <view class="item-number" v-text="showTop[0]">
  55. 0
  56. </view>
  57. </view>
  58. <view class="item">
  59. <view class="item-text">
  60. 拾万
  61. </view>
  62. <view class="item-number" v-text="showTop[1]" >
  63. 0
  64. </view>
  65. </view>
  66. <view class="item">
  67. <view class="item-text">
  68. </view>
  69. <view class="item-number" v-text="showTop[2]">
  70. 0
  71. </view>
  72. </view>
  73. <view class="item">
  74. <view class="item-text">
  75. </view>
  76. <view class="item-number" v-text="showTop[3]">
  77. 0
  78. </view>
  79. </view>
  80. <view class="item">
  81. <view class="item-text">
  82. </view>
  83. <view class="item-number" v-text="showTop[4]">
  84. 0
  85. </view>
  86. </view>
  87. <view class="item">
  88. <view class="item-text">
  89. </view>
  90. <view class="item-number" v-text="showTop[5]">
  91. 7
  92. </view>
  93. </view>
  94. <view class="item">
  95. <view class="item-text">
  96. 1
  97. </view>
  98. <view class="item-number" v-text="showTop[6]">
  99. 7
  100. </view>
  101. </view>
  102. <view class="item">
  103. <view class="item-text">
  104. 0.1
  105. </view>
  106. <view class="item-number decimal" v-text="showTop[7]">
  107. 7
  108. </view>
  109. </view>
  110. </view>
  111. <view class="radio">
  112. <u-radio-group v-model="value" @change="radioGroupChange">
  113. <u-radio @change="radioChange" v-for="(item, index) in list" :key="index" :name="item.id"
  114. :disabled="item.disabled">
  115. {{item.name}}
  116. </u-radio>
  117. </u-radio-group>
  118. </view>
  119. </view>
  120. <!-- 各时段用电量 -->
  121. <view class="electricity-chart">
  122. <view class="title">
  123. <view class="icon">
  124. </view>
  125. <view class="text">
  126. 各时段用电量 (度)
  127. </view>
  128. </view>
  129. <view class="chart">
  130. <view id="pieEcharts" style="min-height:240px;">
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. </template>
  136. <script>
  137. import {
  138. parseUnixTime,
  139. beforeTimeStamp,
  140. getWeek
  141. } from '@/apis/utils'
  142. import * as API from '@/apis/pagejs/tenantElectricityMeter.js'
  143. import * as echarts from "echarts";
  144. export default {
  145. data() {
  146. return {
  147. title:"查询中",
  148. myChart:null,
  149. showTop: [0, 0, 0, 0, 0, 0, 0, 0],
  150. topDate:[],
  151. electricityMeterList:[],
  152. FormData:{
  153. },
  154. endYear:'',
  155. params: {
  156. year: true,
  157. month: true,
  158. day: true,
  159. hour: false,
  160. minute: false,
  161. second: false
  162. },
  163. tabsFrom: {
  164. show1: false,
  165. show1Index:0,
  166. show2Index:'',
  167. show2: false,
  168. show1Text: "全部类型",
  169. show2Text: "全部时间",
  170. selector1:[
  171. {
  172. label: '全部类型',
  173. value: '',
  174. },
  175. {
  176. label: '线上充值',
  177. value: '1',
  178. },
  179. {
  180. label: '线下充值',
  181. value: '2',
  182. },
  183. ]
  184. },
  185. background: {
  186. backgroundColor: '#1677FF',
  187. },
  188. list: [{
  189. id:0,
  190. name: '总用电量',
  191. disabled: false
  192. },
  193. {
  194. id:1,
  195. name: '当日用电量',
  196. disabled: false
  197. },
  198. {
  199. id:2,
  200. name: '当月用电量',
  201. disabled: false
  202. }, {
  203. id:3,
  204. name: '当年用电量',
  205. disabled: false
  206. }, {
  207. id:4,
  208. name: '去年用电量',
  209. disabled: false
  210. }, {
  211. id:10,
  212. name: '指定月份',
  213. disabled: false
  214. }
  215. ],
  216. // u-radio-group的v-model绑定的值如果设置为某个radio的name,就会被默认选中
  217. value: '0',
  218. };
  219. },
  220. onLoad() {
  221. this.endYear=new Date().getFullYear()
  222. this.getElectricityMeterList();
  223. this.FormData.queryDate=parseUnixTime(new Date(), '{y}-{m}-{d}')
  224. this.FormData.type=0
  225. for(var i =4;i>=0;i--){
  226. var time=new Date(beforeTimeStamp(i,new Date()));
  227. this.topDate.push({
  228. num:time.getDate(),
  229. week:i==0?'今日':getWeek(time),
  230. today:i,
  231. queryDate:parseUnixTime(time, '{y}-{m}-{d}')
  232. })
  233. }
  234. console.log( this.topDate)
  235. },
  236. methods: {
  237. titleCk(){
  238. if(this.electricityMeterList.length>1){
  239. this.tabsFrom.show1=true
  240. }
  241. },
  242. selector1confirm(e){
  243. var index=e[0]
  244. this.tabsFrom.show1Index=index
  245. this.tabsFrom.show1Text=this.tabsFrom.selector1[index].label
  246. this.tabsFrom.title=this.tabsFrom.selector1[index].label
  247. this.FormData.meterId=this.tabsFrom.selector1[index].value
  248. this.FormData.queryDate=parseUnixTime(new Date(), '{y}-{m}-{d}')
  249. this.value="0"
  250. this.FormData.type=0
  251. this.getTimeSlotStatistics()
  252. this.getElectricityStatistics()
  253. },
  254. queryDate(queryTime,day){
  255. this.FormData.queryDate=queryTime;
  256. this.FormData.type =day?"9":"10"
  257. this.value="-1"
  258. if(day){
  259. this.getTimeSlotStatistics()
  260. }
  261. this.getElectricityStatistics()
  262. },
  263. getElectricityStatistics(){
  264. uni.showLoading({
  265. title: "加载中",
  266. mask: true,
  267. })
  268. var obj={
  269. ...this.FormData
  270. }
  271. if(obj.type==10){
  272. obj.queryDate+="-01"
  273. }
  274. API.electricityStatistics(obj).then((response) => {
  275. uni.hideLoading();
  276. this.showTop = [0, 0, 0, 0, 0, 0, 0, 0]
  277. var electricity = response.data.kwhMap.kwh;
  278. if (electricity) {
  279. var sz = electricity.split(".")
  280. var str1 = sz[0];
  281. var str2 = [];
  282. if (sz.length > 1) {
  283. str2 = sz[1];
  284. this.showTop[7] = str2[0];
  285. }
  286. var j = 0;
  287. for (var i in str1) {
  288. if (i != undefined) {
  289. this.showTop[6 - str1.length + j + 1] = str1[i]
  290. }
  291. j++;
  292. }
  293. this.$forceUpdate()
  294. }
  295. //this.electricityMeterList=response.data.meterList
  296. }).catch(error => {
  297. uni.showToast({
  298. title: error,
  299. icon: "none"
  300. })
  301. })
  302. },
  303. getTimeSlotStatistics(){
  304. uni.showLoading({
  305. title: "加载中",
  306. mask: true,
  307. })
  308. API.timeSlotStatistics(this.FormData).then((response) => {
  309. uni.hideLoading();
  310. this.hourMap=response.data.hourMap
  311. this.getPle(this.hourMap)
  312. }).catch(error => {
  313. uni.showToast({
  314. title: error,
  315. icon: "none"
  316. })
  317. })
  318. },
  319. getPle(list){
  320. // list={
  321. // "0-2点": 200,
  322. // "2-4点": 1210,
  323. // "4-6点": 2310,
  324. // "6-8点": 20,
  325. // "8-10点": 230,
  326. // "10-12点": 30,
  327. // "12-14点": 440,
  328. // "14-16点": 120,
  329. // "16-18点": 230,
  330. // "18-20点": 20,
  331. // "20-22点": 20,
  332. // "22-24点": 10
  333. // }
  334. if (!this.myChart) {
  335. this.myChart = echarts.init(document.getElementById('pieEcharts'),null,{
  336. width:uni.upx2px(700),height:uni.upx2px(480)
  337. });
  338. }
  339. this.myChart.clear();
  340. var data1=[];
  341. var data2=[];
  342. for(var i in list){
  343. data1.push(i)
  344. data2.push(list[i])
  345. }
  346. var headitemby=""
  347. var showkey = "";
  348. var option = {
  349. tooltip: {
  350. trigger: 'axis'
  351. },
  352. grid: {
  353. top: '6%',
  354. left: '3%',
  355. right: '8%',
  356. bottom: '8%',
  357. containLabel: true
  358. },
  359. xAxis: {
  360. type: 'category',
  361. data: data1,
  362. axisLabel: {
  363. rotate:40,
  364. interval:0,
  365. textStyle: {
  366. color: "#333"
  367. }
  368. },
  369. },
  370. yAxis: {
  371. type: 'value',
  372. },
  373. series: [
  374. {
  375. name: '合计',
  376. data: data2,
  377. type: 'bar'
  378. }
  379. ]
  380. }
  381. console.log(option)
  382. this.myChart.setOption(option);
  383. },
  384. getElectricityMeterList(){
  385. uni.showLoading({
  386. title: "加载中",
  387. mask: true,
  388. })
  389. API.electricityMeterList().then((response) => {
  390. uni.hideLoading();
  391. this.electricityMeterList=response.data.meterList
  392. if(this.electricityMeterList.length){
  393. this.FormData.meterId=this.electricityMeterList[0].id
  394. this.title=this.electricityMeterList[0].name
  395. // {
  396. // label: '全部类型',
  397. // value: '',
  398. // }
  399. this.tabsFrom.selector1=[]
  400. this.tabsFrom.selector1=this.electricityMeterList.map(item=>{
  401. return {
  402. label:item.name,
  403. value:item.id
  404. }
  405. })
  406. this.getTimeSlotStatistics()
  407. this.getElectricityStatistics()
  408. }else{
  409. uni.showModal({
  410. title:"提示",
  411. content:"未绑定电表,请联系管理员!",
  412. showCancel:false,
  413. success() {
  414. uni.navigateBack()
  415. }
  416. })
  417. }
  418. }).catch(error => {
  419. uni.showToast({
  420. title: error,
  421. icon: "none"
  422. })
  423. })
  424. },
  425. selector2confirm(e){
  426. this.tabsFrom.show2Text=e.year+"年"+e.month+"月"
  427. this.tabsFrom.show2Index=e.year+"-"+e.month
  428. if(e.day){
  429. this.tabsFrom.show2Text+=e.day+"日"
  430. this.tabsFrom.show2Index+='-'+e.day
  431. this.queryDate(this.tabsFrom.show2Index,true)
  432. }else{
  433. this.queryDate(this.tabsFrom.show2Index,false)
  434. }
  435. },
  436. selector2reset(e){
  437. console.log(e)
  438. this.tabsFrom.show2Text='全部时间'
  439. this.tabsFrom.show2Index='';
  440. },
  441. // 选中某个单选框时,由radio时触发
  442. radioChange(e) {
  443. //console.log(e);
  444. },
  445. // 选中任一radio时,由radio-group触发
  446. radioGroupChange(e) {
  447. console.log(e);
  448. this.FormData.type=e
  449. if(e==10){
  450. this.tabsFrom.show2=true
  451. this.params.day=false
  452. }else{
  453. this.getElectricityStatistics()
  454. }
  455. }
  456. }
  457. };
  458. </script>
  459. <style lang="scss" scoped>
  460. page {
  461. padding-bottom: 100rpx;
  462. }
  463. .background {
  464. background-color: rgba(22, 119, 255, 1);
  465. padding-bottom: 100rpx;
  466. /deep/.u-border-bottom:after {
  467. border: none;
  468. }
  469. .u-nav-slot {
  470. margin-right: 32rpx;
  471. .img {
  472. width: 48rpx;
  473. height: 48rpx;
  474. vertical-align: middle;
  475. }
  476. }
  477. }
  478. .background::after {
  479. content: '';
  480. position: absolute;
  481. width: 160%;
  482. height: 80px;
  483. background-color: rgba(22, 119, 255, 1);
  484. left: -30%;
  485. border-radius: 0 0 50% 50%;
  486. }
  487. // // 日期
  488. .date-box {
  489. display: flex;
  490. align-items: center;
  491. justify-content: space-between;
  492. margin: 24rpx 32rpx;
  493. .item {
  494. border-radius: 8px;
  495. background-color: rgba(255, 255, 255, 0.1);
  496. border: 1px solid rgba(255, 255, 255, 0.15);
  497. width: 120rpx;
  498. height: 120rpx;
  499. color: #fff;
  500. text-align: center;
  501. display: flex;
  502. flex-direction: column;
  503. justify-content: center;
  504. align-items: center;
  505. .date {
  506. font-size: 40rpx;
  507. }
  508. .dot{
  509. width: 10rpx;
  510. height: 10rpx;
  511. background-color: rgba(255,150,0,1);
  512. border-radius: 999px;
  513. bottom: -5rpx;
  514. left: 50%;
  515. transform: translateX(-50%);
  516. }
  517. }
  518. .item-today {
  519. background-color: rgba(255, 255, 255, 1);
  520. position: relative;
  521. .date {
  522. color: rgba(22, 119, 255, 1);
  523. }
  524. .week {
  525. color: rgba(16, 16, 16, 1);
  526. }
  527. }
  528. }
  529. // 用电量
  530. .electricity-consumption {
  531. background-color: #fff;
  532. padding: 40rpx 32rpx 0rpx;
  533. border-radius: 8px;
  534. margin: -88rpx 32rpx 0;
  535. position: relative;
  536. .title{
  537. color: rgba(16,16,16,1);
  538. font-size: 36rpx;
  539. }
  540. .degree{
  541. display: flex;
  542. margin-top: 32rpx;
  543. .item{
  544. margin-right: 6rpx;
  545. text-align: center;
  546. .item-text{
  547. color: rgba(16,16,16,1);
  548. }
  549. .item-number{
  550. margin-top: 24rpx;
  551. width: 72rpx;
  552. height: 96rpx;
  553. background-color: rgba(16,16,16,1);
  554. color: #fff;
  555. font-size: 72rpx;
  556. }
  557. .decimal{
  558. background-color: #900005;
  559. }
  560. }
  561. }
  562. // .tab {
  563. // width: 240rpx;
  564. // height: 0;
  565. // border-width: 0px 48rpx 72rpx 0px;
  566. // border-radius: 8px 8px 0 0;
  567. // border-style: none solid solid none;
  568. // border-color: transparent transparent #fff;
  569. // position: absolute;
  570. // top: -72rpx;
  571. // left: 0rpx;
  572. // right: 0rpx;
  573. // color: #101010;
  574. // color: rgba(16, 16, 16, 1);
  575. // text-align: center;
  576. // line-height: 72rpx;
  577. // z-index: 999;
  578. // text-indent: 16rpx;
  579. // }
  580. // .tab2 {
  581. // width: 240rpx;
  582. // height: 0;
  583. // border-width: 0px 48rpx 72rpx 0px;
  584. // border-radius: 8px 8px 0 0;
  585. // border-style: none solid solid none;
  586. // border-color: transparent transparent #D4DBE4;
  587. // position: absolute;
  588. // top: -72rpx;
  589. // left: 210rpx;
  590. // right: 0rpx;
  591. // color: #777777;
  592. // text-align: center;
  593. // line-height: 72rpx;
  594. // text-indent: 16rpx;
  595. // }
  596. .radio {
  597. margin-top: 24rpx;
  598. /deep/.u-radio__label {
  599. font-size: 24rpx
  600. }
  601. /deep/.u-radio {
  602. margin-bottom: 16px;
  603. width: 200rpx !important;
  604. }
  605. }
  606. }
  607. //各时段用电量
  608. .electricity-chart {
  609. margin: 24rpx 32rpx;
  610. padding: 40rpx 0rpx;
  611. background-color: #fff;
  612. border-radius: 8px;
  613. .title {
  614. display: flex;
  615. align-items: center;
  616. padding: 0 32rpx;
  617. margin-bottom: 40rpx;
  618. .icon {
  619. width: 36rpx;
  620. height: 36rpx;
  621. background-color: rgba(22, 119, 255, 1);
  622. border: 6px solid rgba(182, 212, 255, 1);
  623. border-radius: 100px;
  624. }
  625. .text {
  626. color: rgba(51, 51, 51, 1);
  627. font-size: 36rpx;
  628. margin-left: 16rpx;
  629. }
  630. }
  631. .chart {
  632. width: 100%;
  633. height: 440rpx;
  634. .img {
  635. width: 100%;
  636. height: 440rpx;
  637. }
  638. }
  639. }
  640. // 异常
  641. .abnormal {
  642. margin: 24rpx 32rpx;
  643. padding: 40rpx 32rpx;
  644. background-color: #fff;
  645. border-radius: 8px;
  646. .headline {
  647. display: flex;
  648. align-items: center;
  649. justify-content: space-between;
  650. }
  651. .title {
  652. display: flex;
  653. align-items: center;
  654. .icon {
  655. width: 36rpx;
  656. height: 36rpx;
  657. background-color: rgba(22, 119, 255, 1);
  658. border: 6px solid rgba(182, 212, 255, 1);
  659. border-radius: 100px;
  660. }
  661. .text {
  662. color: rgba(51, 51, 51, 1);
  663. font-size: 36rpx;
  664. margin-left: 16rpx;
  665. }
  666. }
  667. .more {
  668. color: #838383;
  669. font-size: 24rpx
  670. }
  671. .details {
  672. margin-top: 40rpx;
  673. .item {
  674. display: flex;
  675. align-items: center;
  676. justify-content: space-between;
  677. margin-top: 32rpx;
  678. .name {
  679. color: rgba(51, 51, 51, 1);
  680. }
  681. .time {
  682. color: rgba(119, 119, 119, 1);
  683. font-size: 24rpx;
  684. }
  685. }
  686. }
  687. }
  688. // 能源监测
  689. .energy-inspection,.data-analysis {
  690. margin: 24rpx 32rpx;
  691. padding: 40rpx 32rpx;
  692. background-color: #fff;
  693. border-radius: 8px;
  694. .title {
  695. display: flex;
  696. align-items: center;
  697. .icon {
  698. width: 36rpx;
  699. height: 36rpx;
  700. background-color: rgba(22, 119, 255, 1);
  701. border: 6px solid rgba(182, 212, 255, 1);
  702. border-radius: 100px;
  703. }
  704. .text {
  705. color: rgba(51, 51, 51, 1);
  706. font-size: 36rpx;
  707. margin-left: 16rpx;
  708. }
  709. }
  710. .grid {
  711. .icon {
  712. width: 128rpx;
  713. height: 128rpx;
  714. border-radius: 12px;
  715. background-color: rgba(35, 186, 178, 1);
  716. display: flex;
  717. align-items: center;
  718. justify-content: center;
  719. margin-bottom: 16rpx;
  720. .img {
  721. width: 80rpx;
  722. height: 80rpx;
  723. }
  724. }
  725. .icon2{
  726. background-color: rgba(42,186,72,1);
  727. }
  728. .icon3{
  729. background-color: rgba(78,96,246,1);
  730. }
  731. .icon4{
  732. background-color: rgba(22,119,255,1);
  733. }
  734. .icon5{
  735. background-color: rgba(35,186,178,1);
  736. }
  737. .icon6{
  738. background-color: rgba(42,186,72,1);
  739. }
  740. .icon7{
  741. background-color: rgba(22,119,255,1);
  742. }
  743. .icon8{
  744. background-color: rgba(35,186,178,1);
  745. }
  746. .grid-text {
  747. color: #333333;
  748. }
  749. }
  750. }
  751. </style>