index.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <div class="home">
  3. <div class="home-row">
  4. <el-card class="box-card">
  5. <div slot="header" class="box-header">
  6. <span>能耗汇总</span>
  7. <div class="header-right">
  8. <div :class="{ 'selected': activeDate === item.value }" v-for="item in dateList" :key="item.name"
  9. @click="dateChange(item)">{{ item.name }}</div>
  10. </div>
  11. </div>
  12. <div class="summary">
  13. <div class="summary-item">
  14. <div>
  15. <div class="summary-bg">
  16. <img class="energyImg" src="@/assets/images/energy.svg" alt="">
  17. </div>
  18. <div class="summary-title">
  19. <div>电消耗</div>
  20. <div class="summary-value">
  21. <span class="value">122</span>
  22. <span class="unit">kW·h</span>
  23. </div>
  24. <div class="summary-value">
  25. <span class="value">182</span>
  26. <span class="unit">元</span>
  27. </div>
  28. </div>
  29. </div>
  30. <div>
  31. <div class="summary-bg">
  32. <img src="@/assets/images/water.svg" alt="">
  33. </div>
  34. <div class="summary-title">
  35. <div>水消耗</div>
  36. <div class="summary-value">
  37. <span class="value">132</span>
  38. <span class="unit">吨</span>
  39. </div>
  40. <div class="summary-value">
  41. <span class="value">162</span>
  42. <span class="unit">元</span>
  43. </div>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="summay-chart">
  48. <SubTitle title="费用【单位:元】" style="padding-left: 30px;"/>
  49. <div class="cost">
  50. <span>总费用</span>
  51. <span>344元</span>
  52. </div>
  53. <BaseChart width="100%" height="250px" :option="useOptions" />
  54. </div>
  55. </div>
  56. </el-card>
  57. </div>
  58. <el-card class="box-card">
  59. <div slot="header" class="box-header">
  60. <span>用能趋势分析</span>
  61. <div class="header-right">
  62. <div :class="{ 'selected': activeDimension === item.value }" v-for="item in dimensionList" :key="item.name"
  63. @click="dimensionChange(item)">{{ item.name }}</div>
  64. </div>
  65. </div>
  66. <BaseChart width="100%" height="250px" :option="energyOptions" />
  67. </el-card>
  68. </div>
  69. </template>
  70. <script>
  71. import BaseChart from '@/components/BaseChart'
  72. import SubTitle from '@/components/SubTitle/index.vue'
  73. export default {
  74. name: "Index",
  75. data () {
  76. return {
  77. activeDate: '1',
  78. dateList: [
  79. {name: '上月', value: '1'},
  80. {name: '本月', value: '2'},
  81. {name: '去年', value: '3'},
  82. {name: '本年', value: '4'},
  83. ],
  84. activeDimension: '1',
  85. dimensionList: [
  86. {name: '小时', value: '1'},
  87. {name: '天', value: '2'},
  88. {name: '月', value: '3'},
  89. {name: '年', value: '4'},
  90. ],
  91. consumList: [
  92. {
  93. name: '综合能耗',
  94. value: '',
  95. unit: '',
  96. cost: ''
  97. }
  98. ]
  99. };
  100. },
  101. components: {BaseChart,SubTitle},
  102. computed: {
  103. useOptions () {
  104. return {
  105. tooltip: {
  106. trigger: 'item',
  107. },
  108. legend: {
  109. show: false,
  110. orient: 'vertical',
  111. top: '5%',
  112. left: '5%'
  113. },
  114. series: [
  115. {
  116. name: '费用',
  117. type: 'pie',
  118. radius: ['35%', '55%'],
  119. data: [{
  120. name: '水费', value: '162',
  121. itemStyle: {
  122. normal: {
  123. color: '#1396DB'
  124. }
  125. }
  126. }, {
  127. name: '电费', value: '182',
  128. itemStyle: {
  129. normal: {
  130. color: '#F4EA29'
  131. }
  132. }
  133. }],
  134. emphasis: {
  135. itemStyle: {
  136. shadowBlur: 10,
  137. shadowOffsetX: 0,
  138. shadowColor: 'rgba(0, 0, 0, 0.5)',
  139. }
  140. },
  141. label: {
  142. show: true,
  143. position: 'outside',
  144. formatter: '{b}\n{d}%',
  145. },
  146. labelLine: {
  147. show: true,
  148. length: 30, // 标签线长度
  149. lineStyle: {
  150. width: 1,
  151. type: 'dashed', // 设置虚线样式
  152. }
  153. }
  154. }
  155. ]
  156. }
  157. },
  158. energyOptions () {
  159. const dataArr = []
  160. let dataObj = {
  161. name: "用能趋势分析",
  162. type: "bar",
  163. year: ["2015", "2016", "2017", "2018", "2019", "2020"],
  164. val: [
  165. {
  166. name: '水',
  167. value: ["0", "0", "20", "11", "18", "5"]
  168. },
  169. {
  170. name: '电',
  171. value: ["4", "10", "2", "22", "12", "3"]
  172. }
  173. ]
  174. }
  175. dataObj.val.map(item => {
  176. const newArr = {
  177. name: item.name,
  178. type: 'bar',
  179. smooth: true,
  180. symbolSize: 8,
  181. data: item.value,
  182. barWidth: '17%',
  183. itemStyle: {
  184. normal: {
  185. color: item.name === '水' ? '#1396DB' : '#F4EA29'
  186. }
  187. }
  188. }
  189. dataArr.push(newArr)
  190. })
  191. return {
  192. toolbox: {
  193. itemGap: 10,
  194. itemSize: 16,
  195. right: 10,
  196. top: 0,
  197. show: true,
  198. feature: {
  199. magicType: {
  200. show: true,
  201. type: ['bar', 'line']
  202. },
  203. saveAsImage: {
  204. show: true
  205. }
  206. }
  207. },
  208. // color: ['#f0c725', '#16f892'],
  209. tooltip: {
  210. trigger: 'axis',
  211. axisPointer: { // 坐标轴指示器,坐标轴触发有效
  212. type: 'shadow' // 默认为直线,可选为:'line' | 'shadow'
  213. }
  214. },
  215. legend: {
  216. x: 'center',
  217. top: '0',
  218. textStyle: {
  219. // color: '#c1cadf',
  220. fontSize: 14
  221. }
  222. },
  223. grid: {
  224. left: '5%',
  225. right: '6%',
  226. top: '5%',
  227. bottom: '10%',
  228. containLabel: false
  229. },
  230. xAxis: [{
  231. type: 'category',
  232. boundaryGap: true,
  233. data: dataObj.year,
  234. axisLine: {
  235. lineStyle: {
  236. // color: 'rgba(240,199,37,1)'
  237. }
  238. },
  239. axisLabel: {
  240. interval: 0,
  241. // color: '#c1cadf',
  242. fontSize: '15'
  243. }
  244. }],
  245. yAxis: [{
  246. type: 'value',
  247. name: '(处)',
  248. nameTextStyle: {
  249. // color: '#c1cadf',
  250. align: 'right',
  251. lineHeight: 10
  252. },
  253. axisLine: {
  254. lineStyle: {
  255. // color: 'rgba(240,199,37,1)'
  256. }
  257. },
  258. axisLabel: {
  259. interval: 0,
  260. // color: '#c1cadf',
  261. fontSize: '15'
  262. },
  263. splitLine: {
  264. show: false
  265. }
  266. }],
  267. series: dataArr
  268. }
  269. }
  270. },
  271. methods: {
  272. dateChange (item) {
  273. this.activeDate = item.value
  274. },
  275. dimensionChange (item) {
  276. this.activeDimension = item.value
  277. }
  278. },
  279. };
  280. </script>
  281. <style scoped lang="scss">
  282. .home {
  283. padding: 0 10px;
  284. }
  285. .home-row {
  286. display: flex;
  287. justify-content: space-between;
  288. .box-card:last-of-type {
  289. margin-left: 10px;
  290. }
  291. }
  292. .box-card {
  293. margin-top: 10px;
  294. width: 100%;
  295. .box-header {
  296. display: flex;
  297. align-items: center;
  298. justify-content: space-between;
  299. font-weight: bold;
  300. .header-right {
  301. display: flex;
  302. color: #98999b;
  303. font-weight: normal;
  304. font-size: 14px;
  305. >div {
  306. display: flex;
  307. align-items: center;
  308. cursor: pointer;
  309. &:not(:last-of-type):after {
  310. content: '';
  311. height: 12px;
  312. width: 1px;
  313. background: #d5d8e0;
  314. margin: 0 3px;
  315. }
  316. }
  317. .selected {
  318. color: #409EFF;
  319. }
  320. }
  321. }
  322. }
  323. .summary {
  324. display: flex;
  325. justify-content: space-around;
  326. .summay-chart {
  327. flex: 1;
  328. position: relative;
  329. .cost{
  330. position: absolute;
  331. top: 53%;
  332. left: 50%;
  333. transform: translate(-50%,-50%);
  334. display: flex;
  335. flex-direction: column;
  336. justify-content: center;
  337. align-items: center;
  338. }
  339. }
  340. .summary-item {
  341. flex: 1;
  342. flex-shrink: 0;
  343. display: flex;
  344. justify-content: space-around;
  345. >div {
  346. display: flex;
  347. align-items: center;
  348. justify-content: center;
  349. .summary-bg {
  350. margin-top: 20px;
  351. width: 140px;
  352. height: 140px;
  353. border-radius: 50%;
  354. border: 3px solid #d5d8e0;
  355. box-shadow: 0px 4px 10px 0px rgba(69, 89, 120, 0.3);
  356. display: flex;
  357. justify-content: center;
  358. align-items: center;
  359. img {
  360. height: 60px;
  361. }
  362. .energyImg {
  363. height: 90px;
  364. }
  365. }
  366. .summary-title {
  367. margin-left: 10px;
  368. >div:first-child {
  369. font-weight: bold;
  370. color: #333;
  371. margin-bottom: 10px;
  372. }
  373. .summary-value {
  374. margin-top: 5px;
  375. }
  376. .value {
  377. font-size: 18px;
  378. font-weight: bold;
  379. }
  380. .unit {
  381. margin-left: 10px;
  382. font-size: 12px;
  383. color: #bbbcbf;
  384. }
  385. }
  386. }
  387. }
  388. }
  389. </style>