cm-product.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <template>
  2. <view class="cm-product" @click.stop="detail">
  3. <view class="recommend" v-if="data.recommend === '1'"></view>
  4. <!-- 封面 -->
  5. <image class="cover" :src="data.mainImage"></image>
  6. <view class="content">
  7. <!-- 标题名称 -->
  8. <view class="title">{{ data.name }}</view>
  9. <!-- 标签 -->
  10. <view class="tags">
  11. <!-- <view class="tag type1">自营</view> -->
  12. <view class="tag type3">拼团价</view>
  13. <view class="tag type2" v-if="data.activeStatus == 1">活动价</view>
  14. <view class="tag type2" v-if="data.couponsLogo">优惠券</view>
  15. </view>
  16. <!-- 底部 -->
  17. <view class="footer">
  18. <!-- 价格 -->
  19. <view class="price">
  20. <text>¥{{ data.price | priceFormat }}</text>
  21. <text class="delete">¥{{ data.price | priceFormat }}</text>
  22. </view>
  23. <!-- 加入购物车 -->
  24. <view class="add-cart iconfont icon-gouwuche" @click.stop="addCart"></view>
  25. </view>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. export default {
  31. name: 'cm-product',
  32. props: {
  33. data: {
  34. type: Object,
  35. default: () => {}
  36. }
  37. },
  38. filters: {
  39. priceFormat(val) {
  40. return Number(val).toFixed(2)
  41. }
  42. },
  43. methods: {
  44. // 跳转商品详情
  45. detail() {
  46. uni.navigateTo({
  47. url: `/pages/goods/product-detail?productId=${this.data.productId}&jumpState=1`
  48. })
  49. },
  50. // 加入购物车
  51. addCart() {
  52. this.$store.dispatch('cart/addToCart', { productId: this.data.productId })
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. $width: 339rpx;
  59. $height: 532rpx;
  60. $radius: 16rpx;
  61. $grid: 24rpx;
  62. .cm-product {
  63. position: relative;
  64. width: $width;
  65. height: $height;
  66. background: #fff;
  67. border-radius: $radius;
  68. overflow: hidden;
  69. .recommend {
  70. position: absolute;
  71. top: 0;
  72. left: 34rpx;
  73. width: 68rpx;
  74. height: 55rpx;
  75. background: url(https://static.caimei365.com/app/mini-hehe/icon/recommend.png) no-repeat center;
  76. background-size: 68rpx 55rpx;
  77. }
  78. .cover {
  79. width: $width;
  80. height: $width;
  81. }
  82. .title,
  83. .tags,
  84. .footer {
  85. padding: 0 $grid;
  86. margin: 12rpx 0;
  87. }
  88. .title {
  89. height: 70rpx;
  90. font-size: 26rpx;
  91. line-height: 35rpx;
  92. color: #333333;
  93. overflow: hidden;
  94. text-overflow: ellipsis;
  95. display: -webkit-box;
  96. -webkit-line-clamp: 2; // 这里控制几行显示省略号
  97. -webkit-box-orient: vertical;
  98. }
  99. .tags {
  100. display: flex;
  101. justify-content: flex-start;
  102. align-items: center;
  103. height: 24rpx;
  104. .tag {
  105. display: flex;
  106. justify-content: center;
  107. align-items: center;
  108. height: 30rpx;
  109. margin-right: 8rpx;
  110. font-size: 22rpx;
  111. &.type1 {
  112. width: 56rpx;
  113. background: #ff457b;
  114. border-radius: 4rpx;
  115. color: #ffffff;
  116. }
  117. &.type2 {
  118. width: 80rpx;
  119. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center no-repeat;
  120. background-size: 80rpx 30rpx;
  121. color: #f83c6c;
  122. }
  123. &.type3 {
  124. width: 80rpx;
  125. background: linear-gradient(270deg, #ff457b 0%, #b03bb8 51%, #6431f2 100%);
  126. color: #fff;
  127. border-radius: 4rpx;
  128. }
  129. }
  130. }
  131. .footer {
  132. position: relative;
  133. .add-cart {
  134. position: absolute;
  135. bottom: 0;
  136. right: $grid;
  137. display: flex;
  138. justify-content: center;
  139. align-items: center;
  140. width: 44rpx;
  141. height: 44rpx;
  142. background: #ff457b;
  143. color: #fff;
  144. border-radius: 50%;
  145. }
  146. .price {
  147. overflow: hidden;
  148. text-overflow: ellipsis;
  149. display: -webkit-box;
  150. -webkit-line-clamp: 1; // 这里控制几行显示省略号
  151. -webkit-box-orient: vertical;
  152. box-sizing: border-box;
  153. padding-right: $grid;
  154. font-size: 26rpx;
  155. font-weight: 600;
  156. color: #f83c6c;
  157. .delete{
  158. font-size: 20rpx;
  159. color: #999999;
  160. text-decoration: line-through;
  161. font-weight: normal;
  162. margin-left: 10rpx;
  163. }
  164. }
  165. }
  166. }
  167. </style>