更新:增加课程和图书VIP购买及“我的”主页vip身份显示
This commit is contained in:
@@ -124,22 +124,28 @@
|
||||
<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',
|
||||
allowPointPay: true,
|
||||
orderType: 'order',
|
||||
backStep: 1
|
||||
})
|
||||
|
||||
// 订单备注
|
||||
@@ -185,7 +191,7 @@ const calculateAllPrices = async () => {
|
||||
// 计算商品总价
|
||||
calculateTotalPrice()
|
||||
|
||||
await Promise.all([
|
||||
props.orderType === 'order' && await Promise.all([
|
||||
// 获取VIP优惠
|
||||
calculateVipDiscounted(),
|
||||
|
||||
@@ -319,7 +325,7 @@ const calculateFinalPrice = () => {
|
||||
0,
|
||||
totalAmount.value - couponAmount - pointsDiscounted.value - promotionDiscounted.value - vipDiscounted.value
|
||||
)
|
||||
finalAmount.value = result.toFixed(2)
|
||||
finalAmount.value = result
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -327,7 +333,7 @@ const calculateFinalPrice = () => {
|
||||
*/
|
||||
const validateOrder = (): boolean => {
|
||||
// 验证实付金额是否计算完成
|
||||
if (typeof finalAmount.value != 'number') {
|
||||
if (isNaN(parseFloat(finalAmount.value))) {
|
||||
uni.showToast({
|
||||
title: t('order.invalidPaymentAmount'),
|
||||
icon: 'none'
|
||||
@@ -357,10 +363,19 @@ 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
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -372,18 +387,20 @@ const createOrder = async (): Promise<string | null> => {
|
||||
paymentMethod: 4, // 天医币
|
||||
orderMoney: totalAmount.value,
|
||||
realMoney: finalAmount.value,
|
||||
pointsDeduction: pointsDiscounted.value,
|
||||
jfDeduction: 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.placeCourseOrder(orderParams)
|
||||
const res = await orderApi.placeOrder(orderParams)
|
||||
|
||||
if (res.orderSn) {
|
||||
return res.orderSn
|
||||
|
||||
Reference in New Issue
Block a user