增加商品券选择判断限制
This commit is contained in:
@@ -45,15 +45,22 @@
|
||||
|
||||
<template v-if="myQuan.types.sel==1">
|
||||
<view class="" @click="changeProductCoupon(item)" v-for="(item,index) in myQuan.res.productCoupon"
|
||||
:class="{filtergray:item.status}" :key="index">
|
||||
<view class="quan goods u-row-between u-flex u-col-center u-m-b-32 border-r-10 ">
|
||||
:class="{filtergray:!item.use}" :key="index"
|
||||
>
|
||||
<view class="quan goods u-row-between u-flex u-col-center u-m-b-32 border-r-10 u-relative" >
|
||||
<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.checked">
|
||||
<up-icon name="checkbox-mark" color="#fff"></up-icon>
|
||||
</view>
|
||||
<view class="u-p-t-32 u-p-b-32 u-p-l-24 u-p-r-24">
|
||||
<view class="u-flex">
|
||||
<up-image width="80rpx" height="80rpx" :src="item.productCover"></up-image>
|
||||
<view class="u-m-l-18">{{item.productName}}</view>
|
||||
<view class="u-m-l-18">
|
||||
<view class="u-m-l-18">{{item.productName}}</view>
|
||||
<view class="u-m-l-18 u-m-t-10 u-font-24 color-666">x{{item.num}}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class=" u-m-t-14 u-flex">
|
||||
<view>有效期:</view>
|
||||
@@ -64,6 +71,9 @@
|
||||
</view>
|
||||
</view>
|
||||
<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="color-red font-bold u-m-b-24 ">¥{{item.discountAmount}}</view>
|
||||
</view>
|
||||
<view class="u-flex ">
|
||||
<view class="use-btn" @click.stop="toEmitChooseQuan(item)">去使用</view>
|
||||
</view>
|
||||
@@ -112,12 +122,17 @@
|
||||
import {
|
||||
$activateByOrderId
|
||||
} from '@/http/yskApi/Instead.js'
|
||||
import {
|
||||
queryAllShopUser
|
||||
} from '@/http/yskApi/shop-user.js'
|
||||
import {returnNewGoodsList,returnCoupCanUse,returnProductCoupon} from '../quan_util.js'
|
||||
function back(){
|
||||
uni.navigateBack()
|
||||
}
|
||||
let order=ref({
|
||||
|
||||
})
|
||||
let canDikouGoodsArr=[]
|
||||
const myQuan = reactive({
|
||||
fullReductionCouponSel: {
|
||||
id: ''
|
||||
@@ -136,7 +151,16 @@
|
||||
})
|
||||
|
||||
function changeProductCoupon(item) {
|
||||
if(!item.use){
|
||||
return
|
||||
}
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
function changeFullReductionCouponSel(item) {
|
||||
@@ -150,15 +174,28 @@
|
||||
function toUse(item) {
|
||||
|
||||
}
|
||||
|
||||
let user=reactive({
|
||||
isVip:false
|
||||
})
|
||||
async function getQuan() {
|
||||
order.value=await orderApi.tbOrderInfoDetail(option.orderId)
|
||||
if(order.value.memberId){
|
||||
const userRes= await queryAllShopUser({
|
||||
id: order.value.memberId
|
||||
})
|
||||
if (userRes.content[0]) {
|
||||
user.value = userRes.content[0]
|
||||
}
|
||||
}
|
||||
|
||||
console.log(order.value);
|
||||
const res = await $activateByOrderId(option)
|
||||
canDikouGoodsArr=returnNewGoodsList(order.value.detailList||[])
|
||||
res.fullReductionCoupon = res.fullReductionCoupon.filter((v) => !v.use)
|
||||
res.productCoupon = res.productCoupon.filter((v) => !v.use).map(v => {
|
||||
res.productCoupon = res.productCoupon.map(v => {
|
||||
const calcCoup=returnProductCoupon(v,canDikouGoodsArr,user.value)
|
||||
return {
|
||||
...v,
|
||||
...calcCoup,
|
||||
checked: false
|
||||
}
|
||||
});
|
||||
@@ -201,7 +238,21 @@
|
||||
<style lang="scss" scoped>
|
||||
// $quan-color:rgb(233, 77, 60);
|
||||
$quan-color: #318AFE;
|
||||
|
||||
.no-use{
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
.img{
|
||||
width: 200rpx;
|
||||
height: 200rpx;
|
||||
z-index: 10;
|
||||
}
|
||||
}
|
||||
.fixed-b {
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
|
||||
100
pagesOrder/quan_util.js
Normal file
100
pagesOrder/quan_util.js
Normal file
@@ -0,0 +1,100 @@
|
||||
export function isTui(item){
|
||||
return item.status=='return'||item.status=='refund'||item.status=='refunding'
|
||||
}
|
||||
|
||||
//计算商品券优惠价格
|
||||
export function returnProductCouponPrice(coup, goodsArr, vipUser) {
|
||||
const item = goodsArr.find(v => v.productId == coup.proId);
|
||||
if(!item){
|
||||
return 0
|
||||
}
|
||||
const memberPrice = item.memberPrice ? item.memberPrice : item.price;
|
||||
const price = item ? (vipUser.isVip ? memberPrice : item.price) : 0;
|
||||
return price
|
||||
|
||||
}
|
||||
//返回新的商品列表,过滤掉退菜的,退单的商品
|
||||
export function returnNewGoodsList(arr) {
|
||||
let goodsMap={}
|
||||
return arr.filter(v => !isTui(v))
|
||||
}
|
||||
//根据当前购物车商品以及数量,已选券对应商品数量,判断该券是否可用
|
||||
export function returnCoupCanUse(goodsArr=[],coup,selCoupArr=[]) {
|
||||
// if(!coup.use){
|
||||
// return false
|
||||
// }
|
||||
const findGoods=goodsArr.filter(v=>v.productId==coup.proId)
|
||||
if(!findGoods.length){
|
||||
return false
|
||||
}
|
||||
const findGoodsTotalNumber=findGoods.reduce((prve,cur)=>{
|
||||
return prve+cur.num*1
|
||||
},0)
|
||||
const selCoupNumber=selCoupArr.filter(v=>v.proId==coup.proId).reduce((prve,cur)=>{
|
||||
return prve+cur.num*1
|
||||
},0)
|
||||
if(selCoupNumber>=findGoodsTotalNumber){
|
||||
return false
|
||||
}
|
||||
return findGoodsTotalNumber<coup.num?false:true
|
||||
}
|
||||
//查找购物车商品根据购物车商品数据返回商品券信息(抵扣价格以及是否满足可用需求)
|
||||
export function returnProductCoupon(coup, goodsArr, vipUser) {
|
||||
const newGoodsArr = returnNewGoodsList(goodsArr)
|
||||
const item = newGoodsArr.find(v => v.productId == coup.proId);
|
||||
if(!item){
|
||||
return {...coup, discountAmount: 0,use:false}
|
||||
}
|
||||
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);
|
||||
// const canUse=!coup.use?false:(discountAmount>0)
|
||||
const canUse=discountAmount>0
|
||||
return { ...coup, discountAmount: discountAmount,use:canUse}
|
||||
|
||||
}
|
||||
/**
|
||||
* 根据购物车商品计算商品券抵扣价格以及是否满足可用需求
|
||||
* 1.商品券对应商品数量大于购物车对应商品数量不可用
|
||||
* 2.未在购物车找到相关商品不可用
|
||||
* @param {*} coupArr
|
||||
* @param {*} goodsArr
|
||||
* @param {*} vipUser
|
||||
* @returns
|
||||
*/
|
||||
export function returnProductAllCoup(coupArr, goodsArr, vipUser){
|
||||
return coupArr.map((v) => {
|
||||
return returnProductCoupon(v, goodsArr, vipUser)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
//计算商品券总优惠价格
|
||||
export function returnProductCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||
if(coupArr.length == 0){
|
||||
return 0;
|
||||
}
|
||||
return coupArr.reduce((a, b) => {
|
||||
const price = returnProductCouponPrice(b, goodsArr, vipUser)
|
||||
return a + price;
|
||||
}, 0).toFixed(2);
|
||||
|
||||
}
|
||||
//计算满减券总优惠价格
|
||||
export function returnFullReductionCouponAllPrice(coupArr) {
|
||||
if(coupArr.length == 0){
|
||||
return 0;
|
||||
}
|
||||
return coupArr.filter(v => v.type == 1).reduce((a, b) => {
|
||||
const price = b.discountAmount
|
||||
return a + price;
|
||||
}, 0).toFixed(2);
|
||||
|
||||
}
|
||||
//计算优惠券总价格
|
||||
export function returnCouponAllPrice(coupArr, goodsArr, vipUser) {
|
||||
const poductAllprice=returnProductCouponAllPrice(coupArr, goodsArr, vipUser)
|
||||
const pointAllPrice=returnFullReductionCouponAllPrice(coupArr)
|
||||
return (poductAllprice*1+pointAllPrice*1).toFixed(2);
|
||||
}
|
||||
1
pagesOrder/static/image/no-use.svg
Normal file
1
pagesOrder/static/image/no-use.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 6.4 KiB |
Reference in New Issue
Block a user