代码更新
This commit is contained in:
@@ -99,15 +99,15 @@
|
||||
<text class="u-m-l-10 no-wrap">{{item.payName}}</text>
|
||||
</view>
|
||||
<view class="u-flex color-999 u-font-24">
|
||||
<view class="u-m-r-20" v-if="item.payType=='virtual'&&user.id"
|
||||
<view class="u-m-r-20" v-if="item.payType=='virtual'&&pageData.user.id"
|
||||
@click.stop="chooseUser">
|
||||
<view>
|
||||
<text>会员:</text>
|
||||
<text class="u-m-r-4">{{user.telephone||user.nickName}}</text>
|
||||
<text class="u-m-r-4">{{pageData.user.phone||pageData.user.nickName}}</text>
|
||||
</view>
|
||||
<view>
|
||||
<text>余额:</text>
|
||||
<text>¥{{user.amount||'0'}}</text>
|
||||
<text>¥{{pageData.user.amount||'0'}}</text>
|
||||
</view>
|
||||
<!-- <view>
|
||||
<text>积分:</text>
|
||||
@@ -125,12 +125,12 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="border-bottom-dashed "></view>
|
||||
<view class="u-flex u-row-between u-p-t-24" v-if="user.id" @click="changeAccountPoints">
|
||||
<view class="u-flex u-row-between u-p-t-24" v-if="pageData.user.id" @click="changeAccountPoints">
|
||||
<view class="u-flex ">
|
||||
<view class="">积分抵扣</view>
|
||||
<view class="color-999 u-m-l-10">
|
||||
<text>(</text>
|
||||
<text>{{user.accountPoints||'0'}}</text>
|
||||
<text>{{pageData.user.accountPoints||'0'}}</text>
|
||||
<text>)</text>
|
||||
</view>
|
||||
<!-- <view><text class="color-red font-bold">{{accountPoints.price}}</text>元</view> -->
|
||||
@@ -260,7 +260,13 @@
|
||||
let option = {
|
||||
isNowPay: false
|
||||
}
|
||||
|
||||
const pageData = reactive({
|
||||
goodsList: [], //菜品列表
|
||||
user: { //会员信息
|
||||
userId: null,
|
||||
amount: 0
|
||||
}
|
||||
})
|
||||
const order = reactive({
|
||||
orderAmount: 0
|
||||
})
|
||||
@@ -294,10 +300,7 @@
|
||||
price: 0
|
||||
})
|
||||
let timer = null
|
||||
|
||||
let user = ref({
|
||||
amount: 0
|
||||
});
|
||||
|
||||
const refPoints = ref(null)
|
||||
let payCodeUrl = ref('') //收款二维码地址
|
||||
onShow(() => {
|
||||
@@ -319,6 +322,43 @@
|
||||
uni.$emit('orderDetail:update')
|
||||
console.log('onBackPress');
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
async function init() {
|
||||
// 获取订单详情
|
||||
const orderRes = await getHistoryOrder({orderId:order.orderId})
|
||||
Object.assign(order, orderRes)
|
||||
$goodsPayPriceMap = returnGoodsPayPriceMap(order.detailMap)
|
||||
pageData.goodsList = [];
|
||||
Object.values(orderRes.detailMap).forEach(item=>{
|
||||
pageData.goodsList = [...pageData.goodsList,...item]
|
||||
})
|
||||
const hasSelQuan = orderRes.couponInfoList ? JSON.parse(orderRes.couponInfoList) : {
|
||||
fullReductionCoupon: [],
|
||||
productCoupon: []
|
||||
};
|
||||
const fullReductionCoupon = hasSelQuan.fullReductionCoupon.filter(v => v.type == 1)
|
||||
const productCoupon = hasSelQuan.productCoupon.filter(v => v.type == 2)
|
||||
setQuan([...fullReductionCoupon, ...productCoupon])
|
||||
|
||||
// 获取用户信息
|
||||
console.log(order.userId)
|
||||
console.log(!pageData.user.userId)
|
||||
if (order.userId&&!pageData.user.userId) {
|
||||
calcUsablePoints()
|
||||
if (orderRes.pointsNum) {
|
||||
accountPoints.sel = true
|
||||
}
|
||||
shopUserDetail({
|
||||
userId: order.userId || pageData.user.userId
|
||||
}).then(res => {
|
||||
pageData.user = res
|
||||
})
|
||||
}
|
||||
}
|
||||
const coupAllPrice = computed(() => {
|
||||
const n = pays.quan.reduce((prve, cur) => {
|
||||
return prve + cur.discountAmount * 1
|
||||
@@ -326,43 +366,60 @@
|
||||
return n
|
||||
})
|
||||
|
||||
/**
|
||||
* 支付金额
|
||||
*/
|
||||
const payPrice = computed(() => {
|
||||
const total = (originPrice.value) - vipDiscount.value - productCouponDiscountAmount.value - discount
|
||||
.value -
|
||||
fullCouponDiscountAmount.value - accountPoints.price * (accountPoints.sel ? 1 : 0)
|
||||
return (total < 0 ? 0 : total).toFixed(2)
|
||||
})
|
||||
|
||||
/**
|
||||
* 菜品打包费
|
||||
*/
|
||||
const packAmount = computed(() => {
|
||||
if(pageData.goodsList){
|
||||
let price = pageData.goodsList.filter(v => v.packNumber > 0 && v.status !== "return").reduce((a, b) => {
|
||||
return a + (b.packNumber * b.packAmount)
|
||||
}, 0)
|
||||
return price
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
const originPrice = computed(() => {
|
||||
console.log(order)
|
||||
const n = (order.orderAmount || 0) * 1 + vipDiscount.value * 1 + (order.fullCouponDiscountAmount || 0) + (order
|
||||
.productCouponDiscountAmount || 0) +
|
||||
(order.pointsDiscountAmount || 0)
|
||||
console.log(n)
|
||||
return n.toFixed(2)
|
||||
console.log(packAmount)
|
||||
if(pageData.goodsList){
|
||||
let goodsPrice = pageData.goodsList.filter(v => v.price != 0 && v.status !== "return").reduce((a, b) => {
|
||||
return a + (b.num * b.price)
|
||||
}, 0)
|
||||
return (goodsPrice + order.seatNum + packAmount.value).toFixed(2)
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 会员优惠金额
|
||||
*/
|
||||
const vipDiscount = computed(() => {
|
||||
if (!user.value.isVip) {
|
||||
if (!pageData.user.isVip) {
|
||||
return 0
|
||||
}
|
||||
let goods_list = []
|
||||
Object.values(order.detailMap).forEach(item=>{
|
||||
goods_list = [...goods_list,...item]
|
||||
})
|
||||
const goodsPrice = goods_list.filter(v => v.price != 0 && v.status !== "return" && v.memberPrice && (v.memberPrice != v.price)).reduce((
|
||||
a,
|
||||
b) => {
|
||||
return a + (b.num * (b.price - b.memberPrice))
|
||||
}, 0)
|
||||
console.log(goodsPrice)
|
||||
return goodsPrice.toFixed(2)
|
||||
if(pageData.goodsList){
|
||||
let price = pageData.goodsList.filter(v => v.price != 0 && v.discountSaleAmount <= 0 && v.status !== "return" && v.memberPrice && (v.memberPrice != v.price)).reduce((a, b) => {
|
||||
return a + (b.num * (b.price - b.memberPrice))
|
||||
}, 0)
|
||||
return price.toFixed(2)
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 菜品折扣金额
|
||||
*/
|
||||
const discountSaleAmount = computed(() => {
|
||||
if(pageData.goodsList){
|
||||
let price = pageData.goodsList.filter(v => v.discountSaleAmount > 0 && v.status !== "return").reduce((a, b) => {
|
||||
return a + (b.num * b.discountSaleAmount)
|
||||
}, 0)
|
||||
return price
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* 优惠券金额
|
||||
*/
|
||||
@@ -372,6 +429,7 @@
|
||||
return prve + cur.discountAmount * 1
|
||||
}, 0)
|
||||
})
|
||||
|
||||
/**
|
||||
* 商品券金额
|
||||
*/
|
||||
@@ -385,11 +443,30 @@
|
||||
* 积分计算
|
||||
*/
|
||||
const pointCanDicountPrice = computed(() => {
|
||||
const total = (order.orderAmount || 0) - productCouponDiscountAmount.value - discount.value -
|
||||
let total = (originPrice.value || 0) - productCouponDiscountAmount.value - discount.value -
|
||||
fullCouponDiscountAmount.value
|
||||
return (total < 0 ? 0 : total).toFixed(2)
|
||||
})
|
||||
|
||||
/**
|
||||
* 支付金额
|
||||
*/
|
||||
const payPrice = computed(() => {
|
||||
console.log("originPrice===",originPrice.value)
|
||||
console.log("vipDiscount===",vipDiscount.value)
|
||||
console.log("discountSaleAmount===",discountSaleAmount.value)
|
||||
console.log("pointCanDicountPrice===",pointCanDicountPrice.value)
|
||||
console.log("productCouponDiscountAmount===",productCouponDiscountAmount.value)
|
||||
console.log("discount===",discount.value)
|
||||
console.log("fullCouponDiscountAmount===",fullCouponDiscountAmount.value)
|
||||
console.log("accountPoints===",accountPoints)
|
||||
let total = (originPrice.value*1) - discountSaleAmount.value - (vipDiscount.value*1) - productCouponDiscountAmount.value - discount
|
||||
.value - fullCouponDiscountAmount.value - accountPoints.price * (accountPoints.sel ? 1 : 0)
|
||||
console.log(total)
|
||||
return (total < 0 ? 0 : total).toFixed(2)
|
||||
})
|
||||
|
||||
|
||||
watch(() => accountPoints.sel, (newval) => {
|
||||
if (newval) {
|
||||
calcDeDuctionPoints()
|
||||
@@ -442,58 +519,26 @@
|
||||
* 获取店铺订单支付URL
|
||||
*/
|
||||
function getPayUrl() {
|
||||
getOrderPayUrl({
|
||||
console.log(vipDiscount.value)
|
||||
let par = {
|
||||
shopId: uni.getStorageSync("shopInfo").id,
|
||||
orderId: order.id,
|
||||
orderAmount: payPrice.value,
|
||||
userId: order.userId||user.value.userId,
|
||||
seatNum: order.seatNum, // 用餐人数
|
||||
discountRatio: (discount.discount/100).toFixed(0), // 折扣比例
|
||||
discountAmount: discount.value, // 手动优惠金额
|
||||
fullCouponDiscountAmount: fullCouponDiscountAmount.value, // 满减金额
|
||||
orderAmount: originPrice.value, // 订单金额
|
||||
pointsNum: accountPoints.sel ? accountPoints.num : 0,
|
||||
// couponList: pays.quan.map(v => {
|
||||
// return {
|
||||
// userCouponId: v.id,
|
||||
// num: v.number
|
||||
// }
|
||||
// }),
|
||||
}).then(res => {
|
||||
vipPrice: vipDiscount.value > 0 ? 1: 0, // 是否使用会员价
|
||||
}
|
||||
if( order.userId||pageData.user.userId ){
|
||||
par.userId = order.userId||pageData.user.userId
|
||||
}
|
||||
getOrderPayUrl(par).then(res => {
|
||||
payCodeUrl.value = res
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
async function init() {
|
||||
// 获取订单详情
|
||||
const orderRes = await getHistoryOrder({orderId:order.orderId})
|
||||
Object.assign(order, orderRes)
|
||||
$goodsPayPriceMap = returnGoodsPayPriceMap(order.detailMap)
|
||||
|
||||
const hasSelQuan = orderRes.couponInfoList ? JSON.parse(orderRes.couponInfoList) : {
|
||||
fullReductionCoupon: [],
|
||||
productCoupon: []
|
||||
};
|
||||
const fullReductionCoupon = hasSelQuan.fullReductionCoupon.filter(v => v.type == 1)
|
||||
const productCoupon = hasSelQuan.productCoupon.filter(v => v.type == 2)
|
||||
setQuan([...fullReductionCoupon, ...productCoupon])
|
||||
|
||||
// 获取用户信息
|
||||
if (order.userId||user.value.userId) {
|
||||
calcUsablePoints()
|
||||
if (orderRes.pointsNum) {
|
||||
accountPoints.sel = true
|
||||
}
|
||||
shopUserDetail({
|
||||
userId: order.userId || user.value.userId
|
||||
}).then(res => {
|
||||
user.value = res
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付方式
|
||||
@@ -581,12 +626,11 @@
|
||||
accountPoints.num = e
|
||||
}
|
||||
async function calcUsablePoints(orderAmount) {
|
||||
if (!order.userId&&!user.value.userId) {
|
||||
if (!order.userId&&!pageData.user.userId) {
|
||||
return
|
||||
}
|
||||
console.log(orderAmount);
|
||||
const res = await Api.$calcUsablePoints({
|
||||
userId: order.userId||user.value.userId,
|
||||
userId: order.userId||pageData.user.userId,
|
||||
orderAmount: orderAmount ? orderAmount : payPrice.value
|
||||
})
|
||||
accountPoints.calcRes = res
|
||||
@@ -600,7 +644,7 @@
|
||||
return ''
|
||||
}
|
||||
const res = await Api.$calcDeDuctionPoints({
|
||||
userId: order.userId||user.value.userId,
|
||||
userId: order.userId||pageData.user.userId,
|
||||
orderAmount: originPrice.value,
|
||||
points: accountPoints.num
|
||||
})
|
||||
@@ -626,14 +670,14 @@
|
||||
*/
|
||||
function toQuan() {
|
||||
console.log(order);
|
||||
if (!order.userId&&!user.value.id) {
|
||||
if (!order.userId&&!pageData.user.id) {
|
||||
return infoBox.showToast('请先选择会员', 0.5).then(() => {
|
||||
chooseUser()
|
||||
})
|
||||
}
|
||||
go.to('PAGES_ORDER_QUAN', {
|
||||
orderId: order.id,
|
||||
userId: order.userId||user.value.userId,
|
||||
shopUserId: pageData.user.id,
|
||||
orderPrice: (payPrice.value * 1 + coupAllPrice.value * 1).toFixed(2)
|
||||
})
|
||||
}
|
||||
@@ -683,7 +727,7 @@
|
||||
uni.$off('choose-user')
|
||||
uni.$on('choose-user', (data) => {
|
||||
console.log(data);
|
||||
user.value = data
|
||||
pageData.user = data
|
||||
pays.quan = []
|
||||
init()
|
||||
})
|
||||
@@ -723,8 +767,8 @@
|
||||
}
|
||||
pays.payTypes.selIndex = i
|
||||
console.log(item.payType)
|
||||
console.log(user.value.id)
|
||||
if (item.payType == 'virtual' && !user.value.id) {
|
||||
console.log(pageData.user.id)
|
||||
if (item.payType == 'virtual' && !pageData.user.id) {
|
||||
chooseUser()
|
||||
}
|
||||
}
|
||||
@@ -761,7 +805,7 @@
|
||||
if (payType == 'cash' && payPrice.value * 1 > 0) {
|
||||
return cashConfirmShow()
|
||||
}
|
||||
if (payType == 'virtual' && user.value.amount * 1 < order.orderAmount * 1) {
|
||||
if (payType == 'virtual' && pageData.user.amount * 1 < order.orderAmount * 1) {
|
||||
infoBox.showToast('余额不足')
|
||||
return
|
||||
}
|
||||
@@ -789,12 +833,12 @@
|
||||
shopId: uni.getStorageSync("shopInfo").id,
|
||||
checkOrderPay: {
|
||||
orderId: order.id || order.orderId,
|
||||
userId: order.userId||user.value.userId,
|
||||
seatNum: order.seatNum, // 用餐人数
|
||||
discountRatio: (discount.discount/100).toFixed(0), // 折扣比例
|
||||
discountAmount: discount.value, // 手动优惠金额
|
||||
fullCouponDiscountAmount: fullCouponDiscountAmount.value, // 满减金额
|
||||
orderAmount: originPrice.value, // 订单金额
|
||||
orderAmount: payPrice.value, // 订单金额
|
||||
vipPrice: vipDiscount.value > 0 ? 1: 0, // 是否使用会员价
|
||||
pointsNum: accountPoints.sel ? accountPoints.num : 0,
|
||||
couponList: pays.quan.map(v => {
|
||||
return {
|
||||
@@ -806,16 +850,29 @@
|
||||
},
|
||||
|
||||
}
|
||||
if( order.userId||pageData.user.userId ){
|
||||
params.checkOrderPay.userId = order.userId||pageData.user.userId
|
||||
}
|
||||
console.log(params)
|
||||
if (payType == 'scanCode' || payType == 'deposit' || payType == 'bank') {
|
||||
}
|
||||
if (payType == 'cash' && payPrice.value * 1 > 0) {
|
||||
await cashPay(params)
|
||||
try {
|
||||
await cashPay(params)
|
||||
} catch (error) {
|
||||
payStatus = '';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (payType == 'virtual' && user.value.amount * 1 > order.orderAmount * 1) {
|
||||
if (payType == 'virtual' && pageData.user.amount * 1 > order.orderAmount * 1) {
|
||||
params.payType = 'userPay'
|
||||
params.shopUserId = user.value.id
|
||||
await vipPay(params)
|
||||
params.shopUserId = pageData.user.id
|
||||
try {
|
||||
await vipPay(params)
|
||||
} catch (error) {
|
||||
payStatus = '';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
paySuccess()
|
||||
|
||||
Reference in New Issue
Block a user