cart-item.vue 11 KB

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