cart-item.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. <!-- 倒计时 -->
  39. <view class="countdown-wrap" v-if="item.restTime > 0">
  40. <text>减价即将结束</text>
  41. <u-count-down :timestamp="item.restTime" format="HH:mm:ss" autoStart color="#db0702" font-size="24"
  42. separator-color="#db0702" separator-size="24" @finish="onCountdownFinish"></u-count-down>
  43. </view>
  44. </view>
  45. <!-- 底部价格和操作 -->
  46. <view class="bottom-row">
  47. <view class="price-box">
  48. <text class="symbol">¥</text>
  49. <text class="amount">{{ item.productPrice }}</text>
  50. </view>
  51. <!-- 去减钱按钮 -->
  52. <view class="reduce-btn" v-if="canReduce" @click.stop="handleReduce">
  53. <text>去减钱</text>
  54. </view>
  55. <!-- 数量加减 -->
  56. <u-number-box v-model="item.quantity" :min="1" :max="item.availableStock || 99" :disabled="!isValid"
  57. @change="onNumChange" :size="24"></u-number-box>
  58. </view>
  59. </view>
  60. </view>
  61. </template>
  62. <script>
  63. export default {
  64. props: {
  65. item: {
  66. type: Object,
  67. default: () => ({})
  68. }
  69. },
  70. data() {
  71. return {
  72. };
  73. },
  74. computed: {
  75. conditionName() {
  76. // 如果是数字,映射;如果是字符串,直接显示
  77. return this.$conditionMap[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. onCountdownFinish() {
  109. this.$emit('countdown-finish', this.item);
  110. }
  111. }
  112. };
  113. </script>
  114. <style lang="scss">
  115. .cart-item {
  116. display: flex;
  117. align-items: center;
  118. background-color: #fff;
  119. padding: 20rpx 20rpx;
  120. border-radius: 16rpx;
  121. border-bottom: 1rpx dashed #f5f5f5;
  122. .checkbox-box {
  123. width: 40rpx;
  124. display: flex;
  125. justify-content: center;
  126. flex-shrink: 0;
  127. &.disabled-checkbox {
  128. .circle {
  129. width: 34rpx;
  130. height: 34rpx;
  131. border-radius: 50%;
  132. background-color: #e5e5e5;
  133. }
  134. }
  135. }
  136. .image-wrapper {
  137. position: relative;
  138. width: 150rpx;
  139. height: 200rpx;
  140. border-radius: 8rpx;
  141. overflow: hidden;
  142. flex-shrink: 0;
  143. margin-right: 20rpx;
  144. .book-cover {
  145. width: 100%;
  146. height: 100%;
  147. }
  148. .status-mask {
  149. position: absolute;
  150. bottom: 0;
  151. left: 0;
  152. width: 100%;
  153. height: 40rpx;
  154. background-color: rgba(0, 0, 0, 0.6);
  155. display: flex;
  156. justify-content: center;
  157. align-items: center;
  158. text {
  159. color: #fff;
  160. font-size: 20rpx;
  161. }
  162. }
  163. .stock-mask {
  164. position: absolute;
  165. bottom: 0;
  166. left: 0;
  167. width: 100%;
  168. height: 40rpx;
  169. background-color: #38C148; // 绿色背景
  170. opacity: 0.8;
  171. display: flex;
  172. justify-content: center;
  173. align-items: center;
  174. text {
  175. color: #fff;
  176. font-size: 20rpx;
  177. }
  178. }
  179. }
  180. .info-box {
  181. flex: 1;
  182. height: 220rpx;
  183. display: flex;
  184. flex-direction: column;
  185. justify-content: space-between;
  186. ::v-deep .u-countdown-colon {
  187. font-size: 24rpx !important;
  188. }
  189. .title-row {
  190. display: flex;
  191. justify-content: space-between;
  192. align-items: flex-start;
  193. .title {
  194. flex: 1;
  195. font-size: 28rpx;
  196. color: #333;
  197. line-height: 1.4;
  198. display: -webkit-box;
  199. -webkit-box-orient: vertical;
  200. -webkit-line-clamp: 2;
  201. overflow: hidden;
  202. font-weight: 600;
  203. margin-right: 10rpx;
  204. }
  205. }
  206. .tags-quality-row {
  207. display: flex;
  208. flex-wrap: wrap;
  209. justify-content: space-between;
  210. align-items: center;
  211. margin: 20rpx 0 0 0;
  212. .tag {
  213. font-size: 22rpx;
  214. padding: 2rpx 8rpx;
  215. border-radius: 4rpx;
  216. margin-right: 10rpx;
  217. border: 1rpx solid transparent;
  218. margin-bottom: 6rpx;
  219. &.green-tag {
  220. color: #38C148;
  221. border-color: #38C148;
  222. background-color: rgba(56, 193, 72, 0.1);
  223. }
  224. &.orange-tag {
  225. color: #ff6a00;
  226. border-color: #ff6a00;
  227. background-color: rgba(255, 106, 0, 0.1);
  228. }
  229. &.red-text-tag {
  230. background-color: #38C148;
  231. color: #fff;
  232. border: none;
  233. }
  234. }
  235. .quality-selector {
  236. display: flex;
  237. align-items: center;
  238. font-size: 24rpx;
  239. color: #999;
  240. background-color: #f5f5f5;
  241. padding: 4rpx 12rpx;
  242. border-radius: 4rpx;
  243. width: fit-content;
  244. margin-bottom: 6rpx;
  245. margin-right: 10rpx;
  246. order: -1; // 移到前面
  247. }
  248. .countdown-wrap {
  249. display: flex;
  250. align-items: center;
  251. font-size: 24rpx !important;
  252. color: #db0702;
  253. margin-left: 6rpx;
  254. text {
  255. margin-right: 6rpx;
  256. }
  257. }
  258. }
  259. .bottom-row {
  260. display: flex;
  261. align-items: center;
  262. justify-content: space-between;
  263. margin-top: auto;
  264. .price-box {
  265. color: #e02020;
  266. font-weight: bold;
  267. .symbol {
  268. font-size: 24rpx;
  269. }
  270. .amount {
  271. font-size: 36rpx;
  272. }
  273. }
  274. .reduce-btn {
  275. background-color: #38C148;
  276. color: #fff;
  277. font-size: 20rpx;
  278. padding: 6rpx 16rpx;
  279. border-radius: 20rpx;
  280. margin-left: 10rpx;
  281. margin-right: auto; // 将数字框推到右边
  282. }
  283. }
  284. }
  285. }
  286. </style>