@@ -124,28 +124,22 @@
< script setup lang = "ts" >
import { ref , watch } from 'vue'
import { orderApi } from '@/api/modules/order'
import { getUserInfo } from '@/api/modules/user'
import { useUserStore } from '@/stores/user'
import { t } from '@/utils/i18n'
import type { IGoods , IGoodsDiscountParams } from '@/types/order'
import PayWay from '@/components/order/PayWay.vue'
const userStore = useUserStore ( )
// 使用页面传参
interface Props {
goodsList : IGoods [ ] ,
userInfo : object ,
allowPointPay : boolean ,
orderType : string ,
backStep : number // 购买完成后返回几层页面
}
const props = withDefaults ( defineProps < Props > ( ) , {
goodsList : ( ) => [ ] ,
userInfo : ( ) => ( { } ) ,
allowPointPay : true ,
orderType : 'order' ,
backStep : 1
allowPointPay : ( ) => true ,
orderType : ( ) => 'order' ,
} )
// 订单备注
@@ -191,7 +185,7 @@ const calculateAllPrices = async () => {
// 计算商品总价
calculateTotalPrice ( )
props . orderType === 'order' && await Promise . all ( [
await Promise . all ( [
// 获取VIP优惠
calculateVipDiscounted ( ) ,
@@ -325,7 +319,7 @@ const calculateFinalPrice = () => {
0 ,
totalAmount . value - couponAmount - pointsDiscounted . value - promotionDiscounted . value - vipDiscounted . value
)
finalAmount . value = result
finalAmount . value = result . toFixed ( 2 )
}
/**
@@ -333,7 +327,7 @@ const calculateFinalPrice = () => {
*/
const validateOrder = ( ) : boolean => {
// 验证实付金额是否计算完成
if ( isNaN ( parseFloat ( finalAmount . value ) ) ) {
if ( typeof finalAmount . value != 'number' ) {
uni . showToast ( {
title : t ( 'order.invalidPaymentAmount' ) ,
icon : 'none'
@@ -363,19 +357,10 @@ const handleSubmit = async () => {
// 创建订单 此app用天医币支付, 创建订单成功即支付成功
await createOrder ( )
// 重新获取用户信息更新store和本地缓存
const res = await getUserInfo ( )
userStore . setUserInfo ( res . result )
uni . showToast ( {
title : t ( 'order.orderSuccess' ) ,
icon : 'success'
} )
// 返回上一页
uni . navigateBack ( {
delta : props . backStep
} )
}
/**
@@ -387,20 +372,18 @@ const createOrder = async (): Promise<string | null> => {
paymentMethod : 4 , // 天医币
orderMoney : totalAmount . value ,
realMoney : finalAmount . value ,
jf Deduction: pointsDiscounted . value ,
points Deduction: pointsDiscounted . value ,
// couponId: selectedCoupon.value?.id,
// couponName: selectedCoupon.value?.couponEntity.couponName,
vipDiscountAmount : vipDiscounted . value ,
districtMoney : promotionDiscounted . value ,
remark : remark . value ,
productList : goodsListParams . value ,
orderType : props . orderType ,
productList : props . orderType === 'order' ? goodsListParams . value : null ,
vipBuyConfigId : props . orderType === 'vip' ? props . goodsList [ 0 ] . productId : null ,
abroadVipId : props . orderType === 'abroadVip' ? props . goodsList [ 0 ] . productId : null ,
come : 10
}
const res = await orderApi . placeOrder ( orderParams )
const res = await orderApi . placeCourse Order ( orderParams )
if ( res . orderSn ) {
return res . orderSn