cm-product.vue 3.8 KB

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