OperationDataCard.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <el-card shadow="never">
  3. <template #header>
  4. <CardTitle title="运营数据" />
  5. </template>
  6. <div class="flex flex-row flex-wrap items-center gap-8 p-4">
  7. <div
  8. v-for="item in data"
  9. :key="item.name"
  10. class="h-20 w-20% flex flex-col cursor-pointer items-center justify-center gap-2"
  11. @click="handleClick(item.routerName)"
  12. >
  13. <CountTo
  14. :decimals="item.decimals"
  15. :end-val="item.value"
  16. :prefix="item.prefix"
  17. class="text-3xl"
  18. />
  19. <span class="text-center">{{ item.name }}</span>
  20. </div>
  21. </div>
  22. </el-card>
  23. </template>
  24. <script lang="ts" setup>
  25. import * as ProductSpuApi from '@/api/mall/product/spu'
  26. import * as TradeStatisticsApi from '@/api/mall/statistics/trade'
  27. import * as PayStatisticsApi from '@/api/mall/statistics/pay'
  28. import { CardTitle } from '@/components/Card'
  29. /** 运营数据卡片 */
  30. defineOptions({ name: 'OperationDataCard' })
  31. const router = useRouter() // 路由
  32. /** 数据 */
  33. const data = reactive({
  34. orderUndelivered: { name: '待发货订单', value: 9, routerName: 'TradeOrder' },
  35. orderAfterSaleApply: { name: '退款中订单', value: 4, routerName: 'TradeAfterSale' },
  36. orderWaitePickUp: { name: '待核销订单', value: 0, routerName: 'TradeOrder' },
  37. productAlertStock: { name: '库存预警', value: 0, routerName: 'ProductSpu' },
  38. productForSale: { name: '上架商品', value: 0, routerName: 'ProductSpu' },
  39. productInWarehouse: { name: '仓库商品', value: 0, routerName: 'ProductSpu' },
  40. withdrawAuditing: { name: '提现待审核', value: 0, routerName: 'TradeBrokerageWithdraw' },
  41. rechargePrice: {
  42. name: '账户充值',
  43. value: 0.0,
  44. prefix: '¥',
  45. decimals: 2,
  46. routerName: 'PayWalletRecharge'
  47. }
  48. })
  49. /** 查询订单数据 */
  50. const getOrderData = async () => {
  51. const orderCount = await TradeStatisticsApi.getOrderCount()
  52. if (orderCount.undelivered != null) {
  53. data.orderUndelivered.value = orderCount.undelivered
  54. }
  55. if (orderCount.afterSaleApply != null) {
  56. data.orderAfterSaleApply.value = orderCount.afterSaleApply
  57. }
  58. if (orderCount.pickUp != null) {
  59. data.orderWaitePickUp.value = orderCount.pickUp
  60. }
  61. if (orderCount.auditingWithdraw != null) {
  62. data.withdrawAuditing.value = orderCount.auditingWithdraw
  63. }
  64. }
  65. /** 查询商品数据 */
  66. const getProductData = async () => {
  67. // TODO: @芋艿:这个接口的返回值,是不是用命名字段更好些?
  68. const productCount = await ProductSpuApi.getTabsCount()
  69. data.productForSale.value = productCount['0']
  70. data.productInWarehouse.value = productCount['1']
  71. data.productAlertStock.value = productCount['3']
  72. }
  73. /** 查询钱包充值数据 */
  74. const getWalletRechargeData = async () => {
  75. const paySummary = await PayStatisticsApi.getWalletRechargePrice()
  76. data.rechargePrice.value = paySummary.rechargePrice
  77. }
  78. /**
  79. * 跳转到对应页面
  80. *
  81. * @param routerName 路由页面组件的名称
  82. */
  83. const handleClick = (routerName: string) => {
  84. router.push({ name: routerName })
  85. }
  86. /** 激活时 */
  87. onActivated(() => {
  88. getOrderData()
  89. getProductData()
  90. getWalletRechargeData()
  91. })
  92. /** 初始化 **/
  93. onMounted(() => {
  94. getOrderData()
  95. getProductData()
  96. getWalletRechargeData()
  97. })
  98. </script>