import{d as _,U as m,x as f,y as g,a as n,A as l,P as p,C as x,I as w,E as h,D as b,R as c,bo as v,bp as S}from"./index-971588a5.js";import{C as q}from"./index-d00f4365.js";import{C as i}from"./index-a1fa647c.js";const I="_paydefine_gyhp9_1",C="_amount_gyhp9_16",r={paydefine:I,amount:C,"error-text":"_error-text_gyhp9_27","error-icon":"_error-icon_gyhp9_34"},B=_({name:"pay-define",setup(){const t=m(),e=f({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:{}}),d=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:o}=await b.post("/edu-app/open/userOrder/executePayment",{hideLoading:!1,data:{...a}});console.log(o,"payment"),u(o.reqParams)}catch(a){console.log(a)}},u=a=>{if(e.pay_channel=="alipay_qr"){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=JSON.parse(a.expend.pay_info);e.payInfo=o,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},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)})},y=()=>{const a=e.pay_channel;if(c().weixin)if(a==="wx_pub"){const o=v();console.log(o),o?e.code=o:S(e.wxAppId),e.browserStatus=!0,document.title="微信支付"}else a=="alipay_qr"&&(e.errorText="请使用支付宝扫码");else c().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()}),()=>n("div",{class:r.paydefine},[e.browserStatus&&n("div",{class:r.container},[n("div",{class:r.amount},[n("span",null,[l("￥ ")]),p(e.price)]),n(q,{inset:!0},{default:()=>[n(i,{title:"订单信息",value:e.body,valueClass:r.values},null),n(i,{title:"支付方式",value:e.pay_channel==="wx_pub"?"微信":"支付宝"},null),n(i,{title:"实付金额",value:`￥ ${p(e.price)}元`},null)]}),n(x,{type:"primary",block:!0,size:"large",onClick:d,round:!0},{default:()=>[l("立即支付")]})]),!e.browserStatus&&n("div",{class:r.container},[n("div",{class:r["error-text"]},[e.errorText&&n(w,{class:r["error-icon"],name:"warning-o"},null),e.errorText])])])}});export{B as default};
