ProductRank.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <template>
  2. <el-card shadow="never">
  3. <template #header>
  4. <!-- 标题 -->
  5. <div class="flex flex-row items-center justify-between">
  6. <CardTitle title="商品排行" />
  7. <!-- 查询条件 -->
  8. <ShortcutDateRangePicker ref="shortcutDateRangePicker" @change="handleDateRangeChange" />
  9. </div>
  10. </template>
  11. <!-- 排行列表 -->
  12. <el-table v-loading="loading" :data="list" @sort-change="handleSortChange">
  13. <el-table-column label="商品 ID" prop="spuId" min-width="70" />
  14. <el-table-column label="商品图片" align="center" prop="picUrl" width="80">
  15. <template #default="{ row }">
  16. <el-image
  17. :src="row.picUrl"
  18. :preview-src-list="[row.picUrl]"
  19. class="h-30px w-30px"
  20. preview-teleported
  21. />
  22. </template>
  23. </el-table-column>
  24. <el-table-column label="商品名称" prop="name" min-width="200" :show-overflow-tooltip="true" />
  25. <el-table-column label="浏览量" prop="browseCount" min-width="90" sortable="custom" />
  26. <el-table-column label="访客数" prop="browseUserCount" min-width="90" sortable="custom" />
  27. <el-table-column label="加购件数" prop="cartCount" min-width="105" sortable="custom" />
  28. <el-table-column label="下单件数" prop="orderCount" min-width="105" sortable="custom" />
  29. <el-table-column label="支付件数" prop="orderPayCount" min-width="105" sortable="custom" />
  30. <el-table-column
  31. label="支付金额"
  32. prop="orderPayPrice"
  33. min-width="105"
  34. sortable="custom"
  35. :formatter="fenToYuanFormat"
  36. />
  37. <el-table-column label="收藏数" prop="favoriteCount" min-width="90" sortable="custom" />
  38. <el-table-column
  39. label="访客-支付转化率(%)"
  40. prop="browseConvertPercent"
  41. min-width="180"
  42. sortable="custom"
  43. :formatter="formatConvertRate"
  44. />
  45. </el-table>
  46. <!-- 分页 -->
  47. <Pagination
  48. :total="total"
  49. v-model:page="queryParams.pageNo"
  50. v-model:limit="queryParams.pageSize"
  51. @pagination="getSpuList"
  52. />
  53. </el-card>
  54. </template>
  55. <script lang="ts" setup>
  56. import { ProductStatisticsApi, ProductStatisticsVO } from '@/api/mall/statistics/product'
  57. import { CardTitle } from '@/components/Card'
  58. import { buildSortingField } from '@/utils'
  59. import { fenToYuanFormat } from '@/utils/formatter'
  60. /** 商品排行 */
  61. defineOptions({ name: 'ProductRank' })
  62. // 格式化:访客-支付转化率
  63. const formatConvertRate = (row: ProductStatisticsVO) => {
  64. return `${row.browseConvertPercent}%`
  65. }
  66. const handleSortChange = (params: any) => {
  67. queryParams.sortingFields = [buildSortingField(params)]
  68. getSpuList()
  69. }
  70. const handleDateRangeChange = (times: any[]) => {
  71. queryParams.times = times as []
  72. getSpuList()
  73. }
  74. const shortcutDateRangePicker = ref()
  75. // 查询参数
  76. const queryParams = reactive({
  77. pageNo: 1,
  78. pageSize: 10,
  79. times: [],
  80. sortingFields: {}
  81. })
  82. const loading = ref(false) // 列表的加载中
  83. const total = ref(0) // 列表的总页数
  84. const list = ref<ProductStatisticsVO[]>([]) // 列表的数据
  85. /** 查询商品列表 */
  86. const getSpuList = async () => {
  87. loading.value = true
  88. try {
  89. const data = await ProductStatisticsApi.getProductStatisticsRankPage(queryParams)
  90. list.value = data.list
  91. total.value = data.total
  92. } finally {
  93. loading.value = false
  94. }
  95. }
  96. /** 初始化 **/
  97. onMounted(async () => {
  98. await getSpuList()
  99. })
  100. </script>
  101. <style lang="scss" scoped></style>