import{d as h,ah as x,r as S,$ as v,c as r,q as p,bf as c,B as q,a5 as b,o as N,m as I,f as u,br as y,bs as T,bS as P}from"./index.27735e87.js";import{O as B}from"./index.61a124fa.js";import{C as A}from"./index.5a2d3ded.js";import{C as l}from"./index.997909e4.js";const C="_paydefine_gyhp9_1",J="_amount_gyhp9_16";var i={paydefine:C,amount:J,"error-text":"_error-text_gyhp9_27","error-icon":"_error-icon_gyhp9_34"},M=h({name:"pay-define",setup(){const t=x(),e=S({browserStatus:!1,errorText:"",code:null,pay_channel:t.query.pay_channel,wxAppId:t.query.wxAppId,paymentType:t.query.paymentType,alipayAppId:t.query.alipayAppId,body:t.query.body,price:t.query.price,orderNo:t.query.orderNo,userId:t.query.userId,payInfo:{},isYeePay:!1,dialogStatus:!1,dialogMessage:""}),f=async()=>{var a;try{if(parseFloat(e.price)<=0){N("\u652F\u4ED8\u91D1\u989D\u5F02\u5E38");return}const o={merOrderNo:e.orderNo,paymentChannel:e.pay_channel,userId:e.userId,code:e.code};console.log(o,"payMap");const n=await I.post("/api-student/open/userOrder/executePayment",{hideLoading:!1,data:{...o}});n.code===999?(e.dialogStatus=!0,e.dialogMessage=n.message):(e.isYeePay=((a=n.data.paymentVender)==null?void 0:a.indexOf("yeepay"))!==-1,console.log(n.data,"payment"),m(n.data.reqParams))}catch(o){console.log(o)}},m=a=>{if(e.pay_channel=="alipay_qr")if(e.isYeePay)w(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=="undefined"?document.addEventListener?document.addEventListener("WeixinJSBridgeReady",d,!1):document.attachEvent&&document.attachEvent("WeixinJSBridgeReady",d)(document).attachEvent("onWeixinJSBridgeReady",d):d()}},g=a=>{window.AlipayJSBridge?a&&a():document.addEventListener("AlipayJSBridgeReady",a,!1)},w=a=>{g(function(){window.AlipayJSBridge.call("tradePay",{tradeNO:a},function(o){o.resultCode=="9000",window.location.replace(location.origin+"/orchestra-student/#/payment-result?orderNo="+e.orderNo),window.AlipayJSBridge.call("closeWebview")})})},d=()=>{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+"/orchestra-student/#/payment-result?orderNo="+e.orderNo)})},_=()=>{var n;const a=((n=e.paymentType)==null?void 0:n.indexOf("yeepay"))!==-1;console.log(a,"isYeePay");const o=e.pay_channel;if(u().weixin)if(o==="wx_pub"){const s=y();s?e.code=s:T(e.wxAppId),e.browserStatus=!0,document.title="\u5FAE\u4FE1\u652F\u4ED8"}else o=="alipay_qr"&&(e.errorText="\u8BF7\u4F7F\u7528\u652F\u4ED8\u5B9D\u626B\u7801");else if(u().alipay){if(o==="wx_pub")e.errorText="\u8BF7\u4F7F\u7528\u5FAE\u4FE1\u626B\u7801";else if(o=="alipay_qr"){if(a){const s=y("auth_code")||t.query.auth_code;s?e.code=s:P(e.alipayAppId)}e.browserStatus=!0,document.title="\u652F\u4ED8\u5B9D\u652F\u4ED8"}}else e.errorText="\u8BF7\u5728\u5FAE\u4FE1\u6216\u652F\u4ED8\u5B9D\u5BA2\u6237\u7AEF\u6253\u5F00";e.errorText&&(document.title="ERROR")};return v(()=>{console.log(e),_()}),()=>r("div",{class:i.paydefine},[e.browserStatus&&r("div",{class:i.container},[r("div",{class:i.amount},[r("span",null,[p("\uFFE5 ")]),c(e.price)]),r(A,{inset:!0},{default:()=>[r(l,{title:"\u8BA2\u5355\u4FE1\u606F",value:e.body,valueClass:i.values},null),r(l,{title:"\u652F\u4ED8\u65B9\u5F0F",value:e.pay_channel==="wx_pub"?"\u5FAE\u4FE1":"\u652F\u4ED8\u5B9D"},null),r(l,{title:"\u5B9E\u4ED8\u91D1\u989D",value:`\uFFE5 ${c(e.price)}\u5143`},null)]}),r(q,{type:"primary",block:!0,size:"large",onClick:f,round:!0},{default:()=>[p("\u7ACB\u5373\u652F\u4ED8")]})]),!e.browserStatus&&r("div",{class:i.container},[r("div",{class:i["error-text"]},[e.errorText&&r(b,{class:i["error-icon"],name:"warning-o"},null),e.errorText])]),r(B,{title:"\u63D0\u793A",show:e.dialogStatus,"onUpdate:show":a=>e.dialogStatus=a,message:e.dialogMessage,confirmButtonText:"\u786E\u5B9A",onConfirm:()=>{window.location.replace(location.origin+"/orchestra-student/#/payment-result?orderNo="+e.orderNo)}},null)])}});export{M as default};
