diff --git a/pageProduct/add-Product/add-Product - 副本.vue b/pageProduct/add-Product/add-Product - 副本.vue index f9ec7b6..e08499a 100644 --- a/pageProduct/add-Product/add-Product - 副本.vue +++ b/pageProduct/add-Product/add-Product - 副本.vue @@ -1,189 +1,845 @@ \ No newline at end of file diff --git a/pagesOrder/pay-order/components/edit-accountPoints.vue b/pagesOrder/pay-order/components/edit-accountPoints.vue new file mode 100644 index 0000000..2d317b2 --- /dev/null +++ b/pagesOrder/pay-order/components/edit-accountPoints.vue @@ -0,0 +1,195 @@ + + + + + \ No newline at end of file diff --git a/pagesOrder/pay-order/pay-order.vue b/pagesOrder/pay-order/pay-order.vue index 67897b7..9ae21ad 100644 --- a/pagesOrder/pay-order/pay-order.vue +++ b/pagesOrder/pay-order/pay-order.vue @@ -1,17 +1,30 @@ @@ -131,41 +205,108 @@ onMounted, watch, ref, - onBeforeUnmount + onBeforeUnmount, + computed } from 'vue'; import { onLoad, - onBackPress,onShow + onBackPress, + onShow } from '@dcloudio/uni-app' import go from '@/commons/utils/go.js' import * as Api from '@/http/yskApi/Instead.js' import { queryAllShopUser } from '@/http/yskApi/shop-user.js' - import {hasPermission} from '@/commons/utils/hasPermission.js' + import { + hasPermission + } from '@/commons/utils/hasPermission.js' import * as orderApi from '@/http/yskApi/order.js' import infoBox from '@/commons/utils/infoBox.js' import editDiscount from '@/components/my-components/edit-discount.vue' - function toQuan(){ + import editAccountPoints from './components/edit-accountPoints.vue' + + const refPoints=ref(null) + function refPointsOpen(){ + if(!accountPoints.calcRes.usable&&accountPoints.sel){ + return + } + refPoints.value.open() + } + const accountPoints = reactive({ + sel: false, + num: 0, + calcRes:{ + usable:false, + unusableReason:'', + minDeductionPoints:0, + maxUsablePoints:0 + }, + price:0 + }) + async function calcUsablePoints(){ + const res=await Api.$calcUsablePoints({ + memberId:order.memberId, + orderAmount:order.amount + }) + accountPoints.calcRes=res + accountPoints.num=res.maxUsablePoints + return res; + } + watch(()=>accountPoints.sel,(newval)=>{ + if(newval){ + calcUsablePoints() + } + }) + async function calcDeDuctionPoints(){ + const res=await Api.$calcDeDuctionPoints({ + memberId: order.memberId, + orderAmount: order.amount, + points: accountPoints.num + }) + accountPoints.price=res + return res + } + watch(()=>accountPoints.num,(newval)=>{ + if(!newval){ + accountPoints.price=0 + return + } + calcDeDuctionPoints() + }) + + function changeAccountPoints() { + if(!accountPoints.calcRes.usable){ + return + } + accountPoints.sel = !accountPoints.sel + if (!accountPoints.sel) { + accountPoints.num = 0 + } + } + + function toQuan() { console.log(order); - if(!order.memberId){ - return infoBox.showToast('请先选择会员',0.5).then(()=>{ + if (!order.memberId) { + return infoBox.showToast('请先选择会员', 0.5).then(() => { chooseUser() }) } - go.to('PAGES_ORDER_QUAN',{ - orderId:order.id, - memberId:order.memberId + go.to('PAGES_ORDER_QUAN', { + orderId: order.id, + memberId: order.memberId }) } - async function discountShow(){ - const bol=await hasPermission('yun_xu_da_zhe') - if(bol){ - showModel('editMoney',true) + async function discountShow() { + const bol = await hasPermission('yun_xu_da_zhe') + if (bol) { + showModel('editMoney', true) } } - let option = {isNowPay:false} - let payFinish=ref(false) + let option = { + isNowPay: false + } + let payFinish = ref(false) onBackPress(() => { uni.$emit('orderDetail:update') console.log('onBackPress'); @@ -202,18 +343,18 @@ list: [], selIndex: 0 }, - quan:[] + quan: [] }) - + function chooseUser() { go.to('PAGES_CHOOSE_USER') } //更新选择用户 - function setUser(par) { + function setUser(par) { console.log(option); const submitPar = { tableId: order.tableId, - orderId:order.id, + orderId: order.id, masterId: order.masterId, vipUserId: user.value.id ? user.value.id : '', type: user.value.id ? 0 : 1 //0 设置 1 取消 @@ -221,29 +362,31 @@ Object.assign(submitPar, par) return Api.$setUser(submitPar) } + function watchChooseuser() { uni.$off('choose-user') uni.$on('choose-user', (data) => { console.log(data); - setUser({ - vipUserId: data.id ? data.id : '', - type: data.id ? 0 : 1 //0 设置 1 取消 - }).then(res=>{ - user.value = data - order.memberId=data.id - init() - }) + setUser({ + vipUserId: data.id ? data.id : '', + type: data.id ? 0 : 1 //0 设置 1 取消 + }).then(res => { + user.value = data + order.memberId = data.id + init() + }) }) } + function watchChooseQuan() { uni.$off('choose-quan') uni.$on('choose-quan', (arr) => { console.log(arr); - pays.quan=arr + pays.quan = arr }) } - - onShow(()=>{ + + onShow(() => { watchChooseuser() watchChooseQuan() }) @@ -281,12 +424,22 @@ const discount = reactive({ }) - + 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) + }) function editDiscountConfirm(form) { console.log(form); Object.assign(discount, form) getPayUrl() } + async function getPayType() { const payTypeList = await Api.$getPayType() pays.payTypes.list = payTypeList @@ -294,8 +447,8 @@ function changePayType(i, item) { pays.payTypes.selIndex = i - if (item.payType == 'vipPay' ) { - chooseUser() + if (item.payType == 'vipPay') { + chooseUser() } } //支付成功回调 @@ -303,7 +456,7 @@ infoBox.showToast('支付成功') setTimeout(() => { // uni.$emit('orderDetail:update') - payFinish.value=true + payFinish.value = true uni.$emit('get:table') uni.$emit('update:orderDetail') uni.navigateBack({ @@ -323,8 +476,8 @@ 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 + infoBox.showToast('余额不足') + return } await Api.$payOrder({ tableId: order.tableId, @@ -385,11 +538,12 @@ const orderRes = await orderApi.tbOrderInfoDetail(order.orderId) Object.assign(order, orderRes) if (orderRes.memberId) { + calcUsablePoints() queryAllShopUser({ id: orderRes.memberId }).then(res => { - if(res.content[0]){ - user.value =res.content[0] + if (res.content[0]) { + user.value = res.content[0] } }) } @@ -420,14 +574,16 @@