DimensionProductList.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="dimension-product-list">
  3. <view class="section-header">
  4. <text class="section-title">{{ title }}</text>
  5. </view>
  6. <view class="product-grid" v-if="products.length > 0">
  7. <view class="product-card" v-for="product in products" :key="product.id" @click="goProduct(product)">
  8. <image class="product-cover" :src="product.coverImage || '/static/default-product.png'" mode="aspectFill"></image>
  9. <view class="product-info">
  10. <text class="product-name">{{ product.name }}</text>
  11. <view class="product-price-row">
  12. <text class="product-price">¥{{ (product.price / 100).toFixed(2) }}</text>
  13. <text class="product-reason" v-if="product.reason">{{ product.reason }}</text>
  14. </view>
  15. <view class="match-badge" v-if="product.matchScore">
  16. <text class="match-score">{{ product.matchScore }}分</text>
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. <view class="empty-state" v-else-if="!loading">
  22. <text class="empty-text">暂无推荐商品</text>
  23. </view>
  24. <view class="loading-state" v-if="loading">
  25. <text class="loading-text">加载中...</text>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import { getDimensionProducts, clickRepurchaseReminder } from '../../utils/api.js'
  31. export default {
  32. props: {
  33. dimensionCode: { type: String, required: true },
  34. familyId: { type: [Number, String], required: true },
  35. memberScores: { type: Object, default: function() { return {} } },
  36. title: { type: String, default: '为你推荐' }
  37. },
  38. data: function() {
  39. return {
  40. products: [],
  41. loading: false
  42. }
  43. },
  44. attached: function() {
  45. this.loadProducts()
  46. },
  47. methods: {
  48. loadProducts: function() {
  49. var self = this
  50. self.loading = true
  51. var params = {
  52. dimensionCode: self.dimensionCode,
  53. familyId: self.familyId,
  54. limit: 6
  55. }
  56. if (self.memberScores && Object.keys(self.memberScores).length > 0) {
  57. params.memberScores = self.memberScores
  58. }
  59. getDimensionProducts(params).then(function(res) {
  60. self.loading = false
  61. if (res.code === 200 && res.data) {
  62. self.products = Array.isArray(res.data) ? res.data : (res.data.records || [])
  63. }
  64. }).catch(function() {
  65. self.loading = false
  66. })
  67. },
  68. goProduct: function(product) {
  69. if (!product || !product.id) return
  70. // 如果有点击追踪 API,先调用
  71. // 这里简化处理,直接跳转
  72. uni.navigateTo({
  73. url: '/pages/discover/product-detail/product-detail?id=' + product.id + '&from=dimension'
  74. })
  75. }
  76. }
  77. }
  78. </script>
  79. <style scoped>
  80. .dimension-product-list {
  81. margin: 20rpx 20rpx;
  82. }
  83. .section-header {
  84. display: flex;
  85. justify-content: space-between;
  86. align-items: center;
  87. margin-bottom: 20rpx;
  88. }
  89. .section-title {
  90. font-size: 30rpx;
  91. font-weight: bold;
  92. color: #333;
  93. }
  94. .product-grid {
  95. display: flex;
  96. flex-wrap: wrap;
  97. gap: 20rpx;
  98. }
  99. .product-card {
  100. width: calc(50% - 10rpx);
  101. background: #fff;
  102. border-radius: 16rpx;
  103. overflow: hidden;
  104. box-shadow: 0 2rpx 12rpx rgba(0,0,0,0.06);
  105. }
  106. .product-cover {
  107. width: 100%;
  108. height: 240rpx;
  109. background: #f0f0f0;
  110. }
  111. .product-info {
  112. padding: 16rpx;
  113. }
  114. .product-name {
  115. font-size: 26rpx;
  116. color: #333;
  117. display: block;
  118. margin-bottom: 12rpx;
  119. overflow: hidden;
  120. text-overflow: ellipsis;
  121. display: -webkit-box;
  122. -webkit-line-clamp: 2;
  123. -webkit-box-orient: vertical;
  124. }
  125. .product-price-row {
  126. display: flex;
  127. align-items: center;
  128. justify-content: space-between;
  129. margin-bottom: 8rpx;
  130. }
  131. .product-price {
  132. font-size: 28rpx;
  133. color: #F97316;
  134. font-weight: bold;
  135. }
  136. .product-reason {
  137. font-size: 22rpx;
  138. color: #999;
  139. max-width: 60%;
  140. overflow: hidden;
  141. text-overflow: ellipsis;
  142. white-space: nowrap;
  143. }
  144. .match-badge {
  145. display: inline-block;
  146. background: linear-gradient(135deg, #6366F1, #818CF8);
  147. padding: 4rpx 16rpx;
  148. border-radius: 20rpx;
  149. margin-top: 8rpx;
  150. }
  151. .match-score {
  152. font-size: 22rpx;
  153. color: #fff;
  154. font-weight: 500;
  155. }
  156. .empty-state {
  157. display: flex;
  158. justify-content: center;
  159. padding: 60rpx 0;
  160. }
  161. .empty-text {
  162. font-size: 26rpx;
  163. color: #999;
  164. }
  165. .loading-state {
  166. display: flex;
  167. justify-content: center;
  168. padding: 40rpx 0;
  169. }
  170. .loading-text {
  171. font-size: 24rpx;
  172. color: #999;
  173. }
  174. </style>