订单支付增加优惠券积分
This commit is contained in:
@@ -119,9 +119,13 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="u-flex">
|
<view class="u-flex">
|
||||||
<view class="color-red u-m-r-24" v-if="youhuiAllPrice>0">
|
<view class="u-flex u-m-r-24" v-if="youhuiAllPrice>0">
|
||||||
已优惠¥{{youhuiAllPrice}}
|
<view class="color-red u-m-r-6 " >
|
||||||
|
已优惠¥{{youhuiAllPrice}}
|
||||||
|
</view>
|
||||||
|
<up-icon name="info-circle" color="#999" :size="14" @click="youhuiDetailShow"></up-icon>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view>
|
<view>
|
||||||
<text>小计¥</text>
|
<text>小计¥</text>
|
||||||
<text class="font-bold u-font-32">{{allPrice}}</text>
|
<text class="font-bold u-font-32">{{allPrice}}</text>
|
||||||
@@ -161,12 +165,41 @@
|
|||||||
<my-button @tap="printOrder" type="cancel" :color="color.ColorMain">重新打印</my-button>
|
<my-button @tap="printOrder" type="cancel" :color="color.ColorMain">重新打印</my-button>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<up-popup :round="10" :show="pop.youhui" mode="center" closeOnClickOverlay @close="youhuiDetailHide" >
|
||||||
|
<view class="u-p-30" style="width: 80vw;">
|
||||||
|
<view class="font-bold u-text-center">优惠详情</view>
|
||||||
|
<view class="u-m-t-32">
|
||||||
|
<view class="u-flex u-row-between">
|
||||||
|
<view>满减券抵扣</view>
|
||||||
|
<view class="color-red">
|
||||||
|
<text>¥</text>
|
||||||
|
<text>{{orderInfo.fullCouponDiscountAmount}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="u-flex u-row-between u-m-t-18">
|
||||||
|
<view>商品券抵扣</view>
|
||||||
|
<view class="color-red">
|
||||||
|
<text>¥</text>
|
||||||
|
<text>{{orderInfo.productCouponDiscountAmount}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
<view class="u-flex u-row-between u-m-t-18">
|
||||||
|
<view>积分抵扣</view>
|
||||||
|
<view class="color-red">
|
||||||
|
<text>¥</text>
|
||||||
|
<text>{{orderInfo.pointsDiscountAmount}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</up-popup>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import {
|
import {
|
||||||
computed
|
computed, reactive
|
||||||
} from 'vue';
|
} from 'vue';
|
||||||
import color from '@/commons/color.js'
|
import color from '@/commons/color.js'
|
||||||
import {
|
import {
|
||||||
@@ -178,6 +211,15 @@
|
|||||||
canTuicai,
|
canTuicai,
|
||||||
numSum
|
numSum
|
||||||
} from '@/commons/utils/goodsUtil.js'
|
} from '@/commons/utils/goodsUtil.js'
|
||||||
|
const pop=reactive({
|
||||||
|
youhui:false
|
||||||
|
})
|
||||||
|
function youhuiDetailShow(){
|
||||||
|
pop.youhui=true
|
||||||
|
}
|
||||||
|
function youhuiDetailHide(){
|
||||||
|
pop.youhui=false
|
||||||
|
}
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
orderInfo: {
|
orderInfo: {
|
||||||
type: Object,
|
type: Object,
|
||||||
|
|||||||
@@ -33,7 +33,7 @@
|
|||||||
<view class="color-666 u-m-t-8 u-font-24">余额</view>
|
<view class="color-666 u-m-t-8 u-font-24">余额</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="">
|
<view class="">
|
||||||
<view class="font-bold">{{user.totalScore}}</view>
|
<view class="font-bold">{{user.accountPoints}}</view>
|
||||||
<view class="color-666 u-m-t-8 u-font-24">积分</view>
|
<view class="color-666 u-m-t-8 u-font-24">积分</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="">
|
<view class="">
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
headImg:'',
|
headImg:'',
|
||||||
telephone:'',
|
telephone:'',
|
||||||
amount:'0.00',
|
amount:'0.00',
|
||||||
totalScore:'0.00'
|
accountPoints:'0.00'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -316,7 +316,7 @@
|
|||||||
headImg:'',
|
headImg:'',
|
||||||
telephone:'',
|
telephone:'',
|
||||||
amount:'0.00',
|
amount:'0.00',
|
||||||
totalScore:'0.00'
|
accountPoints:'0.00'
|
||||||
})
|
})
|
||||||
//更新选择用户
|
//更新选择用户
|
||||||
async function setUser(par) {
|
async function setUser(par) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
<view @click="discountShow">修改</view>
|
<view @click="discountShow">修改</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
<view class="content bg-fff border-r-12">
|
<view class="content bg-fff border-r-12">
|
||||||
<view class=" u-p-t-30 u-p-l-26 u-p-r-26 card top u-m-t-30">
|
<view class=" u-p-t-30 u-p-l-26 u-p-r-26 card top u-m-t-30">
|
||||||
@@ -44,6 +44,7 @@
|
|||||||
<view class="u-flex">
|
<view class="u-flex">
|
||||||
<view class="hui">减</view>
|
<view class="hui">减</view>
|
||||||
<view class="u-m-l-18">{{item.name}}</view>
|
<view class="u-m-l-18">{{item.name}}</view>
|
||||||
|
<view class="u-m-l-18 color-999">x{{item.num}}</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="color-red">
|
<view class="color-red">
|
||||||
-¥{{item.discountAmount}}
|
-¥{{item.discountAmount}}
|
||||||
@@ -53,7 +54,7 @@
|
|||||||
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="border-bottom u-p-b-30" v-if="payPrice!=order.amount||accountPoints.sel">
|
<view class="border-bottom u-p-b-30" v-if="discount.price||accountPoints.sel">
|
||||||
<view class="u-flex u-p-l-24 u-p-r-24 u-row-between u-p-t-30 "
|
<view class="u-flex u-p-l-24 u-p-r-24 u-row-between u-p-t-30 "
|
||||||
v-if="discount.price&&discount.currentPrice!=order.amount">
|
v-if="discount.price&&discount.currentPrice!=order.amount">
|
||||||
<view>服务员改价</view>
|
<view>服务员改价</view>
|
||||||
@@ -69,7 +70,7 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
<view class="bg-fff border-r-12 ">
|
<view class="bg-fff border-r-12 ">
|
||||||
<view class="u-p-t-30 u-p-l-50 u-p-r-50 card bottom">
|
<view class="u-p-t-30 u-p-l-50 u-p-r-50 card bottom">
|
||||||
@@ -111,14 +112,14 @@
|
|||||||
<view class="u-flex ">
|
<view class="u-flex ">
|
||||||
<view class="">积分抵扣</view>
|
<view class="">积分抵扣</view>
|
||||||
<view class="color-999 u-m-l-10">
|
<view class="color-999 u-m-l-10">
|
||||||
<text>(</text>
|
<text>(</text>
|
||||||
<text>{{user.accountPoints||'0'}}</text>
|
<text>{{user.accountPoints||'0'}}</text>
|
||||||
<text>)</text>
|
<text>)</text>
|
||||||
</view>
|
</view>
|
||||||
<!-- <view><text class="color-red font-bold">{{accountPoints.price}}</text>元</view> -->
|
<!-- <view><text class="color-red font-bold">{{accountPoints.price}}</text>元</view> -->
|
||||||
</view>
|
</view>
|
||||||
<view class="u-flex">
|
<view class="u-flex">
|
||||||
|
|
||||||
<view class="u-flex" @click.stop="refPointsOpen">
|
<view class="u-flex" @click.stop="refPointsOpen">
|
||||||
<view><text>{{accountPoints.num}}</text></view>
|
<view><text>{{accountPoints.num}}</text></view>
|
||||||
<view v-if="accountPoints.calcRes.usable">
|
<view v-if="accountPoints.calcRes.usable">
|
||||||
@@ -126,22 +127,22 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="u-m-l-32 u-relative" v-if="accountPoints.calcRes.usable" >
|
<view class="u-m-l-32 u-relative" v-if="accountPoints.calcRes.usable">
|
||||||
<view class="u-absolute position-all"></view>
|
<view class="u-absolute position-all"></view>
|
||||||
<my-radio
|
<my-radio :modelValue="accountPoints.sel">
|
||||||
:modelValue="accountPoints.sel">
|
|
||||||
</my-radio>
|
</my-radio>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="color-999 u-font-24 u-m-t-16" >
|
<view class="color-999 u-font-24 u-m-t-16">
|
||||||
<view class="" v-if="accountPoints.calcRes.unusableReason">
|
<view class="" v-if="accountPoints.calcRes.unusableReason">
|
||||||
<text class="color-red">*</text>
|
<text class="color-red">*</text>
|
||||||
<text >{{accountPoints.calcRes.unusableReason}}</text>
|
<text>{{accountPoints.calcRes.unusableReason}}</text>
|
||||||
</view>
|
</view>
|
||||||
<view class="" v-if="accountPoints.calcRes.usable">
|
<view class="" v-if="accountPoints.calcRes.usable">
|
||||||
<text class="color-red">*</text>
|
<text class="color-red">*</text>
|
||||||
<text class="" v-if="accountPoints.calcRes.equivalentPoints">100积分等于{{to2(accountPoints.calcRes.equivalentPoints*100)}}元,</text>
|
<text class=""
|
||||||
|
v-if="accountPoints.calcRes.equivalentPoints">100积分等于{{to2(accountPoints.calcRes.equivalentPoints*100)}}元,</text>
|
||||||
<text>
|
<text>
|
||||||
最大抵扣积分{{accountPoints.calcRes.maxUsablePoints}}
|
最大抵扣积分{{accountPoints.calcRes.maxUsablePoints}}
|
||||||
</text>
|
</text>
|
||||||
@@ -225,10 +226,16 @@
|
|||||||
import infoBox from '@/commons/utils/infoBox.js'
|
import infoBox from '@/commons/utils/infoBox.js'
|
||||||
import editDiscount from '@/components/my-components/edit-discount.vue'
|
import editDiscount from '@/components/my-components/edit-discount.vue'
|
||||||
import editAccountPoints from './components/edit-accountPoints.vue'
|
import editAccountPoints from './components/edit-accountPoints.vue'
|
||||||
|
import {
|
||||||
|
returnGoodsPayPriceMap,returnProCoupStartIndex ,returnProductCoupAllPrice
|
||||||
|
} from '../quan_util.js'
|
||||||
|
//商品数量从0到n每一个对应的价格
|
||||||
|
let $goodsPayPriceMap={}
|
||||||
|
|
||||||
const refPoints=ref(null)
|
const refPoints = ref(null)
|
||||||
function refPointsOpen(){
|
|
||||||
if(!accountPoints.calcRes.usable&&accountPoints.sel){
|
function refPointsOpen() {
|
||||||
|
if (!accountPoints.calcRes.usable && accountPoints.sel) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
refPoints.value.open()
|
refPoints.value.open()
|
||||||
@@ -236,50 +243,50 @@
|
|||||||
const accountPoints = reactive({
|
const accountPoints = reactive({
|
||||||
sel: false,
|
sel: false,
|
||||||
num: 0,
|
num: 0,
|
||||||
calcRes:{
|
calcRes: {
|
||||||
usable:false,
|
usable: false,
|
||||||
unusableReason:'',
|
unusableReason: '',
|
||||||
minDeductionPoints:0,
|
minDeductionPoints: 0,
|
||||||
maxUsablePoints:0
|
maxUsablePoints: 0
|
||||||
},
|
},
|
||||||
price:0
|
price: 0
|
||||||
})
|
})
|
||||||
async function calcUsablePoints(){
|
async function calcUsablePoints() {
|
||||||
if(!order.memberId){
|
if (!order.memberId) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const res=await Api.$calcUsablePoints({
|
const res = await Api.$calcUsablePoints({
|
||||||
memberId:order.memberId,
|
memberId: order.memberId,
|
||||||
orderAmount:pointCanDicountPrice.value
|
orderAmount: pointCanDicountPrice.value
|
||||||
})
|
})
|
||||||
accountPoints.calcRes=res
|
accountPoints.calcRes = res
|
||||||
accountPoints.num=res.maxUsablePoints
|
accountPoints.num = res.maxUsablePoints
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
watch(()=>accountPoints.sel,(newval)=>{
|
watch(() => accountPoints.sel, (newval) => {
|
||||||
if(newval){
|
if (newval) {
|
||||||
calcUsablePoints()
|
calcUsablePoints()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
async function calcDeDuctionPoints(){
|
async function calcDeDuctionPoints() {
|
||||||
const res=await Api.$calcDeDuctionPoints({
|
const res = await Api.$calcDeDuctionPoints({
|
||||||
memberId: order.memberId,
|
memberId: order.memberId,
|
||||||
orderAmount: order.amount,
|
orderAmount: order.amount,
|
||||||
points: accountPoints.num
|
points: accountPoints.num
|
||||||
})
|
})
|
||||||
accountPoints.price=res
|
accountPoints.price = res
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
watch(()=>accountPoints.num,(newval)=>{
|
watch(() => accountPoints.num, (newval) => {
|
||||||
if(!newval){
|
if (!newval) {
|
||||||
accountPoints.price=0
|
accountPoints.price = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
calcDeDuctionPoints()
|
calcDeDuctionPoints()
|
||||||
})
|
})
|
||||||
|
|
||||||
function changeAccountPoints() {
|
function changeAccountPoints() {
|
||||||
if(!accountPoints.calcRes.usable){
|
if (!accountPoints.calcRes.usable) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
accountPoints.sel = !accountPoints.sel
|
accountPoints.sel = !accountPoints.sel
|
||||||
@@ -298,7 +305,7 @@
|
|||||||
go.to('PAGES_ORDER_QUAN', {
|
go.to('PAGES_ORDER_QUAN', {
|
||||||
orderId: order.id,
|
orderId: order.id,
|
||||||
memberId: order.memberId,
|
memberId: order.memberId,
|
||||||
orderPrice:payPrice.value
|
orderPrice: payPrice.value*1+coupAllPrice.value*1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
async function discountShow() {
|
async function discountShow() {
|
||||||
@@ -321,7 +328,6 @@
|
|||||||
// }
|
// }
|
||||||
// return false
|
// return false
|
||||||
})
|
})
|
||||||
let payStatus = ref(null) //loading success
|
|
||||||
|
|
||||||
let timer = null
|
let timer = null
|
||||||
|
|
||||||
@@ -386,7 +392,32 @@
|
|||||||
uni.$off('choose-quan')
|
uni.$off('choose-quan')
|
||||||
uni.$on('choose-quan', (arr) => {
|
uni.$on('choose-quan', (arr) => {
|
||||||
console.log(arr);
|
console.log(arr);
|
||||||
pays.quan = arr
|
const manjianCoup = arr.filter(v => v.type == 1)
|
||||||
|
let productCoup = arr.filter(v => v.type == 2)
|
||||||
|
console.log(productCoup);
|
||||||
|
//商品券分组
|
||||||
|
let coupMap={}
|
||||||
|
for(let i in productCoup){
|
||||||
|
const coup=productCoup[i]
|
||||||
|
if(coupMap.hasOwnProperty(coup.proId)){
|
||||||
|
coupMap[coup.proId].push(coup)
|
||||||
|
}else{
|
||||||
|
coupMap[coup.proId]=[coup]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(let key in coupMap){
|
||||||
|
const arr=coupMap[key]
|
||||||
|
for(let i in arr){
|
||||||
|
const coup=arr[i]
|
||||||
|
const proCoupStartIndex=returnProCoupStartIndex(arr,i)
|
||||||
|
console.log(proCoupStartIndex);
|
||||||
|
console.log($goodsPayPriceMap[coup.proId]);
|
||||||
|
coup.discountAmount=returnProductCoupAllPrice($goodsPayPriceMap[coup.proId],proCoupStartIndex,coup.num)
|
||||||
|
console.log(coup.discountAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
console.log(productCoup);
|
||||||
|
pays.quan = [...manjianCoup, ...productCoup]
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -428,13 +459,13 @@
|
|||||||
const discount = reactive({
|
const discount = reactive({
|
||||||
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function editDiscountConfirm(form) {
|
function editDiscountConfirm(form) {
|
||||||
console.log(form);
|
console.log(form);
|
||||||
Object.assign(discount, form)
|
Object.assign(discount, form)
|
||||||
getPayUrl()
|
getPayUrl()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getPayType() {
|
async function getPayType() {
|
||||||
const payTypeList = await Api.$getPayType()
|
const payTypeList = await Api.$getPayType()
|
||||||
pays.payTypes.list = payTypeList
|
pays.payTypes.list = payTypeList
|
||||||
@@ -446,9 +477,11 @@
|
|||||||
chooseUser()
|
chooseUser()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let payStatus = '';
|
||||||
//支付成功回调
|
//支付成功回调
|
||||||
function paySuccess() {
|
function paySuccess() {
|
||||||
infoBox.showToast('支付成功')
|
infoBox.showToast('支付成功')
|
||||||
|
payStatus = 'success'
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
// uni.$emit('orderDetail:update')
|
// uni.$emit('orderDetail:update')
|
||||||
payFinish.value = true
|
payFinish.value = true
|
||||||
@@ -468,35 +501,44 @@
|
|||||||
}
|
}
|
||||||
payOrder()
|
payOrder()
|
||||||
}
|
}
|
||||||
|
const tipsMap = {
|
||||||
|
paying: '支付中',
|
||||||
|
success: '已支付成功'
|
||||||
|
}
|
||||||
async function payOrder() {
|
async function payOrder() {
|
||||||
const payType = pays.payTypes.list[pays.payTypes.selIndex].payType
|
const payType = pays.payTypes.list[pays.payTypes.selIndex].payType
|
||||||
if (payType == 'vipPay' && user.value.amount * 1 < order.amount * 1) {
|
if (payType == 'vipPay' && user.value.amount * 1 < order.amount * 1) {
|
||||||
infoBox.showToast('余额不足')
|
infoBox.showToast('余额不足')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
await Api.$payOrder({
|
if (payStatus) {
|
||||||
tableId: order.tableId,
|
return infoBox.showToast(tipsMap[payStatus])
|
||||||
masterId: order.masterId,
|
}
|
||||||
orderId: order.id || order.orderId,
|
try {
|
||||||
payType,
|
payStatus = 'paying'
|
||||||
vipUserId: order.memberId,
|
await Api.$payOrder({
|
||||||
discount: 1,
|
tableId: order.tableId,
|
||||||
code: '',
|
masterId: order.masterId,
|
||||||
pointsNum:accountPoints.sel?accountPoints.num:0,
|
orderId: order.id || order.orderId,
|
||||||
userCouponInfos:pays.quan.map(v=>{
|
payType,
|
||||||
return {
|
vipUserId: order.memberId,
|
||||||
userCouponId:v.id,
|
discount: 1,
|
||||||
num:v.num
|
code: '',
|
||||||
}
|
pointsNum: accountPoints.sel ? accountPoints.num : 0,
|
||||||
|
userCouponInfos: pays.quan.map(v => {
|
||||||
|
return {
|
||||||
|
userCouponId: v.id,
|
||||||
|
num: v.num
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
paySuccess()
|
||||||
})
|
} catch (e) {
|
||||||
paySuccess()
|
//TODO handle the exception
|
||||||
|
payStatus = ''
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
getPayType()
|
|
||||||
})
|
|
||||||
const order = reactive({
|
const order = reactive({
|
||||||
amount: 0
|
amount: 0
|
||||||
})
|
})
|
||||||
@@ -540,6 +582,8 @@
|
|||||||
async function init() {
|
async function init() {
|
||||||
const orderRes = await orderApi.tbOrderInfoDetail(order.orderId)
|
const orderRes = await orderApi.tbOrderInfoDetail(order.orderId)
|
||||||
Object.assign(order, orderRes)
|
Object.assign(order, orderRes)
|
||||||
|
$goodsPayPriceMap=returnGoodsPayPriceMap(order.detailList)
|
||||||
|
console.log($goodsPayPriceMap);
|
||||||
if (orderRes.memberId) {
|
if (orderRes.memberId) {
|
||||||
calcUsablePoints()
|
calcUsablePoints()
|
||||||
queryAllShopUser({
|
queryAllShopUser({
|
||||||
@@ -550,7 +594,6 @@
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
getPayUrl()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getPayUrl() {
|
function getPayUrl() {
|
||||||
@@ -561,37 +604,36 @@
|
|||||||
payCodeUrl.value = res
|
payCodeUrl.value = res
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
const coupAllPrice=computed(()=>{
|
const coupAllPrice = computed(() => {
|
||||||
return pays.quan.reduce((prve,cur)=>{
|
return pays.quan.reduce((prve, cur) => {
|
||||||
return prve+cur.discountAmount*1
|
return prve + cur.discountAmount * 1
|
||||||
},0)
|
}, 0)
|
||||||
})
|
})
|
||||||
const payPrice=computed(()=>{
|
const payPrice = computed(() => {
|
||||||
const discountPrice=discount.currentPrice?discount.currentPrice:order.amount
|
const discountPrice = discount.currentPrice ? discount.currentPrice : order.amount
|
||||||
const calcPrice=discountPrice-coupAllPrice.value-accountPoints.price*(accountPoints.sel?1:0)
|
const calcPrice = discountPrice - coupAllPrice.value - accountPoints.price * (accountPoints.sel ? 1 : 0)
|
||||||
return (calcPrice<=0?0:calcPrice).toFixed(2)
|
return (calcPrice <= 0 ? 0 : calcPrice).toFixed(2)
|
||||||
})
|
})
|
||||||
watch(()=>payPrice.value,()=>{
|
watch(() => payPrice.value, () => {
|
||||||
getPayUrl()
|
getPayUrl()
|
||||||
})
|
})
|
||||||
const pointCanDicountPrice=computed(()=>{
|
const pointCanDicountPrice = computed(() => {
|
||||||
const discountPrice=discount.currentPrice?discount.currentPrice:order.amount
|
const discountPrice = discount.currentPrice ? discount.currentPrice : order.amount
|
||||||
const calcPrice=discountPrice-coupAllPrice.value
|
const calcPrice = discountPrice - coupAllPrice.value
|
||||||
return (calcPrice<=0?0:calcPrice).toFixed(2)
|
return (calcPrice <= 0 ? 0 : calcPrice).toFixed(2)
|
||||||
})
|
})
|
||||||
watch(()=>pointCanDicountPrice.value,(newval)=>{
|
watch(() => pointCanDicountPrice.value, (newval) => {
|
||||||
calcUsablePoints()
|
calcUsablePoints()
|
||||||
})
|
})
|
||||||
|
|
||||||
onLoad(async (opt) => {
|
onLoad(async (opt) => {
|
||||||
console.log(opt);
|
console.log(opt);
|
||||||
option = opt
|
option = opt
|
||||||
Object.assign(order, opt)
|
Object.assign(order, opt)
|
||||||
const payTypeList = await Api.$getPayType()
|
getPayType()
|
||||||
pays.payTypes.list = payTypeList
|
|
||||||
init()
|
init()
|
||||||
})
|
})
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
console.log('onBeforeUnmount');
|
console.log('onBeforeUnmount');
|
||||||
clear()
|
clear()
|
||||||
|
|||||||
@@ -6,9 +6,11 @@
|
|||||||
<view class="u-m-t-32">
|
<view class="u-m-t-32">
|
||||||
<template v-if="myQuan.types.sel==0">
|
<template v-if="myQuan.types.sel==0">
|
||||||
<view class="" @click="changeFullReductionCouponSel(item)"
|
<view class="" @click="changeFullReductionCouponSel(item)"
|
||||||
v-for="(item,index) in myQuan.res.fullReductionCoupon" :class="{filtergray:item.status}"
|
v-for="(item,index) in myQuan.res.fullReductionCoupon" :class="{filtergray:!item.use}" :key="index">
|
||||||
:key="index">
|
|
||||||
<view class="quan u-row-between u-flex u-col-center u-m-b-32 border-r-10 ">
|
<view class="quan u-row-between u-flex u-col-center u-m-b-32 border-r-10 ">
|
||||||
|
<view class="no-use" v-if="!item.use">
|
||||||
|
<image class="img" src="/pagesOrder/static/image/no-use.svg" mode=""></image>
|
||||||
|
</view>
|
||||||
<view class="sel u-abso" v-if="item.id==myQuan.fullReductionCouponSel.id ">
|
<view class="sel u-abso" v-if="item.id==myQuan.fullReductionCouponSel.id ">
|
||||||
<up-icon name="checkbox-mark" color="#fff"></up-icon>
|
<up-icon name="checkbox-mark" color="#fff"></up-icon>
|
||||||
</view>
|
</view>
|
||||||
@@ -70,9 +72,9 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="right u-flex u-flex-col u-col-bottom u-row-center">
|
<view class="right u-flex u-flex-col u-col-bottom u-row-center">
|
||||||
<view class="u-flex u-row-center w-full">
|
<!-- <view class="u-flex u-row-center w-full">
|
||||||
<view class="color-red font-bold u-m-b-24 ">¥{{item.discountAmount}}</view>
|
<view class="color-red font-bold u-m-b-24 ">¥{{item.discountAmount}}</view>
|
||||||
</view>
|
</view> -->
|
||||||
<view class="u-flex ">
|
<view class="u-flex ">
|
||||||
<view class="use-btn" @click.stop="toEmitChooseQuan(item)">去使用</view>
|
<view class="use-btn" @click.stop="toEmitChooseQuan(item)">去使用</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -90,10 +92,24 @@
|
|||||||
|
|
||||||
<view :style="{height:safebottomHeight+'px'}"></view>
|
<view :style="{height:safebottomHeight+'px'}"></view>
|
||||||
<view class="fixed-b bottom safe-bottom border-top">
|
<view class="fixed-b bottom safe-bottom border-top">
|
||||||
<view class="u-m-b-32">
|
|
||||||
<text>抵扣金额:</text>
|
<view class="u-m-b-32 u-flex u-row-between u-p-t-10">
|
||||||
<text class="color-red">¥</text>
|
<view class="u-flex">
|
||||||
<text class="color-red">{{discountAmount}}</text>
|
<text>抵扣金额:</text>
|
||||||
|
<text class="color-red">¥</text>
|
||||||
|
<text class="color-red">{{discountAmount}}</text>
|
||||||
|
</view>
|
||||||
|
<view class="u-flex u-relative">
|
||||||
|
<text>支付金额:</text>
|
||||||
|
<text class="color-red">¥</text>
|
||||||
|
<text class="color-red">{{payPrice }}</text>
|
||||||
|
<view class="u-absolute u-flex u-row-between" style="bottom: 100%;right: 0;" v-if="payPrice*1!=option.orderPrice*1">
|
||||||
|
<view class="u-flex line-th color-999">
|
||||||
|
<text class="">¥</text>
|
||||||
|
<text class="">{{option.orderPrice}}</text>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="u-flex gap-20">
|
<view class="u-flex gap-20">
|
||||||
<up-button shape="circle" plain @click="back">
|
<up-button shape="circle" plain @click="back">
|
||||||
@@ -105,7 +121,12 @@
|
|||||||
</view>
|
</view>
|
||||||
|
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<up-modal :title="modal.title" :content="modal.content" :show="modal.clear" :confirmText="modal.confirmText"
|
||||||
|
:cancelText="modal.cancelText" showCancelButton closeOnClickOverlay @confirm="confirmModelConfirm"
|
||||||
|
@cancel="confirmModelCancel" @close="setModalShow('clear',false)" width="300px" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
@@ -129,6 +150,7 @@
|
|||||||
import {
|
import {
|
||||||
$activateByOrderId
|
$activateByOrderId
|
||||||
} from '@/http/yskApi/Instead.js'
|
} from '@/http/yskApi/Instead.js'
|
||||||
|
import infoBox from '@/commons/utils/infoBox.js'
|
||||||
import {
|
import {
|
||||||
queryAllShopUser
|
queryAllShopUser
|
||||||
} from '@/http/yskApi/shop-user.js'
|
} from '@/http/yskApi/shop-user.js'
|
||||||
@@ -136,9 +158,48 @@
|
|||||||
returnNewGoodsList,
|
returnNewGoodsList,
|
||||||
returnCoupCanUse,
|
returnCoupCanUse,
|
||||||
returnCouponAllPrice,
|
returnCouponAllPrice,
|
||||||
returnProductCoupon
|
returnProductCoupon,
|
||||||
|
returnCanUseFullReductionCoupon
|
||||||
} from '../quan_util.js'
|
} from '../quan_util.js'
|
||||||
|
|
||||||
|
const modal = reactive({
|
||||||
|
title: '提示',
|
||||||
|
cancelText: '取消',
|
||||||
|
confirmText: '确定',
|
||||||
|
content: '',
|
||||||
|
key: '',
|
||||||
|
clear: false,
|
||||||
|
data: ''
|
||||||
|
})
|
||||||
|
|
||||||
|
function confirmModelCancel() {
|
||||||
|
setModalShow('clear', false, '')
|
||||||
|
}
|
||||||
|
async function confirmModelConfirm() {
|
||||||
|
if (modal.key == 'clear') {
|
||||||
|
myQuan.fullReductionCouponSel = {
|
||||||
|
id: ''
|
||||||
|
}
|
||||||
|
const item = modal.data
|
||||||
|
item.checked = !item.checked
|
||||||
|
const CheckedArr = myQuan.res.productCoupon.filter(v => v.checked)
|
||||||
|
const noCheckedArr = myQuan.res.productCoupon.filter(v => !v.checked)
|
||||||
|
noCheckedArr.map(v => {
|
||||||
|
console.log(returnCoupCanUse(canDikouGoodsArr, v, CheckedArr));
|
||||||
|
v.use = returnCoupCanUse(canDikouGoodsArr, v, CheckedArr)
|
||||||
|
})
|
||||||
|
setModalShow('clear', false, '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function setModalShow(key = 'show', show = true, data) {
|
||||||
|
modal.key = key
|
||||||
|
modal[key] = show
|
||||||
|
modal.data = data
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function back() {
|
function back() {
|
||||||
uni.navigateBack()
|
uni.navigateBack()
|
||||||
}
|
}
|
||||||
@@ -167,6 +228,22 @@
|
|||||||
if (!item.use) {
|
if (!item.use) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
console.log();
|
||||||
|
if (myQuan.fullReductionCouponSel.id && !item.checked) {
|
||||||
|
const goodsQuan = myQuan.res.productCoupon.filter(v => v.checked)
|
||||||
|
const fullReductionCoupon = myQuan.fullReductionCouponSel.id ? [myQuan.fullReductionCouponSel] : []
|
||||||
|
let coupArr = [...goodsQuan, item]
|
||||||
|
const payPrice = option.orderPrice - returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value)
|
||||||
|
console.log(payPrice);
|
||||||
|
if (myQuan.fullReductionCouponSel.fullAmount > payPrice) {
|
||||||
|
modal.content = '选择该商品券后将不满足选择抵扣券的最低满减需求,继续选择将取消选择的满减券'
|
||||||
|
modal.cancelText = '取消'
|
||||||
|
modal.confirmText = '继续选择'
|
||||||
|
setModalShow('clear', true, item)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
item.checked = !item.checked
|
item.checked = !item.checked
|
||||||
const CheckedArr = myQuan.res.productCoupon.filter(v => v.checked)
|
const CheckedArr = myQuan.res.productCoupon.filter(v => v.checked)
|
||||||
const noCheckedArr = myQuan.res.productCoupon.filter(v => !v.checked)
|
const noCheckedArr = myQuan.res.productCoupon.filter(v => !v.checked)
|
||||||
@@ -177,7 +254,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function changeFullReductionCouponSel(item) {
|
function changeFullReductionCouponSel(item) {
|
||||||
myQuan.fullReductionCouponSel = item
|
if (!item.use) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
console.log(item);
|
||||||
|
if (item.id == myQuan.fullReductionCouponSel.id) {
|
||||||
|
myQuan.fullReductionCouponSel = {
|
||||||
|
id: ''
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
myQuan.fullReductionCouponSel = item
|
||||||
|
}
|
||||||
|
myQuan.res.fullReductionCoupon=returnCanUseFullReductionCoupon($fullReductionCoupon, payPrice.value, myQuan.fullReductionCouponSel)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatStr(str) {
|
function formatStr(str) {
|
||||||
@@ -190,6 +278,9 @@
|
|||||||
let user = reactive({
|
let user = reactive({
|
||||||
isVip: false
|
isVip: false
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let $fullReductionCoupon = []
|
||||||
|
let $productCoupon = []
|
||||||
async function getQuan() {
|
async function getQuan() {
|
||||||
order.value = await orderApi.tbOrderInfoDetail(option.orderId)
|
order.value = await orderApi.tbOrderInfoDetail(option.orderId)
|
||||||
if (order.value.memberId) {
|
if (order.value.memberId) {
|
||||||
@@ -202,9 +293,13 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
console.log(order.value);
|
console.log(order.value);
|
||||||
const res = await $activateByOrderId(option)
|
const res = await $activateByOrderId({
|
||||||
|
orderId: option.orderId,
|
||||||
|
memberId: option.memberId
|
||||||
|
})
|
||||||
canDikouGoodsArr = returnNewGoodsList(order.value.detailList || [])
|
canDikouGoodsArr = returnNewGoodsList(order.value.detailList || [])
|
||||||
res.fullReductionCoupon = res.fullReductionCoupon.filter((v) => v.use&&option.orderPrice*1>=v.fullAmount*1)
|
res.fullReductionCoupon = res.fullReductionCoupon.filter((v) => v.use && option.orderPrice * 1 >= v
|
||||||
|
.fullAmount * 1)
|
||||||
res.productCoupon = res.productCoupon.map(v => {
|
res.productCoupon = res.productCoupon.map(v => {
|
||||||
const calcCoup = returnProductCoupon(v, canDikouGoodsArr, user.value)
|
const calcCoup = returnProductCoupon(v, canDikouGoodsArr, user.value)
|
||||||
return {
|
return {
|
||||||
@@ -212,12 +307,15 @@
|
|||||||
checked: false
|
checked: false
|
||||||
}
|
}
|
||||||
}).filter((v) => v.use);
|
}).filter((v) => v.use);
|
||||||
|
$fullReductionCoupon = res.fullReductionCoupon
|
||||||
|
$productCoupon = res.productCoupon
|
||||||
myQuan.res = res
|
myQuan.res = res
|
||||||
myQuan.hasAjax = true;
|
myQuan.hasAjax = true;
|
||||||
}
|
}
|
||||||
const option = reactive({
|
const option = reactive({
|
||||||
orderId: '',
|
orderId: '',
|
||||||
memberId: ''
|
memberId: '',
|
||||||
|
orderPrice:0
|
||||||
})
|
})
|
||||||
|
|
||||||
function toEmitChooseQuan(item) {
|
function toEmitChooseQuan(item) {
|
||||||
@@ -240,6 +338,18 @@
|
|||||||
let coupArr = [...fullReductionCoupon, ...goodsQuan]
|
let coupArr = [...fullReductionCoupon, ...goodsQuan]
|
||||||
return returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value)
|
return returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value)
|
||||||
})
|
})
|
||||||
|
const payPrice=computed(()=>{
|
||||||
|
const pay= option.orderPrice-discountAmount.value
|
||||||
|
return (pay<0?0:pay).toFixed(2)
|
||||||
|
})
|
||||||
|
watch(() => myQuan.types.sel, (newval) => {
|
||||||
|
if (newval == 0) {
|
||||||
|
myQuan.res.fullReductionCoupon = returnCanUseFullReductionCoupon($fullReductionCoupon, payPrice.value, myQuan.fullReductionCouponSel)
|
||||||
|
}
|
||||||
|
if (newval == 1) {
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
onLoad((opt) => {
|
onLoad((opt) => {
|
||||||
Object.assign(option, opt)
|
Object.assign(option, opt)
|
||||||
getQuan()
|
getQuan()
|
||||||
@@ -247,6 +357,7 @@
|
|||||||
let safebottomHeight = ref(0)
|
let safebottomHeight = ref(0)
|
||||||
onReady(() => {
|
onReady(() => {
|
||||||
getSafeBottomHeight('bottom', 0).then(height => {
|
getSafeBottomHeight('bottom', 0).then(height => {
|
||||||
|
console.log(height);
|
||||||
safebottomHeight.value = height
|
safebottomHeight.value = height
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,58 +1,66 @@
|
|||||||
export function isTui(item){
|
export function isTui(item) {
|
||||||
return item.status=='return'||item.status=='refund'||item.status=='refunding'
|
return item.status == 'return' || item.status == 'refund' || item.status == 'refunding'
|
||||||
}
|
}
|
||||||
|
|
||||||
//计算商品券优惠价格
|
//计算商品券优惠价格
|
||||||
export function returnProductCouponPrice(coup, goodsArr, vipUser) {
|
export function returnProductCouponPrice(coup, goodsArr, vipUser) {
|
||||||
const item = goodsArr.find(v => v.productId == coup.proId);
|
const item = goodsArr.find(v => v.productId == coup.proId);
|
||||||
if(!item){
|
if (!item) {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||||
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
||||||
return price*coup.num
|
return price * coup.num
|
||||||
|
|
||||||
}
|
}
|
||||||
//返回新的商品列表,过滤掉退菜的,退单的商品
|
//返回新的商品列表,过滤掉退菜的,退单的商品
|
||||||
export function returnNewGoodsList(arr) {
|
export function returnNewGoodsList(arr) {
|
||||||
let goodsMap={}
|
let goodsMap = {}
|
||||||
return arr.filter(v => !isTui(v))
|
return arr.filter(v => !isTui(v))
|
||||||
}
|
}
|
||||||
//根据当前购物车商品以及数量,已选券对应商品数量,判断该商品券是否可用
|
//根据当前购物车商品以及数量,已选券对应商品数量,判断该商品券是否可用
|
||||||
export function returnCoupCanUse(goodsArr=[],coup,selCoupArr=[]) {
|
export function returnCoupCanUse(goodsArr = [], coup, selCoupArr = []) {
|
||||||
// if(!coup.use){
|
// if(!coup.use){
|
||||||
// return false
|
// return false
|
||||||
// }
|
// }
|
||||||
const findGoods=goodsArr.filter(v=>v.productId==coup.proId)
|
const findGoods = goodsArr.filter(v => v.productId == coup.proId)
|
||||||
if(!findGoods.length){
|
if (!findGoods.length) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const findGoodsTotalNumber=findGoods.reduce((prve,cur)=>{
|
const findGoodsTotalNumber = findGoods.reduce((prve, cur) => {
|
||||||
return prve+cur.num*1
|
return prve + cur.num * 1
|
||||||
},0)
|
}, 0)
|
||||||
const selCoupNumber=selCoupArr.filter(v=>v.proId==coup.proId).reduce((prve,cur)=>{
|
const selCoupNumber = selCoupArr.filter(v => v.proId == coup.proId).reduce((prve, cur) => {
|
||||||
return prve+cur.num*1
|
return prve + cur.num * 1
|
||||||
},0)
|
}, 0)
|
||||||
if(selCoupNumber>=findGoodsTotalNumber){
|
if (selCoupNumber >= findGoodsTotalNumber) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return findGoodsTotalNumber<(coup.num+selCoupNumber)?false:true
|
return findGoodsTotalNumber < (coup.num + selCoupNumber) ? false : true
|
||||||
}
|
}
|
||||||
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
|
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
|
||||||
export function returnProductCoupon(coup, goodsArr, vipUser,selCoupArr=[]) {
|
export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
|
||||||
const newGoodsArr = returnNewGoodsList(goodsArr)
|
const newGoodsArr = returnNewGoodsList(goodsArr)
|
||||||
const item = newGoodsArr.find(v => v.productId == coup.proId);
|
const item = newGoodsArr.find(v => v.productId == coup.proId);
|
||||||
if(!item){
|
if (!item) {
|
||||||
return {...coup, discountAmount: 0,use:false}
|
return {
|
||||||
}
|
...coup,
|
||||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
discountAmount: 0,
|
||||||
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
use: false
|
||||||
const discountAmount=(price*coup.num).toFixed(2)
|
}
|
||||||
|
}
|
||||||
|
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||||
|
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
||||||
|
const discountAmount = (price * coup.num).toFixed(2)
|
||||||
console.log(discountAmount);
|
console.log(discountAmount);
|
||||||
|
|
||||||
const canUse=!coup.use?false:(discountAmount>0&&returnCoupCanUse(goodsArr,coup,selCoupArr))
|
const canUse = !coup.use ? false : (discountAmount > 0 && returnCoupCanUse(goodsArr, coup, selCoupArr))
|
||||||
// const canUse=discountAmount>0
|
// const canUse=discountAmount>0
|
||||||
return { ...coup, discountAmount: discountAmount,use:canUse}
|
return {
|
||||||
|
...coup,
|
||||||
|
discountAmount: discountAmount,
|
||||||
|
use: canUse
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -64,38 +72,131 @@ export function returnProductCoupon(coup, goodsArr, vipUser,selCoupArr=[]) {
|
|||||||
* @param {*} vipUser
|
* @param {*} vipUser
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function returnProductAllCoup(coupArr, goodsArr, vipUser){
|
export function returnProductAllCoup(coupArr, goodsArr, vipUser) {
|
||||||
return coupArr.map((v) => {
|
return coupArr.map((v) => {
|
||||||
return returnProductCoupon(v, goodsArr, vipUser)
|
return returnProductCoupon(v, goodsArr, vipUser)
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
//返回商品实际支付价格
|
||||||
|
export function returnProductPayPrice(goods,vipUser){
|
||||||
|
const memberPrice = goods.memberPrice ? goods.memberPrice : goods.price;
|
||||||
|
const price = vipUser.isVip ? memberPrice : item.price;
|
||||||
|
return price
|
||||||
|
}
|
||||||
|
//返回商品券抵扣的商品价格
|
||||||
|
export function returnProductCoupAllPrice(productPriceArr,startIndex,num){
|
||||||
|
return productPriceArr.slice(startIndex,startIndex+num).reduce((prve,cur)=>{
|
||||||
|
let curPrice=0
|
||||||
|
if(typeof cur==='object'){
|
||||||
|
curPrice=cur.memberPrice*1
|
||||||
|
}else{
|
||||||
|
curPrice=cur*1
|
||||||
|
}
|
||||||
|
return prve+curPrice
|
||||||
|
},0)
|
||||||
|
}
|
||||||
|
//返回同类商品券在同类商品价格数组里的开始位置
|
||||||
|
export function returnProCoupStartIndex(coupArr,index){
|
||||||
|
return coupArr.slice(0,index).reduce((prve,cur)=>{
|
||||||
|
return prve+cur.num*1
|
||||||
|
},0)
|
||||||
|
}
|
||||||
|
//返回商品数量从0到n每一个对应的价格对照表
|
||||||
|
export function returnGoodsPayPriceMap(goodsArr){
|
||||||
|
return goodsArr.reduce((prve,cur)=>{
|
||||||
|
if(!prve.hasOwnProperty(cur.productId)){
|
||||||
|
prve[cur.productId]=[]
|
||||||
|
}
|
||||||
|
const arr=new Array(cur.num).fill(cur).map(v=>{
|
||||||
|
return {
|
||||||
|
memberPrice:v.memberPrice?v.memberPrice:v.price,
|
||||||
|
price:v.price
|
||||||
|
}
|
||||||
|
})
|
||||||
|
prve[cur.productId].push(...arr)
|
||||||
|
return prve
|
||||||
|
},{})
|
||||||
|
}
|
||||||
//计算商品券总优惠价格
|
//计算商品券总优惠价格
|
||||||
export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) {
|
export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||||
if(coupArr.length == 0){
|
if (coupArr.length == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return coupArr.reduce((a, b) => {
|
//商品分组
|
||||||
const price = returnProductCouponPrice(b, goodsArr, vipUser)
|
const goodsMap={}
|
||||||
return a + price;
|
//商品数量从0到n每一个对应的价格
|
||||||
}, 0).toFixed(2);
|
const goodsPayPriceMap={}
|
||||||
|
//商品券分组
|
||||||
|
let coupMap={}
|
||||||
|
for(let i in coupArr){
|
||||||
|
const coup=coupArr[i]
|
||||||
|
if(coupMap.hasOwnProperty(coup.proId)){
|
||||||
|
coupMap[coup.proId].push(coup)
|
||||||
|
}else{
|
||||||
|
coupMap[coup.proId]=[coup]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let total=0
|
||||||
|
for(let key in coupMap){
|
||||||
|
const arr=coupMap[key]
|
||||||
|
for(let i in arr){
|
||||||
|
const coup=arr[i]
|
||||||
|
if(!goodsMap.hasOwnProperty(coup.proId)){
|
||||||
|
goodsMap[coup.proId]=goodsArr.filter(v=>v.productId==coup.proId).map(v=>{
|
||||||
|
return {
|
||||||
|
...v,
|
||||||
|
payPrice:returnProductPayPrice(v,vipUser)
|
||||||
|
}
|
||||||
|
}).sort((a,b)=>{
|
||||||
|
const aPrice=a.payPrice
|
||||||
|
const bPrice=b.payPrice
|
||||||
|
return aPrice-bPrice
|
||||||
|
})
|
||||||
|
goodsPayPriceMap[coup.proId]=goodsMap[coup.proId].reduce((prve,cur)=>{
|
||||||
|
const arr=new Array(cur.num).fill(cur.payPrice)
|
||||||
|
console.log(arr);
|
||||||
|
prve.push(...arr)
|
||||||
|
return prve
|
||||||
|
},[])
|
||||||
|
}
|
||||||
|
const proCoupStartIndex=returnProCoupStartIndex(arr,i)
|
||||||
|
console.log(proCoupStartIndex);
|
||||||
|
total+=returnProductCoupAllPrice(goodsPayPriceMap[coup.proId],proCoupStartIndex,coup.num)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return total.toFixed(2);
|
||||||
|
|
||||||
}
|
}
|
||||||
//计算满减券总优惠价格
|
//计算满减券总优惠价格
|
||||||
export function returnFullReductionCouponAllPrice(coupArr) {
|
export function returnFullReductionCouponAllPrice(coupArr) {
|
||||||
if(coupArr.length == 0){
|
if (coupArr.length == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return coupArr.filter(v => v.type == 1).reduce((a, b) => {
|
return coupArr.filter(v => v.type == 1).reduce((a, b) => {
|
||||||
const price = b.discountAmount
|
const price = b.discountAmount
|
||||||
return a + price;
|
return a + price;
|
||||||
}, 0).toFixed(2);
|
}, 0).toFixed(2);
|
||||||
|
|
||||||
}
|
}
|
||||||
//计算优惠券总价格
|
//计算优惠券总价格
|
||||||
export function returnCouponAllPrice(coupArr, goodsArr, vipUser) {
|
export function returnCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||||
const poductAllprice=returnProductCouponAllPrice(coupArr, goodsArr, vipUser)
|
const poductAllprice = returnProductCouponAllPrice(coupArr, goodsArr, vipUser)
|
||||||
const pointAllPrice=returnFullReductionCouponAllPrice(coupArr)
|
const pointAllPrice = returnFullReductionCouponAllPrice(coupArr)
|
||||||
return (poductAllprice*1+pointAllPrice*1).toFixed(2);
|
return (poductAllprice * 1 + pointAllPrice * 1).toFixed(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
//返回当前满减券列表可用状态
|
||||||
|
export function returnCanUseFullReductionCoupon(coupArr, payPrice, selCoup) {
|
||||||
|
return coupArr.map(v => {
|
||||||
|
if (v.id == selCoup.id) {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
const isfullAmount = payPrice >= v.fullAmount * 1
|
||||||
|
return {
|
||||||
|
...v,
|
||||||
|
use: v.use && isfullAmount
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user