import{d as O,v as Q,r as y,a as W,G as X,g as d,z as m,k as s,w as l,b as w,e as t,x as S,t as E,l as V,C as Y,c as f,H as Z,F as R,y as U,R as ee,E as D,_ as ae}from"./index-CUnFTKV2.js";import{u as re}from"./signconfig-B-QeZryi.js";import{a as le,R as n}from"./reward-Baf2bADU.js";import{g as te}from"./coupon-C54tWHNa.js";const oe={class:"reward-config-container"},se={class:"config-header"},ne={class:"config-title"},de={key:0,class:"empty-tip"},ie={class:"reward-row"},ue={class:"reward-unit"},ce=O({__name:"RewardConfigDialog",props:{modelValue:{type:Boolean},signConfig:{}},emits:["update:modelValue","success"],setup($,{emit:q}){const u=$,B=q,v=Q({get:()=>u.modelValue,set:a=>B("update:modelValue",a)}),C=y(),h=y(!1),b=y([]),T=y(!1),o=W({rewards:[]}),H=async()=>{T.value=!0;try{const a=await te({page:1,pageSize:1e3});b.value=a.data.list}catch{b.value=[]}finally{T.value=!1}};X(()=>u.modelValue,a=>{var e;a&&(H(),(e=u.signConfig)!=null&&e.rewards&&u.signConfig.rewards.length>0?o.rewards=u.signConfig.rewards.map(p=>({rewardType:p.rewardType,rewardExtend:p.rewardExtend,rewardValue:p.rewardValue})):o.rewards=[])});const F=a=>{switch(a){case n.Diamond:return"钻石";case n.UUCoin:return"HH币";case n.DaDaCoin:return"哈尼券";default:return""}},P=a=>{const e=o.rewards[a];e.rewardType===n.Coupon?(e.rewardValue=1,e.rewardExtend=void 0):(e.rewardExtend=void 0,e.rewardValue=1)},G=()=>{o.rewards.push({rewardType:n.Diamond,rewardValue:1})},I=a=>{o.rewards.splice(a,1)},k=()=>{v.value=!1,o.rewards=[]},M=async()=>{if(C.value&&u.signConfig){try{await C.value.validate()}catch{return}for(const a of o.rewards){if(a.rewardType===n.Coupon&&!a.rewardExtend){D.error("请选择优惠券");return}if(a.rewardType!==n.Coupon&&(!a.rewardValue||a.rewardValue<=0)){D.error("奖励数值必须大于0");return}}h.value=!0;try{const a={rewards:o.rewards.map(e=>({rewardType:e.rewardType,rewardExtend:e.rewardType===n.Coupon?e.rewardExtend:void 0,rewardValue:e.rewardType===n.Coupon?1:e.rewardValue}))};await re(u.signConfig.id,a),D.success("奖励配置更新成功"),B("success"),k()}finally{h.value=!1}}};return(a,e)=>{const p=d("el-icon"),g=d("el-button"),L=d("el-option"),N=d("el-select"),x=d("el-form-item"),j=d("el-input-number"),A=d("el-card"),J=d("el-form"),K=d("el-dialog");return s(),m(K,{modelValue:v.value,"onUpdate:modelValue":e[0]||(e[0]=_=>v.value=_),title:"奖励配置",width:"700px","close-on-click-modal":!1,onClose:k},{footer:l(()=>[t(g,{onClick:k},{default:l(()=>[...e[2]||(e[2]=[E("取消",-1)])]),_:1}),t(g,{type:"primary",loading:h.value,onClick:M},{default:l(()=>[...e[3]||(e[3]=[E(" 保存 ",-1)])]),_:1},8,["loading"])]),default:l(()=>{var _;return[w("div",oe,[w("div",se,[w("span",ne," 配置签到奖励 - "+S(((_=$.signConfig)==null?void 0:_.title)||""),1),t(g,{type:"primary",size:"small",onClick:G},{default:l(()=>[t(p,null,{default:l(()=>[t(V(Y))]),_:1}),e[1]||(e[1]=E("添加奖励 ",-1))]),_:1})]),t(J,{ref_key:"formRef",ref:C,model:o,"label-width":"0"},{default:l(()=>[o.rewards.length===0?(s(),f("div",de,' 暂无奖励配置，请点击"添加奖励"按钮添加 ')):Z("",!0),(s(!0),f(R,null,U(o.rewards,(i,c)=>(s(),f("div",{key:c,class:"reward-item"},[t(A,{shadow:"hover",class:"reward-card"},{default:l(()=>[w("div",ie,[t(x,{prop:`rewards.${c}.rewardType`,rules:[{required:!0,message:"请选择奖励类型",trigger:"change"}],class:"reward-type-item"},{default:l(()=>[t(N,{modelValue:i.rewardType,"onUpdate:modelValue":r=>i.rewardType=r,placeholder:"选择奖励类型",style:{width:"140px"},onChange:r=>P(c)},{default:l(()=>[(s(!0),f(R,null,U(V(le),(r,z)=>(s(),m(L,{key:z,label:r,value:Number(z)},null,8,["label","value"]))),128))]),_:1},8,["modelValue","onUpdate:modelValue","onChange"])]),_:2},1032,["prop"]),i.rewardType===V(n).Coupon?(s(),m(x,{key:0,prop:`rewards.${c}.rewardExtend`,rules:[{required:!0,message:"请选择优惠券",trigger:"change"}],class:"reward-value-item"},{default:l(()=>[t(N,{modelValue:i.rewardExtend,"onUpdate:modelValue":r=>i.rewardExtend=r,placeholder:"请选择优惠券",style:{width:"280px"},filterable:"",loading:T.value},{default:l(()=>[(s(!0),f(R,null,U(b.value,r=>(s(),m(L,{key:r.id,label:`${r.title} (满${r.minPrice}减${r.discountPrice})`,value:r.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue","onUpdate:modelValue","loading"])]),_:2},1032,["prop"])):(s(),m(x,{key:1,prop:`rewards.${c}.rewardValue`,rules:[{required:!0,message:"请输入奖励数值",trigger:"blur"},{type:"number",min:1,message:"奖励数值必须大于0",trigger:"blur"}],class:"reward-value-item"},{default:l(()=>[t(j,{modelValue:i.rewardValue,"onUpdate:modelValue":r=>i.rewardValue=r,min:1,precision:0,placeholder:"奖励数值",style:{width:"200px"}},null,8,["modelValue","onUpdate:modelValue"]),w("span",ue,S(F(i.rewardType)),1)]),_:2},1032,["prop"])),t(g,{type:"danger",icon:V(ee),circle:"",size:"small",onClick:r=>I(c),class:"delete-btn"},null,8,["icon","onClick"])])]),_:2},1024)]))),128))]),_:1},8,["model"])])]}),_:1},8,["modelValue"])}}}),ge=ae(ce,[["__scopeId","data-v-1d138b4d"]]);export{ge as default};
