import{d as W,r as v,v as z,o as A,g as y,J as R,c as f,k as o,K as U,z as k,w as r,H as $,e as l,t as c,l as u,C as w,F as q,y as H,Q as C,b as x,E as i,D as I,_ as J}from"./index-CUnFTKV2.js";import{k as K,P as V,y as L}from"./config-J21_Zans.js";import Q from"./WeixinMerchantForm-CH9dTUsE.js";const j={class:"page-container"},G={class:"card-header"},O={class:"header-actions"},X={key:1,class:"merchant-list"},Y={key:2,class:"footer-actions"},Z=W({__name:"weixinpay",setup(ee){const h=v(!1),_=v(!1),t=v([]),d=v([]),D=z(()=>t.value.map(s=>s.order_prefix||"")),m=()=>({name:"",mch_id:"",order_prefix:"",api_key:"",cert_path:"",is_enabled:"1",notify_url:"",pay_version:V.V2,api_v3_key:"",cert_serial_no:"",private_key_path:"",wechat_public_key_id:"",wechat_public_key_path:""}),M=async()=>{var s,a;h.value=!0;try{const n=await K();(a=(s=n.data)==null?void 0:s.value)!=null&&a.merchants&&n.data.value.merchants.length>0?t.value=n.data.value.merchants.map(e=>({name:e.name||"",mch_id:e.mch_id||"",order_prefix:e.order_prefix||"",api_key:e.api_key||"",cert_path:e.cert_path||"",is_enabled:e.is_enabled||"1",notify_url:e.notify_url||"",pay_version:e.pay_version||V.V2,api_v3_key:e.api_v3_key||"",cert_serial_no:e.cert_serial_no||"",private_key_path:e.private_key_path||"",wechat_public_key_id:e.wechat_public_key_id||"",wechat_public_key_path:e.wechat_public_key_path||""})):t.value=[m()]}catch(n){i.error("加载配置失败"),console.error("加载配置失败:",n),t.value=[m()]}finally{h.value=!1}},g=()=>{t.value.push(m()),i.success("已添加新商户，请填写配置信息")},P=async s=>{if(t.value.length<=1){i.warning("至少保留一个商户配置");return}try{await I.confirm(`确定要删除商户"${t.value[s].name||"未命名"}"吗？`,"删除确认",{confirmButtonText:"确定",cancelButtonText:"取消",type:"warning"}),t.value.splice(s,1),i.success("已删除商户")}catch{}},B=()=>{},F=async()=>!d.value||d.value.length===0?!0:(await Promise.all(d.value.map(a=>{var n;return((n=a==null?void 0:a.validate)==null?void 0:n.call(a))??Promise.resolve(!0)}))).every(a=>a===!0),b=async()=>{if(!await F()){i.warning("请检查表单填写是否正确");return}if(t.value.length===0){i.warning("至少需要配置一个商户");return}const a=t.value.map(e=>e.order_prefix),n=new Set(a);if(a.length!==n.size){i.warning("存在重复的订单前缀，请检查");return}for(const e of t.value)if(e.pay_version===V.V3&&(!e.api_v3_key||!e.cert_serial_no||!e.private_key_path)){i.warning(`商户"${e.name}"使用V3版本，请填写完整的V3配置`);return}_.value=!0;try{const e={merchants:t.value};await L(e),i.success("保存成功")}catch(e){i.error("保存失败"),console.error("保存配置失败:",e)}finally{_.value=!1}};return A(()=>{M()}),(s,a)=>{const n=y("el-icon"),e=y("el-button"),E=y("el-empty"),N=y("el-card"),S=R("loading");return o(),f("div",j,[U((o(),k(N,null,{header:r(()=>[x("div",G,[a[2]||(a[2]=x("span",null,"微信支付配置",-1)),x("div",O,[l(e,{type:"primary",onClick:g},{default:r(()=>[l(n,null,{default:r(()=>[l(u(w))]),_:1}),a[0]||(a[0]=c("添加商户 ",-1))]),_:1}),l(e,{type:"success",loading:_.value,onClick:b},{default:r(()=>[l(n,null,{default:r(()=>[l(u(C))]),_:1}),a[1]||(a[1]=c("保存配置 ",-1))]),_:1},8,["loading"])])])]),default:r(()=>[t.value.length===0?(o(),k(E,{key:0,description:"暂无商户配置，请点击添加商户"},{default:r(()=>[l(e,{type:"primary",onClick:g},{default:r(()=>[l(n,null,{default:r(()=>[l(u(w))]),_:1}),a[3]||(a[3]=c("添加商户 ",-1))]),_:1})]),_:1})):(o(),f("div",X,[(o(!0),f(q,null,H(t.value,(ae,p)=>(o(),k(Q,{key:p,ref_for:!0,ref_key:"merchantFormRefs",ref:d,modelValue:t.value[p],"onUpdate:modelValue":T=>t.value[p]=T,index:p,"can-delete":t.value.length>1,"existing-prefixes":D.value,onDelete:P,onChange:B},null,8,["modelValue","onUpdate:modelValue","index","can-delete","existing-prefixes"]))),128))])),t.value.length>0?(o(),f("div",Y,[l(e,{type:"primary",onClick:g},{default:r(()=>[l(n,null,{default:r(()=>[l(u(w))]),_:1}),a[4]||(a[4]=c("添加商户 ",-1))]),_:1}),l(e,{type:"success",loading:_.value,onClick:b},{default:r(()=>[l(n,null,{default:r(()=>[l(u(C))]),_:1}),a[5]||(a[5]=c("保存配置 ",-1))]),_:1},8,["loading"])])):$("",!0)]),_:1})),[[S,h.value]])])}}}),re=J(Z,[["__scopeId","data-v-502a2ccf"]]);export{re as default};
