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