Coupon flow refined

This commit is contained in:
Vion 2022-01-24 20:30:59 +08:00
parent cab59567e8
commit d6d51f9f5d
2 changed files with 27 additions and 6 deletions

View File

@ -251,7 +251,8 @@ export default {
promotion: "¥167.00", promotion: "¥167.00",
payment: "¥0.00 ", payment: "¥0.00 ",
}, },
discountAmount:0 discountAmount:0,
discountedItemIndex:undefined,
}; };
}, },
computed: { computed: {
@ -266,6 +267,8 @@ export default {
if(this.curCoupon.couponId) { if(this.curCoupon.couponId) {
//Coupon Calculation //Coupon Calculation
let couponUsed=false; let couponUsed=false;
let tmpCounter = 0 ;
this.discountedItemIndex = 0;
for(let itemInCart of this.goldmedal) { for(let itemInCart of this.goldmedal) {
if((!this.curCoupon.productCodes || this.curCoupon.productCodes.indexOf(itemInCart.productCode)>-1) && !couponUsed) { if((!this.curCoupon.productCodes || this.curCoupon.productCodes.indexOf(itemInCart.productCode)>-1) && !couponUsed) {
if(this.curCoupon.minQuantity && this.curCoupon.minQuantity>itemInCart.buyCount) { if(this.curCoupon.minQuantity && this.curCoupon.minQuantity>itemInCart.buyCount) {
@ -280,18 +283,21 @@ export default {
case 1: //Amount deduct case 1: //Amount deduct
total = total + (itemInCart.productPrice * itemInCart.buyCount - this.curCoupon.couponAmount); total = total + (itemInCart.productPrice * itemInCart.buyCount - this.curCoupon.couponAmount);
this.discountAmount = this.curCoupon.couponAmount; this.discountAmount = this.curCoupon.couponAmount;
this.discountedItemIndex = tmpCounter;
couponUsed=true; couponUsed=true;
break; break;
case 2: //Amount deduct with minPrice restriction case 2: //Amount deduct with minPrice restriction
case 6: case 6:
total = total + (itemInCart.productPrice * itemInCart.buyCount) - this.curCoupon.couponAmount; total = total + (itemInCart.productPrice * itemInCart.buyCount) - this.curCoupon.couponAmount;
this.discountAmount = this.curCoupon.couponAmount; this.discountAmount = this.curCoupon.couponAmount;
this.discountedItemIndex = tmpCounter;
couponUsed=true; couponUsed=true;
break; break;
case 3: //Limited product % discount case 3: //Limited product % discount
case 4: //% discount case 4: //% discount
total = total + (itemInCart.productPrice * itemInCart.buyCount) * this.curCoupon.discount; total = total + (itemInCart.productPrice * itemInCart.buyCount) * this.curCoupon.discount;
this.discountAmount = (itemInCart.productPrice * itemInCart.buyCount) * ( 1 - this.curCoupon.discount); this.discountAmount = (itemInCart.productPrice * itemInCart.buyCount) * ( 1 - this.curCoupon.discount);
this.discountedItemIndex = tmpCounter;
couponUsed=true; couponUsed=true;
break; break;
default: default:
@ -303,6 +309,7 @@ export default {
} else { } else {
total += itemInCart.productPrice * itemInCart.buyCount; total += itemInCart.productPrice * itemInCart.buyCount;
} }
tmpCounter++;
} }
} else { } else {
//Normal Calculation //Normal Calculation
@ -320,6 +327,18 @@ export default {
}, },
methods: { methods: {
...mapMutations(["checkIsLogin"]), ...mapMutations(["checkIsLogin"]),
wholeOrderDiscount(){
//TODO
if(this.curCoupon.minPrice && this.curCoupon.minPrice > this.sumPrice) {
if(this.curCoupon.couponAmount && this.curCoupon.couponAmount>0)
return this.sumPrice - this.curCoupon.couponAmount;
else
return 0;
}
},
qualifiedProductDiscount(){
//TODO
},
async getAddressList() { async getAddressList() {
let memberId = JSON.parse(localStorage.getItem("userInfo")).data.id; let memberId = JSON.parse(localStorage.getItem("userInfo")).data.id;
let { data } = await memberAddress("getAll", { memberId: memberId }); let { data } = await memberAddress("getAll", { memberId: memberId });
@ -370,7 +389,7 @@ export default {
if(valDateToTime && curTime > valDateToTime) { if(valDateToTime && curTime > valDateToTime) {
dateChecked=false; dateChecked=false;
} }
if(dateChecked && myCoupon.status == 0 && (myCoupon.productCodes.indexOf(itemInCart.productCode)>-1 || !myCoupon.productCodes)) { if(dateChecked && myCoupon.activityId != 10 && myCoupon.status == 0 && (myCoupon.productCodes.indexOf(itemInCart.productCode)>-1 || !myCoupon.productCodes)) {
_self.drawlist.push(myCoupon); _self.drawlist.push(myCoupon);
} }
} }
@ -459,6 +478,7 @@ export default {
return; return;
} }
let postData = []; let postData = [];
let tmpCounter=0;
this.goldmedal.forEach((item) => { this.goldmedal.forEach((item) => {
let basePoint = (item.basePoint?item.basePoint:0); let basePoint = (item.basePoint?item.basePoint:0);
let oneProduct = { let oneProduct = {
@ -483,7 +503,7 @@ export default {
addressDetailInfo: orderAddress[0].detailAddress, addressDetailInfo: orderAddress[0].detailAddress,
}, },
}; };
if(this.curCoupon.couponId) { if(this.curCoupon.couponId && tmpCounter == this.discountedItemIndex) {
oneProduct.couponId = this.curCoupon.couponId; oneProduct.couponId = this.curCoupon.couponId;
oneProduct.couponTypeId = this.curCoupon.couponTypeId; oneProduct.couponTypeId = this.curCoupon.couponTypeId;
oneProduct.couponName = this.curCoupon.couponName; oneProduct.couponName = this.curCoupon.couponName;
@ -491,6 +511,7 @@ export default {
oneProduct.couponAmount = (this.curCoupon.couponAmount?this.curCoupon.couponAmount:this.curCoupon.discount); oneProduct.couponAmount = (this.curCoupon.couponAmount?this.curCoupon.couponAmount:this.curCoupon.discount);
} }
postData.push(oneProduct); postData.push(oneProduct);
tmpCounter++;
}); });
// let postData = [ // let postData = [
// { // {

View File

@ -551,13 +551,13 @@ export default {
if(valDateToTime && curTime > valDateToTime) { if(valDateToTime && curTime > valDateToTime) {
dateChecked=false; dateChecked=false;
} }
if(dateChecked) { if(dateChecked && item.activityId!=10) {
if(!item.productCodes) { if(!item.productCodes) {
menualist.push(item); menualist.push(item);
} else { } else {
item.productCodes = item.productCodes.split(","); item.productCodes = item.productCodes.split(",");
item.productCodes.forEach((element) => { item.productCodes.forEach((element) => {
if (element == this.curItem.productCode && item.activityId !== 10) { if (element == this.curItem.productCode) {
menualist.push(item); menualist.push(item);
} }
}); });
@ -655,7 +655,7 @@ export default {
this.dialogInfo2 = true; this.dialogInfo2 = true;
return; return;
} else { } else {
this.userdraw(this.usermessage.data.mobile); //this.userdraw(this.usermessage.data.mobile);
this.alldrawlist(this.usermessage.data.id); this.alldrawlist(this.usermessage.data.id);
this.dialogInfo1 = true; this.dialogInfo1 = true;
} }