import{d as W,r as c,v as $,o as j,g as m,J as q,c as h,k as u,K as I,z as w,w as r,H as J,e as l,t as p,l as d,C as H,F as K,y as L,Q as A,b as k,E as i,D as Q,_ as G}from"./index-CUnFTKV2.js";import{i as O,j as X,k as Y,g as Z}from"./config-J21_Zans.js";import ee from"./H5AppForm-BxMD2r1A.js";const ae={class:"page-container"},te={class:"card-header"},ne={class:"header-actions"},se={key:1,class:"h5app-list"},le={key:2,class:"footer-actions"},re=W({__name:"h5",setup(oe){const g=c(!1),f=c(!1),t=c([]),C=c([]),D=c([]),_=c([]),B=$(()=>t.value.map(n=>n.order_prefix||"")),y=()=>({name:"",appid:"",appsecret:"",domain:"",order_prefix:"",is_default:t.value.length===0?1:0,pay_type:"wechat",wx_merchants:[],ali_merchant_index:-1}),M=async()=>{var n,e;try{const a=await Y();(e=(n=a.data)==null?void 0:n.value)!=null&&e.merchants&&(C.value=a.data.value.merchants)}catch(a){console.error("加载微信支付商户列表失败:",a)}},S=async()=>{var n,e;try{const a=await Z();(e=(n=a.data)==null?void 0:n.value)!=null&&e.merchants&&(D.value=a.data.value.merchants)}catch(a){console.error("加载支付宝商户列表失败:",a)}},F=async()=>{g.value=!0;try{await Promise.all([P(),M(),S()])}finally{g.value=!1}},P=async()=>{var n,e;try{const a=await O();(e=(n=a.data)==null?void 0:n.value)!=null&&e.h5apps&&a.data.value.h5apps.length>0?t.value=a.data.value.h5apps.map(s=>({name:s.name||"",appid:s.appid||"",appsecret:s.appsecret||"",domain:s.domain||"",order_prefix:s.order_prefix||"",is_default:s.is_default??0,pay_type:s.pay_type||"wechat",wx_merchants:s.wx_merchants||[],ali_merchant_index:s.ali_merchant_index??-1})):t.value=[y()]}catch(a){i.error("加载配置失败"),console.error("加载配置失败:",a),t.value=[y()]}},x=()=>{t.value.push(y()),i.success("已添加新H5应用，请填写配置信息")},b=async n=>{if(t.value.length<=1){i.warning("至少保留一个H5应用配置");return}const e=t.value[n].is_default===1;try{await Q.confirm(`确定要删除H5应用"${t.value[n].name||"未命名"}"吗？${e?"（该应用为默认H5应用，删除后请设置新的默认应用）":""}`,"删除确认",{confirmButtonText:"确定",cancelButtonText:"取消",type:"warning"}),t.value.splice(n,1),e&&t.value.length>0&&(t.value[0].is_default=1,i.info("已将第一个H5应用设为默认")),i.success("已删除H5应用")}catch{}},E=()=>{},N=n=>{t.value.forEach((e,a)=>{a!==n&&(e.is_default=0)})},T=async()=>!_.value||_.value.length===0?!0:(await Promise.all(_.value.map(e=>{var a;return((a=e==null?void 0:e.validate)==null?void 0:a.call(e))??Promise.resolve(!0)}))).every(e=>e===!0),V=async()=>{if(!await T()){i.warning("请检查表单填写是否正确");return}if(t.value.length===0){i.warning("至少需要配置一个H5应用");return}if(!t.value.some(o=>o.is_default===1)){i.warning("必须设置一个默认H5应用");return}const a=t.value.map(o=>o.order_prefix).filter(o=>o),s=new Set(a);if(a.length!==s.size){i.warning("存在重复的订单前缀，请检查");return}f.value=!0;try{const o={h5apps:t.value};await X(o),i.success("保存成功")}catch(o){i.error("保存失败"),console.error("保存配置失败:",o)}finally{f.value=!1}};return j(()=>{F()}),(n,e)=>{const a=m("el-icon"),s=m("el-button"),o=m("el-empty"),z=m("el-card"),R=q("loading");return u(),h("div",ae,[I((u(),w(z,null,{header:r(()=>[k("div",te,[e[2]||(e[2]=k("span",null,"H5配置",-1)),k("div",ne,[l(s,{type:"primary",onClick:x},{default:r(()=>[l(a,null,{default:r(()=>[l(d(H))]),_:1}),e[0]||(e[0]=p("添加H5应用 ",-1))]),_:1}),l(s,{type:"success",loading:f.value,onClick:V},{default:r(()=>[l(a,null,{default:r(()=>[l(d(A))]),_:1}),e[1]||(e[1]=p("保存配置 ",-1))]),_:1},8,["loading"])])])]),default:r(()=>[t.value.length===0?(u(),w(o,{key:0,description:"暂无H5应用配置，请点击添加H5应用"},{default:r(()=>[l(s,{type:"primary",onClick:x},{default:r(()=>[l(a,null,{default:r(()=>[l(d(H))]),_:1}),e[3]||(e[3]=p("添加H5应用 ",-1))]),_:1})]),_:1})):(u(),h("div",se,[(u(!0),h(K,null,L(t.value,(ie,v)=>(u(),w(ee,{key:v,ref_for:!0,ref_key:"h5appFormRefs",ref:_,modelValue:t.value[v],"onUpdate:modelValue":U=>t.value[v]=U,index:v,"can-delete":t.value.length>1,"existing-prefixes":B.value,"weixin-merchants":C.value,"alipay-merchants":D.value,onDelete:b,onChange:E,onDefaultChange:N},null,8,["modelValue","onUpdate:modelValue","index","can-delete","existing-prefixes","weixin-merchants","alipay-merchants"]))),128))])),t.value.length>0?(u(),h("div",le,[l(s,{type:"primary",onClick:x},{default:r(()=>[l(a,null,{default:r(()=>[l(d(H))]),_:1}),e[4]||(e[4]=p("添加H5应用 ",-1))]),_:1}),l(s,{type:"success",loading:f.value,onClick:V},{default:r(()=>[l(a,null,{default:r(()=>[l(d(A))]),_:1}),e[5]||(e[5]=p("保存配置 ",-1))]),_:1},8,["loading"])])):J("",!0)]),_:1})),[[R,g.value]])])}}}),de=G(re,[["__scopeId","data-v-3ab4e39e"]]);export{de as default};
