import{_ as e,aI as a,r as n,aC as t,az as o,aa as i,G as s,b as r,d as l,p as d,w as c,H as p,i as u,o as f,f as h,k as g,C as m,Y as w}from"./index-2PZN6pGH.js";const y=e({data:()=>({title:"request-payment",loading:!1,price:1,providerList:[]}),onLoad:function(){},methods:{loginMpWeixin:()=>new Promise(((e,o)=>{a({provider:"weixin",success(a){console.warn("此处使用uni-id处理微信小程序登录,详情参考: https://uniapp.dcloud.net.cn/uniCloud/uni-id"),n({url:"https://97fca9f2-41f6-449f-a35e-3f135d4c3875.bspapp.com/http/user-center",method:"POST",data:{action:"loginByWeixin",params:{code:a.code,platform:"mp-weixin"}},success(a){0===a.data.code?(t("openid",a.data.openid),e(a.data.openid)):o(new Error("获取openid失败:",a.result.msg))},fail(e){o(new Error("获取openid失败:"+e))}})},fail(e){o(e)}})})),async weixinPay(){let e=o("openid");if(console.log("发起支付"),this.loading=!0,!e){try{e=await this.loginMpWeixin()}catch(n){console.error(n)}if(!e)return i({content:"获取openid失败",showCancel:!1}),void(this.loading=!1)}this.openid=e;let a=await this.getOrderInfo("wxpay");a?uni.requestPayment({...a,success:e=>{s({title:"感谢您的赞助!"})},fail:e=>{i({content:"支付失败,原因为: "+e.errMsg,showCancel:!1})},complete:()=>{this.loading=!1}}):i({content:"获取支付信息失败",showCancel:!1})},async requestPayment(e,a){this.providerList[a].loading=!0;const n=e.id;let t=await this.getOrderInfo(n);t?(console.log("--------orderInfo--------"),console.log(t),uni.requestPayment({provider:n,orderInfo:t,success:e=>{console.log("success",e),s({title:"感谢您的赞助!"})},fail:e=>{console.log("fail",e),i({content:"支付失败,原因为: "+e.errMsg,showCancel:!1})},complete:()=>{this.providerList[a].loading=!1}})):i({content:"获取支付信息失败",showCancel:!1})},getOrderInfo(e){return new Promise(((a,t)=>{this.price||t(new Error("请输入金额")),console.warn("此处使用uni-pay处理支付,详情参考: https://uniapp.dcloud.io/uniCloud/unipay"),n({method:"POST",url:"https://97fca9f2-41f6-449f-a35e-3f135d4c3875.bspapp.com/http/pay",data:{provider:e,openid:this.openid,totalFee:100*Number(this.price)},success(e){0===e.data.code?a(e.data.orderInfo):t(new Error("获取支付信息失败"+e.data.msg))},fail(e){t(new Error("请求支付接口失败"+e))}})}))},priceChange(e){console.log(e.detail.value),this.price=e.detail.value}}},[["render",function(e,a,n,t,o,i){const s=r(l("page-head"),p),y=m,v=u,x=w;return f(),d(v,null,{default:c((()=>[h(s,{title:o.title},null,8,["title"]),h(v,{class:"uni-padding-wrap"},{default:c((()=>[h(v,{style:{background:"#FFF",padding:"50rpx 0"}},{default:c((()=>[h(v,{class:"uni-hello-text uni-center"},{default:c((()=>[h(y,null,{default:c((()=>[g("支付金额")])),_:1})])),_:1}),h(v,{class:"uni-h1 uni-center uni-common-mt"},{default:c((()=>[h(y,{class:"rmbLogo"},{default:c((()=>[g("¥")])),_:1}),h(x,{class:"price",type:"digit",value:o.price,maxlength:"4",onInput:i.priceChange},null,8,["value","onInput"])])),_:1})])),_:1}),h(v,{class:"uni-btn-v uni-common-mt"})])),_:1})])),_:1})}],["__scopeId","data-v-97e3fe02"]]);export{y as default};