订单支付增加优惠券积分
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
<view @click="discountShow">修改</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
|
||||
</view>
|
||||
<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">
|
||||
@@ -44,6 +44,7 @@
|
||||
<view class="u-flex">
|
||||
<view class="hui">减</view>
|
||||
<view class="u-m-l-18">{{item.name}}</view>
|
||||
<view class="u-m-l-18 color-999">x{{item.num}}</view>
|
||||
</view>
|
||||
<view class="color-red">
|
||||
-¥{{item.discountAmount}}
|
||||
@@ -53,7 +54,7 @@
|
||||
|
||||
</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 "
|
||||
v-if="discount.price&&discount.currentPrice!=order.amount">
|
||||
<view>服务员改价</view>
|
||||
@@ -69,7 +70,7 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
</view>
|
||||
<view class="bg-fff border-r-12 ">
|
||||
<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="">积分抵扣</view>
|
||||
<view class="color-999 u-m-l-10">
|
||||
<text>(</text>
|
||||
<text>(</text>
|
||||
<text>{{user.accountPoints||'0'}}</text>
|
||||
<text>)</text>
|
||||
</view>
|
||||
<!-- <view><text class="color-red font-bold">{{accountPoints.price}}</text>元</view> -->
|
||||
</view>
|
||||
<view class="u-flex">
|
||||
|
||||
|
||||
<view class="u-flex" @click.stop="refPointsOpen">
|
||||
<view><text>{{accountPoints.num}}</text></view>
|
||||
<view v-if="accountPoints.calcRes.usable">
|
||||
@@ -126,22 +127,22 @@
|
||||
</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>
|
||||
<my-radio
|
||||
:modelValue="accountPoints.sel">
|
||||
<my-radio :modelValue="accountPoints.sel">
|
||||
</my-radio>
|
||||
</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">
|
||||
<text class="color-red">*</text>
|
||||
<text >{{accountPoints.calcRes.unusableReason}}</text>
|
||||
<text>{{accountPoints.calcRes.unusableReason}}</text>
|
||||
</view>
|
||||
<view class="" v-if="accountPoints.calcRes.usable">
|
||||
<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>
|
||||
最大抵扣积分{{accountPoints.calcRes.maxUsablePoints}}
|
||||
</text>
|
||||
@@ -225,10 +226,16 @@
|
||||
import infoBox from '@/commons/utils/infoBox.js'
|
||||
import editDiscount from '@/components/my-components/edit-discount.vue'
|
||||
import editAccountPoints from './components/edit-accountPoints.vue'
|
||||
import {
|
||||
returnGoodsPayPriceMap,returnProCoupStartIndex ,returnProductCoupAllPrice
|
||||
} from '../quan_util.js'
|
||||
//商品数量从0到n每一个对应的价格
|
||||
let $goodsPayPriceMap={}
|
||||
|
||||
const refPoints=ref(null)
|
||||
function refPointsOpen(){
|
||||
if(!accountPoints.calcRes.usable&&accountPoints.sel){
|
||||
const refPoints = ref(null)
|
||||
|
||||
function refPointsOpen() {
|
||||
if (!accountPoints.calcRes.usable && accountPoints.sel) {
|
||||
return
|
||||
}
|
||||
refPoints.value.open()
|
||||
@@ -236,50 +243,50 @@
|
||||
const accountPoints = reactive({
|
||||
sel: false,
|
||||
num: 0,
|
||||
calcRes:{
|
||||
usable:false,
|
||||
unusableReason:'',
|
||||
minDeductionPoints:0,
|
||||
maxUsablePoints:0
|
||||
calcRes: {
|
||||
usable: false,
|
||||
unusableReason: '',
|
||||
minDeductionPoints: 0,
|
||||
maxUsablePoints: 0
|
||||
},
|
||||
price:0
|
||||
price: 0
|
||||
})
|
||||
async function calcUsablePoints(){
|
||||
if(!order.memberId){
|
||||
return
|
||||
async function calcUsablePoints() {
|
||||
if (!order.memberId) {
|
||||
return
|
||||
}
|
||||
const res=await Api.$calcUsablePoints({
|
||||
memberId:order.memberId,
|
||||
orderAmount:pointCanDicountPrice.value
|
||||
const res = await Api.$calcUsablePoints({
|
||||
memberId: order.memberId,
|
||||
orderAmount: pointCanDicountPrice.value
|
||||
})
|
||||
accountPoints.calcRes=res
|
||||
accountPoints.num=res.maxUsablePoints
|
||||
accountPoints.calcRes = res
|
||||
accountPoints.num = res.maxUsablePoints
|
||||
return res;
|
||||
}
|
||||
watch(()=>accountPoints.sel,(newval)=>{
|
||||
if(newval){
|
||||
watch(() => accountPoints.sel, (newval) => {
|
||||
if (newval) {
|
||||
calcUsablePoints()
|
||||
}
|
||||
})
|
||||
async function calcDeDuctionPoints(){
|
||||
const res=await Api.$calcDeDuctionPoints({
|
||||
async function calcDeDuctionPoints() {
|
||||
const res = await Api.$calcDeDuctionPoints({
|
||||
memberId: order.memberId,
|
||||
orderAmount: order.amount,
|
||||
points: accountPoints.num
|
||||
})
|
||||
accountPoints.price=res
|
||||
accountPoints.price = res
|
||||
return res
|
||||
}
|
||||
watch(()=>accountPoints.num,(newval)=>{
|
||||
if(!newval){
|
||||
accountPoints.price=0
|
||||
return
|
||||
watch(() => accountPoints.num, (newval) => {
|
||||
if (!newval) {
|
||||
accountPoints.price = 0
|
||||
return
|
||||
}
|
||||
calcDeDuctionPoints()
|
||||
})
|
||||
|
||||
|
||||
function changeAccountPoints() {
|
||||
if(!accountPoints.calcRes.usable){
|
||||
if (!accountPoints.calcRes.usable) {
|
||||
return
|
||||
}
|
||||
accountPoints.sel = !accountPoints.sel
|
||||
@@ -298,7 +305,7 @@
|
||||
go.to('PAGES_ORDER_QUAN', {
|
||||
orderId: order.id,
|
||||
memberId: order.memberId,
|
||||
orderPrice:payPrice.value
|
||||
orderPrice: payPrice.value*1+coupAllPrice.value*1
|
||||
})
|
||||
}
|
||||
async function discountShow() {
|
||||
@@ -321,7 +328,6 @@
|
||||
// }
|
||||
// return false
|
||||
})
|
||||
let payStatus = ref(null) //loading success
|
||||
|
||||
let timer = null
|
||||
|
||||
@@ -386,7 +392,32 @@
|
||||
uni.$off('choose-quan')
|
||||
uni.$on('choose-quan', (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({
|
||||
|
||||
})
|
||||
|
||||
|
||||
function editDiscountConfirm(form) {
|
||||
console.log(form);
|
||||
Object.assign(discount, form)
|
||||
getPayUrl()
|
||||
}
|
||||
|
||||
|
||||
async function getPayType() {
|
||||
const payTypeList = await Api.$getPayType()
|
||||
pays.payTypes.list = payTypeList
|
||||
@@ -446,9 +477,11 @@
|
||||
chooseUser()
|
||||
}
|
||||
}
|
||||
let payStatus = '';
|
||||
//支付成功回调
|
||||
function paySuccess() {
|
||||
infoBox.showToast('支付成功')
|
||||
payStatus = 'success'
|
||||
setTimeout(() => {
|
||||
// uni.$emit('orderDetail:update')
|
||||
payFinish.value = true
|
||||
@@ -468,35 +501,44 @@
|
||||
}
|
||||
payOrder()
|
||||
}
|
||||
const tipsMap = {
|
||||
paying: '支付中',
|
||||
success: '已支付成功'
|
||||
}
|
||||
async function payOrder() {
|
||||
const payType = pays.payTypes.list[pays.payTypes.selIndex].payType
|
||||
if (payType == 'vipPay' && user.value.amount * 1 < order.amount * 1) {
|
||||
infoBox.showToast('余额不足')
|
||||
return
|
||||
}
|
||||
await Api.$payOrder({
|
||||
tableId: order.tableId,
|
||||
masterId: order.masterId,
|
||||
orderId: order.id || order.orderId,
|
||||
payType,
|
||||
vipUserId: order.memberId,
|
||||
discount: 1,
|
||||
code: '',
|
||||
pointsNum:accountPoints.sel?accountPoints.num:0,
|
||||
userCouponInfos:pays.quan.map(v=>{
|
||||
return {
|
||||
userCouponId:v.id,
|
||||
num:v.num
|
||||
}
|
||||
if (payStatus) {
|
||||
return infoBox.showToast(tipsMap[payStatus])
|
||||
}
|
||||
try {
|
||||
payStatus = 'paying'
|
||||
await Api.$payOrder({
|
||||
tableId: order.tableId,
|
||||
masterId: order.masterId,
|
||||
orderId: order.id || order.orderId,
|
||||
payType,
|
||||
vipUserId: order.memberId,
|
||||
discount: 1,
|
||||
code: '',
|
||||
pointsNum: accountPoints.sel ? accountPoints.num : 0,
|
||||
userCouponInfos: pays.quan.map(v => {
|
||||
return {
|
||||
userCouponId: v.id,
|
||||
num: v.num
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
})
|
||||
paySuccess()
|
||||
paySuccess()
|
||||
} catch (e) {
|
||||
//TODO handle the exception
|
||||
payStatus = ''
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getPayType()
|
||||
})
|
||||
const order = reactive({
|
||||
amount: 0
|
||||
})
|
||||
@@ -540,6 +582,8 @@
|
||||
async function init() {
|
||||
const orderRes = await orderApi.tbOrderInfoDetail(order.orderId)
|
||||
Object.assign(order, orderRes)
|
||||
$goodsPayPriceMap=returnGoodsPayPriceMap(order.detailList)
|
||||
console.log($goodsPayPriceMap);
|
||||
if (orderRes.memberId) {
|
||||
calcUsablePoints()
|
||||
queryAllShopUser({
|
||||
@@ -550,7 +594,6 @@
|
||||
}
|
||||
})
|
||||
}
|
||||
getPayUrl()
|
||||
}
|
||||
|
||||
function getPayUrl() {
|
||||
@@ -561,37 +604,36 @@
|
||||
payCodeUrl.value = res
|
||||
})
|
||||
}
|
||||
const coupAllPrice=computed(()=>{
|
||||
return pays.quan.reduce((prve,cur)=>{
|
||||
return prve+cur.discountAmount*1
|
||||
},0)
|
||||
const coupAllPrice = computed(() => {
|
||||
return pays.quan.reduce((prve, cur) => {
|
||||
return prve + cur.discountAmount * 1
|
||||
}, 0)
|
||||
})
|
||||
const payPrice=computed(()=>{
|
||||
const discountPrice=discount.currentPrice?discount.currentPrice:order.amount
|
||||
const calcPrice=discountPrice-coupAllPrice.value-accountPoints.price*(accountPoints.sel?1:0)
|
||||
return (calcPrice<=0?0:calcPrice).toFixed(2)
|
||||
const payPrice = computed(() => {
|
||||
const discountPrice = discount.currentPrice ? discount.currentPrice : order.amount
|
||||
const calcPrice = discountPrice - coupAllPrice.value - accountPoints.price * (accountPoints.sel ? 1 : 0)
|
||||
return (calcPrice <= 0 ? 0 : calcPrice).toFixed(2)
|
||||
})
|
||||
watch(()=>payPrice.value,()=>{
|
||||
watch(() => payPrice.value, () => {
|
||||
getPayUrl()
|
||||
})
|
||||
const pointCanDicountPrice=computed(()=>{
|
||||
const discountPrice=discount.currentPrice?discount.currentPrice:order.amount
|
||||
const calcPrice=discountPrice-coupAllPrice.value
|
||||
return (calcPrice<=0?0:calcPrice).toFixed(2)
|
||||
const pointCanDicountPrice = computed(() => {
|
||||
const discountPrice = discount.currentPrice ? discount.currentPrice : order.amount
|
||||
const calcPrice = discountPrice - coupAllPrice.value
|
||||
return (calcPrice <= 0 ? 0 : calcPrice).toFixed(2)
|
||||
})
|
||||
watch(()=>pointCanDicountPrice.value,(newval)=>{
|
||||
watch(() => pointCanDicountPrice.value, (newval) => {
|
||||
calcUsablePoints()
|
||||
})
|
||||
|
||||
|
||||
onLoad(async (opt) => {
|
||||
console.log(opt);
|
||||
option = opt
|
||||
Object.assign(order, opt)
|
||||
const payTypeList = await Api.$getPayType()
|
||||
pays.payTypes.list = payTypeList
|
||||
getPayType()
|
||||
init()
|
||||
})
|
||||
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
console.log('onBeforeUnmount');
|
||||
clear()
|
||||
|
||||
Reference in New Issue
Block a user