chartMoM.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <view>
  3. <u-navbar :title="title" title-color="#101010">
  4. </u-navbar>
  5. <u-picker-select :noselect="false" @confirm="selector2confirm" @reset="selector2reset" :defaultTime="queryDate"
  6. title="日期选择" v-model="show" mode="time" :params="params"></u-picker-select>
  7. <view class="main">
  8. <view class="title">
  9. <view class="text">
  10. <view class="icon">
  11. </view>
  12. <span>
  13. 环比分析-每月用电量(kW·h)
  14. </span>
  15. </view>
  16. </view>
  17. <view class="chat">
  18. <view id="barEcharts1" style="min-height:440rpx;">
  19. </view>
  20. </view>
  21. <view v-html="description">
  22. </view>
  23. </view>
  24. <view class="main">
  25. <view class="title">
  26. <view class="text">
  27. <view class="icon">
  28. </view>
  29. <span>
  30. 环比分析-每小时用电量(kW·h)
  31. </span>
  32. </view>
  33. <view class="text1" @click="show=true">
  34. {{queryDate==nowDate?'今日':queryDateStr}}<u-icon name="arrow-down"></u-icon>
  35. </view>
  36. </view>
  37. <view class="chat">
  38. <view id="barEcharts2" style="min-height:440rpx;">
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import * as API from '@/apis/pagejs/electricityMeter.js'
  46. import * as echarts from 'echarts';
  47. import {
  48. unixTimeStamp,
  49. currentTimeStamp,
  50. parseUnixTime,
  51. beforeTimeStamp
  52. } from '@/apis/utils'
  53. export default {
  54. data() {
  55. return {
  56. params: {
  57. year: true,
  58. month: true,
  59. day: true,
  60. hour: false,
  61. minute: false,
  62. second: false
  63. },
  64. show: false,
  65. meterNo: '',
  66. type: '',
  67. typeName: '',
  68. nowDate: "",
  69. queryDate: "",
  70. queryDateStr: "",
  71. showlist1: [],
  72. graphMap: {},
  73. graphMap2: {},
  74. description: "",
  75. timeList1: [],
  76. timeList2: [],
  77. nowYear: '',
  78. title:"",
  79. }
  80. },
  81. onLoad(op) {
  82. this.meterNo = op.id
  83. //this.type=op.type
  84. //this.typeName=op.typeName
  85. this.title=op.title
  86. this.nowDate = parseUnixTime(currentTimeStamp(), '{y}-{m}-{d}');
  87. this.queryDate = parseUnixTime(beforeTimeStamp(0), '{y}-{m}-{d}');
  88. this.queryDateStr = parseUnixTime(new Date(this.queryDate), '{y}年{m}月{d}日');
  89. this.nowYear = new Date().getFullYear()
  90. //this.showlist1 = [];
  91. this.electricityMonthTB()
  92. this.electricityHourByYear()
  93. },
  94. methods: {
  95. selector2reset(e){
  96. this.queryDate = parseUnixTime(beforeTimeStamp(0), '{y}-{m}-{d}');
  97. this.queryDateStr = parseUnixTime(new Date(this.queryDate), '{y}年{m}月{d}日');
  98. this.electricityHourByYear()
  99. },
  100. selector2confirm(e){
  101. this.queryDate=e.year+"-"+e.month+'-'+e.day
  102. this.queryDateStr = parseUnixTime(new Date(this.queryDate), '{y}年{m}月{d}日');
  103. this.electricityHourByYear()
  104. },
  105. electricityMonthTB() {
  106. uni.showLoading({
  107. title: "加载中",
  108. mask: true,
  109. })
  110. API.electricityMonthHB({
  111. queryDate: this.queryDate,
  112. meterId: this.meterNo,
  113. }).then(response => {
  114. uni.hideLoading();
  115. this.description = response.data.description;
  116. console.log(this.description)
  117. this.graphMap = response.data.graphMap
  118. this.setMap1();
  119. }).catch(error => {
  120. uni.hideLoading();
  121. uni.showToast({
  122. title: error,
  123. icon: "none"
  124. })
  125. })
  126. },
  127. electricityHourByYear() {
  128. var time1=parseUnixTime(unixTimeStamp(this.queryDate)-1000*60*60*24, '{y}-{m}-{d}')
  129. var time2=parseUnixTime(unixTimeStamp(this.queryDate)-2000*60*60*24, '{y}-{m}-{d}')
  130. this.nowYear=new Date().getFullYear()
  131. this.showlist1=[this.queryDate,time1,time2];
  132. uni.showLoading({
  133. title: "加载中",
  134. mask: true,
  135. })
  136. API.electricityHourByDay({
  137. queryDate: this.queryDate,
  138. meterId: this.meterNo,
  139. }).then(response => {
  140. uni.hideLoading();
  141. this.graphMap2 = response.data.graphMap
  142. this.setMap2();
  143. }).catch(error => {
  144. uni.hideLoading();
  145. uni.showToast({
  146. title: error,
  147. icon: "none"
  148. })
  149. })
  150. },
  151. setMap2() {
  152. this.timeList2 = [];
  153. for (var i in this.graphMap2) {
  154. this.timeList2.push(parseInt(i) + '时')
  155. }
  156. var list1 = [];
  157. var list2 = [];
  158. // var list= this.setSz2(this.graphMap2,'bar')
  159. // this.echarts2('kwPicture2',list);
  160. var list = this.setSz(this.graphMap2, 'line',this.showlist1)
  161. console.log(list)
  162. this.echarts1('barEcharts2', list, this.timeList2,{});
  163. },
  164. setMap1() {
  165. for (var i in this.graphMap) {
  166. this.timeList1.push(parseInt(i) + 1 + '月')
  167. }
  168. var list1 = [];
  169. var list2 = [];
  170. var list = this.setSz(this.graphMap, 'line',[this.nowYear+''])
  171. this.echarts1('barEcharts1', list, this.timeList1,null);
  172. },
  173. setSz(energyCenterMapObj,type,showsz){
  174. var returnsz=[]
  175. for(var j in showsz){
  176. var ap={
  177. name: showsz[j],
  178. type: type,
  179. symbol: 'circle',
  180. data:[]
  181. }
  182. for(var i in energyCenterMapObj){
  183. var sz=energyCenterMapObj[i];
  184. ap.data.push((sz[j]))
  185. }
  186. returnsz.push(ap)
  187. }
  188. return returnsz
  189. },
  190. setSz2(energyCenterMapObj, type) {
  191. var returnsz = [];
  192. for (var i in energyCenterMapObj) {
  193. var sz = energyCenterMapObj[i];
  194. //var obj=[i+'时',sz[0].toFixed(0),sz[1].toFixed(0)]
  195. var obj = [i + '时', parseInt(sz[0]), parseInt(sz[1]), parseInt(sz[2])]
  196. returnsz.push(obj)
  197. }
  198. return returnsz;
  199. },
  200. echarts1(className, seriesdata, timeList,legend) {
  201. var colorName="#333"
  202. var myChart = echarts.init(document.getElementById(className), 'light');
  203. myChart.clear()
  204. var option = {
  205. tooltip: {
  206. trigger: 'axis',
  207. borderColor:"#F0F0F0",
  208. borderWidth:1,
  209. backgroundColor:"#ffffff",
  210. textStyle:{
  211. color:"#333"
  212. }
  213. },
  214. grid: {
  215. left: '3%',
  216. right: '4%',
  217. bottom: '5%',
  218. containLabel: true
  219. },
  220. xAxis: {
  221. type: 'category',
  222. boundaryGap: false,
  223. data: timeList,
  224. axisLabel:{
  225. textStyle:{
  226. color:colorName
  227. }
  228. },
  229. axisLine:{
  230. show:true,
  231. lineStyle:{
  232. color:colorName
  233. }
  234. },
  235. },
  236. yAxis: {
  237. type: 'value',
  238. axisLabel:{
  239. textStyle:{
  240. color:colorName
  241. }
  242. }, axisLine:{
  243. show:true,
  244. lineStyle:{
  245. color:colorName
  246. }
  247. },
  248. },
  249. // dataZoom: [
  250. // {
  251. // type: 'inside',
  252. // start: 0,
  253. // end: 100
  254. // },
  255. // {
  256. // start: 0,
  257. // end: 100
  258. // }
  259. // ],
  260. series: seriesdata
  261. };
  262. if(legend){
  263. option.legend={}
  264. }else{
  265. option.grid.top='3%'
  266. }
  267. //console.log(option)
  268. myChart.setOption(option);
  269. },
  270. echarts2(className, seriesdata) {
  271. var colorName="#333"
  272. var myChart = echarts.init(document.getElementById(className), 'light');
  273. myChart.clear()
  274. var option = {
  275. dataset: {
  276. source:[
  277. ['product',...this.showlist1 ],
  278. ...seriesdata
  279. ]
  280. },
  281. grid: {
  282. left: '3%',
  283. right: '4%',
  284. bottom: '15%',
  285. containLabel: true
  286. },
  287. legend: {
  288. },
  289. tooltip: {
  290. trigger: 'axis',
  291. axisPointer: {
  292. type: 'shadow'
  293. }
  294. },
  295. xAxis: {
  296. type: 'category',
  297. },
  298. yAxis: {
  299. },
  300. // dataZoom: [
  301. // {
  302. // type: 'inside',
  303. // start: 0,
  304. // end: 100
  305. // },
  306. // {
  307. // start: 0,
  308. // end: 100
  309. // }
  310. // ],
  311. series: [{ type: 'bar' }, { type: 'bar' }, { type: 'bar' }]
  312. };
  313. myChart.setOption(option);
  314. }
  315. }
  316. }
  317. </script>
  318. <style lang="scss" scoped>
  319. .slot {
  320. display: flex;
  321. align-items: center;
  322. .img {
  323. width: 48rpx;
  324. height: 48rpx;
  325. margin-right: 4rpx;
  326. }
  327. }
  328. .main {
  329. background-color: #fff;
  330. padding: 32rpx 8rpx 32rpx 32rpx;
  331. margin-bottom: 30rpx;
  332. .title {
  333. display: flex;
  334. align-items: center;
  335. justify-content: space-between;
  336. .icon {
  337. width: 8rpx;
  338. margin-right: 8rpx;
  339. height: 32rpx;
  340. background-color: rgba(22, 119, 255, 1);
  341. }
  342. .text {
  343. display: flex;
  344. align-items: center;
  345. color: rgb(16, 16, 16);
  346. font-size: 36rpx;
  347. margin-left: 12rpx;
  348. font-weight: bold;
  349. }
  350. }
  351. .chat {
  352. width: 100%;
  353. //height: 480rpx;
  354. margin-top: 32rpx;
  355. .img {
  356. width: 100%;
  357. height: 100%;
  358. }
  359. }
  360. // 表格
  361. .table {
  362. margin-top: 60rpx;
  363. border-radius: 8px;
  364. z-index: 999;
  365. table {
  366. background-color: #f1f2f5;
  367. color: #101010;
  368. padding: 20rpx 10rpx;
  369. width: 100%;
  370. td {
  371. text-align: right;
  372. }
  373. }
  374. }
  375. }
  376. </style>