import{q as J,c as T,a as r,b as l,w as o,x as K,k as w,h as i,r as s,v as P,o as _,e as c,t as Q,F as W,i as X,A as Z,y as ee,E as V,f as le}from"./index-NywRioUE.js";import{r as f}from"./index-IKxiqY7O.js";const te={class:"content-card"},ae={class:"card-title"},oe={class:"filter-bar",style:{"margin-bottom":"0"}},ne={style:{"margin-top":"16px"}},de={__name:"TimesheetForm",setup(se){const $=new Date().toISOString().split("T")[0],v=i($),C=i([]),d=i(0),x=i([]),k=i(!1),u=i(!1),b=i(!1),m=i(null),D=i(null),t=le({client_id:"",hours:1,remark:""}),B={client_id:[{required:!0,message:"请选择项目",trigger:"change"}],hours:[{required:!0,message:"请输入工时",trigger:"blur"}]};async function g(){k.value=!0;try{const n=await f.getTimesheets({date:v.value});C.value=n.data.records,d.value=n.data.day_total}finally{k.value=!1}}async function E(){const n=await f.getClients();x.value=n.data}function M(){m.value=null,t.client_id="",t.hours=1,t.remark="",u.value=!0}function U(n){m.value=n.id,t.client_id=n.client_id,t.hours=n.hours,t.remark=n.remark||"",u.value=!0}async function z(){var e;if(await((e=D.value)==null?void 0:e.validate().catch(()=>!1))){b.value=!0;try{m.value?(await f.updateTimesheet(m.value,{hours:t.hours,remark:t.remark}),V.success("更新成功")):(await f.createTimesheet({client_id:t.client_id,work_date:v.value,hours:t.hours,remark:t.remark}),V.success("提交成功")),u.value=!1,g()}finally{b.value=!1}}}async function N(n){await ee.confirm("确定删除该工时记录吗？","确认",{type:"warning"}),await f.deleteTimesheet(n.id),V.success("删除成功"),g()}return J(()=>{g(),E()}),(n,e)=>{const S=s("el-date-picker"),Y=s("el-tag"),p=s("el-button"),y=s("el-table-column"),q=s("el-table"),A=s("el-progress"),F=s("el-option"),I=s("el-select"),h=s("el-form-item"),R=s("el-input-number"),L=s("el-input"),O=s("el-form"),j=s("el-dialog"),G=P("loading");return _(),T("div",null,[e[11]||(e[11]=r("div",{class:"page-header"},[r("h1",null,"每日工时填报"),r("p",null,"选择日期，为参与的项目填写工时")],-1)),r("div",te,[r("div",ae,[r("div",oe,[l(S,{modelValue:v.value,"onUpdate:modelValue":e[0]||(e[0]=a=>v.value=a),type:"date",placeholder:"选择日期","value-format":"YYYY-MM-DD",size:"default",onChange:g},null,8,["modelValue"]),l(Y,{type:"info",effect:"dark",round:"",size:"large",style:{"margin-left":"8px"}},{default:o(()=>[c(" 当日已填: "+Q(d.value)+" / 8 小时 ",1)]),_:1})]),l(p,{type:"primary",onClick:M,disabled:d.value>=8},{default:o(()=>[...e[6]||(e[6]=[c("+ 添加工时",-1)])]),_:1},8,["disabled"])]),K((_(),w(q,{data:C.value,stripe:""},{default:o(()=>[l(y,{prop:"client_name",label:"客户/项目","min-width":"180"}),l(y,{prop:"hours",label:"工时(h)",width:"100"}),l(y,{prop:"remark",label:"备注","min-width":"150"}),l(y,{label:"操作",width:"160"},{default:o(({row:a})=>[l(p,{size:"small",onClick:H=>U(a)},{default:o(()=>[...e[7]||(e[7]=[c("编辑",-1)])]),_:1},8,["onClick"]),l(p,{size:"small",type:"danger",onClick:H=>N(a)},{default:o(()=>[...e[8]||(e[8]=[c("删除",-1)])]),_:1},8,["onClick"])]),_:1})]),_:1},8,["data"])),[[G,k.value]]),r("div",ne,[l(A,{percentage:d.value/8*100,color:d.value>8?"#ef4444":"#6366f1","stroke-width":10,format:()=>`${d.value}/8h`},null,8,["percentage","color","format"])])]),l(j,{modelValue:u.value,"onUpdate:modelValue":e[5]||(e[5]=a=>u.value=a),title:m.value?"编辑工时":"添加工时",width:"460px","destroy-on-close":""},{footer:o(()=>[l(p,{onClick:e[4]||(e[4]=a=>u.value=!1)},{default:o(()=>[...e[9]||(e[9]=[c("取消",-1)])]),_:1}),l(p,{type:"primary",loading:b.value,onClick:z},{default:o(()=>[...e[10]||(e[10]=[c("保存",-1)])]),_:1},8,["loading"])]),default:o(()=>[l(O,{model:t,rules:B,ref_key:"formRef",ref:D,"label-width":"80px"},{default:o(()=>[m.value?Z("",!0):(_(),w(h,{key:0,label:"项目",prop:"client_id"},{default:o(()=>[l(I,{modelValue:t.client_id,"onUpdate:modelValue":e[1]||(e[1]=a=>t.client_id=a),placeholder:"选择客户/项目",style:{width:"100%"},filterable:""},{default:o(()=>[(_(!0),T(W,null,X(x.value,a=>(_(),w(F,{key:a.id,label:`${a.name} (${a.sales_name})`,value:a.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1})),l(h,{label:"工时",prop:"hours"},{default:o(()=>[l(R,{modelValue:t.hours,"onUpdate:modelValue":e[2]||(e[2]=a=>t.hours=a),min:.5,max:8,step:.5,precision:1,style:{width:"100%"}},null,8,["modelValue"])]),_:1}),l(h,{label:"备注"},{default:o(()=>[l(L,{modelValue:t.remark,"onUpdate:modelValue":e[3]||(e[3]=a=>t.remark=a),type:"textarea",rows:2,placeholder:"工作内容说明（选填）"},null,8,["modelValue"])]),_:1})]),_:1},8,["model"])]),_:1},8,["modelValue","title"])])}}};export{de as default};
