更新:谷歌支付、积分列表
This commit is contained in:
@@ -8,8 +8,8 @@
|
||||
<view class="recharge_block" @click="chosPric(item)"
|
||||
:class="aloneItem.priceTypeId === item.priceTypeId ? 'selected' : ''"
|
||||
v-for="item in rechargeList.bookBuyConfigList" :key="item.priceTypeId">
|
||||
<view class="recharge_money">¥{{item.money}}</view>
|
||||
<view>{{item.realMoney}}{{ t('global.coin') }}</view>
|
||||
<view class="recharge_money">¥{{item.realMoney}}</view>
|
||||
<view>{{item.money}}{{ t('global.coin') }}</view>
|
||||
<!-- 红框位置的618活动标签 -->
|
||||
<!-- <view class="activity-tag">618活动</view> -->
|
||||
<span class="activity-label" v-if="item.givejf >0">618充值活动</span>
|
||||
@@ -23,25 +23,26 @@
|
||||
<view class="cha_fangsh">
|
||||
<view class="cf_title PM_font">{{$t('user.paymentMethod')}}</view>
|
||||
<view class="cf_radio">
|
||||
<radio-group v-for="item in iosPaylist" @click="choseType(item.id)">
|
||||
<radio-group v-for="item in iosPaylist">
|
||||
<view style="width: 100%">
|
||||
<view :class="payType == item.id ? 'Tab_xf cf_xuanx' : 'cf_xuanx'">
|
||||
<!-- <image class="pay_item_img" :src="item.imgUrl" mode="aspectFil">
|
||||
</image> -->
|
||||
<text>{{ item.title }}</text>
|
||||
<radio :checked="payType === item.id"></radio>
|
||||
<radio :checked="payType === item.id" @click="choseType(item.id)"></radio>
|
||||
</view>
|
||||
</view>
|
||||
</radio-group>
|
||||
</view>
|
||||
</view>
|
||||
<view class="agree_wo flexbox">
|
||||
<radio-group class="agree" v-for="(item, index) in argee" :key="index" @click="radioCheck">
|
||||
<radio-group class="agree" v-for="(item, index) in argee" :key="index">
|
||||
<view>
|
||||
<radio class="agreeRadio" :value="item.id" :checked="state" color="#007bff"></radio>
|
||||
<radio class="agreeRadio" :value="item.id" :checked="state" color="#007bff" @click="radioCheck"></radio>
|
||||
</view>
|
||||
</radio-group>
|
||||
<view>{{$t('order.readAgree')}}<span class="highlight" @click="showAgreement">《{{$t('order.valueAddedServices')}}》</span></view>
|
||||
<view>{{$t('order.readAgree')}}<span class="highlight"
|
||||
@click="showAgreement">《{{$t('order.valueAddedServices')}}》</span></view>
|
||||
</view>
|
||||
<view class="bottom-button-container">
|
||||
<button class="recharge-button" @click="handleRecharge">{{$t('order.recharge')}}</button>
|
||||
@@ -61,10 +62,13 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, toRefs, reactive } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useMessage } from '@/uni_modules/wot-design-uni'
|
||||
import { getBookBuyConfigList, getAgreement, getActivityDescription } from '@/api/modules/user'
|
||||
// const googlePay = uni.requireNativePlugin("sn-googlepay5");
|
||||
import { getBookBuyConfigList, getAgreement, getActivityDescription, verifyGooglePay, getPlaceOrder } from '@/api/modules/user'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
|
||||
const googlePay = uni.requireNativePlugin("sn-googlepay5");
|
||||
const userStore = useUserStore()
|
||||
const { t } = useI18n()
|
||||
const message = useMessage()
|
||||
const payType = ref('1')
|
||||
@@ -107,13 +111,40 @@
|
||||
|
||||
const remark = ref({})
|
||||
const isConnected = ref(false)
|
||||
const purchaseToken = ref()
|
||||
// 订单编号
|
||||
const orderSn = ref('')
|
||||
|
||||
|
||||
/**
|
||||
/**
|
||||
* 获取订单编号
|
||||
*/
|
||||
const getPlaceOrderObj = async () => {
|
||||
const { priceTypeId, realMoney, money } = toRefs(aloneItem.value)
|
||||
const data = {
|
||||
userId: userStore.userInfo.id, // 用户di
|
||||
paymentMethod: '5', //支付方式4point 5google
|
||||
orderMoney: money.value, //订单金额
|
||||
realMoney: realMoney.value, //实际金额
|
||||
come: '10', //订单来源 2医学吴门医述 10海外读书
|
||||
orderType: 'point', //订单类型, point充值、order课程、书、vip 课vip、abroadVip 书vip、relearn 复读、trainingClass 培训班
|
||||
productId: priceTypeId.value // 商品id
|
||||
}
|
||||
try {
|
||||
const res = await getPlaceOrder(data)
|
||||
orderSn.value = res.orderSn
|
||||
console.log(orderSn.value, '获取订单号');
|
||||
getGooglePay()
|
||||
} catch (error) {
|
||||
console.error('获取订单号失败', error)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取使用环境
|
||||
*/
|
||||
const getDevName = () => {
|
||||
|
||||
|
||||
if (uni.getSystemInfoSync().platform === "android") {
|
||||
qudao.value = 'Google'
|
||||
isAndroid.value = true;
|
||||
@@ -127,7 +158,7 @@
|
||||
|
||||
// 点击金额
|
||||
const chosPric = (item : any) => {
|
||||
console.log(item,'金额每项');
|
||||
console.log(item, '金额每项');
|
||||
aloneItem.value = item;
|
||||
};
|
||||
|
||||
@@ -195,25 +226,25 @@
|
||||
// payType.value = val;
|
||||
}
|
||||
|
||||
const handleRecharge = () => {
|
||||
if(!state.value){
|
||||
const handleRecharge = async () => {
|
||||
if (!state.value) {
|
||||
uni.showToast({
|
||||
title: t('order.readAgreeServices'),
|
||||
icon: 'none'
|
||||
title: t('order.readAgreeServices'),
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
uni.showLoading({ title: '加载中...' })
|
||||
console.log('立即充值');
|
||||
getGooglePay()
|
||||
getPlaceOrderObj()
|
||||
uni.showLoading({ title: '生成订单中...' })
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 初始化
|
||||
*/
|
||||
const getGooglePay = () => {
|
||||
googlePay.init({
|
||||
}, (e:any) => {
|
||||
}, (e : any) => {
|
||||
console.log('init', e);
|
||||
if (e.code == 0) {
|
||||
isConnected.value = true;
|
||||
@@ -225,47 +256,93 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 查询sku
|
||||
*/
|
||||
const getQuerySku = () =>{
|
||||
const getQuerySku = () => {
|
||||
const id = aloneItem.value.priceTypeId
|
||||
console.log(id, '获取每项');
|
||||
googlePay.querySku(
|
||||
{
|
||||
inapp: [id], // 与subs二选一, 参数为商品ID(字符串)数组
|
||||
},
|
||||
(e:any) => {
|
||||
if (e.code == 0) {
|
||||
// 查询成功.
|
||||
console.log('查询成功',e);
|
||||
// e.list; // 查询结果, array
|
||||
} else {
|
||||
console.log('查询失败');
|
||||
// 查询失败
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
const getPayAll = () =>{
|
||||
googlePay.payAll(
|
||||
{
|
||||
productId: "", // 产品id
|
||||
|
||||
},
|
||||
(e) => {
|
||||
if (e.code == 0) {
|
||||
// 支付成功
|
||||
e.data; //支付结果, array [ {original:{ }, signature: ''} ]
|
||||
} else {
|
||||
// 支付失败
|
||||
}
|
||||
},
|
||||
{
|
||||
inapp: [id], // 与subs二选一, 参数为商品ID(字符串)数组
|
||||
},
|
||||
(e : any) => {
|
||||
if (e.code == 0) {
|
||||
// 查询成功.
|
||||
console.log('querySku查询成功', e);
|
||||
uni.hideLoading()
|
||||
getPayAll()
|
||||
} else {
|
||||
console.log('查询失败', e);
|
||||
// 查询失败
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 发起支付
|
||||
*/
|
||||
const getPayAll = () => {
|
||||
console.log(aloneItem.value.priceTypeId, orderSn.value, '发起支付传入产品id,订单id');
|
||||
googlePay.payAll(
|
||||
{
|
||||
productId: aloneItem.value.priceTypeId, // 产品id
|
||||
accountId: orderSn.value // 订单编号
|
||||
},
|
||||
(e : any) => {
|
||||
if (e.code == 0) {
|
||||
purchaseToken.value = e.data[0].original.purchaseToken
|
||||
// 支付成功
|
||||
console.log(e, 'payAll方法成功返参');
|
||||
getConsume()
|
||||
} else {
|
||||
uni.showToast({ title: '支付失败', icon: 'success' })
|
||||
console.log(e, 'e');
|
||||
// 支付失败
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗品 确认交易
|
||||
*/
|
||||
const getConsume = () => {
|
||||
googlePay.consume(
|
||||
{
|
||||
purchaseToken: purchaseToken.value, // 来自支付结果的original.purchaseToken (或 original.token)
|
||||
},
|
||||
(e : any) => {
|
||||
if (e.code == 0) {
|
||||
console.log(e, '确认交易成功');
|
||||
// 确认成功
|
||||
googleVerify()
|
||||
} else {
|
||||
console.log(e, '确认交易失败');
|
||||
// 确认失败
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验订单
|
||||
*/
|
||||
const googleVerify = async () => {
|
||||
try {
|
||||
const obj = await verifyGooglePay(aloneItem.value.priceTypeId, purchaseToken.value, orderSn.value)
|
||||
uni.switchTab({
|
||||
url: '/pages/user/index'
|
||||
})
|
||||
console.log(obj, '校验订单');
|
||||
} catch (error) {
|
||||
console.error('校验订单失败:', error)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
onMounted(() => {
|
||||
getDevName();
|
||||
@@ -387,7 +464,7 @@
|
||||
border-bottom: 1px solid #ededed;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items:center;
|
||||
align-items: center;
|
||||
|
||||
image {
|
||||
width: 40rpx;
|
||||
|
||||
Reference in New Issue
Block a user