巴青农资商城

CheckoutGoodsRow.vue 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <template>
  2. <view class="checkout-goods">
  3. <image-preview class="checkout-goods__pic" :src="goods.mainPic" />
  4. <view class="checkout-goods__info">
  5. <text class="checkout-goods__name">{{ goods.goodsName }}</text>
  6. <view v-if="goods.specList && goods.specList.length" class="checkout-goods__specs">
  7. <text
  8. v-for="(spec, index) in goods.specList"
  9. :key="index"
  10. class="checkout-goods__spec"
  11. >{{ spec }}</text>
  12. </view>
  13. <text v-if="goods.serviceDesc" class="checkout-goods__service">{{ goods.serviceDesc }}</text>
  14. <view class="checkout-goods__price-row">
  15. <text class="checkout-goods__price">¥{{ goods.priceText }}</text>
  16. <view class="checkout-goods__qty">
  17. <view class="qty-btn" @click="onMinus">-</view>
  18. <text class="qty-num">{{ goods.quantity }}</text>
  19. <view class="qty-btn" @click="onPlus">+</view>
  20. </view>
  21. </view>
  22. <text class="checkout-goods__subtotal">小计 ¥{{ goods.subtotalText }}</text>
  23. </view>
  24. </view>
  25. </template>
  26. <script setup>
  27. const props = defineProps({
  28. goods: {
  29. type: Object,
  30. required: true
  31. }
  32. })
  33. const emit = defineEmits(['quantity-change'])
  34. function onMinus() {
  35. const next = Math.max(1, props.goods.quantity - 1)
  36. if (next !== props.goods.quantity) {
  37. emit('quantity-change', next)
  38. }
  39. }
  40. function onPlus() {
  41. const max = props.goods.maxStock || 999999
  42. const next = props.goods.quantity + 1
  43. if (next > max) {
  44. uni.showToast({ title: '库存不足', icon: 'none' })
  45. return
  46. }
  47. emit('quantity-change', next)
  48. }
  49. </script>
  50. <style lang="scss" scoped>
  51. .checkout-goods {
  52. display: flex;
  53. padding: 20rpx 24rpx;
  54. background: #fff;
  55. }
  56. .checkout-goods__pic {
  57. width: 160rpx;
  58. height: 160rpx;
  59. border-radius: 8rpx;
  60. background: #eee;
  61. flex-shrink: 0;
  62. }
  63. .checkout-goods__info {
  64. flex: 1;
  65. margin-left: 16rpx;
  66. min-width: 0;
  67. }
  68. .checkout-goods__name {
  69. font-size: 28rpx;
  70. color: #333;
  71. line-height: 1.4;
  72. }
  73. .checkout-goods__specs {
  74. margin-top: 8rpx;
  75. display: flex;
  76. flex-direction: column;
  77. gap: 4rpx;
  78. }
  79. .checkout-goods__spec {
  80. font-size: 24rpx;
  81. color: #999;
  82. }
  83. .checkout-goods__service {
  84. display: block;
  85. margin-top: 8rpx;
  86. font-size: 22rpx;
  87. color: #2e7d32;
  88. }
  89. .checkout-goods__price-row {
  90. margin-top: 12rpx;
  91. display: flex;
  92. align-items: center;
  93. justify-content: space-between;
  94. }
  95. .checkout-goods__price {
  96. font-size: 30rpx;
  97. color: #e53935;
  98. font-weight: 600;
  99. }
  100. .checkout-goods__qty {
  101. display: flex;
  102. align-items: center;
  103. border: 1rpx solid #e0e0e0;
  104. border-radius: 8rpx;
  105. overflow: hidden;
  106. }
  107. .qty-btn {
  108. width: 52rpx;
  109. height: 52rpx;
  110. line-height: 52rpx;
  111. text-align: center;
  112. font-size: 32rpx;
  113. color: #333;
  114. background: #f5f5f5;
  115. }
  116. .qty-num {
  117. min-width: 56rpx;
  118. text-align: center;
  119. font-size: 26rpx;
  120. }
  121. .checkout-goods__subtotal {
  122. display: block;
  123. margin-top: 8rpx;
  124. font-size: 24rpx;
  125. color: #666;
  126. text-align: right;
  127. }
  128. </style>