lex hace 1 año
padre
commit
f7d6a6ee2d

+ 11 - 12
src/views/member-center/index.tsx

@@ -80,20 +80,17 @@ export default defineComponent({
           {
             requestType: 'form',
             params: {
-              paramNames:
-                'vip_payment_service_provider,vip_payment_service_provider_channel'
+              paramNames: 'vip_payment_service_provider2'
             }
           }
         );
 
         if (data && Array.isArray(data)) {
           data.forEach((item: any) => {
-            if (item.paramName === 'vip_payment_service_provider') {
-              this.paymentType = item.paramValue;
-            } else if (
-              item.paramName === 'vip_payment_service_provider_channel'
-            ) {
-              this.paymentChannel = item.paramValue;
+            if (item.paramName === 'vip_payment_service_provider2') {
+              const provider = JSON.parse(item.paramValue);
+              this.paymentType = provider.vendor;
+              this.paymentChannel = provider.channel;
             }
           });
         }
@@ -122,7 +119,9 @@ export default defineComponent({
               this.$router.push({
                 path: '/order-detail',
                 query: {
-                  config: JSON.stringify(paymentConfig.paymentConfig),
+                  config: JSON.stringify({
+                    ...paymentConfig.paymentConfig
+                  }),
                   paymentType: paymentConfig.paymentType,
                   paymentChannel: this.paymentChannel,
                   orderNo: paymentConfig.orderNo
@@ -206,10 +205,10 @@ export default defineComponent({
             path: '/order-detail',
             query: {
               config: JSON.stringify({
-                ...data.paymentConfig,
-                paymentType: this.paymentType,
-                paymentChannel: this.paymentChannel
+                ...data.paymentConfig
               }),
+              paymentType: this.paymentType,
+              paymentChannel: this.paymentChannel,
               orderNo: data.orderNo
             }
           });

+ 7 - 2
src/views/student-register/index.tsx

@@ -122,6 +122,7 @@ export default defineComponent({
     const forms = reactive({
       schoolId: route.query.sId as any,
       paymentType: '', // 支付类型
+      paymentChannel: '',
       multi_user_limit: 1, // 限制注册学生数量
       // popupShow: false,
       registerDetails: {} as any,
@@ -1022,7 +1023,7 @@ export default defineComponent({
           // 直接去拉取微信支付
           onConfirm({
             payCode: 'payResult',
-            pay_channel: 'wx_pub'
+            pay_channel: forms.paymentChannel
           });
         }
       }
@@ -1260,7 +1261,11 @@ export default defineComponent({
             if (item.paramName === 'contract_sign') {
               forms.contract_sign = item.paramValue === '1' ? true : false;
             } else if (item.paramName === 'payment_service_provider') {
-              forms.paymentType = item.paramValue || '';
+              // forms.paymentType = item.paramValue || '';
+              const provider = JSON.parse(item.paramValue);
+              forms.paymentType = provider.vendor;
+              forms.paymentChannel = provider.channel;
+              console.log(item.paramValue);
             } else if (item.paramName === 'multi_user_limit') {
               forms.multi_user_limit = item.paramValue
                 ? Number(item.paramValue)

+ 95 - 3
src/views/student-register/order-detail.tsx

@@ -3,7 +3,18 @@ import { computed, defineComponent, onMounted, reactive, ref } from 'vue';
 import styles from './order-detail.module.less';
 import Addres from './component/addres';
 import OSticky from '@/components/m-sticky';
-import { Button, Cell, CellGroup, Image, Popup, showToast, Tag } from 'vant';
+import {
+  Button,
+  Cell,
+  CellGroup,
+  closeToast,
+  Image,
+  Popup,
+  showDialog,
+  showLoadingToast,
+  showToast,
+  Tag
+} from 'vant';
 import Payment from '@/views/adapay/payment';
 import { useRoute, useRouter } from 'vue-router';
 import request from '@/helpers/request';
@@ -17,6 +28,7 @@ import ODialog from '@/components/m-dialog';
 import { orderStatus } from '@/helpers/constant';
 import QrcodePayment from './qrcode-payment';
 import { beforeSubmit } from './order-state';
+import { listenerMessage, postMessage } from '@/helpers/native-message';
 
 /**
  * 接入jsdk
@@ -30,13 +42,15 @@ export default defineComponent({
     const route = useRoute();
     const router = useRouter();
     const state = reactive({
-      paymentType: '' as any, // 'adapay' as 'wxpay' | 'adapay', // 支付方式
+      // paymentType: '' as any, // 'adapay' as 'wxpay' | 'adapay', // 支付方式
       orderTimer: null as any,
       paymentStatus: false,
       showQrcode: false,
       qrCodeUrl: '',
       pay_channel: '',
       orderNo: route.query.orderNo,
+      paymentType: route.query.paymentType,
+      paymentChannel: route.query.paymentChannel,
       orderInfo: {} as any, // 订单信息
       goodsInfos: [] as any, // 订单信息列表
       config: route.query.config ? JSON.parse(route.query.config as any) : {},
@@ -113,6 +127,15 @@ export default defineComponent({
       const config: any = state.config;
       state.pay_channel = val.pay_channel;
 
+      // 判断是否为原生支付
+      if (
+        val.pay_channel.indexOf('wxpay-app') !== -1 ||
+        val.pay_channel.indexOf('alipay-app') !== -1
+      ) {
+        submitNativePay();
+        return;
+      }
+
       const params = qs.stringify({
         pay_channel: val.pay_channel,
         wxAppId: config.wxAppId,
@@ -172,6 +195,72 @@ export default defineComponent({
       }, 5000);
     };
 
+    const submitNativePay = async () => {
+      // 支付...
+      try {
+        const { data } = await request.post(
+          '/edu-app/open/userOrder/executePayment',
+          {
+            data: {
+              ...state.config
+            }
+          }
+        );
+
+        const payChannel = state.config.paymentChannel;
+        let payStr = payChannel.indexOf('wxpay') !== -1 ? 'wx_app' : 'ali_app';
+
+        postMessage({
+          api: 'paymentOrder',
+          content: {
+            orderNo: state.orderNo,
+            payChannel: payStr,
+            payInfo: data.reqParams.body || JSON.stringify(data.reqParams)
+          }
+        });
+        showLoadingToast({
+          message: '支付中...',
+          forbidClick: true,
+          duration: 3000,
+          loadingType: 'spinner'
+        });
+        // 唤起支付时状态
+        listenerMessage('paymentOperation', result => {
+          console.log(result, 'init paymentOperation');
+          paymentOperation(result?.content);
+        });
+      } catch (e: any) {
+        console.log(e);
+      }
+    };
+
+    const paymentOperation = (res: any) => {
+      console.log(res, 'paymentOperation');
+      // 支付状态
+      // paymentOperation  支付成功:success 支付失败:error 支付取消:cancel 未安装:fail
+      // error 只有安卓端有
+      closeToast();
+      if (res.status === 'success' || res.status === 'error') {
+        router.replace({
+          path: '/payment-result',
+          query: {
+            orderNo: state.orderNo
+          }
+        });
+      } else if (res.status === 'cancel') {
+      } else if (res.status === 'fail') {
+        const payChannel = state.config.paymentChannel;
+        const message =
+          payChannel.indexOf('wxpay') !== -1
+            ? '您尚未安装微信'
+            : '您尚未安装支付宝';
+        showDialog({
+          title: '提示',
+          message
+        });
+      }
+    };
+
     // 确定支付
     const onSubmit = async () => {
       clearInterval(state.orderTimer);
@@ -470,7 +559,10 @@ export default defineComponent({
           style={{ minHeight: '30%' }}>
           <Payment
             paymentConfig={state.orderInfo}
-            config={state.config}
+            config={{
+              paymentType: state.paymentType,
+              paymentChannel: state.paymentChannel
+            }}
             onClose={() => (state.paymentStatus = false)}
             onBackOut={onBackOut}
             onConfirm={(val: any) => onConfirm(val)}