product-rank.vue 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view class="page">
  3. <NavBar title="商品排行" :showBack="true" />
  4. <scroll-view class="list-scroll" scroll-y @scrolltolower="loadMore">
  5. <view class="card-set">
  6. <view class="card" v-for="(item, idx) in list" :key="item.productId">
  7. <view class="card-head">
  8. <view class="rank-badge" :class="'top' + Math.min(idx + 1, 3)"><text>{{ idx + 1 }}</text></view>
  9. <view class="card-center">
  10. <text class="card-name">{{ item.productName }}</text>
  11. <text class="card-meta">销量 {{ item.salesCount || 0 }}</text>
  12. </view>
  13. <text class="card-amount">{{ formatMoney(item.salesAmount || 0) }}</text>
  14. </view>
  15. </view>
  16. </view>
  17. <view class="load-tip" v-if="loading"><view class="dot-row"><view class="pulse-dot"></view><view class="pulse-dot"></view><view class="pulse-dot"></view></view></view>
  18. <view class="end-tip" v-if="!hasMore && list.length > 0"><text>没有更多了</text></view>
  19. <view class="empty-state" v-if="!loading && list.length === 0"><text class="empty-text">暂无数据</text></view>
  20. </scroll-view>
  21. </view>
  22. </template>
  23. <script setup lang="ts">
  24. import { ref, onMounted } from 'vue';
  25. import NavBar from '@/components/NavBar.vue';
  26. import { get } from '@/utils/request';
  27. import { formatMoney } from '@/utils/common';
  28. const list = ref<any[]>([]); const loading = ref(false); const hasMore = ref(true); const page = ref(1);
  29. const loadData = async () => {
  30. loading.value = true;
  31. try {
  32. const end = new Date().toISOString().slice(0,10); const start = new Date(Date.now()-30*86400000).toISOString().slice(0,10);
  33. const res = await get('/statistics/product/list', { page: page.value, pageSize: 20, startDate: start, endDate: end, sortBy: 'salesAmount', sortOrder: 'desc' });
  34. if (page.value === 1) list.value = res.list || []; else list.value = [...list.value, ...(res.list || [])];
  35. hasMore.value = list.value.length < (res.total || 0);
  36. } catch { }
  37. loading.value = false;
  38. };
  39. const loadMore = () => { if (loading.value || !hasMore.value) return; page.value++; loadData(); };
  40. onMounted(() => loadData());
  41. </script>
  42. <style lang="scss" scoped>
  43. .page { height: 100vh; background: $bg-color-page; display: flex; flex-direction: column; }
  44. .list-scroll { flex: 1; height: 0; }
  45. .card-set { padding: 20rpx 24rpx; display: flex; flex-direction: column; gap: 16rpx; }
  46. .card { background: $bg-color-card; border-radius: $radius-md; padding: 20rpx 24rpx; box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.05); display: flex; flex-direction: column; }
  47. .card-head { display: flex; align-items: center; }
  48. .rank-badge { width: 44rpx; height: 44rpx; border-radius: 10rpx; display: flex; align-items: center; justify-content: center; margin-right: 16rpx; flex-shrink: 0; }
  49. .rank-badge text { font-size: 24rpx; font-weight: 700; color: #fff; }
  50. .rank-badge.top1 { background: #f59e0b; } .rank-badge.top2 { background: #94a3b8; } .rank-badge.top3 { background: #cd853f; }
  51. .card-center { flex: 1; min-width: 0; }
  52. .card-name { font-size: 28rpx; font-weight: 500; color: $text-color-primary; display: block; margin-bottom: 4rpx; }
  53. .card-meta { font-size: 22rpx; color: $text-color-muted; }
  54. .card-amount { font-size: 28rpx; font-weight: 600; color: $primary-color-dark; white-space: nowrap; }
  55. .load-tip { display: flex; justify-content: center; padding: 36rpx 0; }
  56. .dot-row { display: flex; gap: 8rpx; }
  57. .pulse-dot { width: 9rpx; height: 9rpx; background: $text-color-placeholder; border-radius: 50%; animation: pulse 1.2s ease-in-out infinite; }
  58. .pulse-dot:nth-child(2) { animation-delay: 0.2s; } .pulse-dot:nth-child(3) { animation-delay: 0.4s; }
  59. @keyframes pulse { 0%,80%,100% { transform: scale(0.5); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }
  60. .end-tip { text-align: center; padding: 36rpx; font-size: 24rpx; color: $text-color-muted; }
  61. .empty-state { display: flex; align-items: center; justify-content: center; padding: 100rpx 0; }
  62. .empty-text { font-size: 28rpx; color: $text-color-muted; }
  63. </style>