123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <script setup>
  2. import { ref } from 'vue'
  3. import { Head } from '@inertiajs/inertia-vue3'
  4. import AppLayout from '@/layouts/AppLayout.vue'
  5. defineProps({
  6. cardStatistics: Object,
  7. transactionStatistics: Object,
  8. transactionOutletStatistics: Object,
  9. })
  10. const transactionBarData = (chartData) => {
  11. const colors = ['#17b6ff', '#ffb51c']
  12. const data = {
  13. datasets: [],
  14. }
  15. let id = 0
  16. for (const key in chartData) {
  17. data.datasets.push({
  18. label: key,
  19. backgroundColor: colors[id],
  20. data: chartData[key],
  21. })
  22. id++
  23. }
  24. return data
  25. }
  26. const transactionBarOption = ref({
  27. responsive: true,
  28. maintainAspectRatio: false,
  29. datasetFill: false,
  30. scales: {
  31. y: {
  32. ticks: {
  33. beginAtZero: true,
  34. callback: function (label) {
  35. if (Math.floor(label) === label) {
  36. return label
  37. }
  38. },
  39. },
  40. },
  41. },
  42. })
  43. const transactionOutletPieData = (chartData) => {
  44. const labels = []
  45. const data = []
  46. for (const key in chartData) {
  47. labels.push(key)
  48. data.push(chartData[key])
  49. }
  50. return {
  51. labels: labels,
  52. datasets: [
  53. {
  54. data: data,
  55. backgroundColor: ['#17b6ff', '#00c3f7', '#00cbdc', '#00d1b2', '#2bd281', '#86cf50', '#c5c623', '#ffb51c'],
  56. },
  57. ],
  58. }
  59. }
  60. const transactionOutletPieOption = ref({
  61. maintainAspectRatio: false,
  62. datasetFill: false,
  63. plugins: {
  64. legend: {
  65. labels: {
  66. color: '#495057',
  67. },
  68. },
  69. },
  70. })
  71. </script>
  72. <template>
  73. <AppLayout>
  74. <Head title="Dashboard" />
  75. <div class="grid">
  76. <div v-for="cardStatistic in cardStatistics" class="col-12 md:col-3">
  77. <Card class="h-full">
  78. <template #content>
  79. <div class="flex justify-content-between mb-3">
  80. <div>
  81. <span class="block text-500 font-medium mb-3">{{ cardStatistic.title }}</span>
  82. <div v-if="cardStatistic.value" class="text-900 font-medium text-xl">{{ cardStatistic.value }}</div>
  83. </div>
  84. <div
  85. class="flex align-items-center justify-content-center bg-orange-100 border-round"
  86. style="width: 2.5rem; height: 2.5rem"
  87. >
  88. <i class="text-orange-500 text-xl" :class="cardStatistic.icon"></i>
  89. </div>
  90. </div>
  91. <span class="text-green-500 font-medium">{{ cardStatistic.amount }} </span>
  92. <span class="text-500"> {{ ' ' + cardStatistic.amountLabel }}</span>
  93. </template>
  94. </Card>
  95. </div>
  96. <div v-for="transactionStatistic in transactionStatistics" class="col-12 md:col-6">
  97. <Card>
  98. <template #title>{{ transactionStatistic.title }}</template>
  99. <template #content>
  100. <Chart type="bar" :data="transactionBarData(transactionStatistic.data)" :options="transactionBarOption" />
  101. </template>
  102. </Card>
  103. </div>
  104. <div class="col-12 md:col-6">
  105. <Card>
  106. <template #title>{{ transactionOutletStatistics.title }}</template>
  107. <template #content>
  108. <Chart
  109. type="pie"
  110. :width="600"
  111. :height="300"
  112. :data="transactionOutletPieData(transactionOutletStatistics.data)"
  113. :options="transactionOutletPieOption"
  114. />
  115. </template>
  116. </Card>
  117. </div>
  118. </div>
  119. </AppLayout>
  120. </template>