import{d as M,v as V,r as w,a as O,G as h,g as s,z as p,k as n,w as u,e as r,H as b,c as x,F as D,y as B,l as U,I as W,b as X,t as F,E as q,_ as Y}from"./index-CUnFTKV2.js";import{A as t,b as z,u as G,c as H}from"./advert-y3Emov1a.js";const K=M({__name:"AdvertFormDialog",props:{modelValue:{type:Boolean},advert:{},isEdit:{type:Boolean},types:{}},emits:["update:modelValue","success"],setup(g,{emit:A}){const a=g,_=A,c=V({get:()=>a.modelValue,set:d=>_("update:modelValue",d)}),m=w(),y=w(!1),e=O({typeId:void 0,imageUrl:"",sort:0,jumpType:t.None,couponId:void 0,goodsId:void 0,urlLink:""}),v=V(()=>[t.YiFanShang,t.WuXianShang,t.LianJiShang].includes(e.jumpType)),E=V(()=>({typeId:[{required:!0,message:"请选择广告类型",trigger:"change"}],jumpType:[{required:!0,message:"请选择跳转类型",trigger:"change"}],imageUrl:[{required:!0,message:"请输入广告图片URL",trigger:"blur"}],sort:[{required:!0,message:"请输入排序值",trigger:"blur"}],couponId:e.jumpType===t.Coupon?[{required:!0,message:"请输入优惠券ID",trigger:"blur"}]:[],goodsId:v.value?[{required:!0,message:"请输入盒子ID",trigger:"blur"}]:[],urlLink:e.jumpType===t.CustomUrl?[{required:!0,message:"请输入跳转链接",trigger:"blur"}]:[]}));h(()=>a.modelValue,d=>{d&&(a.isEdit&&a.advert?Object.assign(e,{typeId:a.advert.typeId,imageUrl:a.advert.imageUrl,sort:a.advert.sort,jumpType:a.advert.jumpType,couponId:a.advert.couponId,goodsId:a.advert.goodsId,urlLink:a.advert.urlLink||""}):k())}),h(()=>e.jumpType,d=>{d!==t.Coupon&&(e.couponId=void 0),[t.YiFanShang,t.WuXianShang,t.LianJiShang].includes(d)||(e.goodsId=void 0),d!==t.CustomUrl&&(e.urlLink="")});const k=()=>{var d;Object.assign(e,{typeId:void 0,imageUrl:"",sort:0,jumpType:t.None,couponId:void 0,goodsId:void 0,urlLink:""}),(d=m.value)==null||d.resetFields()},f=()=>{c.value=!1,k()},N=async()=>{if(m.value){try{await m.value.validate()}catch{return}y.value=!0;try{const d={typeId:e.typeId,imageUrl:e.imageUrl,sort:e.sort,jumpType:e.jumpType,couponId:e.jumpType===t.Coupon?e.couponId:void 0,goodsId:v.value?e.goodsId:void 0,urlLink:e.jumpType===t.CustomUrl?e.urlLink:void 0};a.isEdit&&a.advert?(await G(a.advert.id,d),q.success("更新成功")):(await H(d),q.success("创建成功")),_("success"),f()}finally{y.value=!1}}};return(d,l)=>{const j=s("el-option"),T=s("el-select"),i=s("el-form-item"),I=s("el-input-number"),S=s("el-input"),J=s("el-form"),L=s("el-button"),R=s("el-dialog");return n(),p(R,{modelValue:c.value,"onUpdate:modelValue":l[7]||(l[7]=o=>c.value=o),title:g.isEdit?"编辑广告":"新增广告",width:"550px","close-on-click-modal":!1,onClose:f},{footer:u(()=>[r(L,{onClick:f},{default:u(()=>[...l[9]||(l[9]=[F("取消",-1)])]),_:1}),r(L,{type:"primary",loading:y.value,onClick:N},{default:u(()=>[...l[10]||(l[10]=[F(" 确定 ",-1)])]),_:1},8,["loading"])]),default:u(()=>[r(J,{ref_key:"formRef",ref:m,model:e,rules:E.value,"label-width":"100px"},{default:u(()=>[r(i,{label:"广告类型",prop:"typeId"},{default:u(()=>[r(T,{modelValue:e.typeId,"onUpdate:modelValue":l[0]||(l[0]=o=>e.typeId=o),placeholder:"请选择广告类型",style:{width:"100%"}},{default:u(()=>[(n(!0),x(D,null,B(g.types,o=>(n(),p(j,{key:o.id,label:o.name,value:o.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),r(i,{label:"跳转类型",prop:"jumpType"},{default:u(()=>[r(T,{modelValue:e.jumpType,"onUpdate:modelValue":l[1]||(l[1]=o=>e.jumpType=o),placeholder:"请选择跳转类型",style:{width:"100%"}},{default:u(()=>[(n(!0),x(D,null,B(U(z),(o,C)=>(n(),p(j,{key:C,label:o,value:Number(C)},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),e.jumpType===U(t).Coupon?(n(),p(i,{key:0,label:"优惠券ID",prop:"couponId"},{default:u(()=>[r(I,{modelValue:e.couponId,"onUpdate:modelValue":l[2]||(l[2]=o=>e.couponId=o),min:1,placeholder:"请输入优惠券ID",style:{width:"100%"},"controls-position":"right"},null,8,["modelValue"])]),_:1})):b("",!0),v.value?(n(),p(i,{key:1,label:"盒子ID",prop:"goodsId"},{default:u(()=>[r(I,{modelValue:e.goodsId,"onUpdate:modelValue":l[3]||(l[3]=o=>e.goodsId=o),min:1,placeholder:"请输入盒子ID",style:{width:"100%"},"controls-position":"right"},null,8,["modelValue"])]),_:1})):b("",!0),e.jumpType===U(t).CustomUrl?(n(),p(i,{key:2,label:"跳转链接",prop:"urlLink"},{default:u(()=>[r(S,{modelValue:e.urlLink,"onUpdate:modelValue":l[4]||(l[4]=o=>e.urlLink=o),placeholder:"请输入跳转链接",maxlength:"500"},null,8,["modelValue"])]),_:1})):b("",!0),r(i,{label:"广告图片",prop:"imageUrl"},{default:u(()=>[r(W,{modelValue:e.imageUrl,"onUpdate:modelValue":l[5]||(l[5]=o=>e.imageUrl=o),placeholder:"点击上传广告图片","url-placeholder":"或输入图片URL",tip:"支持 jpg、png、gif、webp 格式，最大 10MB"},null,8,["modelValue"])]),_:1}),r(i,{label:"排序值",prop:"sort"},{default:u(()=>[r(I,{modelValue:e.sort,"onUpdate:modelValue":l[6]||(l[6]=o=>e.sort=o),min:0,max:9999,placeholder:"请输入排序值",style:{width:"100%"},"controls-position":"right"},null,8,["modelValue"]),l[8]||(l[8]=X("div",{class:"form-tip"},"数值越小排序越靠前",-1))]),_:1})]),_:1},8,["model","rules"])]),_:1},8,["modelValue","title"])}}}),Z=Y(K,[["__scopeId","data-v-0d577a1c"]]);export{Z as default};
