chartYoY.vue 8.6 KB

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