优化:请求接口全局处理loading和错误提示
This commit is contained in:
@@ -90,7 +90,7 @@
|
||||
<text class="label">{{ $t('order.total') }}:</text>
|
||||
<text class="amount">{{ finalAmount }} {{ t('global.coin') }}</text>
|
||||
</view>
|
||||
<wd-button type="primary" :loading="submitting" @click="handleSubmit">
|
||||
<wd-button type="primary" @click="handleSubmit">
|
||||
{{ $t('order.submit') }}
|
||||
</wd-button>
|
||||
</view>
|
||||
@@ -170,12 +170,7 @@ const getDiscountParams = (goodsList: IGoods[]) => {
|
||||
}))
|
||||
}
|
||||
|
||||
|
||||
// 支付相关
|
||||
|
||||
// UI状态
|
||||
const submitting = ref(false)
|
||||
|
||||
// 监听商品列表变化,更新价格
|
||||
watch(() => props.goodsList, () => {
|
||||
getDiscountParams(props.goodsList)
|
||||
// 初始化价格
|
||||
@@ -222,24 +217,16 @@ const calculateTotalPrice = () => {
|
||||
* 计算VIP优惠
|
||||
*/
|
||||
const calculateVipDiscounted = async () => {
|
||||
try {
|
||||
const res = await orderApi.getVipDiscountAmount(goodsListParams.value)
|
||||
vipDiscounted.value = res.discountAmount
|
||||
} catch (error) {
|
||||
console.error('获取VIP优惠失败:', error)
|
||||
}
|
||||
const res = await orderApi.getVipDiscountAmount(goodsListParams.value)
|
||||
vipDiscounted.value = res.discountAmount
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算活动优惠
|
||||
*/
|
||||
const calculatePromotionDiscounted = async () => {
|
||||
try {
|
||||
const res = await orderApi.getDistrictAmount(goodsListParams.value)
|
||||
promotionDiscounted.value = res.districtAmount
|
||||
} catch (error) {
|
||||
console.error('获取地区优惠失败:', error)
|
||||
}
|
||||
const res = await orderApi.getDistrictAmount(goodsListParams.value)
|
||||
promotionDiscounted.value = res.districtAmount
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,71 +350,45 @@ const validateOrder = (): boolean => {
|
||||
/**
|
||||
* 提交订单
|
||||
*/
|
||||
const handleSubmit = async () => {
|
||||
if (submitting.value) {
|
||||
uni.showToast({
|
||||
title: t('order.tooFrequent'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
// 验证订单
|
||||
if (!validateOrder()) return
|
||||
|
||||
try {
|
||||
submitting.value = true
|
||||
|
||||
// 创建订单 此app用天医币支付,创建订单成功即支付成功
|
||||
await createOrder()
|
||||
|
||||
uni.showToast({
|
||||
title: t('order.orderSuccess'),
|
||||
icon: 'success'
|
||||
})
|
||||
|
||||
} catch (error) {
|
||||
console.error('提交订单失败:', error)
|
||||
uni.showToast({
|
||||
title: t('order.orderFailed'),
|
||||
icon: 'none'
|
||||
})
|
||||
} finally {
|
||||
submitting.value = false
|
||||
}
|
||||
// 创建订单 此app用天医币支付,创建订单成功即支付成功
|
||||
await createOrder()
|
||||
|
||||
uni.showToast({
|
||||
title: t('order.orderSuccess'),
|
||||
icon: 'success'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建订单
|
||||
*/
|
||||
const createOrder = async (): Promise<string | null> => {
|
||||
try {
|
||||
const orderParams = {
|
||||
userId: props.userInfo.id,
|
||||
paymentMethod: 4, // 天医币
|
||||
orderMoney: totalAmount.value,
|
||||
realMoney: finalAmount.value,
|
||||
pointsDeduction: 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,
|
||||
come: 10
|
||||
}
|
||||
|
||||
const res = await orderApi.placeCourseOrder(orderParams)
|
||||
|
||||
if (res.orderSn) {
|
||||
return res.orderSn
|
||||
}
|
||||
return null
|
||||
} catch (error) {
|
||||
console.error('下单失败:', error)
|
||||
throw error
|
||||
const orderParams = {
|
||||
userId: props.userInfo.id,
|
||||
paymentMethod: 4, // 天医币
|
||||
orderMoney: totalAmount.value,
|
||||
realMoney: finalAmount.value,
|
||||
pointsDeduction: 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,
|
||||
come: 10
|
||||
}
|
||||
|
||||
const res = await orderApi.placeCourseOrder(orderParams)
|
||||
|
||||
if (res.orderSn) {
|
||||
return res.orderSn
|
||||
}
|
||||
return null
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user