| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <template>
- <view class="content">
- <web-view :src="durl" :update-title="false" @message="handleMessage"></web-view>
- </view>
- </template>
- <script>
- const wxMerchantTransfer = uni.requireNativePlugin('wxMerchantTransfer');
- export default {
- data() {
- return {
- durl:"",
- pageTitle: "" // 存储初始标题
- }
- },
- onLoad(options) {
- this.durl = options.url;
- if(options.name){
- this.pageTitle = options.name; // 保存标题到变量
- uni.setNavigationBarTitle({ title: this.pageTitle });
- }
- },
- onShow() {
- // 每次页面显示时重置标题
- if (this.pageTitle) {
- uni.setNavigationBarTitle({ title: this.pageTitle });
- }
- },
- methods: {
- handleMessage(event) {
- const info = event.detail.data[0]
- // #ifdef APP-PLUS
- if(info.withdrawal==1) {
- this.confirmReceipt(info.withdrawalInfo)
- return
- }
- if(info&&info.pagesUrl) {
- uni.navigateTo({
- url: info.pagesUrl
- })
- }
- // #endif
- },
- // 确认收款(拉起微信收款确认页面)
- confirmReceipt(item) {
- if (!item) {
- uni.showToast({
- title: '信息不完整',
- icon: 'none'
- });
- return;
- }
-
- const appId = item.appId;
- const mchId = item.mchId;
- const packageValue = item.packageInfo;
-
- if (!appId || !mchId || !packageValue) {
- uni.showToast({
- title: '缺少必要参数,无法确认收款',
- icon: 'none'
- });
- return;
- }
-
- // #ifdef APP-PLUS
- const params = {
- appId: String(appId),
- mchId: String(mchId),
- package: String(packageValue)
- };
-
- if (typeof wxMerchantTransfer !== 'undefined' && typeof wxMerchantTransfer.open === 'function') {
- console.log('拉起微信收款确认页面,参数:', params);
- wxMerchantTransfer.open(params, (res) => {
- console.log('确认收款回调结果:', res);
- if (res.code === 0) {
- // 确认收款成功,重新查询订单状态
- console.warn('用户拉起微信');
- // if (item.outBatchNo) {
- // setTimeout(() => {
- // uni.navigateTo({
- // url: '/pages/user/wallet/success?orderCode=' + item.outBatchNo
- // });
- // }, 1000);
- // }
- } else if (res.code === -3) {
- console.warn('用户微信版本过低');
- } else {
- uni.showModal({
- title: '确认收款失败',
- content: res.message || '请稍后重试',
- showCancel: false
- });
- }
- });
- } else {
- console.error('wxMerchantTransfer 插件未正确加载');
- uni.showModal({
- title: '功能不可用',
- content: '微信转账功能未正确初始化,请检查插件配置并重新编译应用。',
- showCancel: false
- });
- }
- // #endif
-
- // #ifndef APP-PLUS
- uni.showToast({
- icon: 'none',
- title: '此功能仅在 APP 中可用',
- });
- // #endif
- }
- }
- }
-
-
- </script>
- <style scoped lang="scss">
- page{
- height: 100%;
- background: #ffffff;
- }
- .content{
- width: 100%;
- height: 100%;
- display: flex;
- align-items: center;
- justify-content: center;
-
- }
-
- </style>
|