|
@@ -39,7 +39,9 @@
|
|
|
<view class="box_center">
|
|
|
<navigator :url="'/pages/product/index?product_id=' + item.product_id" class="car_name">{{ item.name }}</navigator>
|
|
|
<navigator :url="'/pages/product/index?product_id=' + item.product_id" class="car_spec">{{ item.spec }}</navigator>
|
|
|
- <view v-if="item.promo_title" class="promo_title">{{ item.promo_title }}</view>
|
|
|
+ <view v-if="item.promo_title" class="promo_title">
|
|
|
+ <text v-for="(promoText, index) in getPromoText(item.promo_title)" :key="index">{{ promoText }}</text>
|
|
|
+ </view>
|
|
|
<navigator :url="'/pages/product/index?product_id=' + item.product_id" class="car_price">
|
|
|
<text class="price">¥{{ item.price }}</text>
|
|
|
<text class="market_price">¥{{ item.market_price }}</text>
|
|
@@ -75,10 +77,16 @@
|
|
|
></image>
|
|
|
<text class="checkall">全选</text>
|
|
|
</view>
|
|
|
+
|
|
|
<view class="price_box">
|
|
|
- 合计:<text class="price_total">¥{{ priceTotal }}</text>
|
|
|
+ <view style="display: flex; justify-content: flex-start; align-items: baseline; font-size: 24rpx">
|
|
|
+ 已选{{ selectProductNum }}件,合计:<text class="price_total">¥{{ discountPrice }}</text></view
|
|
|
+ >
|
|
|
+ <view v-if="reductionMoney !== 0" style="display: flex; justify-content: flex-start; align-items: center; color: #999; font-size: 24rpx">
|
|
|
+ 优惠减:<text>¥{{ reductionMoney.toFixed(2) }}</text>
|
|
|
+ </view>
|
|
|
</view>
|
|
|
- <view class="to_order" @click="toOrder()">{{ is_pay ? '购买' : '预约' }}</view>
|
|
|
+ <view class="to_order" @click="toOrder()">{{ is_pay ? `${reductionMoney !== 0 ? '优惠' : ''}购买` : `${reductionMoney !== 0 ? '优惠' : ''}预约` }}</view>
|
|
|
</view>
|
|
|
<cc-myTabbar :tabBarShow="3"></cc-myTabbar>
|
|
|
</view>
|
|
@@ -103,8 +111,16 @@ export default {
|
|
|
cartListByGroup: [],
|
|
|
cartList: [],
|
|
|
is_pay: 0,
|
|
|
+ reductionMoney: 0,
|
|
|
+ selectProductNum: 0,
|
|
|
+ debounceTimer: null,
|
|
|
+ changeQuantity: null,
|
|
|
};
|
|
|
},
|
|
|
+ // 在created钩子中初始化
|
|
|
+ created() {
|
|
|
+ this.changeQuantity = this.debounce(this.handleQuantityChange);
|
|
|
+ },
|
|
|
onLoad() {
|
|
|
// #ifdef MP-WEIXIN
|
|
|
uni.hideTabBar();
|
|
@@ -211,12 +227,23 @@ export default {
|
|
|
// 计算价格
|
|
|
this.priceHandler();
|
|
|
},
|
|
|
+ debounce(fn, delay = 500) {
|
|
|
+ return (...args) => {
|
|
|
+ if (this.debounceTimer) {
|
|
|
+ clearTimeout(this.debounceTimer);
|
|
|
+ }
|
|
|
+ this.debounceTimer = setTimeout(() => {
|
|
|
+ fn.apply(this, args);
|
|
|
+ }, delay);
|
|
|
+ };
|
|
|
+ },
|
|
|
// 数量调整
|
|
|
- changeQuantity(pIndex, index, number) {
|
|
|
+ handleQuantityChange(pIndex, index, number) {
|
|
|
+ //修改数量重新计算折扣
|
|
|
// 如果不是0.表示两侧按钮点击,0表示输入的修改
|
|
|
if (number != 0) {
|
|
|
// 计算个数
|
|
|
- this.cartListByGroup[pIndex].products[index].buy_num = this.cartListByGroup[pIndex].products[index].buy_num + number;
|
|
|
+ this.cartListByGroup[pIndex].products[index].buy_num = Number(this.cartListByGroup[pIndex].products[index].buy_num) + Number(number);
|
|
|
}
|
|
|
// 如果大于库存
|
|
|
if (this.cartListByGroup[pIndex].products[index].buy_num > this.cartListByGroup[pIndex].products[index].stock) {
|
|
@@ -249,6 +276,7 @@ export default {
|
|
|
.then((re) => {
|
|
|
if (re.code == 'success') {
|
|
|
// 计算价格
|
|
|
+ this.cartListByGroup[pIndex].products[index].buy_num = re.data.buy_num;
|
|
|
this.priceHandler();
|
|
|
} else {
|
|
|
uni.showToast({
|
|
@@ -412,6 +440,59 @@ export default {
|
|
|
this.deleteCar(e.pIndex, e.index);
|
|
|
},
|
|
|
},
|
|
|
+ watch: {
|
|
|
+ priceTotal: {
|
|
|
+ handler(newVal, oldVal) {
|
|
|
+ // 计算价格
|
|
|
+ // this.priceHandler();
|
|
|
+ let waitList = [];
|
|
|
+ // 循环处理
|
|
|
+ for (let index in this.cartListByGroup) {
|
|
|
+ // 如果选中的
|
|
|
+ for (const key in this.cartListByGroup[index].products) {
|
|
|
+ if (this.cartListByGroup[index].products[key].checked) {
|
|
|
+ // // 如果库存不足
|
|
|
+ // if (newVal[index].products[key].buy_num < 1) {
|
|
|
+ // uni.showToast({ icon: 'none', title: '选择的产品至少需要1个' });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ // // 如果库存不足
|
|
|
+ // if (newVal[index].products[key].buy_num > newVal[index].products[key].stock) {
|
|
|
+ // uni.showToast({ icon: 'none', title: '产品库存不足' });
|
|
|
+ // return;
|
|
|
+ // }
|
|
|
+ waitList.push(this.cartListByGroup[index].products[key].id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.selectProductNum = waitList.length;
|
|
|
+ if (waitList.length > 0) {
|
|
|
+ this.$http.request('api/shop_cart/check_list', { cart_ids: waitList.join(',') }).then((re) => {
|
|
|
+ if (re.code == 'success') {
|
|
|
+ this.reductionMoney = re.reduction;
|
|
|
+ this.priceHandler();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.reductionMoney = 0;
|
|
|
+ this.priceHandler();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deep: true,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ getPromoText() {
|
|
|
+ return (promo_title) => {
|
|
|
+ //在逗号增加换行符
|
|
|
+ if (!promo_title) return [];
|
|
|
+ return promo_title.split(';');
|
|
|
+ };
|
|
|
+ },
|
|
|
+ discountPrice() {
|
|
|
+ return this.$decimal.sub(this.priceTotal, this.reductionMoney).toFixed(2);
|
|
|
+ },
|
|
|
+ },
|
|
|
};
|
|
|
</script>
|
|
|
|
|
@@ -514,12 +595,18 @@ export default {
|
|
|
text-overflow: ellipsis; /* 用省略号表示被隐藏的部分 */
|
|
|
}
|
|
|
.promo_title {
|
|
|
- max-height: 80rpx;
|
|
|
+ max-width: 240rpx;
|
|
|
font-size: 20rpx;
|
|
|
line-height: 40rpx;
|
|
|
overflow: hidden;
|
|
|
padding: 0rpx 0rpx;
|
|
|
color: #dd524d;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+ //超出省省略号
|
|
|
+ // white-space: nowrap; /* 不换行 */
|
|
|
+ // overflow: hidden; /* 隐藏超出的内容 */
|
|
|
+ // text-overflow: ellipsis; /* 用省略号表示被隐藏的部分 */
|
|
|
}
|
|
|
.car_spec {
|
|
|
color: #999999;
|
|
@@ -618,13 +705,15 @@ export default {
|
|
|
z-index: 999;
|
|
|
left: 0rpx;
|
|
|
width: 100%;
|
|
|
- height: 100rpx;
|
|
|
+ height: 120rpx;
|
|
|
display: block;
|
|
|
position: fixed;
|
|
|
overflow: hidden;
|
|
|
background: #ffffff;
|
|
|
padding: 0rpx 35rpx;
|
|
|
bottom: 140rpx;
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
.check_all_label {
|
|
|
float: left;
|
|
|
width: 120rpx;
|
|
@@ -654,15 +743,15 @@ export default {
|
|
|
.price_box {
|
|
|
float: left;
|
|
|
width: 400rpx;
|
|
|
- display: block;
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
color: #666666;
|
|
|
font-size: 26rpx;
|
|
|
text-align: right;
|
|
|
- line-height: 100rpx;
|
|
|
margin-right: 20rpx;
|
|
|
.price_total {
|
|
|
color: red;
|
|
|
- font-size: 30rpx;
|
|
|
+ font-size: 36rpx;
|
|
|
}
|
|
|
}
|
|
|
.to_order {
|
|
@@ -672,7 +761,6 @@ export default {
|
|
|
display: block;
|
|
|
color: #ffffff;
|
|
|
font-size: 28rpx;
|
|
|
- margin-top: 20rpx;
|
|
|
line-height: 60rpx;
|
|
|
padding: 0rpx 0rpx;
|
|
|
text-align: center;
|