巴青农资商城

CartItemRow.vue 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <view class="cart-item" :class="{ 'cart-item--invalid': !item.purchasable }">
  3. <view
  4. class="cart-item__check"
  5. :class="{ 'cart-item__check--disabled': !item.purchasable }"
  6. @click.stop="onCheckTap"
  7. >
  8. <view class="check-icon" :class="{ 'check-icon--on': item.checked && item.purchasable }">
  9. <u-icon v-if="item.checked && item.purchasable" name="checkbox-mark" color="#fff" size="14" />
  10. </view>
  11. </view>
  12. <view class="cart-item__main" @click="emit('goods-click', item)">
  13. <image-preview class="cart-item__pic" :src="item.mainPic" />
  14. <view class="cart-item__info">
  15. <text class="cart-item__name">{{ item.goodsName }}</text>
  16. <view v-if="item.specList && item.specList.length" class="cart-item__specs">
  17. <text
  18. v-for="(spec, specIndex) in item.specList"
  19. :key="specIndex"
  20. class="cart-item__spec"
  21. >{{ spec }}</text>
  22. </view>
  23. <view class="cart-item__price-row">
  24. <text class="cart-item__price">¥{{ item.priceText }}</text>
  25. <text v-if="item.subtotalText" class="cart-item__subtotal">小计 ¥{{ item.subtotalText }}</text>
  26. <text v-if="item.invalidLabel" class="cart-item__tag">{{ item.invalidLabel }}</text>
  27. </view>
  28. </view>
  29. </view>
  30. <view class="cart-item__side">
  31. <view v-if="item.purchasable" class="cart-item__qty">
  32. <view class="qty-btn" @click.stop="onMinus">-</view>
  33. <text class="qty-num">{{ item.quantity }}</text>
  34. <view class="qty-btn" @click.stop="onPlus">+</view>
  35. </view>
  36. <text v-else class="cart-item__qty-text">×{{ item.quantity }}</text>
  37. <text class="cart-item__del" @click.stop="emit('delete', item)">删除</text>
  38. </view>
  39. </view>
  40. </template>
  41. <script setup>
  42. const props = defineProps({
  43. item: {
  44. type: Object,
  45. required: true
  46. }
  47. })
  48. const emit = defineEmits(['check-change', 'quantity-change', 'delete', 'goods-click'])
  49. function onCheckTap() {
  50. if (!props.item.purchasable) return
  51. emit('check-change', props.item, !props.item.checked)
  52. }
  53. function onMinus() {
  54. if (!props.item.purchasable) return
  55. const next = Math.max(1, props.item.quantity - 1)
  56. if (next === props.item.quantity) return
  57. emit('quantity-change', props.item, next)
  58. }
  59. function onPlus() {
  60. if (!props.item.purchasable) return
  61. emit('quantity-change', props.item, props.item.quantity + 1)
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .cart-item {
  66. display: flex;
  67. align-items: flex-start;
  68. padding: 20rpx 0;
  69. border-bottom: 1rpx solid #f5f5f5;
  70. }
  71. .cart-item--invalid {
  72. opacity: 0.72;
  73. }
  74. .cart-item__check {
  75. padding-top: 40rpx;
  76. padding-right: 12rpx;
  77. }
  78. .cart-item__check--disabled {
  79. opacity: 0.4;
  80. }
  81. .check-icon {
  82. width: 36rpx;
  83. height: 36rpx;
  84. border: 2rpx solid #ccc;
  85. border-radius: 50%;
  86. display: flex;
  87. align-items: center;
  88. justify-content: center;
  89. background: #fff;
  90. }
  91. .check-icon--on {
  92. background: #2e7d32;
  93. border-color: #2e7d32;
  94. }
  95. .cart-item__main {
  96. flex: 1;
  97. display: flex;
  98. min-width: 0;
  99. }
  100. .cart-item__pic {
  101. width: 160rpx;
  102. height: 160rpx;
  103. border-radius: 8rpx;
  104. background: #eee;
  105. flex-shrink: 0;
  106. }
  107. .cart-item__info {
  108. flex: 1;
  109. margin-left: 16rpx;
  110. min-width: 0;
  111. }
  112. .cart-item__name {
  113. font-size: 28rpx;
  114. color: #333;
  115. line-height: 1.4;
  116. display: -webkit-box;
  117. -webkit-line-clamp: 2;
  118. -webkit-box-orient: vertical;
  119. overflow: hidden;
  120. }
  121. .cart-item__specs {
  122. margin-top: 8rpx;
  123. display: flex;
  124. flex-direction: column;
  125. gap: 4rpx;
  126. }
  127. .cart-item__spec {
  128. font-size: 24rpx;
  129. color: #999;
  130. line-height: 1.4;
  131. }
  132. .cart-item__price-row {
  133. margin-top: 12rpx;
  134. display: flex;
  135. align-items: center;
  136. flex-wrap: wrap;
  137. gap: 12rpx;
  138. }
  139. .cart-item__price {
  140. font-size: 30rpx;
  141. color: #e53935;
  142. font-weight: 600;
  143. }
  144. .cart-item__subtotal {
  145. font-size: 24rpx;
  146. color: #666;
  147. }
  148. .cart-item__tag {
  149. font-size: 22rpx;
  150. color: #e65100;
  151. background: #fff3e0;
  152. padding: 4rpx 10rpx;
  153. border-radius: 6rpx;
  154. }
  155. .cart-item__side {
  156. display: flex;
  157. flex-direction: column;
  158. align-items: flex-end;
  159. padding-top: 8rpx;
  160. margin-left: 8rpx;
  161. }
  162. .cart-item__qty {
  163. display: flex;
  164. align-items: center;
  165. border: 1rpx solid #e0e0e0;
  166. border-radius: 8rpx;
  167. overflow: hidden;
  168. }
  169. .qty-btn {
  170. width: 52rpx;
  171. height: 52rpx;
  172. line-height: 52rpx;
  173. text-align: center;
  174. font-size: 32rpx;
  175. color: #333;
  176. background: #f5f5f5;
  177. }
  178. .qty-num {
  179. min-width: 56rpx;
  180. text-align: center;
  181. font-size: 26rpx;
  182. color: #333;
  183. }
  184. .cart-item__qty-text {
  185. font-size: 26rpx;
  186. color: #999;
  187. }
  188. .cart-item__del {
  189. margin-top: 16rpx;
  190. font-size: 24rpx;
  191. color: #999;
  192. }
  193. </style>