mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-10-02 02:06:38 +08:00
Coupon calculation refined
This commit is contained in:
parent
cd45fca6c0
commit
b9c0a1394e
@ -93,7 +93,7 @@
|
|||||||
<em>{{ discountAmount }}</em>
|
<em>{{ discountAmount }}</em>
|
||||||
</div>
|
</div>
|
||||||
<i>合计金额:</i>
|
<i>合计金额:</i>
|
||||||
<em>{{ discountedSumPrice }}</em>
|
<em>{{ finalAmount }}</em>
|
||||||
</div>
|
</div>
|
||||||
<div style="font-weight: bold">
|
<div style="font-weight: bold">
|
||||||
<span @click="preJiesuan()">提交订单</span>
|
<span @click="preJiesuan()">提交订单</span>
|
||||||
@ -252,7 +252,8 @@ export default {
|
|||||||
payment: "¥0.00 ",
|
payment: "¥0.00 ",
|
||||||
},
|
},
|
||||||
discountAmount:0,
|
discountAmount:0,
|
||||||
discountedItemIndex:undefined,
|
finalAmount:0,
|
||||||
|
discountedProductCode:undefined,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@ -262,94 +263,39 @@ export default {
|
|||||||
}, 0);
|
}, 0);
|
||||||
},
|
},
|
||||||
// 折扣计算
|
// 折扣计算
|
||||||
discountedSumPrice() {
|
|
||||||
let total = 0;
|
|
||||||
if(this.curCoupon.couponId) {
|
|
||||||
//Coupon Calculation
|
|
||||||
let couponUsed=false;
|
|
||||||
let tmpCounter = 0 ;
|
|
||||||
this.discountedItemIndex = 0;
|
|
||||||
for(let itemInCart of this.goldmedal) {
|
|
||||||
if((!this.curCoupon.productCodes || this.curCoupon.productCodes.indexOf(itemInCart.productCode)>-1) && !couponUsed) {
|
|
||||||
if(this.curCoupon.minQuantity && this.curCoupon.minQuantity>itemInCart.buyCount) {
|
|
||||||
//Check minQuantity
|
|
||||||
total+=(itemInCart.buyCount * itemInCart.productPrice);
|
|
||||||
} else if(this.curCoupon.minPrice && this.curCoupon.minPrice > (itemInCart.buyCount * itemInCart.productPrice)) {
|
|
||||||
//Check minPrice
|
|
||||||
total+=(itemInCart.buyCount * itemInCart.productPrice);
|
|
||||||
} else {
|
|
||||||
//Into coupon discount calculation
|
|
||||||
switch(this.curCoupon.couponTypeId) {
|
|
||||||
case 1: //Amount deduct
|
|
||||||
total = total + (itemInCart.productPrice * itemInCart.buyCount - this.curCoupon.couponAmount);
|
|
||||||
this.discountAmount = this.curCoupon.couponAmount;
|
|
||||||
this.discountedItemIndex = tmpCounter;
|
|
||||||
couponUsed=true;
|
|
||||||
break;
|
|
||||||
case 2: //Amount deduct with minPrice restriction
|
|
||||||
case 6:
|
|
||||||
total = total + (itemInCart.productPrice * itemInCart.buyCount) - this.curCoupon.couponAmount;
|
|
||||||
this.discountAmount = this.curCoupon.couponAmount;
|
|
||||||
this.discountedItemIndex = tmpCounter;
|
|
||||||
couponUsed=true;
|
|
||||||
break;
|
|
||||||
case 3: //Limited product % discount
|
|
||||||
case 4: //% discount
|
|
||||||
debugger;
|
|
||||||
total = total + (itemInCart.productPrice * itemInCart.buyCount) * this.curCoupon.discount;
|
|
||||||
this.discountAmount = (itemInCart.productPrice * itemInCart.buyCount) * ( 1 - this.curCoupon.discount);
|
|
||||||
this.discountedItemIndex = tmpCounter;
|
|
||||||
couponUsed=true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
total += itemInCart.productPrice * itemInCart.buyCount;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
//Into coupon discount calculation end
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
total += itemInCart.productPrice * itemInCart.buyCount;
|
|
||||||
}
|
|
||||||
tmpCounter++;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
//Normal Calculation
|
|
||||||
total=this.goldmedal.reduce((pre, cur) => {
|
|
||||||
return pre + cur.buyCount * cur.productPrice;
|
|
||||||
}, 0);
|
|
||||||
}
|
|
||||||
if(this.discountAmount)
|
|
||||||
this.discountAmount = this.discountAmount.toFixed(2);
|
|
||||||
if(!total)
|
|
||||||
total=0;
|
|
||||||
total = total.toFixed(2);
|
|
||||||
return total;
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
...mapMutations(["checkIsLogin"]),
|
...mapMutations(["checkIsLogin"]),
|
||||||
|
discountedSumPrice() {
|
||||||
|
let total = 0;
|
||||||
|
if(this.curCoupon.productCodes)
|
||||||
|
this.finalAmount = this.qualifiedProductDiscount();
|
||||||
|
else
|
||||||
|
this.finalAmount = this.wholeOrderDiscount();
|
||||||
|
this.finalAmount = parseFloat(this.finalAmount).toFixed(2);
|
||||||
|
this.discountAmount = parseFloat(this.discountAmount).toFixed(2);
|
||||||
|
},
|
||||||
wholeOrderDiscount(){
|
wholeOrderDiscount(){
|
||||||
this.discountedItemIndex = 0;
|
this.discountedItemIndex = 0;
|
||||||
if(this.curCoupon.minPrice && this.curCoupon.minPrice > this.sumPrice) {
|
if(this.curCoupon.minPrice && this.curCoupon.minPrice < this.sumPrice) {
|
||||||
if(this.curCoupon.couponAmount && this.curCoupon.couponAmount>0) {
|
if(this.curCoupon.couponAmount && this.curCoupon.couponAmount>0) {
|
||||||
this.discountAmount = this.curCoupon.discount;
|
this.discountAmount = this.curCoupon.couponAmount;
|
||||||
return this.sumPrice - this.curCoupon.couponAmount;
|
return this.sumPrice - this.curCoupon.couponAmount;
|
||||||
} else if(this.curCoupon.discount && this.curCoupon.discount>0) {
|
} else if(this.curCoupon.discount && this.curCoupon.discount>0) {
|
||||||
this.discountAmount = this.sumPrice*this.curCoupon.discount;
|
this.discountAmount = this.sumPrice*this.curCoupon.discount;
|
||||||
return this.sumPrice * (1-this.curCoupon.discount);
|
return this.sumPrice * (1-this.curCoupon.discount);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return this.sumPrice;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
qualifiedProductDiscount(){
|
qualifiedProductDiscount(){
|
||||||
//TODO
|
|
||||||
this.discountedItemIndex = 0;
|
this.discountedItemIndex = 0;
|
||||||
let tmpCounter = 0 ;
|
let total = 0;
|
||||||
|
let couponUsed = false;
|
||||||
//Sort items by items amount
|
let tmpShoppingCartList = this.arrSort(this.goldmedal);
|
||||||
|
|
||||||
//Sort items by items amount end
|
for(let itemInCart of tmpShoppingCartList) {
|
||||||
|
|
||||||
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) {
|
||||||
//Check minQuantity
|
//Check minQuantity
|
||||||
@ -363,21 +309,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;
|
this.discountedProductCode = itemInCart.productCode;
|
||||||
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;
|
this.discountedProductCode = itemInCart.productCode;
|
||||||
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;
|
this.discountedProductCode = itemInCart.productCode;
|
||||||
couponUsed=true;
|
couponUsed=true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -389,8 +335,21 @@ export default {
|
|||||||
} else {
|
} else {
|
||||||
total += itemInCart.productPrice * itemInCart.buyCount;
|
total += itemInCart.productPrice * itemInCart.buyCount;
|
||||||
}
|
}
|
||||||
tmpCounter++;
|
|
||||||
}
|
}
|
||||||
|
return total;
|
||||||
|
},
|
||||||
|
arrSort(arr) {
|
||||||
|
let userarr=[]
|
||||||
|
let a=[];
|
||||||
|
for(let i in arr){
|
||||||
|
arr[i].total=arr[i].productPrice*arr[i].buyCount;
|
||||||
|
if(arr[i].total){
|
||||||
|
userarr.push(arr[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return userarr.sort((n1,n2)=>{
|
||||||
|
return n2.total-n1.total;
|
||||||
|
});
|
||||||
},
|
},
|
||||||
async getAddressList() {
|
async getAddressList() {
|
||||||
let memberId = JSON.parse(localStorage.getItem("userInfo")).data.id;
|
let memberId = JSON.parse(localStorage.getItem("userInfo")).data.id;
|
||||||
@ -423,9 +382,11 @@ export default {
|
|||||||
let valDateFromTime=0;
|
let valDateFromTime=0;
|
||||||
let valDateToTime=0;
|
let valDateToTime=0;
|
||||||
let dateChecked=true;
|
let dateChecked=true;
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
this.drawlist=[];
|
this.drawlist=[];
|
||||||
for(let itemInCart of this.goldmedal) {
|
for(let itemInCart of this.goldmedal) {
|
||||||
|
let tmpIndex=0;
|
||||||
for(let myCoupon of data.data) {
|
for(let myCoupon of data.data) {
|
||||||
valDateFromTime=0;
|
valDateFromTime=0;
|
||||||
valDateToTime=0;
|
valDateToTime=0;
|
||||||
@ -442,9 +403,18 @@ export default {
|
|||||||
if(valDateToTime && curTime > valDateToTime) {
|
if(valDateToTime && curTime > valDateToTime) {
|
||||||
dateChecked=false;
|
dateChecked=false;
|
||||||
}
|
}
|
||||||
if(dateChecked && myCoupon.activityId != 10 && myCoupon.status == 0 && (myCoupon.productCodes.indexOf(itemInCart.productCode)>-1 || !myCoupon.productCodes)) {
|
if(myCoupon.minQuantity && myCoupon.minQuantity>itemInCart.buyCount) {
|
||||||
|
dateChecked=false;
|
||||||
|
}
|
||||||
|
if(myCoupon.minPrice && myCoupon.minPrice>this.sumPrice) {
|
||||||
|
dateChecked=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(dateChecked && myCoupon.activityId != 10 && myCoupon.status == 0 && (!myCoupon.productCodes || myCoupon.productCodes.indexOf(itemInCart.productCode)>-1)) {
|
||||||
|
data.data.splice(tmpIndex,1);
|
||||||
_self.drawlist.push(myCoupon);
|
_self.drawlist.push(myCoupon);
|
||||||
}
|
}
|
||||||
|
tmpIndex++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -452,6 +422,7 @@ export default {
|
|||||||
pickCoupon(item){
|
pickCoupon(item){
|
||||||
this.curCoupon = item;
|
this.curCoupon = item;
|
||||||
this.dialogInfo1 = false;
|
this.dialogInfo1 = false;
|
||||||
|
this.discountedSumPrice();
|
||||||
},
|
},
|
||||||
editAddress(item) {
|
editAddress(item) {
|
||||||
this.dialogAddTitle = "修改收货地址";
|
this.dialogAddTitle = "修改收货地址";
|
||||||
@ -556,7 +527,7 @@ export default {
|
|||||||
addressDetailInfo: orderAddress[0].detailAddress,
|
addressDetailInfo: orderAddress[0].detailAddress,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
if(this.curCoupon.couponId && tmpCounter == this.discountedItemIndex) {
|
if(this.curCoupon.couponId && item.productCode == this.discountedProductCode) {
|
||||||
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;
|
||||||
@ -644,6 +615,7 @@ export default {
|
|||||||
this.goldmedal = JSON.parse(this.$route.query.list);
|
this.goldmedal = JSON.parse(this.$route.query.list);
|
||||||
this.getAddressList();
|
this.getAddressList();
|
||||||
this.checkIsLogin();
|
this.checkIsLogin();
|
||||||
|
this.finalAmount = this.sumPrice;
|
||||||
// this.addressstype = this.$route.query.stype;
|
// this.addressstype = this.$route.query.stype;
|
||||||
// this.orderNumber = this.$route.query.orderNumber;
|
// this.orderNumber = this.$route.query.orderNumber;
|
||||||
// this.canceldanhao(this.orderNumber);
|
// this.canceldanhao(this.orderNumber);
|
||||||
|
Loading…
Reference in New Issue
Block a user