cm-product.vue 3.7 KB

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