index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /* eslint-disable vue/valid-template-root */
  2. <template>
  3. <div class="app-container">
  4. <div class="filter-container">
  5. <div class="block">
  6. <el-date-picker v-model="yearDate" :clearable="false" type="year" placeholder="选择年" />
  7. </div>
  8. </div>
  9. <el-row v-if="isBarChart1" style="position: relative;">
  10. <p style="position: absolute;top:-12px;left:40%;color:rgb(130, 165, 252);background:rgb(230, 243, 255);border:1px solid rgb(130, 165, 252);padding:10px;border-radius:10px">
  11. {{ year }}年集团用电量:{{ total }}万度
  12. </p>
  13. <el-col :span="24">
  14. <div id="barChart1" style="width: 100%;height:400px;" />
  15. </el-col>
  16. </el-row>
  17. <!-- 年度维修成本 -->
  18. <el-row>
  19. <el-col :span="12">
  20. <div id="lineChart1" style="width: 100%;height:400px;" />
  21. </el-col>
  22. <el-col :span="12">
  23. <div id="lineChart2" style="width: 100%;height:400px;" />
  24. </el-col>
  25. </el-row>
  26. <el-row>
  27. <el-col :span="12">
  28. <div id="pieChart1" style="width: 100%;height:400px;" />
  29. </el-col>
  30. <el-col :span="12">
  31. <div id="barChart2" style="width: 100%;height:400px;" />
  32. </el-col>
  33. </el-row>
  34. </div>
  35. </template>
  36. <script>
  37. import echarts from 'echarts'
  38. require('echarts/theme/macarons') // echarts theme
  39. // eslint-disable-next-line no-unused-vars
  40. import waves from '@/directive/waves' // waves directive
  41. import Pagination from '@/components/Pagination' // secondary package based on el-pagination
  42. import { GetDataByName, GetDataByNames, GetReportform, checkButtons } from '@/api/common'
  43. import { parseTime } from '@/utils/index.js'
  44. import Cookies from 'js-cookie'
  45. export default {
  46. name: 'QueryElec',
  47. directives: { waves },
  48. components: { Pagination },
  49. data() {
  50. return {
  51. yearDate: new Date(),
  52. pasture: Cookies.get('pasturename'),
  53. year: new Date().getFullYear(),
  54. month: new Date().getMonth() < 9 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1,
  55. deptment: '维修处',
  56. total: '',
  57. getBarChart1Parm: {
  58. name: 'getpSumNowElec',
  59. parammaps: {
  60. receiveTime: new Date().getFullYear(),
  61. center:'',
  62. pastureName: Cookies.get('pasturename')
  63. }
  64. },
  65. getLineChart1Parm: {
  66. name: 'getPastureSumMonthElec',
  67. parammaps: {
  68. receiveTime: new Date().getFullYear(),
  69. pastureName: Cookies.get('pasturename')
  70. }
  71. },
  72. getLineChart2Parm: {
  73. name: 'getPastureSumDayElec',
  74. parammaps: {
  75. receiveTime: new Date().getFullYear() + '-' + (new Date().getMonth() <= 9 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1),
  76. pastureName: Cookies.get('pasturename')
  77. }
  78. },
  79. getPieChart1Parm: {
  80. name: 'getdeptSumMonthElec',
  81. parammaps: {
  82. receiveTime: new Date().getFullYear() + '-' + (new Date().getMonth() <= 9 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1),
  83. pastureName: Cookies.get('pasturename')
  84. }
  85. },
  86. getBarChart2Parm: {
  87. name: 'geteqclassSumMonthElec',
  88. parammaps: {
  89. receiveTime: new Date().getFullYear() + '-' + (new Date().getMonth() <= 9 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1),
  90. pastureName: Cookies.get('pasturename'),
  91. deptName: ''
  92. }
  93. },
  94. barChart1: null,
  95. lineChart1: null,
  96. lineChart2: null,
  97. pieChart1: null,
  98. barChart2: null,
  99. chart_data1: {
  100. // pasture: ['宝鸡', '恒盛', '塞一', '塞二', '塞三', '塞四', '塞五', '通山', '合肥', '和林'],
  101. // nowYear: [123, 332, 222, 333, 444, 333, 222, 334, 234, 223],
  102. // lastYear: [22, 44, 77, 88, 444, 234, 342, 234, 234, 66]
  103. },
  104. chart_data2: {
  105. // months: ['2019-01', '2019-02', '2019-01', '2019-01', '2019-01', '2019-01', '2019-01', '2019-01', '2019-01', '2019-01'],
  106. // nowYear: [123, 332, 222, 333, 444, 333, 222, 334, 234, 223],
  107. // lastYear: [22, 44, 77, 88, 444, 234, 342, 234, 234, 66]
  108. },
  109. chart_data3: {
  110. // day: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'],
  111. // nowYear: [123, 332, 222, 333, 444, 333, 222, 334, 234, 223],
  112. // lastYear: [22, 44, 77, 88, 444, 234, 342, 234, 234, 66]
  113. },
  114. chart_data4: {
  115. // name: ['饲养处', '其他部门', '设备处', '能源处', '牧场办公室'],
  116. // psum: [
  117. // { value: 335, name: '饲养处' },
  118. // { value: 310, name: '其他部门' },
  119. // { value: 234, name: '设备处' },
  120. // { value: 135, name: '能源处' },
  121. // { value: 1548, name: '牧场办公室' }
  122. // ]
  123. },
  124. chart_data5: {
  125. // typeName: ['小型装载机', '叉车', '拖拉机', '抛料机', '搅拌机'],
  126. // eqCost: [123, 332, 222, 333, 444],
  127. // lastYear: [22, 342, 234, 234, 66]
  128. },
  129. tableKey: 0,
  130. list: null,
  131. total: 0,
  132. listLoading: true,
  133. rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
  134. cellStyle: { padding: 0 + 'px' },
  135. dialogFormVisibleCard: false,
  136. listLoadingSee: true,
  137. rowSeeData: {},
  138. listSee: [],
  139. totalSee: 0,
  140. getdataListParmSee: {
  141. name: 'geteqclassSumDay',
  142. page: 1,
  143. offset: 1,
  144. pagecount: 10,
  145. returntype: 'Map',
  146. parammaps: {
  147. receiveTime: new Date().getFullYear() + '-' + (new Date().getMonth() <= 9 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1),
  148. pastureName: Cookies.get('pasturename'),
  149. deptName: '',
  150. typeName: '',
  151. assetCode: '',
  152. eqName: '',
  153. startTime: '',
  154. stopTime: '',
  155. pastureId: Cookies.get('pastureid')
  156. }
  157. },
  158. buttons: [],
  159. isBarChart1: []
  160. }
  161. },
  162. watch: {
  163. 'yearDate': {
  164. deep: true,
  165. handler: function(newVal, oldVal) {
  166. var time = this.yearDate
  167. console.log(newVal.getFullYear())
  168. this.year = time.getFullYear()
  169. this.getBarChart1Parm.parammaps.receiveTime = time.getFullYear()
  170. this.getLineChart1Parm.parammaps.receiveTime = time.getFullYear()
  171. this.getLineChart2Parm.parammaps.receiveTime = time.getFullYear() + '-' + (new Date().getMonth() <= 9 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1)
  172. this.getPieChart1Parm.parammaps.receiveTime = time.getFullYear() + '-' + (new Date().getMonth() <= 9 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1)
  173. this.getBarChart2Parm.parammaps.receiveTime = time.getFullYear() + '-' + (new Date().getMonth() <= 9 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1)
  174. this.getBarChart1()
  175. this.getLineChart1()
  176. this.getLineChart2()
  177. this.getPieChart1()
  178. }
  179. }
  180. },
  181. created() {
  182. this.getBarChart1()
  183. this.getLineChart1()
  184. this.getLineChart2()
  185. this.getPieChart1()
  186. const that = this
  187. GetDataByName({ 'name': 'getUserPCButtons', 'parammaps': { 'jwt_username': Cookies.get('name') }}).then(response => {
  188. that.buttons = response.data.list
  189. that.get_auto_buttons()
  190. })
  191. },
  192. mounted() {
  193. // this.roadBarChart1(this.chart_data1)
  194. // this.roadlineChart1(this.chart_data2, this.pasture, this.year)
  195. // this.roadlineChart2(this.chart_data3, this.pasture, this.month)
  196. // this.roadpieChart1(this.chart_data4, this.month)
  197. // this.roadBarChart2(this.chart_data5, this.deptment)
  198. },
  199. methods: {
  200. get_auto_buttons() {
  201. // 图1
  202. const BarChart1 = 'report:queryElec:pastures'
  203. const isBarChart1 = checkButtons(this.$store.state.user.buttons, BarChart1)
  204. this.isBarChart1 = isBarChart1
  205. },
  206. // 各牧场年度维修成本对比
  207. getBarChart1() {
  208. GetReportform(this.getBarChart1Parm).then(response => {
  209. console.log('图1', response)
  210. let pasture = response.data.chart_data.pasture
  211. let keys = []
  212. pasture.forEach((item,key)=>{
  213. if(item.includes("公司")){
  214. keys.push(key)
  215. }
  216. })
  217. let lastYear = response.data.chart_data.lastYear
  218. let new_pasture = pasture.splice(keys[0],keys.length)
  219. let new_lastYear = lastYear.splice(keys[0],keys.length)
  220. let NowYear = response.data.chart_data.nowYear
  221. let new_NowYear = NowYear.splice(keys[0],keys.length)
  222. this.chart_data1.pasture = pasture
  223. this.chart_data1.lastYear = lastYear
  224. this.chart_data1.nowYear = NowYear
  225. // this.chart_data1 = response.data.chart_data
  226. this.roadBarChart1(this.chart_data1)
  227. var nowYear = response.data.chart_data.nowYear
  228. var total = 0
  229. if (nowYear !== null || nowYear !== undefined) {
  230. nowYear.forEach(function(item, index) {
  231. console.log(parseFloat(item))
  232. total = total + parseFloat(item)
  233. })
  234. }
  235. this.total = total.toFixed(4)
  236. })
  237. },
  238. getLineChart1() {
  239. GetReportform(this.getLineChart1Parm).then(response => {
  240. console.log('图2', response)
  241. this.chart_data2 = response.data.chart_data
  242. this.roadlineChart1(this.chart_data2, this.pasture, this.year)
  243. })
  244. },
  245. getLineChart2() {
  246. GetReportform(this.getLineChart2Parm).then(response => {
  247. console.log('图3', response)
  248. this.chart_data3 = response.data.chart_data
  249. this.roadlineChart2(this.chart_data3, this.pasture, this.month)
  250. })
  251. },
  252. getPieChart1() {
  253. GetDataByName(this.getPieChart1Parm).then(response => {
  254. console.log('图4', response)
  255. if (response.data === null || response.data.list === null) {
  256. this.chart_data4 = { name: [], psum: [] }
  257. this.roadpieChart1(this.chart_data4, this.month)
  258. } else {
  259. this.chart_data4.psum = response.data.list
  260. var name = []
  261. console.log(response.data.list)
  262. response.data.list.forEach(function(i) {
  263. name.push(i.name)
  264. })
  265. console.log(this.chart_data4)
  266. this.chart_data4.name = name
  267. this.roadpieChart1(this.chart_data4, this.month)
  268. this.deptment = name[0]
  269. this.getdataListParmSee.parammaps.deptName = name[0]
  270. this.getBarChart2Parm.parammaps.deptName = name[0]
  271. this.getBarChart2()
  272. }
  273. })
  274. },
  275. getBarChart2() {
  276. GetReportform(this.getBarChart2Parm).then(response => {
  277. console.log('图5', response)
  278. this.chart_data5 = response.data.chart_data
  279. this.roadBarChart2(this.chart_data5, this.deptment)
  280. })
  281. },
  282. // 各牧场年度维修成本对比
  283. roadBarChart1(chart_data1) {
  284. if (this.barChart1 != null) {
  285. this.barChart1.dispose()
  286. }
  287. this.barChart1 = echarts.init(document.getElementById('barChart1'))
  288. var option = {
  289. title: { text: '各牧场年度用电量对比', textStyle: { color: '#769cfc' }},
  290. tooltip: { trigger: 'axis' },
  291. legend: {
  292. data: ['今年用量', '去年同期'],
  293. right: 40
  294. },
  295. color: ['#2dc0e8', '#769cfc', '#FFB800'],
  296. grid: { left: '3%', right: '4%', bottom: '4%', containLabel: true },
  297. xAxis: [{ type: 'category', data: chart_data1.pasture, axisLabel: { interval: 0, rotate: 30 }}],
  298. yAxis: [{ type: 'value', name: '电量(度)', axisLabel: { formatter: '{value}万' }}],
  299. series: [
  300. {
  301. name: '今年用量',
  302. type: 'bar',
  303. data: chart_data1.nowYear,
  304. emphasis: { label: { show: true, position: 'inside' }}
  305. },
  306. {
  307. name: '去年同期',
  308. type: 'bar',
  309. data: chart_data1.lastYear,
  310. emphasis: { label: { show: true, position: 'inside' }}
  311. }
  312. ]
  313. }
  314. this.barChart1.setOption(option)
  315. window.onresize = function() {
  316. this.barChart1.resize()
  317. }
  318. var that = this
  319. this.barChart1.on('click', function(param, i) {
  320. console.log(param)
  321. that.pasture = param.name
  322. that.getLineChart1Parm.parammaps.pastureName = param.name
  323. that.getLineChart2Parm.parammaps.pastureName = param.name
  324. that.getPieChart1Parm.parammaps.pastureName = param.name
  325. that.getBarChart2Parm.parammaps.pastureName = param.name
  326. that.getLineChart1()
  327. that.getLineChart2()
  328. that.getPieChart1()
  329. })
  330. },
  331. // 每月维修成本对比
  332. roadlineChart1(chart_data2, pasture, year) {
  333. if (this.lineChart1 != null) {
  334. this.lineChart1.dispose()
  335. }
  336. this.lineChart1 = echarts.init(document.getElementById('lineChart1'))
  337. var option = {
  338. title: { text: pasture + year + '每月用电量对比', textStyle: { color: '#769cfc' }},
  339. tooltip: { trigger: 'axis' },
  340. legend: {
  341. data: ['今年用量', '去年同期用量'],
  342. x: 'right'
  343. },
  344. color: [ '#769cfc', '#FFB800'],
  345. grid: { left: '3%', right: '5%', bottom: '4%', containLabel: true },
  346. xAxis: [{ type: 'category', data: chart_data2.months, name: '月份', axisLabel: { interval: 0, rotate: 30 }}],
  347. yAxis: [{ type: 'value', name: '电量(度)', axisLabel: { formatter: '{value}万' }}],
  348. series: [
  349. {
  350. name: '今年用量',
  351. type: 'line',
  352. data: chart_data2.nowYear,
  353. emphasis: { label: { show: true, position: 'inside' }}
  354. },
  355. {
  356. name: '去年同期用量',
  357. type: 'line',
  358. data: chart_data2.lastYear,
  359. emphasis: { label: { show: true, position: 'inside' }}
  360. }
  361. ]
  362. }
  363. this.lineChart1.setOption(option)
  364. window.onresize = function() {
  365. this.lineChart1.resize()
  366. }
  367. var that = this
  368. this.lineChart1.on('click', function(param, i) {
  369. console.log(param)
  370. that.getLineChart2Parm.parammaps.receiveTime = param.name
  371. that.getPieChart1Parm.parammaps.receiveTime = param.name
  372. that.getBarChart2Parm.parammaps.receiveTime = param.name
  373. var num = param.name.substring(5)
  374. console.log(num)
  375. that.month = num
  376. that.getLineChart2()
  377. that.getPieChart1()
  378. })
  379. },
  380. // 每月维修成本对比
  381. roadlineChart2(chart_data3, pasture, month) {
  382. if (this.lineChart2 != null) {
  383. this.lineChart2.dispose()
  384. }
  385. this.lineChart2 = echarts.init(document.getElementById('lineChart2'))
  386. var option = {
  387. title: { text: pasture + month + '月每日用电量对比', textStyle: { color: '#769cfc' }},
  388. tooltip: { trigger: 'axis' },
  389. legend: {
  390. data: ['今年日用量', '去年同期'],
  391. x: 'right'
  392. },
  393. color: [ '#769cfc', '#FFB800'],
  394. grid: { left: '3%', right: '5%', bottom: '4%', containLabel: true },
  395. xAxis: [{ type: 'category', data: chart_data3.day, name: '日期', axisLabel: { interval: 0 }}],
  396. yAxis: [{ type: 'value', name: '电量(度)', axisLabel: { formatter: '{value}' }}],
  397. series: [
  398. {
  399. name: '今年日用量',
  400. type: 'line',
  401. data: chart_data3.nowYear,
  402. emphasis: { label: { show: true, position: 'inside' }}
  403. },
  404. {
  405. name: '去年同期',
  406. type: 'line',
  407. data: chart_data3.lastYear,
  408. emphasis: { label: { show: true, position: 'inside' }}
  409. }
  410. ]
  411. }
  412. this.lineChart2.setOption(option)
  413. window.onresize = function() {
  414. this.lineChart2.resize()
  415. }
  416. this.lineChart2.on('click', function(param, i) {
  417. console.log(param)
  418. })
  419. },
  420. // 部门统计
  421. roadpieChart1(chart_data4, month) {
  422. if (this.pieChart1 != null) {
  423. this.pieChart1.dispose()
  424. }
  425. this.pieChart1 = echarts.init(document.getElementById('pieChart1'))
  426. var option = {
  427. title: { text: month + '月部门统计', textStyle: { color: '#769cfc' }},
  428. tooltip: {
  429. trigger: 'item',
  430. formatter: '{a} <br/>{b} : {c} ({d}%)'
  431. },
  432. legend: {
  433. data: chart_data4.name, top: 40, x: 'right'
  434. },
  435. color: ['#769cfc', '#FFB800'],
  436. grid: { left: '3%', right: '5%', bottom: '4%', containLabel: true },
  437. series: [
  438. {
  439. name: '',
  440. type: 'pie',
  441. radius: '55%',
  442. center: ['50%', '60%'],
  443. data: chart_data4.psum,
  444. emphasis: {
  445. itemStyle: {
  446. shadowBlur: 10,
  447. shadowOffsetX: 0,
  448. shadowColor: 'rgba(0, 0, 0, 0.5)'
  449. }
  450. }
  451. }
  452. ]
  453. }
  454. this.pieChart1.setOption(option)
  455. window.onresize = function() {
  456. this.pieChart1.resize()
  457. }
  458. var that = this
  459. this.pieChart1.on('click', function(param, i) {
  460. console.log(param)
  461. that.deptment = param.name
  462. that.getBarChart2Parm.parammaps.deptName = param.name
  463. that.getBarChart2()
  464. })
  465. },
  466. // 维修成本
  467. roadBarChart2(chart_data5, deptment) {
  468. if (this.barChart2 != null) {
  469. this.barChart2.dispose()
  470. }
  471. this.barChart2 = echarts.init(document.getElementById('barChart2'))
  472. var option = {
  473. title: { text: deptment + '用电量', textStyle: { color: '#769cfc' }},
  474. tooltip: { trigger: 'axis' },
  475. legend: {
  476. data: ['用电量'],
  477. x: 'right'
  478. },
  479. color: [ '#769cfc', '#FFB800'],
  480. grid: { left: '3%', right: '10%', bottom: '4%', containLabel: true },
  481. xAxis: [{ type: 'category', data: chart_data5.typeName, name: '电表名称', axisLabel: { interval: 0 }}],
  482. yAxis: [{ type: 'value', name: '电量(度)', axisLabel: { formatter: '{value}万' }}],
  483. series: [
  484. {
  485. name: '用电量',
  486. type: 'bar',
  487. barWidth: 14,
  488. data: chart_data5.eqCost,
  489. emphasis: { label: { show: true, position: 'inside' }}
  490. }
  491. ]
  492. }
  493. this.barChart2.setOption(option)
  494. window.onresize = function() {
  495. this.barChart2.resize()
  496. }
  497. }
  498. }
  499. }
  500. </script>
  501. <style>
  502. .el-row {
  503. margin-bottom: 40px;
  504. &:last-child {
  505. margin-bottom: 0;
  506. }
  507. }
  508. </style>
  509. <style lang="scss" scoped>
  510. .dashboard-editor-container {
  511. padding: 20px;
  512. background-color: rgb(240, 242, 245);
  513. position: relative;
  514. .github-corner {
  515. position: absolute;
  516. top: 0px;
  517. border: 0;
  518. right: 0;
  519. }
  520. .chart-wrapper {
  521. background: #fff;
  522. padding: 16px 16px 0;
  523. }
  524. }
  525. @media (max-width:1024px) {
  526. .chart-wrapper {
  527. padding: 8px;
  528. }
  529. }
  530. </style>