cart-item.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <view class="cart-item">
  3. <!-- 复选框 -->
  4. <view class="checkbox-box">
  5. <u-checkbox v-model="item.checked" shape="circle" active-color="#38C148"
  6. @change="onCheckChange" :disabled="!isValid"></u-checkbox>
  7. </view>
  8. <!-- 商品图片 -->
  9. <view class="image-wrapper">
  10. <image :src="item.cover" mode="aspectFill" class="book-cover"></image>
  11. <!-- 状态遮罩 -->
  12. <view class="status-mask" v-if="!isValid">
  13. <text>{{ statusText }}</text>
  14. </view>
  15. <!-- 库存紧张遮罩 -->
  16. <view class="stock-mask" v-if="isValid && item.stockWarning">
  17. <text>库存紧张</text>
  18. </view>
  19. </view>
  20. <!-- 商品信息 -->
  21. <view class="info-box">
  22. <view class="title">{{ item.title }}</view>
  23. <!-- 标签和品相区域 -->
  24. <view class="tags-quality-row">
  25. <!-- 品相选择 (模拟) -->
  26. <view class="quality-selector">
  27. <text>品相:{{ item.quality || '中等' }}</text>
  28. <u-icon name="arrow-down" size="20" color="#999" style="margin-left: 4rpx;"></u-icon>
  29. </view>
  30. <!-- 已降价标签 -->
  31. <view class="tag green-tag" v-if="item.reducedAmount > 0">
  32. <text>已降¥{{ item.reducedAmount }}</text>
  33. </view>
  34. <!-- 可降价标签 -->
  35. <view class="tag orange-tag" v-if="item.canReduceAmount > 0" @click.stop="handleReduce">
  36. <text>可降¥{{ item.canReduceAmount }}</text>
  37. </view>
  38. </view>
  39. <!-- 底部价格和操作 -->
  40. <view class="bottom-row">
  41. <view class="price-box">
  42. <text class="symbol">¥</text>
  43. <text class="amount">{{ item.price }}</text>
  44. </view>
  45. <!-- 去减钱按钮 -->
  46. <view class="reduce-btn" v-if="item.canReduceAmount > 0" @click.stop="handleReduce">
  47. <text>去减钱</text>
  48. </view>
  49. <!-- 数量加减 -->
  50. <u-number-box v-model="item.num" :min="1" :max="item.stock || 99" :disabled="!isValid"
  51. @change="onNumChange" :size="24"></u-number-box>
  52. </view>
  53. </view>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. props: {
  59. item: {
  60. type: Object,
  61. default: () => ({})
  62. }
  63. },
  64. computed: {
  65. isValid() {
  66. // status: 1-正常, 0-无效/无库存
  67. return this.item.status === 1 && this.item.stock > 0;
  68. },
  69. statusText() {
  70. if (this.item.stock <= 0) return '暂无库存';
  71. if (this.item.status !== 1) return '失效';
  72. return '';
  73. }
  74. },
  75. methods: {
  76. onCheckChange(val) {
  77. this.$emit('check', { id: this.item.id, checked: val.value });
  78. },
  79. onNumChange(val) {
  80. this.$emit('changeNum', { id: this.item.id, num: val.value });
  81. },
  82. handleReduce() {
  83. this.$emit('reduce', this.item);
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .cart-item {
  90. display: flex;
  91. align-items: center;
  92. background-color: #fff;
  93. padding: 30rpx 20rpx;
  94. border-radius: 16rpx;
  95. margin-bottom: 20rpx;
  96. .checkbox-box {
  97. width: 50rpx;
  98. display: flex;
  99. justify-content: center;
  100. flex-shrink: 0;
  101. &.disabled-checkbox {
  102. .circle {
  103. width: 34rpx;
  104. height: 34rpx;
  105. border-radius: 50%;
  106. background-color: #e5e5e5;
  107. }
  108. }
  109. }
  110. .image-wrapper {
  111. position: relative;
  112. width: 150rpx;
  113. height: 200rpx;
  114. border-radius: 8rpx;
  115. overflow: hidden;
  116. flex-shrink: 0;
  117. margin-right: 20rpx;
  118. .book-cover {
  119. width: 100%;
  120. height: 100%;
  121. }
  122. .status-mask {
  123. position: absolute;
  124. bottom: 0;
  125. left: 0;
  126. width: 100%;
  127. height: 40rpx;
  128. background-color: rgba(0, 0, 0, 0.6);
  129. display: flex;
  130. justify-content: center;
  131. align-items: center;
  132. text {
  133. color: #fff;
  134. font-size: 20rpx;
  135. }
  136. }
  137. .stock-mask {
  138. position: absolute;
  139. bottom: 0;
  140. left: 0;
  141. width: 100%;
  142. height: 40rpx;
  143. background-color: #38C148; // Green background
  144. opacity: 0.8;
  145. display: flex;
  146. justify-content: center;
  147. align-items: center;
  148. text {
  149. color: #fff;
  150. font-size: 20rpx;
  151. }
  152. }
  153. }
  154. .info-box {
  155. flex: 1;
  156. height: 220rpx;
  157. display: flex;
  158. flex-direction: column;
  159. justify-content: space-between;
  160. .title {
  161. font-size: 28rpx;
  162. color: #333;
  163. line-height: 1.4;
  164. display: -webkit-box;
  165. -webkit-box-orient: vertical;
  166. -webkit-line-clamp: 2;
  167. overflow: hidden;
  168. font-weight: 500;
  169. }
  170. .tags-quality-row {
  171. display: flex;
  172. flex-wrap: wrap;
  173. justify-content: space-between;
  174. align-items: center;
  175. margin: 20rpx 0 0 0;
  176. .tag {
  177. font-size: 22rpx;
  178. padding: 2rpx 8rpx;
  179. border-radius: 4rpx;
  180. margin-right: 10rpx;
  181. border: 1rpx solid transparent;
  182. margin-bottom: 6rpx;
  183. &.green-tag {
  184. color: #38C148;
  185. border-color: #38C148;
  186. background-color: rgba(56, 193, 72, 0.1);
  187. }
  188. &.orange-tag {
  189. color: #ff6a00;
  190. border-color: #ff6a00;
  191. background-color: rgba(255, 106, 0, 0.1);
  192. }
  193. &.red-text-tag {
  194. background-color: #38C148;
  195. color: #fff;
  196. border: none;
  197. }
  198. }
  199. .quality-selector {
  200. display: flex;
  201. align-items: center;
  202. font-size: 24rpx;
  203. color: #999;
  204. background-color: #f5f5f5;
  205. padding: 4rpx 12rpx;
  206. border-radius: 4rpx;
  207. width: fit-content;
  208. margin-bottom: 6rpx;
  209. margin-right: 10rpx;
  210. order: -1; // Move to front
  211. }
  212. }
  213. .bottom-row {
  214. display: flex;
  215. align-items: center;
  216. justify-content: space-between;
  217. margin-top: auto;
  218. .price-box {
  219. color: #e02020;
  220. font-weight: bold;
  221. .symbol {
  222. font-size: 24rpx;
  223. }
  224. .amount {
  225. font-size: 36rpx;
  226. }
  227. }
  228. .reduce-btn {
  229. background-color: #38C148;
  230. color: #fff;
  231. font-size: 20rpx;
  232. padding: 6rpx 16rpx;
  233. border-radius: 20rpx;
  234. margin-left: 10rpx;
  235. margin-right: auto; // Push num box to right
  236. }
  237. }
  238. }
  239. }
  240. </style>