cm-product.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. .recommend {
  65. position: absolute;
  66. top: 0;
  67. left: 34rpx;
  68. width: 68rpx;
  69. height: 55rpx;
  70. background: url(https://static.caimei365.com/app/mini-hehe/icon/recommend.png) no-repeat center;
  71. background-size: 68rpx 55rpx;
  72. }
  73. .cover {
  74. width: $width;
  75. height: $width;
  76. }
  77. .title,
  78. .tags,
  79. .footer {
  80. padding: 0 $grid;
  81. margin: 12rpx 0;
  82. }
  83. .title {
  84. height: 66rpx;
  85. font-size: 26rpx;
  86. color: #333333;
  87. overflow: hidden;
  88. text-overflow: ellipsis;
  89. display: -webkit-box;
  90. -webkit-line-clamp: 2; // 这里控制几行显示省略号
  91. -webkit-box-orient: vertical;
  92. }
  93. .tags {
  94. display: flex;
  95. justify-content: flex-start;
  96. align-items: center;
  97. height: 24rpx;
  98. .tag {
  99. display: flex;
  100. justify-content: center;
  101. align-items: center;
  102. height: 30rpx;
  103. margin-right: 8rpx;
  104. font-size: 22rpx;
  105. &.type1 {
  106. width: 56rpx;
  107. background: #ff457b;
  108. border-radius: 4rpx;
  109. color: #ffffff;
  110. }
  111. &.type2 {
  112. width: 80rpx;
  113. background: url(https://static.caimei365.com/app/mini-hehe/icon/icon-active.png) top center no-repeat;
  114. background-size: 80rpx 30rpx;
  115. color: #f83c6c;
  116. }
  117. }
  118. }
  119. .footer {
  120. display: flex;
  121. justify-content: space-between;
  122. align-items: center;
  123. .add-cart {
  124. display: flex;
  125. justify-content: center;
  126. align-items: center;
  127. width: 44rpx;
  128. height: 44rpx;
  129. background: #ff457b;
  130. color: #fff;
  131. border-radius: 50%;
  132. }
  133. .price {
  134. flex: 1;
  135. font-size: 26rpx;
  136. font-weight: 600;
  137. color: #f83c6c;
  138. }
  139. }
  140. }
  141. </style>