| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <template>
- <view class="cart-item">
- <!-- 复选框 -->
- <view class="checkbox-box">
- <u-checkbox v-model="item.checked" shape="circle" active-color="#38C148" @change="onCheckChange"
- :disabled="!isValid" style="width:100%"></u-checkbox>
- </view>
- <!-- 商品图片 -->
- <view class="image-wrapper">
- <image :src="item.cover" mode="aspectFill" class="book-cover"></image>
- <!-- 状态遮罩 -->
- <view class="status-mask" v-if="!isValid">
- <text>{{ statusText }}</text>
- </view>
- <!-- 库存紧张遮罩 -->
- <view class="stock-mask" v-if="isValid && item.stockStatus === 2">
- <text>库存紧张</text>
- </view>
- </view>
- <!-- 商品信息 -->
- <view class="info-box">
- <view class="title" style="font-weight:500">{{ item.bookName }}</view>
- <!-- 标签和品相区域 -->
- <view class="tags-quality-row">
- <!-- 品相选择 -->
- <view class="quality-selector" @click.stop="handleSelectCondition">
- <text>品相:{{ conditionName }}</text>
- <u-icon name="arrow-down" size="20" color="#999" style="margin-left: 4rpx;"></u-icon>
- </view>
- <!-- 已降价标签 -->
- <view class="tag green-tag" v-if="item.currReduceMoney > 0">
- <text>已降¥{{ item.currReduceMoney }}</text>
- </view>
- <!-- 可降价标签 -->
- <view class="tag orange-tag" v-if="canReduce" @click.stop="handleReduce">
- <text>可降¥{{ item.reduceMoney }}</text>
- </view>
- </view>
- <!-- 底部价格和操作 -->
- <view class="bottom-row">
- <view class="price-box">
- <text class="symbol">¥</text>
- <text class="amount">{{ item.productPrice }}</text>
- </view>
- <!-- 去减钱按钮 -->
- <view class="reduce-btn" v-if="canReduce" @click.stop="handleReduce">
- <text>去减钱</text>
- </view>
- <!-- 数量加减 -->
- <u-number-box v-model="item.quantity" :min="1" :max="item.availableStock || 99" :disabled="!isValid"
- @change="onNumChange" :size="24"></u-number-box>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- props: {
- item: {
- type: Object,
- default: () => ({})
- }
- },
- data() {
- return {
- conditionMap: {
- 1: '良好',
- 2: '中等',
- 3: '次品',
- 4: '全新'
- }
- };
- },
- computed: {
- conditionName() {
- // 如果是数字,映射;如果是字符串,直接显示
- return this.conditionMap[this.item.conditionType] || this.item.conditionType || '中等';
- },
- isValid() {
- // stockStatus: 1-有库存 2-库存紧张 3-暂无库存
- return this.item.stockStatus !== 3 && this.item.availableStock > 0;
- },
- statusText() {
- if (this.item.stockStatus === 3 || this.item.availableStock <= 0) return '暂无库存';
- // 如果后端定义了其他状态,你可能需要处理它们
- return '';
- },
- canReduce() {
- // 逻辑:如果成功减价次数少于允许的最大次数,且 reduceMoney > 0
- // 或者简单地如果 reduceMoney > 0 且我们还没有达到限制?
- // 假设 reduceMoney 是单价减少额。
- return (this.item.reduceNum < this.item.maxReduceNum) && (this.item.reduceMoney > 0);
- }
- },
- methods: {
- onCheckChange(val) {
- this.$emit('check', { id: this.item.id, checked: val.value });
- },
- onNumChange(val) {
- this.$emit('changeNum', { id: this.item.id, num: val.value });
- },
- handleReduce() {
- this.$emit('reduce', this.item);
- },
- handleSelectCondition() {
- this.$emit('selectCondition', this.item);
- }
- }
- };
- </script>
- <style lang="scss">
- .cart-item {
- display: flex;
- align-items: center;
- background-color: #fff;
- padding: 20rpx 20rpx;
- border-radius: 16rpx;
- border-bottom: 1rpx dashed #f5f5f5;
- .checkbox-box {
- width: 40rpx;
- display: flex;
- justify-content: center;
- flex-shrink: 0;
- &.disabled-checkbox {
- .circle {
- width: 34rpx;
- height: 34rpx;
- border-radius: 50%;
- background-color: #e5e5e5;
- }
- }
- }
- .image-wrapper {
- position: relative;
- width: 150rpx;
- height: 200rpx;
- border-radius: 8rpx;
- overflow: hidden;
- flex-shrink: 0;
- margin-right: 20rpx;
- .book-cover {
- width: 100%;
- height: 100%;
- }
- .status-mask {
- position: absolute;
- bottom: 0;
- left: 0;
- width: 100%;
- height: 40rpx;
- background-color: rgba(0, 0, 0, 0.6);
- display: flex;
- justify-content: center;
- align-items: center;
- text {
- color: #fff;
- font-size: 20rpx;
- }
- }
- .stock-mask {
- position: absolute;
- bottom: 0;
- left: 0;
- width: 100%;
- height: 40rpx;
- background-color: #38C148; // 绿色背景
- opacity: 0.8;
- display: flex;
- justify-content: center;
- align-items: center;
- text {
- color: #fff;
- font-size: 20rpx;
- }
- }
- }
- .info-box {
- flex: 1;
- height: 220rpx;
- display: flex;
- flex-direction: column;
- justify-content: space-between;
- .title-row {
- display: flex;
- justify-content: space-between;
- align-items: flex-start;
- .title {
- flex: 1;
- font-size: 28rpx;
- color: #333;
- line-height: 1.4;
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-line-clamp: 2;
- overflow: hidden;
- font-weight: 600;
- margin-right: 10rpx;
- }
- }
- .tags-quality-row {
- display: flex;
- flex-wrap: wrap;
- justify-content: space-between;
- align-items: center;
- margin: 20rpx 0 0 0;
- .tag {
- font-size: 22rpx;
- padding: 2rpx 8rpx;
- border-radius: 4rpx;
- margin-right: 10rpx;
- border: 1rpx solid transparent;
- margin-bottom: 6rpx;
- &.green-tag {
- color: #38C148;
- border-color: #38C148;
- background-color: rgba(56, 193, 72, 0.1);
- }
- &.orange-tag {
- color: #ff6a00;
- border-color: #ff6a00;
- background-color: rgba(255, 106, 0, 0.1);
- }
- &.red-text-tag {
- background-color: #38C148;
- color: #fff;
- border: none;
- }
- }
- .quality-selector {
- display: flex;
- align-items: center;
- font-size: 24rpx;
- color: #999;
- background-color: #f5f5f5;
- padding: 4rpx 12rpx;
- border-radius: 4rpx;
- width: fit-content;
- margin-bottom: 6rpx;
- margin-right: 10rpx;
- order: -1; // 移到前面
- }
- }
- .bottom-row {
- display: flex;
- align-items: center;
- justify-content: space-between;
- margin-top: auto;
- .price-box {
- color: #e02020;
- font-weight: bold;
- .symbol {
- font-size: 24rpx;
- }
- .amount {
- font-size: 36rpx;
- }
- }
- .reduce-btn {
- background-color: #38C148;
- color: #fff;
- font-size: 20rpx;
- padding: 6rpx 16rpx;
- border-radius: 20rpx;
- margin-left: 10rpx;
- margin-right: auto; // 将数字框推到右边
- }
- }
- }
- }
- </style>
|