普兆健康管家前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

148 lines
3.4 KiB

2 months ago
2 months ago
2 months ago
  1. <template>
  2. <view class="card product-card__view" :style="cardStyle" @click="jumpToProductDetail">
  3. <view class="card-img flex" :style="imgStyle">
  4. <image class="img" :src="coverImg" mode="aspectFit"></image>
  5. </view>
  6. <view class="card-detail">
  7. <view class="product-name text-ellipsis">{{ data.name }}</view>
  8. <view class="product-sales" v-if="data.sold">{{ `已售出${data.sold}` }}</view>
  9. <view class="flex product-price">
  10. <view>
  11. <view class="product-price-val">
  12. <text>¥</text>
  13. <text class="highlight">{{ data.currentPrice }}</text>
  14. <text>{{ `/${data.unit}` }}</text>
  15. </view>
  16. <view class="product-price-bef" v-if="data.originalPrice">
  17. {{ `¥${data.originalPrice}/${data.unit}` }}
  18. </view>
  19. </view>
  20. <button class="btn flex" @click.stop="onAddCart(data.id)">
  21. <image class="btn-img" src="@/pages_order/static/report/plus.png" mode="widthFix"></image>
  22. </button>
  23. </view>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. props: {
  30. data: {
  31. type: Object,
  32. default() {
  33. return {}
  34. },
  35. },
  36. cardStyle: {
  37. type: String,
  38. default: '',
  39. },
  40. imgStyle: {
  41. type: String,
  42. default: '',
  43. }
  44. },
  45. computed: {
  46. coverImg() {
  47. const { image } = this.data
  48. return image?.split(',')?.[0] || ''
  49. },
  50. },
  51. methods: {
  52. async onAddCart(id) {
  53. const succ = await this.$store.dispatch('addCart', this.data)
  54. console.log('addCartSucc', succ)
  55. succ && this.$emit('addCartSucc')
  56. },
  57. jumpToProductDetail() {
  58. this.$utils.navigateTo(`/pages_order/product/productDetail?id=${this.data.id}`)
  59. },
  60. },
  61. }
  62. </script>
  63. <style scoped lang="scss">
  64. .card {
  65. font-size: 0;
  66. height: 420rpx;
  67. background-image: linear-gradient(#FAFAFF, #F3F3F3);
  68. border: 2rpx solid #FFFFFF;
  69. border-radius: 32rpx;
  70. overflow: hidden;
  71. &-img {
  72. width: 100%;
  73. height: 220rpx;
  74. .img {
  75. width: 100%;
  76. height: 100%;
  77. }
  78. }
  79. &-detail {
  80. padding: 16rpx 24rpx 0 24rpx;
  81. .product {
  82. &-name {
  83. width: 100%;
  84. font-family: PingFang SC;
  85. font-weight: 600;
  86. font-size: 28rpx;
  87. line-height: 1.4;
  88. color: #000000;
  89. }
  90. &-sales {
  91. margin-top: 8rpx;
  92. font-family: PingFang SC;
  93. font-weight: 400;
  94. font-size: 24rpx;
  95. line-height: 1;
  96. color: #8B8B8B;
  97. }
  98. &-price {
  99. margin-top: 16rpx;
  100. justify-content: space-between;
  101. &-val {
  102. font-family: PingFang SC;
  103. font-weight: 600;
  104. font-size: 24rpx;
  105. line-height: 1.4;
  106. color: $uni-color;
  107. .highlight {
  108. font-size: 32rpx;
  109. margin: 0 8rpx;
  110. }
  111. }
  112. &-bef {
  113. margin-top: 4rpx;
  114. text-decoration: line-through;
  115. font-family: PingFang SC;
  116. font-weight: 400;
  117. font-size: 24rpx;
  118. line-height: 1;
  119. color: #8B8B8B;
  120. }
  121. .btn {
  122. width: 56rpx;
  123. height: 56rpx;
  124. border-radius: 50%;
  125. background: $uni-color;
  126. &-img {
  127. width: 20rpx;
  128. height: 20rpx;
  129. }
  130. }
  131. }
  132. }
  133. }
  134. }
  135. </style>