import{d as _,u as f,$ as m,E as g,g as r,h as c,ap as l,B as x,I as w,f as h,a as b,p as u,bm as v,bn as S}from"./index-bc617d61.js";import{C as q}from"./index-344192ea.js";import{C as i}from"./index-917ed250.js";const I="_paydefine_gyhp9_1",B="_amount_gyhp9_16",o={paydefine:I,amount:B,"error-text":"_error-text_gyhp9_27","error-icon":"_error-icon_gyhp9_34"},T=_({name:"pay-define",setup(){const t=f(),e=m({browserStatus:!1,errorText:"",code:null,pay_channel:t.query.pay_channel,wxAppId:t.query.wxAppId,body:t.query.body,price:t.query.price,orderNo:t.query.orderNo,userId:t.query.userId,payInfo:{}}),p=async()=>{try{if(parseFloat(e.price)<=0){h("支付金额异常");return}const a={merOrderNo:e.orderNo,paymentChannel:e.pay_channel,userId:e.userId};e.pay_channel=="wx_pub"&&(a.code=e.code),console.log(a,"payMap");const{data:n}=await b.post("/edu-app/open/userOrder/executePayment",{hideLoading:!1,data:{...a}});console.log(n,"payment"),d(n.reqParams)}catch(a){console.log(a)}},d=a=>{if(e.pay_channel=="alipay_qr"){const n=a.prod_mode==="false"?a.expend.qrcode_url+"?payment_id="+a.id+"&pay_channel="+a.pay_channel:a.expend.qrcode_url;window.location.href=n}else if(e.pay_channel=="wx_pub"){const n=JSON.parse(a.expend.pay_info);e.payInfo=n,typeof window.WeixinJSBridge>"u"?document.addEventListener?document.addEventListener("WeixinJSBridgeReady",s,!1):document.attachEvent&&document.attachEvent("WeixinJSBridgeReady",s)(document).attachEvent("onWeixinJSBridgeReady",s):s()}},s=()=>{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},n=>{n.err_msg=="get_brand_wcpay_request:cancel"||n.err_msg=="get_brand_wcpay_request:fail",window.location.replace(location.origin+"/orchestra-student/#/payment-result?orderNo="+e.orderNo)})},y=()=>{const a=e.pay_channel;if(u().weixin)if(a==="wx_pub"){const n=v();console.log(n),n?e.code=n:S(e.wxAppId),e.browserStatus=!0,document.title="微信支付"}else a=="alipay_qr"&&(e.errorText="请使用支付宝扫码");else u().alipay?a==="wx_pub"?e.errorText="请使用微信扫码":a=="alipay_qr"&&(e.browserStatus=!0,document.title="支付宝支付"):e.errorText="请在微信或支付宝客户端打开";e.errorText&&(document.title="ERROR")};return g(()=>{console.log(e),y()}),()=>r("div",{class:o.paydefine},[e.browserStatus&&r("div",{class:o.container},[r("div",{class:o.amount},[r("span",null,[c("￥ ")]),l(e.price)]),r(q,{inset:!0},{default:()=>[r(i,{title:"订单信息",value:e.body,valueClass:o.values},null),r(i,{title:"支付方式",value:e.pay_channel==="wx_pub"?"微信":"支付宝"},null),r(i,{title:"实付金额",value:`￥ ${l(e.price)}元`},null)]}),r(x,{type:"primary",block:!0,size:"large",onClick:p,round:!0},{default:()=>[c("立即支付")]})]),!e.browserStatus&&r("div",{class:o.container},[r("div",{class:o["error-text"]},[e.errorText&&r(w,{class:o["error-icon"],name:"warning-o"},null),e.errorText])])])}});export{T as default};
