order 7.23

This commit is contained in:
2020-07-23 14:56:20 +08:00
parent 2e087313d4
commit be9f2ec1c7
9 changed files with 209 additions and 142 deletions

View File

@@ -33,10 +33,10 @@
</view>
</view>
<view class="order-info">
<view @click="showCoupon({type: 2, store_id: item[0].store_id})" v-if="orderInfo.ifcart != 0">
<view @click="showCoupon({type: 2, store_id: item[0].store_id})" v-if="orderType == 1 || orderType == 5">
<view class="title">优惠券折扣</view>
<view class="value">
<view>{{ item.coupon_price ? item.coupon_price : '0.00' }}</view>
<view>-{{ storeCoupon[item[0].store_id] ? storeCoupon[item[0].store_id].voucher_price.toFixed(2) : '0.00' }}</view>
<image src="../static/image/1.png"></image>
</view>
</view>
@@ -50,10 +50,10 @@
</view>
</view>
<view class="common-active">
<view @click="showCoupon({type: 1})" v-if="orderInfo.ifcart != 0">
<view @click="showCoupon({type: 1})" v-if="orderType == 1 || orderType == 5">
<view class="title">平台优惠券</view>
<view class="value">
<view>-{{ choiceCoupon.vouchertemplate_id ? choiceCoupon.voucher_price : '0.00' }}</view>
<view>-{{ choiceCoupon.vouchertemplate_id ? choiceCoupon.voucher_price.toFixed(2) : '0.00' }}</view>
<image src="../static/image/1.png"></image>
</view>
</view>
@@ -66,11 +66,17 @@
</view>
</view>
<u-popup v-model="couponStatus" mode="bottom">
<scroll-view class="coupon-choose" style="height: 800rpx;">
<scroll-view class="coupon-choose" scroll-y style="height: 800rpx;" v-if="this.couponType.type == 1">
<view class="title">优惠券详情</view>
<view class="text">使用优惠券</view>
<Coupon :couponInfo="coupon" @use="useCoupon($event)" :goodsClass="goodsClass" v-for="(coupon, index) in couponList" :key="index"></Coupon>
<u-empty text="无可用优惠券" mode="coupon" v-if="!couponList.length"></u-empty>
<view class="text">店铺优惠券</view>
<Coupon :couponInfo="coupon" @use="useCoupon($event)" :goodsClass="goodsClass" v-for="(coupon, index) in orderInfo.store_voucher_all_list" :key="index"></Coupon>
<u-empty text="无可用优惠券" mode="coupon" v-if="!orderInfo.store_voucher_all_list.length"></u-empty>
</scroll-view>
<scroll-view class="coupon-choose" scroll-y style="height: 800rpx;" v-if="this.couponType.type == 2">
<view class="title">优惠券详情</view>
<view class="text">平台优惠券</view>
<Coupon :couponInfo="coupon" @use="useCoupon($event)" :goodsClass="goodsClass" v-for="(coupon, index) in orderInfo.store_voucher_list[this.couponType.store_id]" :key="index"></Coupon>
<u-empty text="无可用优惠券" mode="coupon" v-if="!orderInfo.store_voucher_list[this.couponType.store_id].length"></u-empty>
</scroll-view>
</u-popup>
<view class="bottom">
@@ -110,9 +116,12 @@ export default {
}, // 配送方式
couponList: [],
couponStatus: false,
couponType: {}, // 选择的优惠券
storeCoupon: {}, // 选中的店铺优惠券
choiceCoupon: {}, // 使用的平台优惠券
goodsClass: [],
orderType: '', // 订单类型 1 普通订单 2 拼团订单 3 秒杀订单 4 优惠券 5 购物车订单
}
},
components: {
@@ -140,6 +149,7 @@ export default {
this.orderInfo = this.$store.state.orderInfo;
console.log(this.orderType);
console.log(this.orderInfo);
this.getGoodsClass();
},
onShow() {
// 判断是不是从选择地址页面返回
@@ -156,7 +166,21 @@ export default {
'$store.state.orderAddress'(value) {
this.addressInfo = value;
this.getFreight();
}
},
// storeCoupon: {
// deep: true,
// handler() {
// console.log(222);
// this.setTotalPrice(); // 计算总价
// }
// },
// choiceCoupon: {
// deep: true,
// handler() {
// console.log(111);
// this.setTotalPrice(); // 计算总价
// }
// },
},
methods: {
// 如果有pintuangroup_headid为参团不然为开团
@@ -198,16 +222,32 @@ export default {
})
}
}
// 拼接优惠券
let coupon = [];
for (const key in this.storeCoupon) {
if (this.storeCoupon.hasOwnProperty(key)) {
const element = this.storeCoupon[key];
temp = key + '|' + element.voucher_id;
coupon.push(temp);
temp = '';
}
}
// 平台券store_id写0
if(JSON.stringify(this.choiceCoupon) != '{}') {
coupon.push(0 + '|' + this.choiceCoupon.voucher_id)
}
let params = {
ifcart: ifcart,
cart_id: id,
address_id: this.addressInfo.address_id,
buy_city_id: this.addressInfo.city_id,
voucher_id: coupon,
}
if(this.orderType == 2) {
Object.assign(params, { pintuan_id: this.orderInfo.pintuan_id })
if(this.orderInfo.pintuangroup_id) Object.assign(params, { pintuangroup_id: this.orderInfo.pintuangroup_id })
}
// console.log(params);
this.$u.api.sendOrder(params).then(res => {
if(res.errCode == 0) {
this.$u.route({
@@ -222,36 +262,24 @@ export default {
}
})
},
async getCoupon({ type, store_id, status }) {
const res = await this.$u.api.getMemberCouponList({
showCoupon({ type, store_id = -1 } = {}) {
this.couponType = {
type: type,
store_id: store_id,
status: status,
})
return res;
},
showCoupon({ type, gc_id, store_id }) {
// this.getCoupon({
// type: type, // 优惠券类型: 1平台券, 2店铺券
// store_id: store_id,
// status: 1, // 代金券状态 1:未用 2:已用 3:过期 4:收回
// }).then(res => {
// this.couponStatus = true;
// })
let params = {
type: type, // 优惠券类型: 1平台券, 2店铺券
status: 1, // 代金券状态 1:未用 2:已用 3:过期 4:收回
store_id: store_id
}
if(store_id) Object.assign(params, 'store_id', store_id);
if(gc_id) Object.assign(params, 'gc_id', gc_id);
this.$u.api.getMemberCouponList(params).then(res => {
this.couponList = res.data;
this.couponStatus = true;
})
this.couponStatus = true;
},
useCoupon(coupon) {
this.choiceCoupon = coupon;
if(this.couponType.type == 1) this.choiceCoupon = coupon;
if(this.couponType.type == 2) {
Object.assign(this.storeCoupon, {
[this.couponType.store_id]: coupon
})
}
// console.log(this.choiceCoupon);
// console.log(this.storeCoupon);
this.couponStatus = false;
this.setTotalPrice(); // 计算总价
},
getFreight() {
this.$u.api.getFreight({
@@ -267,10 +295,11 @@ export default {
}
})
},
setTotalPrice(object) {
setTotalPrice() {
const goods = this.orderInfo.store_goods_total;
const freight = this.freight;
let price = 0;
// 商品价格加上运费
[goods, freight].forEach(object => {
for (const key in object) {
if (object.hasOwnProperty(key)) {
@@ -279,8 +308,20 @@ export default {
}
}
})
// 减去优惠券
// 平台
if(JSON.stringify(this.choiceCoupon) != '{}') price -= Number(this.choiceCoupon.voucher_price);
// 店铺
if(JSON.stringify(this.storeCoupon) != '{}') {
for (const key in this.storeCoupon) {
if (this.storeCoupon.hasOwnProperty(key)) {
const element = this.storeCoupon[key];
price -= element.voucher_price;
}
}
}
// console.log(price);
this.totalPrice = price.toFixed(2);
this.totalPrice = price.toFixed(2);
},
setDelivery(index) {
if(index == 1) {

View File

@@ -100,7 +100,7 @@ export default {
// ifcart 结算方式 1:购物车 0:直接结算(立即购买/拼团/秒杀)
this.$u.api.settlementOrder({ ifcart: 1, cart_id: id }).then(res => {
if(res.errCode == 0) {
this.$store.commit('orderType', 2);
this.$store.commit('setOrderType', 5);
this.$store.commit('updateOrderInfo', res.data);
this.$u.route({
url: '/pageC/cart/ConfirmOrder'