index.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div class="dashboard-container">
  3. <el-row :gutter="20">
  4. <el-col :span="6">
  5. <el-card class="stat-card">
  6. <div class="stat-icon tenant-icon">
  7. <i class="el-icon-user" />
  8. </div>
  9. <div class="stat-info">
  10. <div class="stat-value">{{ dashboardData.tenantCount }}</div>
  11. <div class="stat-label">下属租户数</div>
  12. </div>
  13. </el-card>
  14. </el-col>
  15. <el-col :span="6">
  16. <el-card class="stat-card">
  17. <div class="stat-icon profit-icon">
  18. <i class="el-icon-money" />
  19. </div>
  20. <div class="stat-info">
  21. <div class="stat-value">¥{{ dashboardData.monthProfit }}</div>
  22. <div class="stat-label">本月分账</div>
  23. </div>
  24. </el-card>
  25. </el-col>
  26. <el-col :span="6">
  27. <el-card class="stat-card">
  28. <div class="stat-icon withdraw-icon">
  29. <i class="el-icon-wallet" />
  30. </div>
  31. <div class="stat-info">
  32. <div class="stat-value">{{ dashboardData.pendingWithdraw }}</div>
  33. <div class="stat-label">待审核提现</div>
  34. </div>
  35. </el-card>
  36. </el-col>
  37. <el-col :span="6">
  38. <el-card class="stat-card">
  39. <div class="stat-icon active-icon">
  40. <i class="el-icon-trending-up" />
  41. </div>
  42. <div class="stat-info">
  43. <div class="stat-value">{{ dashboardData.activeTenant }}</div>
  44. <div class="stat-label">活跃租户</div>
  45. </div>
  46. </el-card>
  47. </el-col>
  48. </el-row>
  49. <el-row :gutter="20" style="margin-top: 20px;">
  50. <el-col :span="12">
  51. <el-card title="租户业绩排行" class="chart-card">
  52. <div class="ranking-list">
  53. <div v-for="(item, index) in topTenants" :key="item.tenantId" class="ranking-item">
  54. <span class="rank" :class="'rank-' + (index + 1)">{{ index + 1 }}</span>
  55. <span class="name">{{ item.tenantName }}</span>
  56. <span class="amount">¥{{ item.amount }}</span>
  57. </div>
  58. </div>
  59. </el-card>
  60. </el-col>
  61. <el-col :span="12">
  62. <el-card title="本月消费趋势" class="chart-card">
  63. <div id="consumeChart" style="height: 250px;" />
  64. </el-card>
  65. </el-col>
  66. </el-row>
  67. </div>
  68. </template>
  69. <script>
  70. import { getDashboardData } from '@/api/dashboard'
  71. import echarts from 'echarts'
  72. export default {
  73. name: 'Dashboard',
  74. data() {
  75. return {
  76. dashboardData: {
  77. tenantCount: 0,
  78. monthProfit: 0,
  79. pendingWithdraw: 0,
  80. activeTenant: 0
  81. },
  82. topTenants: []
  83. }
  84. },
  85. mounted() {
  86. this.loadDashboardData()
  87. },
  88. methods: {
  89. async loadDashboardData() {
  90. try {
  91. const response = await getDashboardData()
  92. const d = response.data
  93. this.dashboardData = d
  94. this.topTenants = d.topTenants || []
  95. this.renderChart(d.trendData || [])
  96. } catch (error) {
  97. console.error('加载数据失败', error)
  98. }
  99. },
  100. renderChart(trendData) {
  101. const el = document.getElementById('consumeChart')
  102. if (!el) return
  103. const chart = echarts.init(el)
  104. const dates = trendData.map(t => t.date || t.statDate || '')
  105. const values = trendData.map(t => t.amount || t.consumeAmount || 0)
  106. chart.setOption({
  107. tooltip: { trigger: 'axis' },
  108. xAxis: { type: 'category', data: dates },
  109. yAxis: { type: 'value' },
  110. series: [{
  111. name: '消费金额',
  112. data: values,
  113. type: 'line',
  114. smooth: true,
  115. areaStyle: { color: 'rgba(52,144,220,0.2)' },
  116. lineStyle: { color: '#3490dc' }
  117. }]
  118. })
  119. }
  120. }
  121. }
  122. </script>
  123. <style lang="scss" scoped>
  124. .dashboard-container {
  125. padding: 20px;
  126. }
  127. .stat-card {
  128. display: flex;
  129. align-items: center;
  130. padding: 20px;
  131. border-radius: 12px;
  132. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  133. }
  134. .stat-icon {
  135. width: 60px;
  136. height: 60px;
  137. border-radius: 50%;
  138. display: flex;
  139. align-items: center;
  140. justify-content: center;
  141. margin-right: 20px;
  142. font-size: 24px;
  143. color: #fff;
  144. &.tenant-icon {
  145. background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  146. }
  147. &.profit-icon {
  148. background: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
  149. }
  150. &.withdraw-icon {
  151. background: linear-gradient(135deg, #fc4a1a 0%, #f7b733 100%);
  152. }
  153. &.active-icon {
  154. background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
  155. }
  156. }
  157. .stat-info {
  158. .stat-value {
  159. font-size: 24px;
  160. font-weight: bold;
  161. color: #333;
  162. }
  163. .stat-label {
  164. font-size: 14px;
  165. color: #999;
  166. margin-top: 5px;
  167. }
  168. }
  169. .chart-card {
  170. height: 320px;
  171. }
  172. .ranking-list {
  173. .ranking-item {
  174. display: flex;
  175. align-items: center;
  176. padding: 10px 0;
  177. border-bottom: 1px solid #f0f0f0;
  178. &:last-child {
  179. border-bottom: none;
  180. }
  181. .rank {
  182. width: 24px;
  183. height: 24px;
  184. border-radius: 50%;
  185. background: #eee;
  186. display: flex;
  187. align-items: center;
  188. justify-content: center;
  189. font-size: 12px;
  190. margin-right: 10px;
  191. &.rank-1 {
  192. background: #ffd700;
  193. color: #fff;
  194. }
  195. &.rank-2 {
  196. background: #c0c0c0;
  197. color: #fff;
  198. }
  199. &.rank-3 {
  200. background: #cd7f32;
  201. color: #fff;
  202. }
  203. }
  204. .name {
  205. flex: 1;
  206. font-size: 14px;
  207. color: #333;
  208. }
  209. .amount {
  210. font-size: 14px;
  211. font-weight: bold;
  212. color: #3490dc;
  213. }
  214. }
  215. }
  216. </style>