import{g as B,u as D,a as L,c as M,b as N}from"./rank-XE5cpzWb.js";import{d as j,v as O,r as f,a as W,G,o as H,g as s,z as v,k as d,w as o,e as i,c as w,F as S,y as A,H as J,t as U,E as P,_ as K}from"./index-CUnFTKV2.js";const Q={key:0,class:"image-preview"},X=j({__name:"RankPrizeFormDialog",props:{modelValue:{type:Boolean},prize:{},isEdit:{type:Boolean},type:{}},emits:["update:modelValue","success"],setup(y,{emit:T}){const r=y,b=T,u=O({get:()=>r.modelValue,set:a=>b("update:modelValue",a)}),p=f(),m=f(!1),_=f([]),e=W({rank:1,title:"",imgUrl:"",price:0,costPrice:0,prizeTypeId:void 0}),x={rank:[{required:!0,message:"请输入排名",trigger:"blur"},{type:"number",min:1,message:"排名必须大于0",trigger:"blur"}],title:[{required:!0,message:"请输入奖品名称",trigger:"blur"},{min:1,max:100,message:"名称长度在1-100个字符",trigger:"blur"}],prizeTypeId:[{required:!0,message:"请选择奖品类型",trigger:"change"}],price:[{required:!0,message:"请输入售价",trigger:"blur"},{type:"number",min:0,message:"售价不能为负数",trigger:"blur"}],costPrice:[{required:!0,message:"请输入采购价",trigger:"blur"},{type:"number",min:0,message:"采购价不能为负数",trigger:"blur"}],imgUrl:[{required:!0,message:"请输入图片URL",trigger:"blur"}]},I=async()=>{try{const a=await B();_.value=a.data}catch{}};G(()=>r.modelValue,a=>{a&&(r.isEdit&&r.prize?Object.assign(e,{rank:r.prize.rank,title:r.prize.title,imgUrl:r.prize.imgUrl,price:r.prize.price,costPrice:r.prize.costPrice,prizeTypeId:r.prize.prizeTypeId||void 0}):z())});const z=()=>{var a;Object.assign(e,{rank:1,title:"",imgUrl:"",price:0,costPrice:0,prizeTypeId:void 0}),(a=p.value)==null||a.resetFields()},c=()=>{u.value=!1,z()},h=async()=>{if(p.value){try{await p.value.validate()}catch{return}m.value=!0;try{const a={rank:e.rank,title:e.title,imgUrl:e.imgUrl,price:e.price,costPrice:e.costPrice,prizeTypeId:e.prizeTypeId||0};r.isEdit&&r.prize?(r.type==="week"?await D(r.prize.id,a):await L(r.prize.id,a),P.success("更新成功")):(r.type==="week"?await M(a):await N(a),P.success("创建成功")),b("success"),c()}finally{m.value=!1}}};return H(()=>{I()}),(a,l)=>{const g=s("el-input-number"),n=s("el-form-item"),V=s("el-input"),C=s("el-option"),E=s("el-select"),R=s("el-image"),q=s("el-form"),k=s("el-button"),F=s("el-dialog");return d(),v(F,{modelValue:u.value,"onUpdate:modelValue":l[6]||(l[6]=t=>u.value=t),title:y.isEdit?"编辑奖品":"新增奖品",width:"550px","close-on-click-modal":!1,onClose:c},{footer:o(()=>[i(k,{onClick:c},{default:o(()=>[...l[7]||(l[7]=[U("取消",-1)])]),_:1}),i(k,{type:"primary",loading:m.value,onClick:h},{default:o(()=>[...l[8]||(l[8]=[U(" 确定 ",-1)])]),_:1},8,["loading"])]),default:o(()=>[i(q,{ref_key:"formRef",ref:p,model:e,rules:x,"label-width":"100px"},{default:o(()=>[i(n,{label:"排名",prop:"rank"},{default:o(()=>[i(g,{modelValue:e.rank,"onUpdate:modelValue":l[0]||(l[0]=t=>e.rank=t),min:1,max:999,placeholder:"请输入排名",style:{width:"100%"}},null,8,["modelValue"])]),_:1}),i(n,{label:"奖品名称",prop:"title"},{default:o(()=>[i(V,{modelValue:e.title,"onUpdate:modelValue":l[1]||(l[1]=t=>e.title=t),placeholder:"请输入奖品名称",maxlength:"100","show-word-limit":""},null,8,["modelValue"])]),_:1}),i(n,{label:"奖品类型",prop:"prizeTypeId"},{default:o(()=>[i(E,{modelValue:e.prizeTypeId,"onUpdate:modelValue":l[2]||(l[2]=t=>e.prizeTypeId=t),placeholder:"请选择奖品类型",style:{width:"100%"}},{default:o(()=>[(d(!0),w(S,null,A(_.value,t=>(d(),v(C,{key:t.id,label:t.title,value:t.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),i(n,{label:"售价",prop:"price"},{default:o(()=>[i(g,{modelValue:e.price,"onUpdate:modelValue":l[3]||(l[3]=t=>e.price=t),min:0,max:999999,precision:2,placeholder:"请输入售价",style:{width:"100%"}},null,8,["modelValue"])]),_:1}),i(n,{label:"采购价",prop:"costPrice"},{default:o(()=>[i(g,{modelValue:e.costPrice,"onUpdate:modelValue":l[4]||(l[4]=t=>e.costPrice=t),min:0,max:999999,precision:2,placeholder:"请输入采购价",style:{width:"100%"}},null,8,["modelValue"])]),_:1}),i(n,{label:"奖品图片",prop:"imgUrl"},{default:o(()=>[i(V,{modelValue:e.imgUrl,"onUpdate:modelValue":l[5]||(l[5]=t=>e.imgUrl=t),placeholder:"请输入图片URL"},null,8,["modelValue"]),e.imgUrl?(d(),w("div",Q,[i(R,{src:e.imgUrl,fit:"cover",class:"preview-img"},null,8,["src"])])):J("",!0)]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue","title"])}}}),$=K(X,[["__scopeId","data-v-7b317bde"]]);export{$ as default};
