import{Q as h,a as D,b as R}from"./qylevel-DtP7HHIT.js";import{g as U}from"./coupon-C54tWHNa.js";import{d as $,v as q,r as d,a as j,G as N,g as s,z,k as v,w as n,e as i,c as O,F as S,y as T,t as w,E as r,_ as G}from"./index-CUnFTKV2.js";const M=$({__name:"QyLevelPrizeFormDialog",props:{modelValue:{type:Boolean},levelId:{},prize:{},isEdit:{type:Boolean}},emits:["update:modelValue","success"],setup(g,{emit:C}){const t=g,_=C,c=q({get:()=>t.modelValue,set:e=>_("update:modelValue",e)}),u=d(),m=d(!1),p=d([]),f=d(!1),l=j({couponId:void 0,quantity:1}),k=q(()=>({couponId:[{required:!0,message:"请选择优惠券",trigger:"change"}],quantity:[{required:!0,message:"请输入数量",trigger:"blur"},{type:"number",min:1,message:"数量必须大于0",trigger:"blur"}]})),L=async()=>{f.value=!0;try{const e=await U({page:1,pageSize:1e3});p.value=e.data.list}catch{p.value=[]}finally{f.value=!1}};N(()=>t.modelValue,e=>{e&&(L(),t.isEdit&&t.prize?Object.assign(l,{couponId:t.prize.couponId,quantity:t.prize.quantity||1}):b())});const b=()=>{var e;Object.assign(l,{couponId:void 0,quantity:1}),(e=u.value)==null||e.resetFields()},y=()=>{c.value=!1,b()},x=async()=>{if(u.value){try{await u.value.validate()}catch{return}if(!l.couponId){r.error("请选择优惠券");return}if(l.quantity<=0){r.error("数量必须大于0");return}m.value=!0;try{const e={type:h.Coupon,couponId:l.couponId,quantity:l.quantity};if(t.isEdit&&t.prize)await D(t.prize.id,e),r.success("更新成功");else{if(!t.levelId){r.error("未选择权益等级");return}await R(t.levelId,e),r.success("创建成功")}_("success"),y()}finally{m.value=!1}}};return(e,a)=>{const E=s("el-option"),P=s("el-select"),V=s("el-form-item"),F=s("el-input-number"),Q=s("el-form"),I=s("el-button"),B=s("el-dialog");return v(),z(B,{modelValue:c.value,"onUpdate:modelValue":a[2]||(a[2]=o=>c.value=o),title:g.isEdit?"编辑奖品":"新增奖品",width:"600px","close-on-click-modal":!1,onClose:y},{footer:n(()=>[i(I,{onClick:y},{default:n(()=>[...a[3]||(a[3]=[w("取消",-1)])]),_:1}),i(I,{type:"primary",loading:m.value,onClick:x},{default:n(()=>[...a[4]||(a[4]=[w(" 确定 ",-1)])]),_:1},8,["loading"])]),default:n(()=>[i(Q,{ref_key:"formRef",ref:u,model:l,rules:k.value,"label-width":"100px"},{default:n(()=>[i(V,{label:"选择优惠券",prop:"couponId"},{default:n(()=>[i(P,{modelValue:l.couponId,"onUpdate:modelValue":a[0]||(a[0]=o=>l.couponId=o),placeholder:"请选择优惠券",style:{width:"100%"},filterable:"",loading:f.value},{default:n(()=>[(v(!0),O(S,null,T(p.value,o=>(v(),z(E,{key:o.id,label:`${o.title} (满${o.minPrice}减${o.discountPrice})`,value:o.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue","loading"])]),_:1}),i(V,{label:"数量",prop:"quantity"},{default:n(()=>[i(F,{modelValue:l.quantity,"onUpdate:modelValue":a[1]||(a[1]=o=>l.quantity=o),min:1,precision:0,placeholder:"请输入优惠券数量",style:{width:"100%"}},null,8,["modelValue"])]),_:1})]),_:1},8,["model","rules"])]),_:1},8,["modelValue","title"])}}}),K=G(M,[["__scopeId","data-v-098f7498"]]);export{K as default};
