cart-item.vue 11 KB

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