Dashboard.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. <template>
  2. <div class="dash-container" v-loading="loading">
  3. <div class="filter">
  4. <el-select
  5. v-model="providerPk"
  6. class="filter-item"
  7. @change="changeProvider">
  8. <el-option
  9. v-for="(item, index) in providerList"
  10. :key="index"
  11. :value="item.value"
  12. :label="item.name"/>
  13. </el-select>
  14. <el-button
  15. type="primary"
  16. style="margin-left: 10px;"
  17. @click="toMaps">Maps</el-button>
  18. </div>
  19. <div class="charts-card">
  20. <div class="chart-title">Hourly Utilization(kWH)</div>
  21. <LineChart :chartData="hourlyData"></LineChart>
  22. </div>
  23. <div class="card-group">
  24. <div class="card-view">
  25. <div class="card-title">Stations | Connector Status</div>
  26. <div class="line-horizontal"></div>
  27. <div class="flex">
  28. <div class="glance-total-view">
  29. <div class="total-upcase">Total</div>
  30. <div class="totals">{{stationsData.total ? stationsData.total : 0}}</div>
  31. <div class="total-bottom-title">Stations</div>
  32. </div>
  33. <div class="glance-total-list">
  34. <div class="total-list-item mini">
  35. <span>In use</span>
  36. <label>{{stationsData.inUse ? stationsData.inUse : 0}}</label>
  37. </div>
  38. <div class="total-list-item mini">
  39. <span>Reserved</span>
  40. <label>{{stationsData.reserved ? stationsData.reserved : 0}}</label>
  41. </div>
  42. <div class="total-list-item mini">
  43. <span>Faulted</span>
  44. <label>{{stationsData.faulted ? stationsData.faulted : 0}}</label>
  45. </div>
  46. <div class="total-list-item mini">
  47. <span>Available</span>
  48. <label>{{stationsData.available ? stationsData.available : 0}}</label>
  49. </div>
  50. <div class="total-list-item mini">
  51. <span>Unavailable</span>
  52. <label>{{stationsData.unAvailable ? stationsData.unAvailable : 0}}</label>
  53. </div>
  54. <div class="total-list-item mini">
  55. <span>Finishing</span>
  56. <label>{{stationsData.finishing ? stationsData.finishing : 0}}</label>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. <div class="card-view">
  62. <div class="card-title">Consumption | Today's Consumption</div>
  63. <div class="line-horizontal"></div>
  64. <div class="flex">
  65. <div class="glance-total-view">
  66. <div class="total-upcase">Total</div>
  67. <div class="totals total-power">{{consumptionData.total ? consumptionData.total : 0}}</div>
  68. <div class="total-bottom-title">kWh</div>
  69. </div>
  70. <div class="glance-total-list">
  71. <div class="total-list-item">
  72. <span>Transaction Completed</span>
  73. <label>{{consumptionData.transactionCompleted ? consumptionData.transactionCompleted : 0}}</label>
  74. </div>
  75. <div class="total-list-item">
  76. <span>Transactions Ongoing</span>
  77. <label>{{consumptionData.transactionsOngoing ? consumptionData.transactionsOngoing : 0}}</label>
  78. </div>
  79. <div class="total-list-item">
  80. <span>Highest Delivered</span>
  81. <label>{{consumptionData.highestDelivered ? consumptionData.highestDelivered : 0}}kWh</label>
  82. </div>
  83. <div class="total-list-item">
  84. <span>Lowest Delivered</span>
  85. <label>{{consumptionData.lowestDelivered ? consumptionData.lowestDelivered : 0}}kWh</label>
  86. </div>
  87. </div>
  88. </div>
  89. </div>
  90. <div class="card-view">
  91. <div class="card-title">Revenue | Today's Revenue</div>
  92. <div class="line-horizontal"></div>
  93. <div class="flex">
  94. <div class="glance-total-view">
  95. <div class="total-upcase">Total</div>
  96. <div class="totals total-amount">{{revenueData.total ? revenueData.total : 0}}</div>
  97. <div class="total-bottom-title">SGD</div>
  98. </div>
  99. <div class="glance-total-list">
  100. <div class="total-list-item">
  101. <span>Transaction Completed</span>
  102. <label>{{revenueData.transactionCompleted ? revenueData.transactionCompleted : 0}}</label>
  103. </div>
  104. <div class="total-list-item">
  105. <span>Transactions Ongoing</span>
  106. <label>{{revenueData.transactionsOngoing ? revenueData.transactionsOngoing : 0}}</label>
  107. </div>
  108. <div class="total-list-item">
  109. <span>Highest Transaction</span>
  110. <label>${{revenueData.highestTransaction ? revenueData.highestTransaction : 0}}</label>
  111. </div>
  112. <div class="total-list-item">
  113. <span>Lowest Transaction</span>
  114. <label>${{revenueData.lowestTransaction ? revenueData.lowestTransaction : 0}}</label>
  115. </div>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. <div class="charts-card">
  121. <div class="radio-group">
  122. <el-radio-group
  123. v-model="dateTabIndex"
  124. size="small"
  125. @change="changeTab">
  126. <el-radio-button
  127. v-for="(item,index) in dateRangeTab"
  128. :key="index"
  129. :label="item.value">
  130. {{item.name}}
  131. </el-radio-button>
  132. </el-radio-group>
  133. </div>
  134. <el-row
  135. class="barGroup"
  136. v-loading="barLoading">
  137. <el-col
  138. class="barView"
  139. :sm="12"
  140. :md="8"
  141. v-if="barChartData.utilization">
  142. <BarChart
  143. :index="0"
  144. :chartData="barChartData.utilization"
  145. unit="%"
  146. title="Utilization Rate so far"/>
  147. </el-col>
  148. <el-col
  149. class="barView"
  150. :sm="12"
  151. :md="8"
  152. v-if="barChartData.consumption">
  153. <BarChart
  154. :index="1"
  155. :chartData="barChartData.consumption"
  156. unit="kWh"
  157. title="Consumption so far"/>
  158. </el-col>
  159. <el-col
  160. class="barView"
  161. :sm="12"
  162. :md="8"
  163. v-if="barChartData.revenue">
  164. <BarChart
  165. :index="2"
  166. :chartData="barChartData.revenue"
  167. unit="$"
  168. :leftUnit="true"
  169. title="Revenue so far"/>
  170. </el-col>
  171. </el-row>
  172. </div>
  173. </div>
  174. </template>
  175. <script>
  176. import BarChart from './chart/BarChart.vue'
  177. import LineChart from './chart/LineChart.vue'
  178. import api from '../../http/api/dashboard'
  179. export default {
  180. components: {
  181. BarChart,
  182. LineChart
  183. },
  184. data() {
  185. return {
  186. loading: true,
  187. barLoading: true,
  188. providerPk: '',
  189. providerList: [],
  190. hourlyData: {
  191. xdata: [],
  192. ydata: []
  193. },
  194. stationsData: {},
  195. consumptionData: {},
  196. revenueData: {},
  197. dateTabIndex: 0,
  198. dateRangeTab: [],
  199. barChartData: {},
  200. changeLoading: false
  201. }
  202. },
  203. created() {
  204. this.getProvider()
  205. },
  206. methods: {
  207. changeProvider() {
  208. setTimeout(() => {
  209. if (this.changeLoading)
  210. this.loading = true
  211. }, 300)
  212. this.changeLoading = true
  213. this.getLineChart()
  214. this.getCardData()
  215. this.getBarChartData()
  216. },
  217. changeTab() {
  218. setTimeout(() => {
  219. if (this.changeLoading)
  220. this.barLoading = true
  221. }, 300)
  222. this.changeLoading = true
  223. this.getBarChartData()
  224. },
  225. async getProvider() {
  226. const data = await api.getProviderList()
  227. if (data.success && data.data) {
  228. this.providerList = data.data
  229. if (data.data.length > 0) {
  230. this.providerPk = data.data[0].value
  231. this.getLineChart()
  232. this.getCardData()
  233. this.getRangeTabList()
  234. } else {
  235. this.loading = false
  236. }
  237. }
  238. console.log(data.data);
  239. },
  240. async getLineChart() {
  241. const data = await api.getHourlyUtilization(this.providerPk)
  242. this.changeLoading = false
  243. if (data.data.xdata && data.data.ydata) {
  244. this.hourlyData = data.data
  245. } else {
  246. this.hourlyData = undefined
  247. }
  248. this.loading = false
  249. },
  250. async getCardData() {
  251. const data = await api.getCardSection(this.providerPk)
  252. this.changeLoading = false
  253. if (data.success) {
  254. this.stationsData = data.data.stations
  255. this.consumptionData = data.data.consumption
  256. this.revenueData = data.data.revenue
  257. } else {
  258. this.stationsData = {}
  259. this.consumptionData = {}
  260. this.revenueData = {}
  261. }
  262. this.loading = false
  263. },
  264. async getRangeTabList() {
  265. const data = await api.getRangeTab()
  266. if (data.success) {
  267. this.dateRangeTab = data.data
  268. if (data.data.length > 0) {
  269. this.dateTabIndex = data.data[0].value
  270. this.getBarChartData()
  271. }
  272. } else {
  273. this.dateRangeTab = [];
  274. }
  275. },
  276. async getBarChartData() {
  277. const data = await api.getBarChart({
  278. tabType: this.dateTabIndex,
  279. providerPk: this.providerPk
  280. })
  281. this.changeLoading = false
  282. if (data.success) {
  283. this.barChartData = data.data
  284. } else {
  285. this.barChartData = {}
  286. }
  287. this.barLoading = false
  288. },
  289. toMaps() {
  290. this.$router.push({path: '/maps'})
  291. /*this.$notify({
  292. title: 'It works!',
  293. type: 'success',
  294. message: 'We\'ve laid the ground work for you. It\'s time for you to build something epic!',
  295. duration: 5000
  296. })*/
  297. }
  298. }
  299. }
  300. </script>
  301. <style scoped="scoped">
  302. .dash-container {
  303. width: 100%;
  304. padding: 1px 20px 20px;
  305. background-color: #E5E5E5;
  306. }
  307. .filter {
  308. display: flex;
  309. align-items: center;
  310. padding-top: 15px;
  311. justify-content: space-between;
  312. }
  313. .filter-item {
  314. width: 100%;
  315. max-width: 300px;
  316. }
  317. .card-group {
  318. display: flex;
  319. flex-wrap: wrap;
  320. flex-flow: wrap;
  321. margin: 0 -5px;
  322. align-items: flex-start;
  323. align-content: flex-start;
  324. }
  325. .card-view {
  326. margin: 15px 5px 0;
  327. padding: 12px 15px;
  328. border-radius: 6px;
  329. background-color: white;
  330. }
  331. .card-title {
  332. color: #333;
  333. font-size: 14px;
  334. position: relative;
  335. }
  336. .card-title::before {
  337. top: -12px;
  338. left: -15px;
  339. right: -15px;
  340. bottom: -10px;
  341. content: " ";
  342. opacity: .7;
  343. position: absolute;
  344. border-radius: 6px 6px 0 0;
  345. background-color: rgba(0, 0, 0, .05);
  346. }
  347. .line-horizontal {
  348. height: 2px;
  349. margin: 10px -8px;
  350. background-color: #F0F5FC;
  351. }
  352. .glance-total-view {
  353. flex: 2;
  354. padding: 2px 15px;
  355. }
  356. .total-upcase {
  357. padding-top: 8px;
  358. font-size: 18px;
  359. font-family: sans-serif;
  360. text-transform: uppercase;
  361. }
  362. .total-bottom-title {
  363. color: #333;
  364. font-size: 14px;
  365. padding-top: 6px;
  366. }
  367. .totals {
  368. flex: 1;
  369. color: #F3B901;
  370. cursor: pointer;
  371. font-size: 36px;
  372. padding: 16px 0;
  373. user-select: none;
  374. line-height: 36px;
  375. position: relative;
  376. transition: all .4s;
  377. }
  378. .totals:hover {
  379. font-size: 42px;
  380. }
  381. .totals::after {
  382. left: 0;
  383. right: 0;
  384. bottom: 8px;
  385. height: 3px;
  386. content: " ";
  387. border-radius: 10px;
  388. position: absolute;
  389. background-image: linear-gradient(to right, #F3B901, #FFFAE8);
  390. }
  391. .total-power {
  392. color: #3179E4;
  393. }
  394. .total-power::after {
  395. background-image: linear-gradient(to right, #3179E4, #E8F0FC);
  396. }
  397. .total-amount {
  398. color: #0BD373;
  399. }
  400. .total-amount::after {
  401. background-image: linear-gradient(to right, #0BD373, #E4FAEF);
  402. }
  403. .glance-total-list {
  404. flex: 3;
  405. padding: 3px 5px 3px 15px;
  406. border-left: 2px solid #F0F5FC;
  407. }
  408. .total-list-item {
  409. display: flex;
  410. padding: 6px;
  411. line-height: 22px;
  412. align-items: center;
  413. justify-content: space-between;
  414. }
  415. .total-list-item + .total-list-item {
  416. border-top: 2px solid #F0F5FC;;
  417. }
  418. .total-list-item span {
  419. color: #434343;
  420. font-size: 13px;
  421. }
  422. .total-list-item label {
  423. color: #333;
  424. font-size: 15px;
  425. }
  426. .total-list-item.mini {
  427. padding: 4px 6px;
  428. line-height: 14px;
  429. }
  430. .total-list-item.mini span {
  431. color: #434343;
  432. font-size: 12px;
  433. }
  434. .total-list-item.mini label {
  435. color: #333;
  436. font-size: 14px;
  437. }
  438. .charts-card {
  439. display: flex;
  440. flex-direction: column;
  441. margin-top: 15px;
  442. padding: 10px 20px;
  443. border-radius: 6px;
  444. background-color: white;
  445. }
  446. .chart-title {
  447. color: #333;
  448. font-size: 16px;
  449. padding-top: 5px;
  450. padding-bottom: 15px;
  451. }
  452. .radio-group {
  453. padding-top: 5px;
  454. text-align: center;
  455. }
  456. .barView {
  457. padding-bottom: 10px;
  458. }
  459. @media screen and (max-width: 520px) {
  460. .dash-container {
  461. padding: 1px 10px 15px;
  462. }
  463. .filter {
  464. padding-top: 10px;
  465. }
  466. .card-view {
  467. flex: 1;
  468. margin: 10px 5px 0;
  469. }
  470. .glance-total-list {
  471. padding: 5px;
  472. }
  473. .charts-card {
  474. margin: 10px 0 0;
  475. }
  476. }
  477. @media screen and (min-width: 520px) {
  478. .card-view {
  479. flex-grow: 1;
  480. }
  481. }
  482. @media screen and (min-width: 768px) {
  483. .barView + .barView {
  484. border-left: 10px solid #F0F5FC;
  485. }
  486. .barView + .barView + .barView {
  487. border-left: none;
  488. }
  489. }
  490. @media screen and (min-width: 992px) {
  491. .barView + .barView + .barView {
  492. border-left: 10px solid #F0F5FC;
  493. }
  494. }
  495. @media screen and (min-width: 1366px) {
  496. .card-view {
  497. flex: 1;
  498. }
  499. }
  500. .barGroup {
  501. margin-top: 15px;
  502. padding-top: 18px;
  503. border-top: 1px solid #F0F5FC;
  504. }
  505. </style>