mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-11-22 10:27:01 +08:00
Coupon flow refined
This commit is contained in:
@@ -88,8 +88,12 @@
|
||||
<div class="rc-foot">
|
||||
<div class="rc-foo">
|
||||
<div>
|
||||
<div class="discountInfo" v-if="discountAmount">
|
||||
<i>优惠金额:</i>
|
||||
<em>{{ discountAmount }}</em>
|
||||
</div>
|
||||
<i>合计金额:</i>
|
||||
<em>{{ sumPrice }}</em>
|
||||
<em>{{ discountedSumPrice }}</em>
|
||||
</div>
|
||||
<div style="font-weight: bold">
|
||||
<span @click="preJiesuan()">提交订单</span>
|
||||
@@ -147,7 +151,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
<el-dialog :visible.sync="dialogInfo1" class="pop_coupon">
|
||||
<el-dialog :visible.sync="dialogInfo1" class="pop_coupon" :close-on-click-modal="false">
|
||||
<div class="ts-no-data" v-if="drawlist.length<=0">您还没有优惠券,可在商品的详情页面中领取</div>
|
||||
<div class="rs-dis">
|
||||
<div
|
||||
@@ -155,26 +159,33 @@
|
||||
v-for="(item, index) in drawlist"
|
||||
:key="index"
|
||||
>
|
||||
<img :src="userimage" alt="" />
|
||||
<div class="rc-contair">
|
||||
<div class="rc-left">
|
||||
<div v-if="item.couponAmount">
|
||||
<i>¥</i><span>{{ item.couponAmount }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="rc-right">
|
||||
<i>
|
||||
{{ item.couponDesc }}
|
||||
</i>
|
||||
<div v-show="item.validTo">
|
||||
<span>有效期</span>
|
||||
<em>{{ item.validTo }}</em>
|
||||
</div>
|
||||
<div class="rc-footer">
|
||||
<span @click="pickCoupon(item)">立即使用</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<img :src="userimage" alt="" />
|
||||
<div class="rc-contair">
|
||||
<div class="rc-left" :style='usercolor'>
|
||||
<div>
|
||||
<i v-if="(item.couponTypeId!='4' && item.couponAmount>0)">
|
||||
¥
|
||||
</i>
|
||||
<span>
|
||||
{{item.couponTypeId=='4'?parseInt(((item.discount)*10))+'折':item.couponAmount}}
|
||||
</span>
|
||||
</div>
|
||||
<strong>{{ item.couponName }}</strong>
|
||||
</div>
|
||||
<div class="rc-right">
|
||||
<i :style='usercolor'>
|
||||
{{ item.couponName }}
|
||||
</i>
|
||||
<div class="rc-userfont">
|
||||
<strong>有效期</strong>
|
||||
<span>{{item.validFrom}}至</span>
|
||||
<em>{{item.validTo}}</em>
|
||||
</div>
|
||||
<div class="rc-footer">
|
||||
<span @click="pickCoupon(item)">立即使用</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</el-dialog>
|
||||
@@ -201,6 +212,7 @@ export default {
|
||||
path:'/personal/settlement'
|
||||
}
|
||||
],
|
||||
usercolor:{color:'#e1001a'},
|
||||
userimage: require("../../assets/image/unused.png"),
|
||||
curCoupon:{couponName:'未选择可用优惠券'},
|
||||
drawlist:[],
|
||||
@@ -239,14 +251,71 @@ export default {
|
||||
promotion: "¥167.00",
|
||||
payment: "¥0.00 ",
|
||||
},
|
||||
discountAmount:0
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
// 总价计算
|
||||
sumPrice() {
|
||||
return this.goldmedal.reduce((pre, cur) => {
|
||||
return pre + cur.buyCount * cur.productPrice;
|
||||
}, 0);
|
||||
sumPrice() {
|
||||
return this.goldmedal.reduce((pre, cur) => {
|
||||
return pre + cur.buyCount * cur.productPrice;
|
||||
}, 0);
|
||||
},
|
||||
// 折扣计算
|
||||
discountedSumPrice() {
|
||||
let total = 0;
|
||||
if(this.curCoupon.couponId) {
|
||||
//Coupon Calculation
|
||||
let couponUsed=false;
|
||||
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;
|
||||
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;
|
||||
couponUsed=true;
|
||||
break;
|
||||
case 3: //Limited product % discount
|
||||
case 4: //% discount
|
||||
total = total + (itemInCart.productPrice * itemInCart.buyCount) * (1-this.curCoupon.discount);
|
||||
this.discountAmount = (itemInCart.productPrice * itemInCart.buyCount) * this.curCoupon.discount;
|
||||
couponUsed=true;
|
||||
break;
|
||||
default:
|
||||
total += itemInCart.productPrice * itemInCart.buyCount;
|
||||
break;
|
||||
}
|
||||
//Into coupon discount calculation end
|
||||
}
|
||||
} else {
|
||||
total += itemInCart.productPrice * itemInCart.buyCount;
|
||||
}
|
||||
}
|
||||
} 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: {
|
||||
@@ -278,14 +347,34 @@ export default {
|
||||
async userdraw(mobile) {
|
||||
let data = await getdraw(mobile);
|
||||
let _self = this;
|
||||
let curTime = new Date().getTime();
|
||||
let valDateFromTime=0;
|
||||
let valDateToTime=0;
|
||||
let dateChecked=true;
|
||||
if (data) {
|
||||
//TODO check status = 0
|
||||
this.drawlist=[];
|
||||
data.data.forEach((item) => {
|
||||
if(item.status==0) {
|
||||
_self.drawlist.push(item);
|
||||
for(let itemInCart of this.goldmedal) {
|
||||
for(let myCoupon of data.data) {
|
||||
valDateFromTime=0;
|
||||
valDateToTime=0;
|
||||
dateChecked=true;
|
||||
if(myCoupon.fValidFrom) {
|
||||
valDateFromTime = new Date(myCoupon.fValidFrom).getTime();
|
||||
}
|
||||
if(myCoupon.fValidTo) {
|
||||
valDateToTime = new Date(myCoupon.fValidTo).getTime();
|
||||
}
|
||||
if(valDateFromTime && curTime < valDateFromTime) {
|
||||
dateChecked=false;
|
||||
}
|
||||
if(valDateToTime && curTime > valDateToTime) {
|
||||
dateChecked=false;
|
||||
}
|
||||
if(dateChecked && myCoupon.status == 0 && (myCoupon.productCodes.indexOf(itemInCart.productCode)>-1 || !myCoupon.productCodes)) {
|
||||
_self.drawlist.push(myCoupon);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
pickCoupon(item){
|
||||
@@ -450,8 +539,8 @@ export default {
|
||||
let res = await generateOrderWX(postData);
|
||||
if (res.success) {
|
||||
let userPayData = {
|
||||
orderId: res.data,
|
||||
userprice: this.sumPrice,
|
||||
orderId: res.data.orderNumber,
|
||||
userprice: parseFloat(res.data.orderAmount).toFixed(2),
|
||||
userinformation:
|
||||
postData[0].orderAddress.addressUserName +
|
||||
" " +
|
||||
|
||||
Reference in New Issue
Block a user