cart-item.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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" @change="onCheckChange"
  6. :disabled="!isValid" style="width:100%"></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.stockStatus === 2">
  17. <text>库存紧张</text>
  18. </view>
  19. </view>
  20. <!-- 商品信息 -->
  21. <view class="info-box">
  22. <view class="title" style="font-weight:500">{{ item.bookName }}</view>
  23. <!-- 标签和品相区域 -->
  24. <view class="tags-quality-row">
  25. <!-- 品相选择 -->
  26. <view class="quality-selector" @click.stop="handleSelectCondition">
  27. <text>品相:{{ conditionName }}</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.currReduceMoney > 0">
  32. <text>已降¥{{ item.currReduceMoney }}</text>
  33. </view>
  34. <!-- 可降价标签 -->
  35. <view class="tag orange-tag" v-if="canReduce" @click.stop="handleReduce">
  36. <text>可降¥{{ item.reduceMoney }}</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.productPrice }}</text>
  44. </view>
  45. <!-- 去减钱按钮 -->
  46. <view class="reduce-btn" v-if="canReduce" @click.stop="handleReduce">
  47. <text>去减钱</text>
  48. </view>
  49. <!-- 数量加减 -->
  50. <u-number-box v-model="item.quantity" :min="1" :max="item.availableStock || 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. data() {
  65. return {
  66. };
  67. },
  68. computed: {
  69. conditionName() {
  70. // 如果是数字,映射;如果是字符串,直接显示
  71. return this.$conditionMap[this.item.conditionType] || this.item.conditionType || '-';
  72. },
  73. isValid() {
  74. // stockStatus: 1-有库存 2-库存紧张 3-暂无库存
  75. return this.item.stockStatus !== 3 && this.item.availableStock > 0;
  76. },
  77. statusText() {
  78. if (this.item.stockStatus === 3 || this.item.availableStock <= 0) return '暂无库存';
  79. // 如果后端定义了其他状态,你可能需要处理它们
  80. return '';
  81. },
  82. canReduce() {
  83. // 逻辑:如果成功减价次数少于允许的最大次数,且 reduceMoney > 0
  84. // 或者简单地如果 reduceMoney > 0 且我们还没有达到限制?
  85. // 假设 reduceMoney 是单价减少额。
  86. return (this.item.reduceNum < this.item.maxReduceNum) && (this.item.reduceMoney > 0);
  87. }
  88. },
  89. methods: {
  90. onCheckChange(val) {
  91. this.$emit('check', { id: this.item.id, checked: val.value });
  92. },
  93. onNumChange(val) {
  94. this.$emit('changeNum', { id: this.item.id, num: val.value });
  95. },
  96. handleReduce() {
  97. this.$emit('reduce', this.item);
  98. },
  99. handleSelectCondition() {
  100. this.$emit('selectCondition', this.item);
  101. }
  102. }
  103. };
  104. </script>
  105. <style lang="scss">
  106. .cart-item {
  107. display: flex;
  108. align-items: center;
  109. background-color: #fff;
  110. padding: 20rpx 20rpx;
  111. border-radius: 16rpx;
  112. border-bottom: 1rpx dashed #f5f5f5;
  113. .checkbox-box {
  114. width: 40rpx;
  115. display: flex;
  116. justify-content: center;
  117. flex-shrink: 0;
  118. &.disabled-checkbox {
  119. .circle {
  120. width: 34rpx;
  121. height: 34rpx;
  122. border-radius: 50%;
  123. background-color: #e5e5e5;
  124. }
  125. }
  126. }
  127. .image-wrapper {
  128. position: relative;
  129. width: 150rpx;
  130. height: 200rpx;
  131. border-radius: 8rpx;
  132. overflow: hidden;
  133. flex-shrink: 0;
  134. margin-right: 20rpx;
  135. .book-cover {
  136. width: 100%;
  137. height: 100%;
  138. }
  139. .status-mask {
  140. position: absolute;
  141. bottom: 0;
  142. left: 0;
  143. width: 100%;
  144. height: 40rpx;
  145. background-color: rgba(0, 0, 0, 0.6);
  146. display: flex;
  147. justify-content: center;
  148. align-items: center;
  149. text {
  150. color: #fff;
  151. font-size: 20rpx;
  152. }
  153. }
  154. .stock-mask {
  155. position: absolute;
  156. bottom: 0;
  157. left: 0;
  158. width: 100%;
  159. height: 40rpx;
  160. background-color: #38C148; // 绿色背景
  161. opacity: 0.8;
  162. display: flex;
  163. justify-content: center;
  164. align-items: center;
  165. text {
  166. color: #fff;
  167. font-size: 20rpx;
  168. }
  169. }
  170. }
  171. .info-box {
  172. flex: 1;
  173. height: 220rpx;
  174. display: flex;
  175. flex-direction: column;
  176. justify-content: space-between;
  177. .title-row {
  178. display: flex;
  179. justify-content: space-between;
  180. align-items: flex-start;
  181. .title {
  182. flex: 1;
  183. font-size: 28rpx;
  184. color: #333;
  185. line-height: 1.4;
  186. display: -webkit-box;
  187. -webkit-box-orient: vertical;
  188. -webkit-line-clamp: 2;
  189. overflow: hidden;
  190. font-weight: 600;
  191. margin-right: 10rpx;
  192. }
  193. }
  194. .tags-quality-row {
  195. display: flex;
  196. flex-wrap: wrap;
  197. justify-content: space-between;
  198. align-items: center;
  199. margin: 20rpx 0 0 0;
  200. .tag {
  201. font-size: 22rpx;
  202. padding: 2rpx 8rpx;
  203. border-radius: 4rpx;
  204. margin-right: 10rpx;
  205. border: 1rpx solid transparent;
  206. margin-bottom: 6rpx;
  207. &.green-tag {
  208. color: #38C148;
  209. border-color: #38C148;
  210. background-color: rgba(56, 193, 72, 0.1);
  211. }
  212. &.orange-tag {
  213. color: #ff6a00;
  214. border-color: #ff6a00;
  215. background-color: rgba(255, 106, 0, 0.1);
  216. }
  217. &.red-text-tag {
  218. background-color: #38C148;
  219. color: #fff;
  220. border: none;
  221. }
  222. }
  223. .quality-selector {
  224. display: flex;
  225. align-items: center;
  226. font-size: 24rpx;
  227. color: #999;
  228. background-color: #f5f5f5;
  229. padding: 4rpx 12rpx;
  230. border-radius: 4rpx;
  231. width: fit-content;
  232. margin-bottom: 6rpx;
  233. margin-right: 10rpx;
  234. order: -1; // 移到前面
  235. }
  236. }
  237. .bottom-row {
  238. display: flex;
  239. align-items: center;
  240. justify-content: space-between;
  241. margin-top: auto;
  242. .price-box {
  243. color: #e02020;
  244. font-weight: bold;
  245. .symbol {
  246. font-size: 24rpx;
  247. }
  248. .amount {
  249. font-size: 36rpx;
  250. }
  251. }
  252. .reduce-btn {
  253. background-color: #38C148;
  254. color: #fff;
  255. font-size: 20rpx;
  256. padding: 6rpx 16rpx;
  257. border-radius: 20rpx;
  258. margin-left: 10rpx;
  259. margin-right: auto; // 将数字框推到右边
  260. }
  261. }
  262. }
  263. }
  264. </style>