import{C as x,a as C,b as z,c as G,u as M,e as S}from"./coupon-C54tWHNa.js";import{d as A,v as H,r as D,a as I,G as J,g as u,z as b,k as m,w as o,e as i,c as k,F as U,y as E,l as F,t as d,E as q}from"./index-CUnFTKV2.js";const W=A({__name:"CouponFormDialog",props:{modelValue:{type:Boolean},coupon:{},isEdit:{type:Boolean}},emits:["update:modelValue","success"],setup(V,{emit:N}){const a=V,v=N,c=H({get:()=>a.modelValue,set:s=>v("update:modelValue",s)}),p=D(),f=D(!1),t=I({title:"",minPrice:0,discountPrice:0,validDays:7,type:C.FullReduction,useLimit:x.NoLimit}),B={title:[{required:!0,message:"请输入优惠券名称",trigger:"blur"},{min:1,max:50,message:"名称长度在1-50个字符",trigger:"blur"}],type:[{required:!0,message:"请选择优惠券类型",trigger:"change"}],useLimit:[{required:!0,message:"请选择使用限制",trigger:"change"}],minPrice:[{required:!0,message:"请输入满减门槛",trigger:"blur"},{type:"number",min:0,message:"满减门槛不能为负数",trigger:"blur"}],discountPrice:[{required:!0,message:"请输入优惠金额",trigger:"blur"},{type:"number",min:.01,message:"优惠金额必须大于0",trigger:"blur"}],validDays:[{required:!0,message:"请输入有效期",trigger:"blur"},{type:"number",min:1,max:365,message:"有效期在1-365天之间",trigger:"blur"}]};J(()=>a.modelValue,s=>{s&&(a.isEdit&&a.coupon?Object.assign(t,{title:a.coupon.title,minPrice:a.coupon.minPrice,discountPrice:a.coupon.discountPrice,validDays:a.coupon.validDays,type:a.coupon.type,useLimit:a.coupon.useLimit}):_())});const _=()=>{var s;Object.assign(t,{title:"",minPrice:0,discountPrice:0,validDays:7,type:C.FullReduction,useLimit:x.NoLimit}),(s=p.value)==null||s.resetFields()},g=()=>{c.value=!1,_()},R=async()=>{if(p.value){try{await p.value.validate()}catch{return}f.value=!0;try{const s={title:t.title,minPrice:t.minPrice,discountPrice:t.discountPrice,validDays:t.validDays,type:t.type,useLimit:t.useLimit};a.isEdit&&a.coupon?(await M(a.coupon.id,s),q.success("更新成功")):(await S(s),q.success("创建成功")),v("success"),g()}finally{f.value=!1}}};return(s,e)=>{const P=u("el-option"),L=u("el-select"),n=u("el-form-item"),T=u("el-input"),y=u("el-input-number"),j=u("el-form"),w=u("el-button"),O=u("el-dialog");return m(),b(O,{modelValue:c.value,"onUpdate:modelValue":e[6]||(e[6]=l=>c.value=l),title:V.isEdit?"编辑优惠券":"新增优惠券",width:"550px","close-on-click-modal":!1,onClose:g},{footer:o(()=>[i(w,{onClick:g},{default:o(()=>[...e[10]||(e[10]=[d("取消",-1)])]),_:1}),i(w,{type:"primary",loading:f.value,onClick:R},{default:o(()=>[...e[11]||(e[11]=[d(" 确定 ",-1)])]),_:1},8,["loading"])]),default:o(()=>[i(j,{ref_key:"formRef",ref:p,model:t,rules:B,"label-width":"100px"},{default:o(()=>[i(n,{label:"优惠券类型",prop:"type"},{default:o(()=>[i(L,{modelValue:t.type,"onUpdate:modelValue":e[0]||(e[0]=l=>t.type=l),placeholder:"请选择类型",style:{width:"100%"}},{default:o(()=>[(m(!0),k(U,null,E(F(z),(l,r)=>(m(),b(P,{key:r,label:l,value:Number(r)},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),i(n,{label:"使用限制",prop:"useLimit"},{default:o(()=>[i(L,{modelValue:t.useLimit,"onUpdate:modelValue":e[1]||(e[1]=l=>t.useLimit=l),placeholder:"请选择使用限制",style:{width:"100%"}},{default:o(()=>[(m(!0),k(U,null,E(F(G),(l,r)=>(m(),b(P,{key:r,label:l,value:Number(r)},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),i(n,{label:"优惠券名称",prop:"title"},{default:o(()=>[i(T,{modelValue:t.title,"onUpdate:modelValue":e[2]||(e[2]=l=>t.title=l),placeholder:"请输入优惠券名称",maxlength:"50","show-word-limit":""},null,8,["modelValue"])]),_:1}),i(n,{label:"满减门槛",prop:"minPrice"},{default:o(()=>[i(y,{modelValue:t.minPrice,"onUpdate:modelValue":e[3]||(e[3]=l=>t.minPrice=l),min:0,max:999999,precision:2,placeholder:"请输入满减门槛",style:{width:"100%"}},{suffix:o(()=>[...e[7]||(e[7]=[d("元",-1)])]),_:1},8,["modelValue"])]),_:1}),i(n,{label:"优惠金额",prop:"discountPrice"},{default:o(()=>[i(y,{modelValue:t.discountPrice,"onUpdate:modelValue":e[4]||(e[4]=l=>t.discountPrice=l),min:.01,max:999999,precision:2,placeholder:"请输入优惠金额",style:{width:"100%"}},{suffix:o(()=>[...e[8]||(e[8]=[d("元",-1)])]),_:1},8,["modelValue"])]),_:1}),i(n,{label:"有效期",prop:"validDays"},{default:o(()=>[i(y,{modelValue:t.validDays,"onUpdate:modelValue":e[5]||(e[5]=l=>t.validDays=l),min:1,max:365,placeholder:"请输入有效期天数",style:{width:"100%"}},{suffix:o(()=>[...e[9]||(e[9]=[d("天",-1)])]),_:1},8,["modelValue"])]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue","title"])}}});export{W as _};
