import{R as d,a as H,u as M,c as A}from"./reward-Baf2bADU.js";import{g as I}from"./coupon-C54tWHNa.js";import{d as J,v as h,r as w,a as K,G as B,g as s,z as u,k as i,w as o,e as n,H as F,c as L,F as U,y as N,l as _,t as q,E as c}from"./index-CUnFTKV2.js";const Y=J({__name:"RewardFormDialog",props:{modelValue:{type:Boolean},reward:{},isEdit:{type:Boolean}},emits:["update:modelValue","success"],setup(f,{emit:D}){const t=f,T=D,y=h({get:()=>t.modelValue,set:l=>T("update:modelValue",l)}),p=w(),V=w(!1),g=w([]),v=w(!1),e=K({rewardType:void 0,rewardExtend:void 0,rewardValue:1,description:""}),$=h(()=>({rewardType:[{required:!0,message:"请选择奖励类型",trigger:"change"}],rewardExtend:e.rewardType===d.Coupon?[{required:!0,message:"请选择优惠券",trigger:"change"}]:[],rewardValue:e.rewardType&&e.rewardType!==d.Coupon?[{required:!0,message:"请输入奖励数值",trigger:"blur"},{type:"number",min:1,message:"奖励数值必须大于0",trigger:"blur"}]:[]})),j=async()=>{v.value=!0;try{const l=await I({page:1,pageSize:1e3});g.value=l.data.list}catch{g.value=[]}finally{v.value=!1}};B(()=>t.modelValue,l=>{l&&(j(),t.isEdit&&t.reward?Object.assign(e,{rewardType:t.reward.rewardType,rewardExtend:t.reward.rewardExtend,rewardValue:t.reward.rewardValue||1,description:t.reward.description||""}):x())}),B(()=>e.rewardType,(l,r)=>{r!==void 0&&l!==r&&(l===d.Coupon?e.rewardValue=1:e.rewardExtend=void 0)});const x=()=>{var l;Object.assign(e,{rewardType:void 0,rewardExtend:void 0,rewardValue:1,description:""}),(l=p.value)==null||l.resetFields()},b=()=>{y.value=!1,x()},z=async()=>{if(p.value){try{await p.value.validate()}catch{return}if(e.rewardType===d.Coupon&&!e.rewardExtend){c.error("请选择优惠券");return}if(e.rewardType!==d.Coupon&&e.rewardValue<=0){c.error("奖励数值必须大于0");return}V.value=!0;try{const l={rewardType:e.rewardType,rewardExtend:e.rewardType===d.Coupon?e.rewardExtend:void 0,rewardValue:e.rewardType===d.Coupon?1:e.rewardValue,description:e.description||void 0};t.isEdit&&t.reward?(await M(t.reward.id,l),c.success("更新成功")):(await A(l),c.success("创建成功")),T("success"),b()}finally{V.value=!1}}};return(l,r)=>{const E=s("el-option"),C=s("el-select"),m=s("el-form-item"),O=s("el-input-number"),P=s("el-input"),S=s("el-form"),k=s("el-button"),G=s("el-dialog");return i(),u(G,{modelValue:y.value,"onUpdate:modelValue":r[4]||(r[4]=a=>y.value=a),title:f.isEdit?"编辑奖励":"新增奖励",width:"550px","close-on-click-modal":!1,onClose:b},{footer:o(()=>[n(k,{onClick:b},{default:o(()=>[...r[5]||(r[5]=[q("取消",-1)])]),_:1}),n(k,{type:"primary",loading:V.value,onClick:z},{default:o(()=>[...r[6]||(r[6]=[q(" 确定 ",-1)])]),_:1},8,["loading"])]),default:o(()=>[n(S,{ref_key:"formRef",ref:p,model:e,rules:$.value,"label-width":"100px"},{default:o(()=>[n(m,{label:"奖励类型",prop:"rewardType"},{default:o(()=>[n(C,{modelValue:e.rewardType,"onUpdate:modelValue":r[0]||(r[0]=a=>e.rewardType=a),placeholder:"请选择奖励类型",style:{width:"100%"},disabled:f.isEdit},{default:o(()=>[(i(!0),L(U,null,N(_(H),(a,R)=>(i(),u(E,{key:R,label:a,value:Number(R)},null,8,["label","value"]))),128))]),_:1},8,["modelValue","disabled"])]),_:1}),e.rewardType===_(d).Coupon?(i(),u(m,{key:0,label:"选择优惠券",prop:"rewardExtend"},{default:o(()=>[n(C,{modelValue:e.rewardExtend,"onUpdate:modelValue":r[1]||(r[1]=a=>e.rewardExtend=a),placeholder:"请选择优惠券",style:{width:"100%"},filterable:"",loading:v.value},{default:o(()=>[(i(!0),L(U,null,N(g.value,a=>(i(),u(E,{key:a.id,label:`${a.title} (满${a.minPrice}减${a.discountPrice})`,value:a.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue","loading"])]),_:1})):F("",!0),e.rewardType&&e.rewardType!==_(d).Coupon?(i(),u(m,{key:1,label:"奖励数值",prop:"rewardValue"},{default:o(()=>[n(O,{modelValue:e.rewardValue,"onUpdate:modelValue":r[2]||(r[2]=a=>e.rewardValue=a),min:1,precision:0,placeholder:"请输入奖励数值",style:{width:"100%"}},null,8,["modelValue"])]),_:1})):F("",!0),n(m,{label:"描述",prop:"description"},{default:o(()=>[n(P,{modelValue:e.description,"onUpdate:modelValue":r[3]||(r[3]=a=>e.description=a),type:"textarea",rows:3,placeholder:"请输入描述（可选）",maxlength:"200","show-word-limit":""},null,8,["modelValue"])]),_:1})]),_:1},8,["model","rules"])]),_:1},8,["modelValue","title"])}}});export{Y as _};
