import{T as q,u as D,c as L}from"./task-DlYETVMU.js";import{d as R,v as j,r as N,a as O,G,g as n,z,k as g,w as s,e as r,c as M,F as S,y as A,l as H,t as E,E as d}from"./index-CUnFTKV2.js";const K=R({__name:"TaskFormDialog",props:{modelValue:{type:Boolean},task:{},isEdit:{type:Boolean}},emits:["update:modelValue","success"],setup(y,{emit:x}){const l=y,V=x,p=j({get:()=>l.modelValue,set:a=>V("update:modelValue",a)}),m=N(),b=N(!1),t=O({title:"",type:void 0,cate:1,number:1,zNumber:1,sort:0}),_=(a,e,u)=>{e==null||e===""?u(new Error("此字段为必填项")):typeof e!="number"||e<=0?u(new Error("必须为大于0的正整数")):u()},C={title:[{required:!0,message:"请输入任务标题",trigger:"blur"},{min:1,max:100,message:"标题长度在1-100个字符之间",trigger:"blur"}],type:[{required:!0,message:"请选择任务分类",trigger:"change"}],number:[{required:!0,validator:_,trigger:"blur"}],zNumber:[{required:!0,validator:_,trigger:"blur"}],sort:[{type:"number",min:0,message:"排序值不能为负数",trigger:"blur"}]};G(()=>l.modelValue,a=>{a&&(l.isEdit&&l.task?Object.assign(t,{title:l.task.title||"",type:l.task.type,cate:l.task.cate||1,number:l.task.number||1,zNumber:l.task.zNumber||1,sort:l.task.sort||0}):k())});const k=()=>{var a;Object.assign(t,{title:"",type:void 0,cate:1,number:1,zNumber:1,sort:0}),(a=m.value)==null||a.resetFields()},c=()=>{p.value=!1,k()},T=async()=>{if(m.value){try{await m.value.validate()}catch{return}if(t.number<=0){d.error("任务次数必须大于0");return}if(t.zNumber<=0){d.error("欧气值必须大于0");return}b.value=!0;try{const a={title:t.title,type:t.type,cate:t.cate,number:t.number,zNumber:t.zNumber,sort:t.sort};l.isEdit&&l.task?(await D(l.task.id,a),d.success("更新成功")):(await L(a),d.success("创建成功")),V("success"),c()}finally{b.value=!1}}};return(a,e)=>{const u=n("el-input"),i=n("el-form-item"),U=n("el-option"),B=n("el-select"),f=n("el-input-number"),F=n("el-form"),v=n("el-button"),h=n("el-dialog");return g(),z(h,{modelValue:p.value,"onUpdate:modelValue":e[5]||(e[5]=o=>p.value=o),title:y.isEdit?"编辑任务":"新增任务",width:"550px","close-on-click-modal":!1,onClose:c},{footer:s(()=>[r(v,{onClick:c},{default:s(()=>[...e[6]||(e[6]=[E("取消",-1)])]),_:1}),r(v,{type:"primary",loading:b.value,onClick:T},{default:s(()=>[...e[7]||(e[7]=[E(" 确定 ",-1)])]),_:1},8,["loading"])]),default:s(()=>[r(F,{ref_key:"formRef",ref:m,model:t,rules:C,"label-width":"100px"},{default:s(()=>[r(i,{label:"任务标题",prop:"title"},{default:s(()=>[r(u,{modelValue:t.title,"onUpdate:modelValue":e[0]||(e[0]=o=>t.title=o),placeholder:"请输入任务标题",maxlength:"100","show-word-limit":""},null,8,["modelValue"])]),_:1}),r(i,{label:"任务分类",prop:"type"},{default:s(()=>[r(B,{modelValue:t.type,"onUpdate:modelValue":e[1]||(e[1]=o=>t.type=o),placeholder:"请选择任务分类",style:{width:"100%"}},{default:s(()=>[(g(!0),M(S,null,A(H(q),(o,w)=>(g(),z(U,{key:w,label:o,value:Number(w)},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),r(i,{label:"任务次数",prop:"number"},{default:s(()=>[r(f,{modelValue:t.number,"onUpdate:modelValue":e[2]||(e[2]=o=>t.number=o),min:1,precision:0,placeholder:"请输入完成次数要求",style:{width:"100%"}},null,8,["modelValue"])]),_:1}),r(i,{label:"欧气值",prop:"zNumber"},{default:s(()=>[r(f,{modelValue:t.zNumber,"onUpdate:modelValue":e[3]||(e[3]=o=>t.zNumber=o),min:1,precision:0,placeholder:"请输入奖励欧气值",style:{width:"100%"}},null,8,["modelValue"])]),_:1}),r(i,{label:"排序",prop:"sort"},{default:s(()=>[r(f,{modelValue:t.sort,"onUpdate:modelValue":e[4]||(e[4]=o=>t.sort=o),min:0,precision:0,placeholder:"请输入排序值",style:{width:"100%"}},null,8,["modelValue"])]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue","title"])}}});export{K as _};
