订单支付增加优惠券积分

This commit is contained in:
2024-11-18 11:03:39 +08:00
parent d5dbd51c80
commit c9825f8df7
6 changed files with 455 additions and 159 deletions

View File

@@ -6,9 +6,11 @@
<view class="u-m-t-32">
<template v-if="myQuan.types.sel==0">
<view class="" @click="changeFullReductionCouponSel(item)"
v-for="(item,index) in myQuan.res.fullReductionCoupon" :class="{filtergray:item.status}"
:key="index">
v-for="(item,index) in myQuan.res.fullReductionCoupon" :class="{filtergray:!item.use}" :key="index">
<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 ">
<up-icon name="checkbox-mark" color="#fff"></up-icon>
</view>
@@ -70,9 +72,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="u-flex u-row-center w-full">
<view class="color-red font-bold u-m-b-24 ">{{item.discountAmount}}</view>
</view>
</view> -->
<view class="u-flex ">
<view class="use-btn" @click.stop="toEmitChooseQuan(item)">去使用</view>
</view>
@@ -90,10 +92,24 @@
<view :style="{height:safebottomHeight+'px'}"></view>
<view class="fixed-b bottom safe-bottom border-top">
<view class="u-m-b-32">
<text>抵扣金额</text>
<text class="color-red"></text>
<text class="color-red">{{discountAmount}}</text>
<view class="u-m-b-32 u-flex u-row-between u-p-t-10">
<view class="u-flex">
<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 class="u-flex gap-20">
<up-button shape="circle" plain @click="back">
@@ -105,7 +121,12 @@
</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>
</template>
<script setup>
@@ -129,6 +150,7 @@
import {
$activateByOrderId
} from '@/http/yskApi/Instead.js'
import infoBox from '@/commons/utils/infoBox.js'
import {
queryAllShopUser
} from '@/http/yskApi/shop-user.js'
@@ -136,9 +158,48 @@
returnNewGoodsList,
returnCoupCanUse,
returnCouponAllPrice,
returnProductCoupon
returnProductCoupon,
returnCanUseFullReductionCoupon
} 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() {
uni.navigateBack()
}
@@ -167,6 +228,22 @@
if (!item.use) {
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
const CheckedArr = myQuan.res.productCoupon.filter(v => v.checked)
const noCheckedArr = myQuan.res.productCoupon.filter(v => !v.checked)
@@ -177,7 +254,18 @@
}
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) {
@@ -190,6 +278,9 @@
let user = reactive({
isVip: false
})
let $fullReductionCoupon = []
let $productCoupon = []
async function getQuan() {
order.value = await orderApi.tbOrderInfoDetail(option.orderId)
if (order.value.memberId) {
@@ -202,9 +293,13 @@
}
console.log(order.value);
const res = await $activateByOrderId(option)
const res = await $activateByOrderId({
orderId: option.orderId,
memberId: option.memberId
})
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 => {
const calcCoup = returnProductCoupon(v, canDikouGoodsArr, user.value)
return {
@@ -212,12 +307,15 @@
checked: false
}
}).filter((v) => v.use);
$fullReductionCoupon = res.fullReductionCoupon
$productCoupon = res.productCoupon
myQuan.res = res
myQuan.hasAjax = true;
}
const option = reactive({
orderId: '',
memberId: ''
memberId: '',
orderPrice:0
})
function toEmitChooseQuan(item) {
@@ -240,6 +338,18 @@
let coupArr = [...fullReductionCoupon, ...goodsQuan]
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) => {
Object.assign(option, opt)
getQuan()
@@ -247,6 +357,7 @@
let safebottomHeight = ref(0)
onReady(() => {
getSafeBottomHeight('bottom', 0).then(height => {
console.log(height);
safebottomHeight.value = height
})
})