cart-item.vue 9.6 KB

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