GoodsCard.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <view class="goods-card" @click="showProduct(item)">
  3. <view class="img-wrap">
  4. <image class="img" :src="item.image" mode="aspectFill"></image>
  5. <view class="tag-row" v-if="tagList && tagList.length > 0">
  6. <text class="tag-chip" v-for="(t, i) in tagList" :key="i">{{ t }}</text>
  7. </view>
  8. </view>
  9. <view class="info">
  10. <view class="title line2">{{ item.productName }}</view>
  11. <view class="x-bc">
  12. <view class="price-row">
  13. <text class="unit"v-if="showPrice">¥</text>
  14. <text class="price" v-if="showPrice">{{item.price != null ? item.price : item.payPrice || 0 }}</text>
  15. <text class="ot-price" v-if="item.otPrice != null">原价¥{{item.otPrice }}</text>
  16. </view>
  17. <view class="meta-row" v-if="item.sales != null || item.positiveRating != null">
  18. <text class="sales" v-if="item.sales != null">已售{{ item.sales }}</text>
  19. <text v-if="item.positiveRating">I</text>
  20. <text class="good-rate" v-if="item.positiveRating != null">好评{{ item.positiveRating }}%</text>
  21. </view>
  22. </view>
  23. </view>
  24. </view>
  25. </template>
  26. <script>
  27. export default {
  28. name: 'GoodsCard',
  29. props: {
  30. item: { type: Object, required: true },
  31. showPrice: { type: Boolean, default: true },
  32. defaultImg: {
  33. type: String,
  34. default: 'https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/no-img.png'
  35. }
  36. },
  37. computed: {
  38. tagList() {
  39. const item = this.item
  40. if (!item) return []
  41. if (Array.isArray(item.tagList)) return item.tagList
  42. if (Array.isArray(item.tagNames)) return item.tagNames
  43. if (Array.isArray(item.tags)) return item.tags.map(t => typeof t === 'string' ? t : (t.tagName || t.name))
  44. if (item.tag) return [item.tag]
  45. return []
  46. }
  47. },
  48. methods:{
  49. showProduct(item) {
  50. uni.navigateTo({ url: '/pages/shopping/productDetails?productId=' + item.productId })
  51. }
  52. }
  53. };
  54. </script>
  55. <style lang="scss" scoped>
  56. .goods-card {
  57. width: 100%;
  58. background: #fff;
  59. border-radius: 16rpx;
  60. overflow: hidden;
  61. box-sizing: border-box;
  62. display: flex;
  63. flex-direction:column;
  64. align-items: stretch;
  65. }
  66. .img-wrap {
  67. width: 100%;
  68. height: 394rpx;
  69. flex-shrink: 0;
  70. background: #f5f5f5;
  71. position: relative;
  72. }
  73. .img {
  74. width: 100%;
  75. height: 100%;
  76. }
  77. .info {
  78. flex: 1;
  79. padding: 20rpx;
  80. display: flex;
  81. flex-direction: column;
  82. justify-content: space-between;
  83. min-width: 0;
  84. }
  85. .tag-row {
  86. position: absolute;
  87. bottom:0;
  88. display: flex;
  89. flex-wrap: wrap;
  90. gap: 12rpx;
  91. padding: 0 12rpx;
  92. margin-bottom: 12rpx;
  93. }
  94. .tag-chip {
  95. font-family: PingFangSC, PingFang SC;
  96. font-weight: 400;
  97. font-size: 30rpx;
  98. color: #AA4726;
  99. line-height: 42rpx;
  100. background: #FFF4F1;
  101. padding: 4rpx 12rpx;
  102. border-radius: 6rpx;
  103. }
  104. .title {
  105. font-family: PingFangSC, PingFang SC;
  106. font-weight: 500;
  107. font-size: 36rpx;
  108. color: rgba(0,0,0,0.85);
  109. line-height: 50rpx;
  110. }
  111. .line2 {
  112. display: -webkit-box;
  113. -webkit-line-clamp: 1;
  114. -webkit-box-orient: vertical;
  115. overflow: hidden;
  116. }
  117. .price-row {
  118. display: flex;
  119. align-items: baseline;
  120. gap: 12rpx;
  121. margin-top: 8rpx;
  122. }
  123. .unit{
  124. font-weight: 600;
  125. font-size: 28rpx;
  126. color: #FF233C;
  127. }
  128. .price {
  129. font-size: 44rpx;
  130. font-weight: 600;
  131. color: #FF233C;
  132. }
  133. .ot-price {
  134. font-size: 28rpx;
  135. color: #999;
  136. text-decoration: line-through;
  137. }
  138. .meta-row {
  139. display: flex;
  140. align-items: center;
  141. gap: 8rpx;
  142. margin-top: 8rpx;
  143. font-size: 28rpx;
  144. color: #999;
  145. }
  146. // .sales,
  147. // .good-rate {
  148. // font-size: 28rpx;
  149. // color: #999;
  150. // }
  151. .sales{
  152. // border-right: 1rpx solid #e5e5e5; /* 右侧竖线 */
  153. // padding-right: 14rpx; /* 竖线与文字的间距 */
  154. }
  155. </style>