import{d as g,U as x,x as h,y as S,a as r,A as d,P as l,C as v,I,E as b,D as q,R as c,bj as y,bk as N,bl as T}from"./index-5a763f46.js";import{C as A}from"./index-f9bc0cc5.js";import{C as s}from"./index-18ed1ff2.js";const P="_paydefine_gyhp9_1",C="_amount_gyhp9_16",t={paydefine:P,amount:C,"error-text":"_error-text_gyhp9_27","error-icon":"_error-icon_gyhp9_34"},E=g({name:"pay-define",setup(){const n=x(),e=h({browserStatus:!1,errorText:"",code:null,pay_channel:n.query.pay_channel,wxAppId:n.query.wxAppId,paymentType:n.query.paymentType,alipayAppId:n.query.alipayAppId,body:n.query.body,price:n.query.price,orderNo:n.query.orderNo,userId:n.query.userId,payInfo:{},isYeePay:!1}),u=async()=>{var a;try{if(parseFloat(e.price)<=0){b("支付金额异常");return}const o={merOrderNo:e.orderNo,paymentChannel:e.pay_channel,userId:e.userId,code:e.code},{data:p}=await q.post("/edu-app/open/userOrder/executePayment",{hideLoading:!1,data:{...o}});e.isYeePay=((a=p.paymentVender)==null?void 0:a.indexOf("yeepay"))!==-1,m(p.reqParams)}catch(o){console.log(o)}},m=a=>{if(e.pay_channel=="alipay_qr")if(e.isYeePay)_(a.prePayTn);else{const o=a.prod_mode==="false"?a.expend.qrcode_url+"?payment_id="+a.id+"&pay_channel="+a.pay_channel:a.expend.qrcode_url;window.location.href=o}else if(e.pay_channel=="wx_pub"){const o=e.isYeePay?JSON.parse(a.prePayTn):JSON.parse(a.expend.pay_info);e.payInfo=o,typeof window.WeixinJSBridge>"u"?document.addEventListener?document.addEventListener("WeixinJSBridgeReady",i,!1):document.attachEvent&&document.attachEvent("WeixinJSBridgeReady",i)(document).attachEvent("onWeixinJSBridgeReady",i):i()}},f=a=>{window.AlipayJSBridge?a&&a():document.addEventListener("AlipayJSBridgeReady",a,!1)},_=a=>{f(function(){window.AlipayJSBridge.call("tradePay",{tradeNO:a},function(o){o.resultCode=="9000",window.location.replace(location.origin+"/classroom-app/#/payment-result?orderNo="+e.orderNo),window.AlipayJSBridge.call("closeWebview")})})},i=()=>{const a=e.payInfo;window.WeixinJSBridge.invoke("getBrandWCPayRequest",{appId:a.appId,timeStamp:a.timeStamp,nonceStr:a.nonceStr,package:a.package,signType:a.signType,paySign:a.paySign},o=>{o.err_msg=="get_brand_wcpay_request:cancel"||o.err_msg=="get_brand_wcpay_request:fail",window.location.replace(location.origin+"/classroom-app/#/payment-result?orderNo="+e.orderNo)})},w=()=>{const a=e.pay_channel;if(e.paymentType.indexOf("yeepay"),c().weixin)if(a==="wx_pub"){const o=y();o?e.code=o:N(e.wxAppId),e.browserStatus=!0,document.title="微信支付"}else a=="alipay_qr"&&(e.errorText="请使用支付宝扫码");else if(c().alipay){if(a==="wx_pub")e.errorText="请使用微信扫码";else if(a=="alipay_qr"){const o=y("auth_code");o?e.code=o:T(e.alipayAppId),e.browserStatus=!0,document.title="支付宝支付"}}else e.errorText="请在微信或支付宝客户端打开";e.errorText&&(document.title="ERROR")};return S(()=>{console.log(e),w()}),()=>r("div",{class:t.paydefine},[e.browserStatus&&r("div",{class:t.container},[r("div",{class:t.amount},[r("span",null,[d("￥ ")]),l(e.price)]),r(A,{inset:!0},{default:()=>[r(s,{title:"订单信息",value:e.body,valueClass:t.values},null),r(s,{title:"支付方式",value:e.pay_channel==="wx_pub"?"微信":"支付宝"},null),r(s,{title:"实付金额",value:`￥ ${l(e.price)}元`},null)]}),r(v,{type:"primary",block:!0,size:"large",onClick:u,round:!0},{default:()=>[d("立即支付")]})]),!e.browserStatus&&r("div",{class:t.container},[r("div",{class:t["error-text"]},[e.errorText&&r(I,{class:t["error-icon"],name:"warning-o"},null),e.errorText])])])}});export{E as default};
