修改使用优惠券逻辑
This commit is contained in:
@@ -227,7 +227,7 @@
|
|||||||
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 {
|
import {
|
||||||
returnGoodsPayPriceMap,returnProCoupStartIndex ,returnProductCoupAllPrice
|
returnGoodsPayPriceMap,returnProCoupStartIndex ,returnProductCoupAllPrice,returnProductCanUseNum
|
||||||
} from '../quan_util.js'
|
} from '../quan_util.js'
|
||||||
//商品数量从0到n每一个对应的价格
|
//商品数量从0到n每一个对应的价格
|
||||||
let $goodsPayPriceMap={}
|
let $goodsPayPriceMap={}
|
||||||
@@ -396,7 +396,7 @@
|
|||||||
uni.$on('choose-quan', (arr) => {
|
uni.$on('choose-quan', (arr) => {
|
||||||
console.log(arr);
|
console.log(arr);
|
||||||
const manjianCoup = arr.filter(v => v.type == 1&&v.num>=1)
|
const manjianCoup = arr.filter(v => v.type == 1&&v.num>=1)
|
||||||
let productCoup = arr.filter(v => v.type == 2&&v.num>=1)
|
let productCoup = arr.filter(v => v.type == 2)
|
||||||
console.log(productCoup);
|
console.log(productCoup);
|
||||||
//商品券分组
|
//商品券分组
|
||||||
let coupMap={}
|
let coupMap={}
|
||||||
@@ -408,16 +408,20 @@
|
|||||||
coupMap[coup.proId]=[coup]
|
coupMap[coup.proId]=[coup]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.log(coupMap);
|
||||||
for(let key in coupMap){
|
for(let key in coupMap){
|
||||||
const arr=coupMap[key]
|
const arr=coupMap[key]
|
||||||
for(let i in arr){
|
for(let i in arr){
|
||||||
const coup=arr[i]
|
const coup=arr[i]
|
||||||
const proCoupStartIndex=returnProCoupStartIndex(arr,i)
|
const proCoupStartIndex=returnProCoupStartIndex(arr,i)
|
||||||
const num=Math.min($goodsPayPriceMap[coup.proId].length,coup.num)
|
console.log(proCoupStartIndex);
|
||||||
|
const coupUseNum=returnProductCanUseNum($goodsPayPriceMap[coup.proId],proCoupStartIndex,coup.num)
|
||||||
|
const num=Math.min($goodsPayPriceMap[coup.proId].length,coupUseNum)
|
||||||
coup.num=num
|
coup.num=num
|
||||||
coup.discountAmount=returnProductCoupAllPrice($goodsPayPriceMap[coup.proId],proCoupStartIndex,num).toFixed(2)
|
coup.discountAmount=returnProductCoupAllPrice($goodsPayPriceMap[coup.proId],proCoupStartIndex,num).toFixed(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
productCoup=productCoup.filter(v=>v.num>=1)
|
||||||
console.log(productCoup);
|
console.log(productCoup);
|
||||||
pays.quan = [...manjianCoup, ...productCoup]
|
pays.quan = [...manjianCoup, ...productCoup]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -21,7 +21,8 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class=" u-m-t-20 u-flex">
|
<view class=" u-m-t-20 u-flex">
|
||||||
<view>有效期:</view>
|
<view>有效期:</view>
|
||||||
<view class="u-font-24 u-m-l-6"> {{dayjs(item.endTime).format('YYYY-MM-DD HH:mm:ss') }}</view>
|
<view class="u-font-24 u-m-l-6"> {{dayjs(item.endTime).format('YYYY-MM-DD HH:mm:ss') }}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="u-m-t-10 color-999 u-font-24">
|
<view class="u-m-t-10 color-999 u-font-24">
|
||||||
{{ formatStr(item.useRestrictions)}}
|
{{ formatStr(item.useRestrictions)}}
|
||||||
@@ -65,7 +66,8 @@
|
|||||||
</view>
|
</view>
|
||||||
<view class=" u-m-t-14 u-flex">
|
<view class=" u-m-t-14 u-flex">
|
||||||
<view>有效期:</view>
|
<view>有效期:</view>
|
||||||
<view class="u-font-24 u-m-l-6"> {{dayjs(item.endTime).format('YYYY-MM-DD HH:mm:ss') }}</view>
|
<view class="u-font-24 u-m-l-6"> {{dayjs(item.endTime).format('YYYY-MM-DD HH:mm:ss') }}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="u-m-t-10 color-999 u-font-24">
|
<view class="u-m-t-10 color-999 u-font-24">
|
||||||
{{ formatStr(item.useRestrictions)}}
|
{{ formatStr(item.useRestrictions)}}
|
||||||
@@ -92,7 +94,7 @@
|
|||||||
|
|
||||||
<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 u-flex u-row-between u-p-t-10">
|
<view class="u-m-b-32 u-flex u-row-between u-p-t-10">
|
||||||
<view class="u-flex">
|
<view class="u-flex">
|
||||||
<text>抵扣金额:</text>
|
<text>抵扣金额:</text>
|
||||||
@@ -103,7 +105,8 @@
|
|||||||
<text>支付金额:</text>
|
<text>支付金额:</text>
|
||||||
<text class="color-red">¥</text>
|
<text class="color-red">¥</text>
|
||||||
<text class="color-red">{{payPrice }}</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-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">
|
<view class="u-flex line-th color-999">
|
||||||
<text class="">¥</text>
|
<text class="">¥</text>
|
||||||
<text class="">{{option.orderPrice}}</text>
|
<text class="">{{option.orderPrice}}</text>
|
||||||
@@ -229,13 +232,18 @@
|
|||||||
if (!item.use) {
|
if (!item.use) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
console.log();
|
|
||||||
if (myQuan.fullReductionCouponSel.id && !item.checked) {
|
if (myQuan.fullReductionCouponSel.id && !item.checked) {
|
||||||
const goodsQuan = myQuan.res.productCoupon.filter(v => v.checked)
|
const goodsQuan = myQuan.res.productCoupon.filter(v => v.checked)
|
||||||
const fullReductionCoupon = myQuan.fullReductionCouponSel.id ? [myQuan.fullReductionCouponSel] : []
|
const fullReductionCoupon = myQuan.fullReductionCouponSel.id ? [myQuan.fullReductionCouponSel] : []
|
||||||
let coupArr = [...goodsQuan, item]
|
let coupArr = [...goodsQuan, item]
|
||||||
const payPrice = option.orderPrice - returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value)
|
const payPrice = option.orderPrice - returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value)
|
||||||
console.log(payPrice);
|
if (payPrice<=0) {
|
||||||
|
modal.content = '选择该商品券后支付金额将为0,继续选择将取消选择的满减券'
|
||||||
|
modal.cancelText = '取消'
|
||||||
|
modal.confirmText = '继续选择'
|
||||||
|
setModalShow('clear', true, item)
|
||||||
|
return
|
||||||
|
}
|
||||||
if (myQuan.fullReductionCouponSel.fullAmount > payPrice) {
|
if (myQuan.fullReductionCouponSel.fullAmount > payPrice) {
|
||||||
modal.content = '选择该商品券后将不满足选择抵扣券的最低满减需求,继续选择将取消选择的满减券'
|
modal.content = '选择该商品券后将不满足选择抵扣券的最低满减需求,继续选择将取消选择的满减券'
|
||||||
modal.cancelText = '取消'
|
modal.cancelText = '取消'
|
||||||
@@ -247,11 +255,18 @@
|
|||||||
|
|
||||||
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)
|
||||||
|
if (CheckedArr.length <= 0) {
|
||||||
|
return myQuan.res.productCoupon.map(v => {
|
||||||
|
v.use = true
|
||||||
|
})
|
||||||
|
}
|
||||||
const noCheckedArr = myQuan.res.productCoupon.filter(v => !v.checked)
|
const noCheckedArr = myQuan.res.productCoupon.filter(v => !v.checked)
|
||||||
noCheckedArr.map(v => {
|
noCheckedArr.map(v => {
|
||||||
console.log(returnCoupCanUse(canDikouGoodsArr, v, CheckedArr));
|
console.log(returnCoupCanUse(canDikouGoodsArr, v, CheckedArr));
|
||||||
v.use = returnCoupCanUse(canDikouGoodsArr, v, CheckedArr)
|
v.use = returnCoupCanUse(canDikouGoodsArr, v, CheckedArr)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeFullReductionCouponSel(item) {
|
function changeFullReductionCouponSel(item) {
|
||||||
@@ -263,10 +278,11 @@
|
|||||||
myQuan.fullReductionCouponSel = {
|
myQuan.fullReductionCouponSel = {
|
||||||
id: ''
|
id: ''
|
||||||
}
|
}
|
||||||
}else{
|
} else {
|
||||||
myQuan.fullReductionCouponSel = item
|
myQuan.fullReductionCouponSel = item
|
||||||
}
|
}
|
||||||
myQuan.res.fullReductionCoupon=returnCanUseFullReductionCoupon($fullReductionCoupon, payPrice.value, myQuan.fullReductionCouponSel)
|
myQuan.res.fullReductionCoupon = returnCanUseFullReductionCoupon($fullReductionCoupon, payPrice.value, myQuan
|
||||||
|
.fullReductionCouponSel)
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatStr(str) {
|
function formatStr(str) {
|
||||||
@@ -316,7 +332,7 @@
|
|||||||
const option = reactive({
|
const option = reactive({
|
||||||
orderId: '',
|
orderId: '',
|
||||||
memberId: '',
|
memberId: '',
|
||||||
orderPrice:0
|
orderPrice: 0
|
||||||
})
|
})
|
||||||
|
|
||||||
function toEmitChooseQuan(item) {
|
function toEmitChooseQuan(item) {
|
||||||
@@ -339,13 +355,14 @@
|
|||||||
let coupArr = [...fullReductionCoupon, ...goodsQuan]
|
let coupArr = [...fullReductionCoupon, ...goodsQuan]
|
||||||
return returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value)
|
return returnCouponAllPrice(coupArr, canDikouGoodsArr, user.value)
|
||||||
})
|
})
|
||||||
const payPrice=computed(()=>{
|
const payPrice = computed(() => {
|
||||||
const pay= option.orderPrice-discountAmount.value
|
const pay = option.orderPrice - discountAmount.value
|
||||||
return (pay<0?0:pay).toFixed(2)
|
return (pay < 0 ? 0 : pay).toFixed(2)
|
||||||
})
|
})
|
||||||
watch(() => myQuan.types.sel, (newval) => {
|
watch(() => myQuan.types.sel, (newval) => {
|
||||||
if (newval == 0) {
|
if (newval == 0) {
|
||||||
myQuan.res.fullReductionCoupon = returnCanUseFullReductionCoupon($fullReductionCoupon, payPrice.value, myQuan.fullReductionCouponSel)
|
myQuan.res.fullReductionCoupon = returnCanUseFullReductionCoupon($fullReductionCoupon, payPrice.value,
|
||||||
|
myQuan.fullReductionCouponSel)
|
||||||
}
|
}
|
||||||
if (newval == 1) {
|
if (newval == 1) {
|
||||||
|
|
||||||
|
|||||||
@@ -40,7 +40,8 @@ export function returnCoupCanUse(goodsArr = [], coup, selCoupArr = []) {
|
|||||||
if (selCoupNumber >= findGoodsTotalNumber) {
|
if (selCoupNumber >= findGoodsTotalNumber) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return findGoodsTotalNumber < (coup.num + selCoupNumber) ? false : true
|
console.log(selCoupNumber,findGoodsTotalNumber);
|
||||||
|
return findGoodsTotalNumber < selCoupNumber ? false : true
|
||||||
}
|
}
|
||||||
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
|
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
|
||||||
export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
|
export function returnProductCoupon(coup, goodsArr, vipUser, selCoupArr = []) {
|
||||||
@@ -101,6 +102,23 @@ export function returnProductCoupAllPrice(productPriceArr,startIndex,num){
|
|||||||
return prve+curPrice
|
return prve+curPrice
|
||||||
},0)
|
},0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//返回商品券可抵扣的商品数量
|
||||||
|
export function returnProductCanUseNum(productPriceArr,startIndex,num){
|
||||||
|
console.log(productPriceArr);
|
||||||
|
console.log(num);
|
||||||
|
let n=0;
|
||||||
|
for(let i=0;i<num;i++){
|
||||||
|
if(productPriceArr[startIndex*1+i]){
|
||||||
|
n+=1
|
||||||
|
console.log(n);
|
||||||
|
}else{
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
//返回同类商品券在同类商品价格数组里的开始位置
|
//返回同类商品券在同类商品价格数组里的开始位置
|
||||||
export function returnProCoupStartIndex(coupArr,index){
|
export function returnProCoupStartIndex(coupArr,index){
|
||||||
return coupArr.slice(0,index).reduce((prve,cur)=>{
|
return coupArr.slice(0,index).reduce((prve,cur)=>{
|
||||||
@@ -201,6 +219,12 @@ export function returnCanUseFullReductionCoupon(coupArr, payPrice, selCoup) {
|
|||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
const isfullAmount = payPrice >= v.fullAmount * 1
|
const isfullAmount = payPrice >= v.fullAmount * 1
|
||||||
|
if(payPrice<=0){
|
||||||
|
return {
|
||||||
|
...v,
|
||||||
|
use: false
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...v,
|
...v,
|
||||||
use: v.use && isfullAmount
|
use: v.use && isfullAmount
|
||||||
|
|||||||
Reference in New Issue
Block a user