import{d as I,r as _,o as N,g as m,J as S,c as y,k as u,K as T,z as k,w as s,H as P,e as t,t as c,l as i,C as w,F as R,y as U,Q as V,b as C,E as o,D as z,_ as H}from"./index-CUnFTKV2.js";import{g as J,u as L}from"./config-J21_Zans.js";import Q from"./AlipayMerchantForm-DgXwaba8.js";const $={class:"page-container"},j={class:"card-header"},q={class:"header-actions"},G={key:1,class:"merchant-list"},O={key:2,class:"footer-actions"},W=I({__name:"alipay",setup(X){const f=_(!1),d=_(!1),a=_([]),p=_([]),h=()=>({name:"",appId:"",privateKey:"",publicKey:"",weight:1,is_enabled:1,remark:""}),D=async()=>{var r,e;f.value=!0;try{const l=await J();(e=(r=l.data)==null?void 0:r.value)!=null&&e.merchants&&l.data.value.merchants.length>0?a.value=l.data.value.merchants.map(n=>({name:n.name||"",appId:n.appId||"",privateKey:n.privateKey||"",publicKey:n.publicKey||"",weight:n.weight??1,is_enabled:n.is_enabled??1,remark:n.remark||""})):a.value=[h()]}catch(l){o.error("加载配置失败"),console.error("加载配置失败:",l),a.value=[h()]}finally{f.value=!1}},g=()=>{a.value.push(h()),o.success("已添加新商户，请填写配置信息")},M=async r=>{if(a.value.length<=1){o.warning("至少保留一个商户配置");return}try{await z.confirm(`确定要删除商户"${a.value[r].name||"未命名"}"吗？`,"删除确认",{confirmButtonText:"确定",cancelButtonText:"取消",type:"warning"}),a.value.splice(r,1),o.success("已删除商户")}catch{}},B=()=>{},K=async()=>!p.value||p.value.length===0?!0:(await Promise.all(p.value.map(e=>{var l;return((l=e==null?void 0:e.validate)==null?void 0:l.call(e))??Promise.resolve(!0)}))).every(e=>e===!0),b=async()=>{if(!await K()){o.warning("请检查表单填写是否正确");return}if(a.value.length===0){o.warning("至少需要配置一个商户");return}d.value=!0;try{const e={merchants:a.value};await L(e),o.success("保存成功")}catch(e){o.error("保存失败"),console.error("保存配置失败:",e)}finally{d.value=!1}};return N(()=>{D()}),(r,e)=>{const l=m("el-icon"),n=m("el-button"),F=m("el-empty"),x=m("el-card"),A=S("loading");return u(),y("div",$,[T((u(),k(x,null,{header:s(()=>[C("div",j,[e[2]||(e[2]=C("span",null,"支付宝支付配置",-1)),C("div",q,[t(n,{type:"primary",onClick:g},{default:s(()=>[t(l,null,{default:s(()=>[t(i(w))]),_:1}),e[0]||(e[0]=c("添加商户 ",-1))]),_:1}),t(n,{type:"success",loading:d.value,onClick:b},{default:s(()=>[t(l,null,{default:s(()=>[t(i(V))]),_:1}),e[1]||(e[1]=c("保存配置 ",-1))]),_:1},8,["loading"])])])]),default:s(()=>[a.value.length===0?(u(),k(F,{key:0,description:"暂无商户配置，请点击添加商户"},{default:s(()=>[t(n,{type:"primary",onClick:g},{default:s(()=>[t(l,null,{default:s(()=>[t(i(w))]),_:1}),e[3]||(e[3]=c("添加商户 ",-1))]),_:1})]),_:1})):(u(),y("div",G,[(u(!0),y(R,null,U(a.value,(Y,v)=>(u(),k(Q,{key:v,ref_for:!0,ref_key:"merchantFormRefs",ref:p,modelValue:a.value[v],"onUpdate:modelValue":E=>a.value[v]=E,index:v,"can-delete":a.value.length>1,onDelete:M,onChange:B},null,8,["modelValue","onUpdate:modelValue","index","can-delete"]))),128))])),a.value.length>0?(u(),y("div",O,[t(n,{type:"primary",onClick:g},{default:s(()=>[t(l,null,{default:s(()=>[t(i(w))]),_:1}),e[4]||(e[4]=c("添加商户 ",-1))]),_:1}),t(n,{type:"success",loading:d.value,onClick:b},{default:s(()=>[t(l,null,{default:s(()=>[t(i(V))]),_:1}),e[5]||(e[5]=c("保存配置 ",-1))]),_:1},8,["loading"])])):P("",!0)]),_:1})),[[A,f.value]])])}}}),te=H(W,[["__scopeId","data-v-0a76b1a9"]]);export{te as default};
