import{dimensionApi as E}from"./index-CuBy5RvH.js";import{_ as Q,i as R,o as C,c as D,a as r,d as a,w as o,s as O,t as W,p as X,n as Y,h as v,r as s,y as B,b as p,A as f,E as Z}from"./index-BQtfiLxw.js";const ee={class:"app-page dimension-workbench"},le={class:"dimension-header"},ae={class:"header-actions"},ne={key:0,class:"dirty-mark"},oe={class:"sort-ctrl"},te={key:1,class:"empty"},se={__name:"DimensionConfigView",setup(ue){const n=v([]),V=v(!1),w=v(!1),d=v(!1),c=v(null),u=v({name:"",maxScore:10}),k=B(()=>n.value.reduce((l,e)=>l+(e.maxScore||0),0)),N=B(()=>k.value===40?"sum-ok":"sum-bad");R(()=>A());async function A(){const l=await E.list();n.value=l.map(U),w.value=!1}function U(l,e=0){return{...l,sortOrder:l.sortOrder??e+1,_rowKey:l.id??`local-${Date.now()}-${Math.random()}`}}function _(){w.value=!0}function M(){c.value=null,u.value={name:"",maxScore:10},d.value=!0}function $(l){c.value=l,u.value={name:l.name,maxScore:l.maxScore},d.value=!0}async function K(){if(!u.value.name.trim()){f.warning("请填写维度名称");return}c.value?(c.value.name=u.value.name.trim(),c.value.maxScore=u.value.maxScore):n.value.push(U({id:null,name:u.value.name.trim(),maxScore:u.value.maxScore,sortOrder:n.value.length+1},n.value.length)),_(),d.value=!1}async function P(l){await Z.confirm("确定删除该维度？删除后需点击保存配置才会生效。","提示",{type:"warning"}),n.value.splice(l,1),g(),_()}function q(l){if(l===0)return;const e=n.value[l],b=n.value[l-1];n.value[l-1]=e,n.value[l]=b,g(),_()}function F(l){if(l===n.value.length-1)return;const e=n.value[l],b=n.value[l+1];n.value[l+1]=e,n.value[l]=b,g(),_()}function g(){n.value.forEach((l,e)=>{l.sortOrder=e+1})}async function I(){if(!n.value.length){f.warning("至少保留一个考核维度");return}if(n.value.some(l=>{var e;return!((e=l.name)!=null&&e.trim())})){f.warning("维度名称不能为空");return}if(k.value!==40){f.error("分值合计必须为 40 后才能保存");return}V.value=!0;try{g(),await E.saveAll(n.value.map(l=>({id:l.id,name:l.name.trim(),maxScore:l.maxScore,sortOrder:l.sortOrder}))),f.success("配置已保存"),await A()}catch(l){f.error(l.message||"保存失败，请检查分值总和是否为40")}finally{V.value=!1}}return(l,e)=>{const b=s("Plus"),S=s("el-icon"),i=s("el-button"),T=s("ArrowUp"),j=s("ArrowDown"),y=s("el-table-column"),h=s("el-input-number"),G=s("el-table"),H=s("el-input"),z=s("el-form-item"),J=s("el-form"),L=s("el-dialog");return C(),D("div",ee,[r("div",le,[e[6]||(e[6]=r("div",null,[r("h3",null,"考核维度配置"),r("p",null,"绩效维度总分固定为 40 分，页面内调整后统一保存。")],-1)),r("div",ae,[a(i,{onClick:M},{default:o(()=>[a(S,null,{default:o(()=>[a(b)]),_:1}),e[4]||(e[4]=p(" 添加维度",-1))]),_:1}),a(i,{type:"primary",loading:V.value,disabled:!w.value,onClick:I},{default:o(()=>[...e[5]||(e[5]=[p(" 保存配置 ",-1)])]),_:1},8,["loading","disabled"])])]),r("div",{class:O(["hint-bar",{"hint-bar--invalid":k.value!==40}])},[e[7]||(e[7]=r("span",null,"绩效维度满分合计",-1)),r("strong",{class:O(N.value)},W(k.value),3),e[8]||(e[8]=r("span",null,"/ 40",-1)),w.value?(C(),D("span",ne,"有未保存修改")):X("",!0)],2),n.value.length?(C(),Y(G,{key:0,data:n.value,"row-key":"_rowKey",class:"dimension-table"},{default:o(()=>[a(y,{label:"排序",width:"80"},{default:o(({row:t,$index:m})=>[r("div",oe,[a(i,{link:"",size:"small",disabled:m===0,"aria-label":"上移",onClick:x=>q(m)},{default:o(()=>[a(S,null,{default:o(()=>[a(T)]),_:1})]),_:1},8,["disabled","onClick"]),a(i,{link:"",size:"small",disabled:m===n.value.length-1,"aria-label":"下移",onClick:x=>F(m)},{default:o(()=>[a(S,null,{default:o(()=>[a(j)]),_:1})]),_:1},8,["disabled","onClick"])])]),_:1}),a(y,{prop:"name",label:"维度名称"}),a(y,{label:"满分分值",width:"120"},{default:o(({row:t})=>[a(h,{modelValue:t.maxScore,"onUpdate:modelValue":m=>t.maxScore=m,min:1,max:40,step:1,size:"small",onChange:_},null,8,["modelValue","onUpdate:modelValue"])]),_:1}),a(y,{label:"操作",width:"100"},{default:o(({row:t,$index:m})=>[a(i,{link:"",size:"small",onClick:x=>$(t)},{default:o(()=>[...e[9]||(e[9]=[p("改名",-1)])]),_:1},8,["onClick"]),a(i,{link:"",size:"small",type:"danger",onClick:x=>P(m)},{default:o(()=>[...e[10]||(e[10]=[p("删除",-1)])]),_:1},8,["onClick"])]),_:1})]),_:1},8,["data"])):(C(),D("div",te,"暂无维度，请添加")),a(L,{modelValue:d.value,"onUpdate:modelValue":e[3]||(e[3]=t=>d.value=t),title:c.value?"编辑维度":"添加维度",width:"400px"},{footer:o(()=>[a(i,{onClick:e[2]||(e[2]=t=>d.value=!1)},{default:o(()=>[...e[11]||(e[11]=[p("取消",-1)])]),_:1}),a(i,{type:"primary",onClick:K},{default:o(()=>[...e[12]||(e[12]=[p("保存",-1)])]),_:1})]),default:o(()=>[a(J,{"label-width":"80px"},{default:o(()=>[a(z,{label:"名称"},{default:o(()=>[a(H,{modelValue:u.value.name,"onUpdate:modelValue":e[0]||(e[0]=t=>u.value.name=t),placeholder:"如：交付质量"},null,8,["modelValue"])]),_:1}),a(z,{label:"满分分值"},{default:o(()=>[a(h,{modelValue:u.value.maxScore,"onUpdate:modelValue":e[1]||(e[1]=t=>u.value.maxScore=t),min:1,max:40,step:1},null,8,["modelValue"])]),_:1})]),_:1})]),_:1},8,["modelValue","title"])])}}},me=Q(se,[["__scopeId","data-v-40c6a3ad"]]);export{me as default};
