|
@@ -2,28 +2,93 @@
|
|
|
import router from '@/router'
|
|
import router from '@/router'
|
|
|
import { StaticUrl } from '@/config'
|
|
import { StaticUrl } from '@/config'
|
|
|
|
|
|
|
|
|
|
+const { userInfo } = storeToRefs(useUserStore())
|
|
|
definePage({
|
|
definePage({
|
|
|
name: 'charge-voucher',
|
|
name: 'charge-voucher',
|
|
|
- islogin: false,
|
|
|
|
|
|
|
+ islogin: true,
|
|
|
style: {
|
|
style: {
|
|
|
navigationBarTitleText: '',
|
|
navigationBarTitleText: '',
|
|
|
navigationStyle: 'custom',
|
|
navigationStyle: 'custom',
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
const { statusBarHeight, MenuButtonHeight, opcity } = storeToRefs(useSysStore())
|
|
const { statusBarHeight, MenuButtonHeight, opcity } = storeToRefs(useSysStore())
|
|
|
|
|
+const couponBalance = ref()
|
|
|
|
|
+onLoad((options: any) => {
|
|
|
|
|
+ console.log(options, '路由参数')
|
|
|
|
|
+ couponBalance.value = options.couponBalance
|
|
|
|
|
+})
|
|
|
onMounted(() => {
|
|
onMounted(() => {
|
|
|
opcity.value = 0
|
|
opcity.value = 0
|
|
|
|
|
+ getRechargeLevels()
|
|
|
})
|
|
})
|
|
|
onPageScroll((e) => {
|
|
onPageScroll((e) => {
|
|
|
const calculatedOpacity = e.scrollTop / 100
|
|
const calculatedOpacity = e.scrollTop / 100
|
|
|
opcity.value = Math.min(1, Math.max(0.1, calculatedOpacity))
|
|
opcity.value = Math.min(1, Math.max(0.1, calculatedOpacity))
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
-const selectIndex = ref(0)
|
|
|
|
|
|
|
+const selectIndex = ref<number>()
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 获取充值挡位
|
|
|
|
|
+ */
|
|
|
|
|
+const rechargeLevels = ref<Api.RechargeLevel[]>([])
|
|
|
|
|
+async function getRechargeLevels() {
|
|
|
|
|
+ const res = await Apis.charge.getReChargeLevel({})
|
|
|
|
|
+ rechargeLevels.value = res.data
|
|
|
|
|
+}
|
|
|
function selectVoucher(index: number) {
|
|
function selectVoucher(index: number) {
|
|
|
selectIndex.value = index
|
|
selectIndex.value = index
|
|
|
console.log('Selected voucher index:', index)
|
|
console.log('Selected voucher index:', index)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+// 安全获取充值档位
|
|
|
|
|
+function getSelectedLevel(): Api.RechargeLevel | undefined {
|
|
|
|
|
+ if (selectIndex.value === undefined || !rechargeLevels.value)
|
|
|
|
|
+ return undefined
|
|
|
|
|
+ return rechargeLevels.value[selectIndex.value]
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+/**
|
|
|
|
|
+ * 提交支付
|
|
|
|
|
+ */
|
|
|
|
|
+async function submitPay() {
|
|
|
|
|
+ if (selectIndex.value === undefined) {
|
|
|
|
|
+ return useGlobalMessage().alert('请选择充值金额')
|
|
|
|
|
+ }
|
|
|
|
|
+ const selectedLevel = getSelectedLevel()
|
|
|
|
|
+ if (!selectedLevel) {
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ try {
|
|
|
|
|
+ uni.showLoading({ title: '下单中...', mask: true })
|
|
|
|
|
+ const orderRes = await Apis.charge.addPurchaseRecord({
|
|
|
|
|
+ data: {
|
|
|
|
|
+ couponAmount: selectedLevel.money,
|
|
|
|
|
+ consigneeName: userInfo.value?.nickName || '',
|
|
|
|
|
+ consigneeMobile: userInfo.value?.mobile || '',
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+ const orderNumber = orderRes.data
|
|
|
|
|
+ if (!orderNumber) {
|
|
|
|
|
+ uni.hideLoading()
|
|
|
|
|
+ uni.showToast({ title: '下单失败', icon: 'none' })
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ const payRes = await Apis.charge.wxJsApiPay({
|
|
|
|
|
+ data: {
|
|
|
|
|
+ orderNumber,
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+ uni.hideLoading()
|
|
|
|
|
+ await useUserStore().getWxCommonPayment(payRes.data)
|
|
|
|
|
+ useUserStore().paySuccess('charge-buy-a-ticket-list', '/subPack-charge/chargeBuyaTicketList/chargeBuyaTicketList')
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (error) {
|
|
|
|
|
+ uni.hideLoading()
|
|
|
|
|
+ console.error('支付失败:', error)
|
|
|
|
|
+ useUserStore().payError('charge-buy-a-ticket-list', '/subPack-charge/chargeBuyaTicketList/chargeBuyaTicketList')
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
<template>
|
|
@@ -45,7 +110,8 @@ function selectVoucher(index: number) {
|
|
|
平台券金额
|
|
平台券金额
|
|
|
</view>
|
|
</view>
|
|
|
<view class="mt-16rpx text-28rpx font-800">
|
|
<view class="mt-16rpx text-28rpx font-800">
|
|
|
- 100<text class="text-24rpx">
|
|
|
|
|
|
|
+ {{ couponBalance }}
|
|
|
|
|
+ <text class="text-24rpx">
|
|
|
元
|
|
元
|
|
|
</text>
|
|
</text>
|
|
|
</view>
|
|
</view>
|
|
@@ -65,14 +131,14 @@ function selectVoucher(index: number) {
|
|
|
本次充值
|
|
本次充值
|
|
|
</view>
|
|
</view>
|
|
|
<view class="mt-24rpx flex flex-wrap items-center justify-start gap-20rpx">
|
|
<view class="mt-24rpx flex flex-wrap items-center justify-start gap-20rpx">
|
|
|
- <view v-for="(item, index) in 6" :key="index" class="h-136rpx w-220rpx text-center" :class="selectIndex === index ? 'text-[#9ED605]' : 'text-#2B303Ac'" :style="{ backgroundImage: `url(${StaticUrl}/${selectIndex === index ? 'buy-center-rechargesel' : 'buy-center-recharge'}.png)`, backgroundSize: 'cover', backgroundPosition: 'center' }" @click="selectVoucher(index)">
|
|
|
|
|
|
|
+ <view v-for="(item, index) in rechargeLevels" :key="index" class="h-136rpx w-220rpx text-center" :class="selectIndex === index ? 'text-[#9ED605]' : 'text-#2B303Ac'" :style="{ backgroundImage: `url(${StaticUrl}/${selectIndex === index ? 'buy-center-rechargesel' : 'buy-center-recharge'}.png)`, backgroundSize: 'cover', backgroundPosition: 'center' }" @click="selectVoucher(index)">
|
|
|
<view class="h-80rpx text-28rpx font-bold line-height-[80rpx]">
|
|
<view class="h-80rpx text-28rpx font-bold line-height-[80rpx]">
|
|
|
- 10<text class="text-24rpx">
|
|
|
|
|
|
|
+ {{ item?.money }}<text class="text-24rpx">
|
|
|
元
|
|
元
|
|
|
</text>
|
|
</text>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="h-46rpx text-28rpx font-bold line-height-[46rpx] font-italic">
|
|
<view class="h-46rpx text-28rpx font-bold line-height-[46rpx] font-italic">
|
|
|
- 充电优惠券
|
|
|
|
|
|
|
+ {{ item?.name }}
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
@@ -94,7 +160,11 @@ function selectVoucher(index: number) {
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="fixed bottom-66rpx left-24rpx h-100rpx w-702rpx rounded-16rpx bg-[linear-gradient(90deg,#DBFC81_0%,#9ED605_100%)] text-center text-28rpx font-800 line-height-[100rpx] shadow-[inset_0rpx_6rpx_20rpx_2rpx_#FFFFFF]">
|
|
|
|
|
|
|
+ <view
|
|
|
|
|
+ class="fixed bottom-66rpx left-24rpx h-100rpx w-702rpx rounded-16rpx text-center text-28rpx font-800 line-height-[100rpx]"
|
|
|
|
|
+ :class="selectIndex === undefined ? 'bg-[#CCCCCC] text-white' : 'bg-[linear-gradient(90deg,#DBFC81_0%,#9ED605_100%)] text-black shadow-[inset_0rpx_6rpx_20rpx_2rpx_#FFFFFF]'"
|
|
|
|
|
+ @click="submitPay"
|
|
|
|
|
+ >
|
|
|
立即支付
|
|
立即支付
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|