cart-item.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <template>
  2. <view class="cart-item" @click="goToDetail">
  3. <!-- 复选框扩大点击区域 -->
  4. <view class="checkbox-box" @click.stop="toggleCheck">
  5. <u-checkbox v-model="item.checked" shape="circle" active-color="#38C148" @change="onCheckChange"
  6. :disabled="!isValid" style="width:100%; pointer-events: none;"></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 && canReduce" @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. toggleCheck() {
  99. if (!this.isValid) return;
  100. const newChecked = !this.item.checked;
  101. this.item.checked = newChecked;
  102. this.$emit('check', { id: this.item.id, checked: newChecked });
  103. },
  104. onCheckChange(val) {
  105. this.$emit('check', { id: this.item.id, checked: val.value });
  106. },
  107. onNumChange(val) {
  108. this.$emit('changeNum', { id: this.item.id, num: val.value });
  109. },
  110. handleReduce() {
  111. this.$emit('reduce', this.item);
  112. },
  113. handleSelectCondition() {
  114. this.$emit('selectCondition', this.item);
  115. },
  116. onCountdownFinish() {
  117. this.$emit('countdown-finish', this.item);
  118. },
  119. goToDetail() {
  120. const isbn = this.item.isbn || this.item.bookIsbn || this.item.id;
  121. if (isbn) {
  122. uni.navigateTo({
  123. url: `/pages-sell/pages/detail?isbn=${isbn}`
  124. });
  125. }
  126. }
  127. }
  128. };
  129. </script>
  130. <style lang="scss">
  131. .cart-item {
  132. display: flex;
  133. align-items: center;
  134. background-color: #fff;
  135. padding: 20rpx 20rpx;
  136. border-radius: 16rpx;
  137. border-bottom: 1rpx dashed #f5f5f5;
  138. .checkbox-box {
  139. width: 80rpx;
  140. height: 100%;
  141. min-height: 200rpx;
  142. display: flex;
  143. justify-content: center;
  144. align-items: center;
  145. flex-shrink: 0;
  146. margin-right: -20rpx;
  147. position: relative;
  148. z-index: 10;
  149. &.disabled-checkbox {
  150. .circle {
  151. width: 34rpx;
  152. height: 34rpx;
  153. border-radius: 50%;
  154. background-color: #e5e5e5;
  155. }
  156. }
  157. }
  158. .image-wrapper {
  159. position: relative;
  160. width: 150rpx;
  161. height: 200rpx;
  162. border-radius: 8rpx;
  163. overflow: hidden;
  164. flex-shrink: 0;
  165. margin-right: 20rpx;
  166. .book-cover {
  167. width: 100%;
  168. height: 100%;
  169. }
  170. .status-mask {
  171. position: absolute;
  172. bottom: 0;
  173. left: 0;
  174. width: 100%;
  175. height: 40rpx;
  176. background-color: rgba(0, 0, 0, 0.6);
  177. display: flex;
  178. justify-content: center;
  179. align-items: center;
  180. text {
  181. color: #fff;
  182. font-size: 20rpx;
  183. }
  184. }
  185. .stock-mask {
  186. position: absolute;
  187. bottom: 0;
  188. left: 0;
  189. width: 100%;
  190. height: 40rpx;
  191. background-color: #38C148; // 绿色背景
  192. opacity: 0.8;
  193. display: flex;
  194. justify-content: center;
  195. align-items: center;
  196. text {
  197. color: #fff;
  198. font-size: 20rpx;
  199. }
  200. }
  201. }
  202. .info-box {
  203. flex: 1;
  204. height: 220rpx;
  205. display: flex;
  206. flex-direction: column;
  207. justify-content: space-between;
  208. ::v-deep .u-countdown-colon {
  209. font-size: 24rpx !important;
  210. }
  211. .title-row {
  212. display: flex;
  213. justify-content: space-between;
  214. align-items: flex-start;
  215. .title {
  216. flex: 1;
  217. font-size: 28rpx;
  218. color: #333;
  219. line-height: 1.4;
  220. display: -webkit-box;
  221. -webkit-box-orient: vertical;
  222. -webkit-line-clamp: 2;
  223. overflow: hidden;
  224. font-weight: 600;
  225. margin-right: 10rpx;
  226. }
  227. }
  228. .tags-quality-row {
  229. display: flex;
  230. flex-wrap: wrap;
  231. justify-content: space-between;
  232. align-items: center;
  233. margin: 20rpx 0 0 0;
  234. .tag {
  235. font-size: 22rpx;
  236. padding: 2rpx 8rpx;
  237. border-radius: 4rpx;
  238. margin-right: 10rpx;
  239. border: 1rpx solid transparent;
  240. margin-bottom: 6rpx;
  241. &.green-tag {
  242. color: #38C148;
  243. border-color: #38C148;
  244. background-color: rgba(56, 193, 72, 0.1);
  245. }
  246. &.orange-tag {
  247. color: #ff6a00;
  248. border-color: #ff6a00;
  249. background-color: rgba(255, 106, 0, 0.1);
  250. }
  251. &.red-text-tag {
  252. background-color: #38C148;
  253. color: #fff;
  254. border: none;
  255. }
  256. }
  257. .quality-selector {
  258. display: flex;
  259. align-items: center;
  260. font-size: 24rpx;
  261. color: #999;
  262. background-color: #f5f5f5;
  263. padding: 4rpx 12rpx;
  264. border-radius: 4rpx;
  265. width: fit-content;
  266. margin-bottom: 6rpx;
  267. margin-right: 10rpx;
  268. order: -1; // 移到前面
  269. }
  270. .countdown-wrap {
  271. display: flex;
  272. align-items: center;
  273. font-size: 24rpx !important;
  274. color: #db0702;
  275. margin-left: 6rpx;
  276. text {
  277. margin-right: 6rpx;
  278. }
  279. }
  280. }
  281. .bottom-row {
  282. display: flex;
  283. align-items: center;
  284. justify-content: space-between;
  285. margin-top: auto;
  286. .price-box {
  287. color: #e02020;
  288. font-weight: bold;
  289. .symbol {
  290. font-size: 24rpx;
  291. }
  292. .amount {
  293. font-size: 36rpx;
  294. }
  295. }
  296. .reduce-btn {
  297. background-color: #38C148;
  298. color: #fff;
  299. font-size: 24rpx;
  300. padding: 6rpx 16rpx;
  301. border-radius: 26rpx;
  302. margin-left: 10rpx;
  303. margin-right: auto; // 将数字框推到右边
  304. }
  305. }
  306. }
  307. }
  308. </style>