| | |
| | | } |
| | | |
| | | /** |
| | | * 打开整课购买支付弹窗。 |
| | | * 直接领取整课,不展示支付方式弹窗。 |
| | | */ |
| | | function handleCoursePurchase() { |
| | | if (isReadonlyDisplayMode) { |
| | | return |
| | | } |
| | | if (!courseId.value || courseDetail.value.courseOwned || memberJoinSubmitting.value) { |
| | | if (!courseId.value || courseDetail.value.courseOwned || memberJoinSubmitting.value || purchaseSubmitting.value) { |
| | | return |
| | | } |
| | | if (courseDetail.value.isMember) { |
| | | submitMemberJoin() |
| | | return |
| | | } |
| | | if (isIosApp) { |
| | | selectedPaymentMethod.value = 'appleiap' |
| | | } |
| | | activePurchaseTarget.value = 'COURSE' |
| | | activePurchaseVideoId.value = null |
| | | showPaymentPopup.value = true |
| | | void submitZeroPricePurchase() |
| | | } |
| | | |
| | | /** |
| | | * 处理付费小节点击,未购买时进入对应支付弹窗。 |
| | | * 处理付费小节点击,未购买时直接走 0 元领取流程。 |
| | | */ |
| | | function handlePaidVideoTap(item : CourseVideo) { |
| | | if (isReadonlyDisplayMode) { |
| | | return |
| | | } |
| | | if (!courseId.value || courseDetail.value.courseOwned || item.purchased) { |
| | | if (!courseId.value || courseDetail.value.courseOwned || item.purchased || purchaseSubmitting.value) { |
| | | return |
| | | } |
| | | if (isIosApp) { |
| | | selectedPaymentMethod.value = 'appleiap' |
| | | } |
| | | activePurchaseTarget.value = 'VIDEO' |
| | | activePurchaseVideoId.value = item.id |
| | | showPaymentPopup.value = true |
| | | void submitZeroPricePurchase() |
| | | } |
| | | |
| | | /** |
| | |
| | | * 提交当前购买目标的直付订单。 |
| | | */ |
| | | async function submitPurchase() { |
| | | const payload = selectedPaymentMethod.value === 'appleiap' |
| | | ? await buildAppleIapPurchasePayload() |
| | | : { |
| | | paymentMethod: selectedPaymentMethod.value === 'wechat' ? 'WECHAT' : 'ALIPAY', |
| | | } |
| | | if (!payload) { |
| | | return |
| | | } |
| | | await submitPurchaseWithPayload(payload, '购买成功') |
| | | } |
| | | |
| | | /** |
| | | * 提交当前领取目标的 0 元订单,占位支付方式仅用于兼容后端校验。 |
| | | */ |
| | | async function submitZeroPricePurchase() { |
| | | await submitPurchaseWithPayload({ |
| | | paymentMethod: 'WECHAT', |
| | | }, '领取成功') |
| | | } |
| | | |
| | | /** |
| | | * 使用指定支付载荷提交当前购买或领取目标。 |
| | | */ |
| | | async function submitPurchaseWithPayload(payload : Record<string, unknown>, successTitle : string) { |
| | | if (isReadonlyDisplayMode) { |
| | | return |
| | | } |
| | |
| | | } |
| | | purchaseSubmitting.value = true |
| | | try { |
| | | const payload = selectedPaymentMethod.value === 'appleiap' |
| | | ? await buildAppleIapPurchasePayload() |
| | | : { |
| | | paymentMethod: selectedPaymentMethod.value === 'wechat' ? 'WECHAT' : 'ALIPAY', |
| | | } |
| | | if (!payload) { |
| | | return |
| | | } |
| | | const response = activePurchaseTarget.value === 'VIDEO' && activePurchaseVideoId.value !== null |
| | | ? await purchaseHealthCourseVideo(courseId.value, activePurchaseVideoId.value, payload) |
| | | : await purchaseHealthCourse(courseId.value, payload) |
| | |
| | | activePurchaseTarget.value = 'COURSE' |
| | | activePurchaseVideoId.value = null |
| | | uni.showToast({ |
| | | title: '购买成功', |
| | | title: successTitle, |
| | | icon: 'none', |
| | | }) |
| | | } finally { |