import{dimensionApi as d}from"./index-3KNrlnzw.js";import{_ as T,h as j,o as w,c as V,a as f,b as l,w as t,e as i,q as G,t as H,m as J,g as k,r,x as O,z as _,E as K}from"./index-BO9jfAEj.js";const L={class:"app-page dimension-workbench"},Q={class:"page-header"},R={class:"hint-bar"},W={class:"sort-ctrl"},X={key:1,class:"empty"},Y={__name:"DimensionConfigView",setup(Z){const n=k([]),c=k(!1),b=k(null),s=k({name:"",maxScore:10}),y=O(()=>n.value.reduce((a,e)=>a+(e.maxScore||0),0)),z=O(()=>y.value===40?"sum-ok":"sum-bad");j(()=>v());async function v(){n.value=await d.list()}function D(){b.value=null,s.value={name:"",maxScore:10},c.value=!0}function U(a){b.value=a,s.value={name:a.name,maxScore:a.maxScore},c.value=!0}async function B(){if(!s.value.name.trim()){_.warning("请填写维度名称");return}try{b.value?await d.update(b.value.id,{name:s.value.name,maxScore:s.value.maxScore}):await d.create({name:s.value.name,maxScore:s.value.maxScore,sortOrder:n.value.length+1}),_.success("保存成功"),c.value=!1,await v()}catch(a){_.error(a.message||"保存失败，请检查分值总和是否为40")}}async function E(a,e){try{await d.update(a.id,{name:a.name,maxScore:e,sortOrder:a.sortOrder})}catch{_.error("分值总和必须为40"),a.maxScore=a._oldScore||10}}async function M(a){await K.confirm("确定删除该维度？如果删除后分值总数不为40将无法保存。","提示",{type:"warning"});try{await d.delete(a),await v(),_.success("已删除")}catch(e){_.error(e.message||"无法删除，分值总和必须保持40"),await v()}}async function N(a){if(a===0)return;const e=n.value[a],u=n.value[a-1];await d.update(e.id,{...e,sortOrder:u.sortOrder}),await d.update(u.id,{...u,sortOrder:e.sortOrder}),v()}async function $(a){if(a===n.value.length-1)return;const e=n.value[a],u=n.value[a+1];await d.update(e.id,{...e,sortOrder:u.sortOrder}),await d.update(u.id,{...u,sortOrder:e.sortOrder}),v()}return(a,e)=>{const u=r("Plus"),P=r("el-icon"),p=r("el-button"),g=r("el-table-column"),C=r("el-input-number"),q=r("el-table"),A=r("el-input"),S=r("el-form-item"),F=r("el-form"),I=r("el-dialog");return w(),V("div",L,[f("div",Q,[e[5]||(e[5]=f("h3",null,"考核维度配置",-1)),l(p,{type:"primary",onClick:D},{default:t(()=>[l(P,null,{default:t(()=>[l(u)]),_:1}),e[4]||(e[4]=i(" 添加维度",-1))]),_:1})]),f("div",R,[e[6]||(e[6]=i(" 所有维度满分之和必须为 ",-1)),e[7]||(e[7]=f("strong",null,"40",-1)),e[8]||(e[8]=i("，当前合计：",-1)),f("span",{class:G(z.value)},H(y.value),3),e[9]||(e[9]=i(" / 40 ",-1))]),n.value.length?(w(),J(q,{key:0,data:n.value,style:{width:"100%"}},{default:t(()=>[l(g,{label:"排序",width:"80"},{default:t(({row:o,$index:m})=>[f("div",W,[l(p,{link:"",size:"small",disabled:m===0,onClick:x=>N(m)},{default:t(()=>[...e[10]||(e[10]=[i("↑",-1)])]),_:1},8,["disabled","onClick"]),l(p,{link:"",size:"small",disabled:m===n.value.length-1,onClick:x=>$(m)},{default:t(()=>[...e[11]||(e[11]=[i("↓",-1)])]),_:1},8,["disabled","onClick"])])]),_:1}),l(g,{prop:"name",label:"维度名称"}),l(g,{label:"满分分值",width:"120"},{default:t(({row:o})=>[l(C,{modelValue:o.maxScore,"onUpdate:modelValue":m=>o.maxScore=m,min:1,max:40,step:1,size:"small",onChange:m=>E(o,m)},null,8,["modelValue","onUpdate:modelValue","onChange"])]),_:1}),l(g,{label:"操作",width:"100"},{default:t(({row:o,$index:m})=>[l(p,{link:"",size:"small",onClick:x=>U(o)},{default:t(()=>[...e[12]||(e[12]=[i("改名",-1)])]),_:1},8,["onClick"]),l(p,{link:"",size:"small",type:"danger",onClick:x=>M(o.id)},{default:t(()=>[...e[13]||(e[13]=[i("删除",-1)])]),_:1},8,["onClick"])]),_:1})]),_:1},8,["data"])):(w(),V("div",X,"暂无维度，请添加")),l(I,{modelValue:c.value,"onUpdate:modelValue":e[3]||(e[3]=o=>c.value=o),title:b.value?"编辑维度":"添加维度",width:"400px"},{footer:t(()=>[l(p,{onClick:e[2]||(e[2]=o=>c.value=!1)},{default:t(()=>[...e[14]||(e[14]=[i("取消",-1)])]),_:1}),l(p,{type:"primary",onClick:B},{default:t(()=>[...e[15]||(e[15]=[i("保存",-1)])]),_:1})]),default:t(()=>[l(F,{"label-width":"80px"},{default:t(()=>[l(S,{label:"名称"},{default:t(()=>[l(A,{modelValue:s.value.name,"onUpdate:modelValue":e[0]||(e[0]=o=>s.value.name=o),placeholder:"如：交付质量"},null,8,["modelValue"])]),_:1}),l(S,{label:"满分分值"},{default:t(()=>[l(C,{modelValue:s.value.maxScore,"onUpdate:modelValue":e[1]||(e[1]=o=>s.value.maxScore=o),min:1,max:40,step:1},null,8,["modelValue"])]),_:1})]),_:1})]),_:1},8,["modelValue","title"])])}}},ae=T(Y,[["__scopeId","data-v-c4460f45"]]);export{ae as default};
