electricityStatistics.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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}}<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(index)">
  31. <view class="item-left">
  32. <view class="number">
  33. {{index+1}}月 用电 {{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. data1.push(i+'月');
  99. data2.push(list[i].kwh);
  100. sumQuantity += list[i].kwh;
  101. electricityList.push(list[i]);
  102. }
  103. this.sumQuantity = sumQuantity;
  104. this.electricityList = electricityList;
  105. var axisLabel = {
  106. rotate: 40,
  107. interval: 0,
  108. textStyle: {
  109. color: "#333"
  110. }
  111. }
  112. if (data1.length < 7) {
  113. axisLabel = {
  114. interval: 0,
  115. textStyle: {
  116. color: "#333"
  117. },
  118. }
  119. }
  120. var option = {
  121. tooltip: {
  122. trigger: 'axis',
  123. axisPointer: {
  124. type: 'shadow'
  125. }
  126. },
  127. grid: {
  128. top: '6%',
  129. left: '3%',
  130. right: '8%',
  131. bottom: '8%',
  132. containLabel: true
  133. },
  134. xAxis: {
  135. type: 'category',
  136. data: data1,
  137. axisLabel: axisLabel
  138. },
  139. yAxis: {
  140. type: 'value'
  141. },
  142. series: [{
  143. name: '电量',
  144. type: 'line',
  145. data: data2
  146. }]
  147. };
  148. this.myLineChart.setOption(option);
  149. },
  150. getElectricityConsumptionStatistics() {
  151. uni.showLoading({
  152. title: "加载中",
  153. mask: true,
  154. })
  155. API_electricityMeter.electricityConsumptionStatistics({
  156. meterId: this.meterId,
  157. queryDate: this.queryDate+'-01-01'
  158. }).then((res) => {
  159. uni.hideLoading();
  160. this.graphMap = res.data.graphMap;
  161. this.getLineCharts(this.graphMap);
  162. }).catch(error => {
  163. uni.showToast({
  164. title: error,
  165. icon: "none"
  166. })
  167. })
  168. },
  169. timeChange(params) {
  170. this.queryDate = params.year;
  171. this.getElectricityConsumptionStatistics();
  172. },
  173. toElectricityDetails(index) {
  174. var month = index+1 >= 10 ? index+1 : '0'+(index+1);
  175. var date = this.queryDate + '-' + month;
  176. uni.navigateTo({
  177. url: '/pages/equipmentDataMonitoring/electricityDetails?id='+this.meterId+'&queryDate='+date
  178. })
  179. }
  180. }
  181. }
  182. </script>
  183. <style lang="scss" scoped>
  184. // 折线图
  185. .chat-box {
  186. background: linear-gradient(180deg, rgba(203, 234, 255, 1) 0%, rgba(255, 255, 255, 1) 75%);
  187. padding: 24rpx 32rpx;
  188. .title {
  189. display: flex;
  190. align-items: center;
  191. justify-content: space-between;
  192. .month {
  193. color: rgba(16, 16, 16, 1);
  194. }
  195. .month-pick {
  196. color: rgba(51, 51, 51, 1);
  197. }
  198. }
  199. .degree {
  200. color: rgb(51, 51, 51);
  201. font-size: 64rpx;
  202. .unit {
  203. color: rgb(16, 16, 16);
  204. font-size: 28rpx;
  205. margin-left: 8rpx;
  206. }
  207. }
  208. .chat {
  209. width: 100%;
  210. height: 240rpx;
  211. margin-top: 8rpx;
  212. .img {
  213. width: 100%;
  214. height: 100%;
  215. }
  216. }
  217. }
  218. // 记录
  219. .record {
  220. .total {
  221. color: rgba(119, 119, 119, 1);
  222. font-size: 32rpx;
  223. padding: 24rpx 32rpx;
  224. }
  225. .record-item {
  226. background-color: #fff;
  227. padding: 32rpx;
  228. display: flex;
  229. align-items: center;
  230. justify-content: space-between;
  231. border-bottom: 1px solid rgba(244, 244, 244, 1);
  232. .item-left {
  233. .number {
  234. color: rgba(51, 51, 51, 1);
  235. font-size: 32rpx;
  236. font-weight: bold;
  237. }
  238. .date {
  239. color: rgb(153, 153, 153);
  240. font-size: 24rpx;
  241. margin-top: 4rpx;
  242. }
  243. }
  244. .money {
  245. color: rgb(16, 16, 16);
  246. font-size: 40rpx;
  247. display: flex;
  248. align-items: center;
  249. .more {
  250. margin-left: 8rpx;
  251. }
  252. }
  253. }
  254. }
  255. </style>