electricityStatistics.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view>
  3. <u-navbar title="用电统计" title-color="#101010">
  4. </u-navbar>
  5. <!-- 折线图 -->
  6. <view class="chat-box">
  7. <view class="title">
  8. <view class="month">
  9. {{queryDate}}年 共用电
  10. </view>
  11. <view class="month-pick" @click="show = true">
  12. {{queryDate}}年<u-icon name="arrow-down"></u-icon>
  13. </view>
  14. </view>
  15. <view class="degree">
  16. {{sumQuantity.toFixed(2)}}<text class="unit">度</text>
  17. </view>
  18. <view class="chat">
  19. <view id="lineEcharts" style="min-height:240rpx;">
  20. </view>
  21. <!-- <image class="img" src="@/assets/img/jVzkNKE@1x.png" mode=""></image> -->
  22. </view>
  23. </view>
  24. <u-picker mode="time" :defaultTime="defaultTime" v-model="show" :params="params" @confirm="timeChange"></u-picker>
  25. <!-- 记录 -->
  26. <view class="record">
  27. <view class="total">
  28. </view>
  29. <view class="record-item" v-for="(item,index) in electricityList" :key="index"
  30. @click="toElectricityDetails(item.yue)">
  31. <view class="item-left">
  32. <view class="number">
  33. {{item.yue}}月 用电 {{item.kwh}} 度
  34. </view>
  35. <view class="date">
  36. <!-- 01-03 00:01 -->
  37. </view>
  38. </view>
  39. <view class="money">
  40. {{item.fee}}元
  41. <!-- 箭头 -->
  42. <view class="more">
  43. <u-icon name="arrow-right" color="#acacac" size="24"></u-icon>
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import * as API_electricityMeter from '@/apis/pagejs/electricityMeter.js'
  52. import * as echarts from 'echarts';
  53. export default {
  54. data() {
  55. return {
  56. show: false, // 时间选择
  57. defaultTime: '',
  58. params: {
  59. year: true,
  60. month: false,
  61. day: false,
  62. hour: false,
  63. minute: false,
  64. second: false,
  65. timestamp: false
  66. },
  67. queryDate: '',
  68. meterId: '',
  69. myLineChart: null,
  70. sumQuantity: 0,
  71. electricityList: [],
  72. graphMap: {}
  73. }
  74. },
  75. onLoad(op) {
  76. var date = new Date();
  77. var year = date.getFullYear();
  78. this.queryDate = year;
  79. if (op.id) {
  80. this.meterId = op.id;
  81. this.getElectricityConsumptionStatistics();
  82. }
  83. },
  84. methods: {
  85. getLineCharts(list) {
  86. if (!this.myLineChart) {
  87. this.myLineChart = echarts.init(document.getElementById('lineEcharts'), null, {
  88. width: uni.upx2px(700),
  89. height: uni.upx2px(240)
  90. });
  91. }
  92. this.myLineChart.clear();
  93. var data1 = [];
  94. var data2 = [];
  95. var sumQuantity = 0;
  96. var electricityList = [];
  97. for (var i in list) {
  98. var obj=list[i]
  99. obj.yue=i
  100. data1.push(i+'月');
  101. data2.push(list[i].kwh);
  102. sumQuantity += list[i].kwh;
  103. electricityList.push(obj);
  104. }
  105. this.sumQuantity = sumQuantity;
  106. this.electricityList = electricityList.reverse();
  107. var axisLabel = {
  108. rotate: 40,
  109. interval: 0,
  110. textStyle: {
  111. color: "#333"
  112. }
  113. }
  114. if (data1.length < 7) {
  115. axisLabel = {
  116. interval: 0,
  117. textStyle: {
  118. color: "#333"
  119. },
  120. }
  121. }
  122. var option = {
  123. tooltip: {
  124. trigger: 'axis',
  125. axisPointer: {
  126. type: 'shadow'
  127. }
  128. },
  129. grid: {
  130. top: '6%',
  131. left: '3%',
  132. right: '8%',
  133. bottom: '8%',
  134. containLabel: true
  135. },
  136. xAxis: {
  137. type: 'category',
  138. data: data1,
  139. axisLabel: axisLabel
  140. },
  141. yAxis: {
  142. type: 'value'
  143. },
  144. series: [{
  145. name: '电量',
  146. type: 'line',
  147. data: data2
  148. }]
  149. };
  150. this.myLineChart.setOption(option);
  151. },
  152. getElectricityConsumptionStatistics() {
  153. uni.showLoading({
  154. title: "加载中",
  155. mask: true,
  156. })
  157. API_electricityMeter.electricityConsumptionStatistics({
  158. meterId: this.meterId,
  159. queryDate: this.queryDate+'-01-01'
  160. }).then((res) => {
  161. uni.hideLoading();
  162. this.graphMap = res.data.graphMap;
  163. this.getLineCharts(this.graphMap);
  164. }).catch(error => {
  165. uni.showToast({
  166. title: error,
  167. icon: "none"
  168. })
  169. })
  170. },
  171. timeChange(params) {
  172. this.queryDate = params.year;
  173. this.getElectricityConsumptionStatistics();
  174. },
  175. toElectricityDetails(index) {
  176. //var month = index+1 >= 10 ? index+1 : '0'+(index+1);
  177. var date = this.queryDate + '-' + index;
  178. uni.navigateTo({
  179. url: '/pages/equipmentDataMonitoring/electricityDetails?id='+this.meterId+'&queryDate='+date
  180. })
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss" scoped>
  186. // 折线图
  187. .chat-box {
  188. background: linear-gradient(180deg, rgba(203, 234, 255, 1) 0%, rgba(255, 255, 255, 1) 75%);
  189. padding: 24rpx 32rpx;
  190. .title {
  191. display: flex;
  192. align-items: center;
  193. justify-content: space-between;
  194. .month {
  195. color: rgba(16, 16, 16, 1);
  196. }
  197. .month-pick {
  198. color: rgba(51, 51, 51, 1);
  199. }
  200. }
  201. .degree {
  202. color: rgb(51, 51, 51);
  203. font-size: 64rpx;
  204. .unit {
  205. color: rgb(16, 16, 16);
  206. font-size: 28rpx;
  207. margin-left: 8rpx;
  208. }
  209. }
  210. .chat {
  211. width: 100%;
  212. height: 240rpx;
  213. margin-top: 8rpx;
  214. .img {
  215. width: 100%;
  216. height: 100%;
  217. }
  218. }
  219. }
  220. // 记录
  221. .record {
  222. .total {
  223. color: rgba(119, 119, 119, 1);
  224. font-size: 32rpx;
  225. padding: 24rpx 32rpx;
  226. }
  227. .record-item {
  228. background-color: #fff;
  229. padding: 32rpx;
  230. display: flex;
  231. align-items: center;
  232. justify-content: space-between;
  233. border-bottom: 1px solid rgba(244, 244, 244, 1);
  234. .item-left {
  235. .number {
  236. color: rgba(51, 51, 51, 1);
  237. font-size: 32rpx;
  238. font-weight: bold;
  239. }
  240. .date {
  241. color: rgb(153, 153, 153);
  242. font-size: 24rpx;
  243. margin-top: 4rpx;
  244. }
  245. }
  246. .money {
  247. color: rgb(16, 16, 16);
  248. font-size: 40rpx;
  249. display: flex;
  250. align-items: center;
  251. .more {
  252. margin-left: 8rpx;
  253. }
  254. }
  255. }
  256. }
  257. </style>