import{u as C,c as B}from"./qylevel-DtP7HHIT.js";import{d as D,v as L,r as b,a as U,G as h,g as a,z as k,k as F,w as s,e as i,t as q,E as u}from"./index-CUnFTKV2.js";const z=D({__name:"QyLevelFormDialog",props:{modelValue:{type:Boolean},level:{},isEdit:{type:Boolean}},emits:["update:modelValue","success"],setup(c,{emit:w}){const o=c,g=w,m=L({get:()=>o.modelValue,set:t=>g("update:modelValue",t)}),d=b(),p=b(!1),l=U({level:1,title:"",requiredPoints:0}),y={level:[{required:!0,validator:(t,e,r)=>{e==null||e===""?r(new Error("此字段为必填项")):typeof e!="number"||e<=0?r(new Error("必须为大于0的正整数")):r()},trigger:"blur"}],title:[{required:!0,message:"请输入等级名称",trigger:"blur"},{min:1,max:50,message:"名称长度在1-50个字符之间",trigger:"blur"}],requiredPoints:[{required:!0,validator:(t,e,r)=>{e==null||e===""?r(new Error("此字段为必填项")):typeof e!="number"||e<0?r(new Error("必须为非负整数")):r()},trigger:"blur"}]};h(()=>o.modelValue,t=>{t&&(o.isEdit&&o.level?Object.assign(l,{level:o.level.level||1,title:o.level.title||"",requiredPoints:o.level.requiredPoints||0}):V())});const V=()=>{var t;Object.assign(l,{level:1,title:"",requiredPoints:0}),(t=d.value)==null||t.resetFields()},f=()=>{m.value=!1,V()},P=async()=>{if(d.value){try{await d.value.validate()}catch{return}if(l.level<=0){u.error("等级必须大于0");return}if(l.requiredPoints<0){u.error("所需欧气值不能为负数");return}p.value=!0;try{if(o.isEdit){if(!o.level){u.error("未选择要编辑的等级");return}const t={level:l.level,title:l.title,requiredPoints:l.requiredPoints};await C(o.level.id,t),u.success("更新成功")}else{const t={level:l.level,title:l.title,requiredPoints:l.requiredPoints};await B(t),u.success("创建成功")}g("success"),f()}finally{p.value=!1}}};return(t,e)=>{const r=a("el-input-number"),v=a("el-form-item"),E=a("el-input"),x=a("el-form"),_=a("el-button"),N=a("el-dialog");return F(),k(N,{modelValue:m.value,"onUpdate:modelValue":e[3]||(e[3]=n=>m.value=n),title:c.isEdit?"编辑权益等级":"新增权益等级",width:"500px","close-on-click-modal":!1,onClose:f},{footer:s(()=>[i(_,{onClick:f},{default:s(()=>[...e[4]||(e[4]=[q("取消",-1)])]),_:1}),i(_,{type:"primary",loading:p.value,onClick:P},{default:s(()=>[...e[5]||(e[5]=[q(" 确定 ",-1)])]),_:1},8,["loading"])]),default:s(()=>[i(x,{ref_key:"formRef",ref:d,model:l,rules:y,"label-width":"100px"},{default:s(()=>[i(v,{label:"等级",prop:"level"},{default:s(()=>[i(r,{modelValue:l.level,"onUpdate:modelValue":e[0]||(e[0]=n=>l.level=n),min:1,precision:0,placeholder:"请输入等级",style:{width:"100%"}},null,8,["modelValue"])]),_:1}),i(v,{label:"等级名称",prop:"title"},{default:s(()=>[i(E,{modelValue:l.title,"onUpdate:modelValue":e[1]||(e[1]=n=>l.title=n),placeholder:"请输入等级名称",maxlength:"50","show-word-limit":""},null,8,["modelValue"])]),_:1}),i(v,{label:"所需欧气值",prop:"requiredPoints"},{default:s(()=>[i(r,{modelValue:l.requiredPoints,"onUpdate:modelValue":e[2]||(e[2]=n=>l.requiredPoints=n),min:0,precision:0,placeholder:"请输入所需欧气值",style:{width:"100%"}},null,8,["modelValue"])]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue","title"])}}});export{z as _};
