|
|
@ -64,6 +64,13 @@ |
|
|
|
/> |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
<div style="display: flex;justify-content: right;align-items: center" v-if="integralShow"> |
|
|
|
<span style="font-size: 15px;margin-right: 5px">可用{{ integralNum }}积分抵扣{{ integralPrice.toFixed(2) }}元</span> |
|
|
|
<el-checkbox v-model="selectIntegral" |
|
|
|
@change='changeIntegral()' |
|
|
|
:true-label='1' |
|
|
|
:false-label='0'/> |
|
|
|
</div> |
|
|
|
<div class="payBox"> |
|
|
|
<div class="payTit">选择支付方式</div> |
|
|
|
<div class="payList"> |
|
|
@ -213,7 +220,8 @@ import { |
|
|
|
orderSubmit, |
|
|
|
getSettlement, |
|
|
|
getGroupSettle, |
|
|
|
checkOrderResult |
|
|
|
checkOrderResult, |
|
|
|
queryDict |
|
|
|
} from '@/api/user/order.js' |
|
|
|
import { |
|
|
|
getCartList, |
|
|
@ -286,6 +294,12 @@ export default { |
|
|
|
couponShopAmount: 0, // 商家券总折扣 |
|
|
|
hasCheck: 0, // 含有不可叠加券: 1.平台券 2.商家券 |
|
|
|
disabledButton: false, // 获地址是否符合商家配送范围内 |
|
|
|
selectIntegral: true, |
|
|
|
integralNum: 0, |
|
|
|
integralRatio: 0, // 积分兑换比例 |
|
|
|
integralPrice: 0, // 总积分可减多少元 |
|
|
|
orderCreditThreshold: 0, // 满多少元可以抵扣 |
|
|
|
integralShow: false, // 显示隐藏积分 |
|
|
|
} |
|
|
|
}, |
|
|
|
created () { |
|
|
@ -317,6 +331,7 @@ export default { |
|
|
|
mounted () { |
|
|
|
// 获取地址列表 |
|
|
|
this.getAddressList() |
|
|
|
this.queryDict() |
|
|
|
if (this.$route.query.type) { |
|
|
|
this.getSetProList() |
|
|
|
} else { |
|
|
@ -858,6 +873,8 @@ export default { |
|
|
|
if (this.checkedPlatformCoupon) { |
|
|
|
this.totalPrice = shopSumPrice - this.couponAmount |
|
|
|
} |
|
|
|
// 积分支付计算 |
|
|
|
this.calcCredit() |
|
|
|
// 加上每个商家的运费 |
|
|
|
this.settlement.shops.forEach((item) => { |
|
|
|
this.totalPrice = this.totalPrice + (item.distribution.distributionPrice || 0) |
|
|
@ -893,6 +910,120 @@ export default { |
|
|
|
} |
|
|
|
this.couponAmount = parseFloat(tmpAmount) |
|
|
|
}, |
|
|
|
|
|
|
|
calcCredit () { |
|
|
|
let shopsLen = this.settlement.shops.length |
|
|
|
const skuRemainMap = this.calcSkuRemainMap() |
|
|
|
const skuCreditMap = this.settlement.skuCreditMap; |
|
|
|
if (skuCreditMap && this.integralRatio > 0) { |
|
|
|
this.orderCreditThreshold = this.settlement.orderCreditThreshold |
|
|
|
let remainUserCredit = this.settlement.userTotalCredit |
|
|
|
let remainTotalPrice = Math.round((this.totalPrice + Number.EPSILON) * 100) / 100 |
|
|
|
let remainDeductLimit = this.settlement.creditDeductLimit |
|
|
|
// 只有订单金额达到阈值,并且用户还有剩余的积分,才能进行积分抵扣 |
|
|
|
if (this.totalPrice >= this.orderCreditThreshold && remainUserCredit > 0 && remainDeductLimit > 0) { |
|
|
|
for (let i = 0; i < shopsLen; i++) { |
|
|
|
const curShop = this.settlement.shops[i] |
|
|
|
let skuLen = curShop.skus.length |
|
|
|
for (let j = 0; j < skuLen; j++) { |
|
|
|
const curSku = curShop.skus[j] |
|
|
|
const skuId = curSku.skuId |
|
|
|
if (skuCreditMap[skuId] > 0 && skuRemainMap[skuId] > 0 && remainUserCredit > 0 && |
|
|
|
remainTotalPrice > 0) { |
|
|
|
// 抵扣之后,必须保证整个订单至少还有0.01元,可用于支付 |
|
|
|
if (remainTotalPrice - skuRemainMap[skuId] < 0.01) { |
|
|
|
skuRemainMap[skuId] -= 0.01 |
|
|
|
} |
|
|
|
// 按照比例换算成需要多少积分抵扣(取整) |
|
|
|
let finalSkuCredit = parseInt((skuRemainMap[skuId] / this.integralRatio).toString()); |
|
|
|
// 优先以商家配置的商品可抵扣积分为准 |
|
|
|
if (skuCreditMap[skuId] < finalSkuCredit) { |
|
|
|
finalSkuCredit = skuCreditMap[skuId] |
|
|
|
} |
|
|
|
// 不能超过用户剩余积分 |
|
|
|
if (remainUserCredit < finalSkuCredit) { |
|
|
|
finalSkuCredit = remainUserCredit |
|
|
|
} |
|
|
|
// 不能超过整个订单可抵扣积分 |
|
|
|
if (remainDeductLimit < finalSkuCredit) { |
|
|
|
finalSkuCredit = remainDeductLimit |
|
|
|
} |
|
|
|
curSku.cachedCredit = finalSkuCredit |
|
|
|
this.integralNum += finalSkuCredit |
|
|
|
remainUserCredit -= finalSkuCredit |
|
|
|
remainDeductLimit -= finalSkuCredit |
|
|
|
remainTotalPrice -= finalSkuCredit |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//计算抵扣价格 |
|
|
|
if (this.integralNum !== 0) { |
|
|
|
this.integralNum = parseInt(this.integralNum) |
|
|
|
this.integralPrice = this.integralNum * this.integralRatio |
|
|
|
if (this.integralNum !== 0) { |
|
|
|
this.integralShow = true |
|
|
|
} |
|
|
|
if (this.selectIntegral) { |
|
|
|
this.totalPrice = this.totalPrice - this.integralPrice |
|
|
|
} |
|
|
|
} else { |
|
|
|
this.integralShow = false |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
/** |
|
|
|
* 计算sku在整个运单价格中的剩余价值 1元的订单,打1折优惠之后,剩余价值就是0.1元 |
|
|
|
*/ |
|
|
|
calcSkuRemainMap () { |
|
|
|
let skuRemainMap = {} |
|
|
|
let shopsLen = this.settlement.shops.length |
|
|
|
const skuCreditMap = this.settlement.skuCreditMap |
|
|
|
for (let i = 0; i < shopsLen; i++) { |
|
|
|
const curShop = this.settlement.shops[i] |
|
|
|
let skuLen = curShop.skus.length |
|
|
|
let checkedShopCoupon = undefined |
|
|
|
curShop.shopCoupons.forEach((item) => { |
|
|
|
if (item.checked) { |
|
|
|
checkedShopCoupon = item |
|
|
|
} |
|
|
|
}) |
|
|
|
for (let j = 0; j < skuLen; j++) { |
|
|
|
const curSku = curShop.skus[j] |
|
|
|
const skuId = curSku.skuId |
|
|
|
// 不是定价捆绑,并且有配置可抵扣的积分,才有必要计算比例 |
|
|
|
if (!curSku.priceId > 0 && skuCreditMap[skuId] > 0) { |
|
|
|
let remainSkuMoney = curSku.price * curSku.number |
|
|
|
if (checkedShopCoupon) { |
|
|
|
let skuShopPercent = remainSkuMoney / curShop.total |
|
|
|
let curReduceMoney = 0 |
|
|
|
if (checkedShopCoupon.couponType === 1) { |
|
|
|
curReduceMoney = checkedShopCoupon.reduceMoney * skuShopPercent |
|
|
|
} else { |
|
|
|
curReduceMoney = remainSkuMoney * (10 - checkedShopCoupon.reduceMoney) / 10 |
|
|
|
} |
|
|
|
remainSkuMoney = remainSkuMoney - curReduceMoney |
|
|
|
} |
|
|
|
// 使用平台券 |
|
|
|
if (this.checkedPlatformCoupon && remainSkuMoney > 0) { |
|
|
|
// 满减 |
|
|
|
if (this.checkedPlatformCoupon.couponType === 1) { |
|
|
|
let skuTotalPercent = remainSkuMoney / this.totalPrice |
|
|
|
remainSkuMoney -= this.checkedPlatformCoupon.reduceMoney * skuTotalPercent |
|
|
|
} |
|
|
|
// 折扣 |
|
|
|
else { |
|
|
|
remainSkuMoney = remainSkuMoney * this.checkedPlatformCoupon.reduceMoney / 10 |
|
|
|
} |
|
|
|
} |
|
|
|
skuRemainMap[skuId] = remainSkuMoney |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return skuRemainMap |
|
|
|
}, |
|
|
|
|
|
|
|
// 选择支付方式 |
|
|
|
selectPay (payType) { |
|
|
|
this.payType = payType |
|
|
@ -926,7 +1057,9 @@ export default { |
|
|
|
sceneId: k.sceneId, |
|
|
|
useMember: k.useMember, |
|
|
|
buyerCouponId: k.buyerCouponId, |
|
|
|
buyerShopCouponId: k.buyerShopCouponId |
|
|
|
buyerShopCouponId: k.buyerShopCouponId, |
|
|
|
useCredit: this.selectIntegral && k.cachedCredit ? k.cachedCredit : undefined, |
|
|
|
useCreditAmount: this.selectIntegral && k.cachedCredit ? (k.cachedCredit * this.integralRatio).toFixed(2) : undefined |
|
|
|
}) |
|
|
|
} |
|
|
|
}) |
|
|
@ -1059,6 +1192,23 @@ export default { |
|
|
|
}, |
|
|
|
toOrder () { |
|
|
|
this.$router.push({path: '/myOrder'}) |
|
|
|
}, |
|
|
|
|
|
|
|
// 积分价格计算 |
|
|
|
changeIntegral () { |
|
|
|
this.selectIntegral = !this.selectIntegral |
|
|
|
if (this.selectIntegral) { |
|
|
|
this.totalPrice = this.totalPrice - this.integralPrice |
|
|
|
} else { |
|
|
|
this.totalPrice = this.totalPrice + this.integralPrice |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
async queryDict () { |
|
|
|
const response = await queryDict({ |
|
|
|
name: 'credit_exchange_rate' |
|
|
|
}) |
|
|
|
this.integralRatio = parseFloat(response.data.data.dictDescribe) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|