import{d as P,v as Q,r as _,a as E,G as W,g as r,J as X,z as b,k as i,w as l,b as F,K as Y,c as y,H as Z,e as n,t as d,l as B,C as ee,f as te,F as h,x as z,M as ae,E as u,D as le,_ as ne}from"./index-CUnFTKV2.js";import{_ as se}from"./AdvertTypeForm.vue_vue_type_script_setup_true_lang-CGXeAtbP.js";import{g as oe,e as ie,f as de,h as re}from"./advert-y3Emov1a.js";const ue={class:"type-dialog-content"},me={class:"action-bar"},ce={key:0,class:"add-form"},pe=P({__name:"AdvertTypeDialog",props:{modelValue:{type:Boolean}},emits:["update:modelValue","refresh"],setup($,{emit:K}){const A=$,g=K,x=Q({get:()=>A.modelValue,set:t=>g("update:modelValue",t)}),w=_(!1),k=_([]),f=_(!1),N=_();let s=E({name:"",sort:0});const m=_(null),o=E({name:"",sort:0}),C=async()=>{w.value=!0;try{const t=await oe();k.value=t.data}finally{w.value=!1}};W(()=>A.modelValue,t=>{t&&C()});const S=()=>{f.value=!0,s.name="",s.sort=0},U=async()=>{if(!s.name.trim()){u.warning("请输入类型名称");return}if(k.value.some(e=>e.name===s.name.trim())){u.warning("类型名称已存在");return}try{await ie({name:s.name.trim(),sort:s.sort}),u.success("添加成功"),f.value=!1,C(),g("refresh")}catch{}},I=()=>{f.value=!1},M=t=>{m.value=t.id,o.name=t.name,o.sort=t.sort},D=async t=>{if(!o.name.trim()){u.warning("请输入类型名称");return}if(k.value.some(V=>V.name===o.name.trim()&&V.id!==t.id)){u.warning("类型名称已存在");return}try{await de(t.id,{name:o.name.trim(),sort:o.sort}),u.success("更新成功"),m.value=null,C(),g("refresh")}catch{}},R=()=>{m.value=null},G=async t=>{if(t.advertCount>0){u.warning(`该类型下有 ${t.advertCount} 个广告，无法删除`);return}try{await le.confirm(`确定要删除类型 "${t.name}" 吗？`,"删除确认",{type:"warning"}),await re(t.id),u.success("删除成功"),C(),g("refresh")}catch{}},T=()=>{x.value=!1,f.value=!1,m.value=null};return(t,e)=>{const V=r("el-icon"),p=r("el-button"),v=r("el-table-column"),H=r("el-input"),J=r("el-input-number"),L=r("el-tag"),j=r("el-table"),q=r("el-dialog"),O=X("loading");return i(),b(q,{modelValue:x.value,"onUpdate:modelValue":e[3]||(e[3]=a=>x.value=a),title:"广告类型管理",width:"650px","close-on-click-modal":!1,onClose:T},{footer:l(()=>[n(p,{onClick:T},{default:l(()=>[...e[9]||(e[9]=[d("关闭",-1)])]),_:1})]),default:l(()=>[F("div",ue,[F("div",me,[n(p,{type:"primary",size:"small",onClick:S},{default:l(()=>[n(V,null,{default:l(()=>[n(B(ee))]),_:1}),e[4]||(e[4]=d("添加类型 ",-1))]),_:1})]),Y((i(),b(j,{data:k.value,border:"",stripe:"",size:"small"},{default:l(()=>[n(v,{prop:"id",label:"ID",width:"80",align:"center"}),n(v,{prop:"name",label:"类型名称","min-width":"150"},{default:l(({row:a})=>[m.value===a.id?(i(),b(H,{key:0,modelValue:o.name,"onUpdate:modelValue":e[0]||(e[0]=c=>o.name=c),size:"small",placeholder:"请输入类型名称",onKeyup:te(c=>D(a),["enter"])},null,8,["modelValue","onKeyup"])):(i(),y(h,{key:1},[d(z(a.name),1)],64))]),_:1}),n(v,{prop:"sort",label:"排序",width:"120",align:"center"},{default:l(({row:a})=>[m.value===a.id?(i(),b(J,{key:0,modelValue:o.sort,"onUpdate:modelValue":e[1]||(e[1]=c=>o.sort=c),size:"small",min:0,max:9999,"controls-position":"right"},null,8,["modelValue"])):(i(),y(h,{key:1},[d(z(a.sort),1)],64))]),_:1}),n(v,{prop:"advertCount",label:"广告数量",width:"100",align:"center"},{default:l(({row:a})=>[n(L,{size:"small",type:a.advertCount>0?"success":"info"},{default:l(()=>[d(z(a.advertCount),1)]),_:2},1032,["type"])]),_:1}),n(v,{label:"操作",width:"150",align:"center",fixed:"right"},{default:l(({row:a})=>[m.value===a.id?(i(),y(h,{key:0},[n(p,{type:"success",link:"",size:"small",onClick:c=>D(a)},{default:l(()=>[...e[5]||(e[5]=[d(" 保存 ",-1)])]),_:1},8,["onClick"]),n(p,{type:"info",link:"",size:"small",onClick:R},{default:l(()=>[...e[6]||(e[6]=[d(" 取消 ",-1)])]),_:1})],64)):(i(),y(h,{key:1},[n(p,{type:"primary",link:"",size:"small",onClick:c=>M(a)},{default:l(()=>[...e[7]||(e[7]=[d(" 编辑 ",-1)])]),_:1},8,["onClick"]),n(p,{type:"danger",link:"",size:"small",onClick:c=>G(a)},{default:l(()=>[...e[8]||(e[8]=[d(" 删除 ",-1)])]),_:1},8,["onClick"])],64))]),_:1})]),_:1},8,["data"])),[[O,w.value]]),f.value?(i(),y("div",ce,[n(se,{ref_key:"addFormRef",ref:N,modelValue:B(s),"onUpdate:modelValue":e[2]||(e[2]=a=>ae(s)?s.value=a:s=a),onSubmit:U,onCancel:I},null,8,["modelValue"])])):Z("",!0)])]),_:1},8,["modelValue"])}}}),ye=ne(pe,[["__scopeId","data-v-f8b0e1a3"]]);export{ye as default};
