import{d as L,U as Y,A as j,C as R}from"./api.Cpwr_LRz.js";import{E as p}from"./index.CN1lNsL-.js";import{a as T,r as m,q as A,aj as s,J as h,o as f,K as o,S as t,M as _,c as D,R as O,a9 as F,P as y}from"./vue.YrNK8sx4.js";const G=T({__name:"index",emits:["saved"],setup(J,{expose:x,emit:C}){const v=m([]),U=C;async function w(){const n=await L();v.value=n.data}A(()=>{w()});const V=m(),B={class_date:[{required:!0,message:"请选择上课日期",trigger:"change"}],teacher:[{required:!0,message:"请选择老师",trigger:"change"}],classdetail:[{required:!0,message:"请填写课程名称",trigger:"change"}],classroom:[{required:!0,message:"请填写教室",trigger:"change"}]},u=m(!1),i=m(!1),a=m({class_date:"",time:1,classdetail:"",teacher:null,semester:1,grade:1,class_number:1,classroom:"",total_lessons:48});function $(n){n?(a.value={...n},i.value=!0):(a.value={class_date:"",time:1,classdetail:"",teacher:null,semester:1,grade:1,class_number:1,classroom:"",total_lessons:48},i.value=!1),u.value=!0}function N(){u.value=!1}async function q(){var n;try{(n=V.value)==null||n.validate(async e=>{if(e){const d=!!a.value.id;console.log("保存课程:",a.value),d?await Y(a.value):(await j(a.value),await R({source_date:a.value.class_date,mode:"rest_of_semester"})),u.value=!1,p.success(d?"编辑成功":"创建成功"),U("saved")}else p.success("表单校验未通过！")})}catch(e){console.error("保存失败",e),p.error("保存失败！")}}return x({open:$}),(n,e)=>{const d=s("el-date-picker"),r=s("el-form-item"),c=s("el-option"),b=s("el-select"),g=s("el-input"),K=s("el-input-number"),E=s("el-form"),k=s("el-button"),M=s("el-dialog");return f(),h(M,{modelValue:u.value,"onUpdate:modelValue":e[9]||(e[9]=l=>u.value=l),title:i.value?"编辑课程":"添加课程",width:"500px"},{footer:o(()=>[t(k,{onClick:N},{default:o(()=>e[10]||(e[10]=[y("取消")])),_:1}),t(k,{type:"primary",onClick:q},{default:o(()=>e[11]||(e[11]=[y("保存")])),_:1})]),default:o(()=>[t(E,{model:a.value,rules:B,ref_key:"formRef",ref:V,"label-width":"100px"},{default:o(()=>[t(r,{label:"上课日期",prop:"class_date"},{default:o(()=>[t(d,{modelValue:a.value.class_date,"onUpdate:modelValue":e[0]||(e[0]=l=>a.value.class_date=l),type:"date","value-format":"YYYY-MM-DD"},null,8,["modelValue"])]),_:1}),t(r,{label:"时间段",prop:"time"},{default:o(()=>[t(b,{modelValue:a.value.time,"onUpdate:modelValue":e[1]||(e[1]=l=>a.value.time=l),placeholder:"选择时间段"},{default:o(()=>[t(c,{label:"上午",value:1}),t(c,{label:"下午",value:2}),t(c,{label:"晚上",value:3})]),_:1},8,["modelValue"])]),_:1}),t(r,{label:"课程名称",prop:"classdetail"},{default:o(()=>[t(g,{modelValue:a.value.classdetail,"onUpdate:modelValue":e[2]||(e[2]=l=>a.value.classdetail=l)},null,8,["modelValue"])]),_:1}),t(r,{label:"教师",prop:"teacher"},{default:o(()=>[t(b,{modelValue:a.value.teacher,"onUpdate:modelValue":e[3]||(e[3]=l=>a.value.teacher=l),placeholder:"请选择教师"},{default:o(()=>[(f(!0),D(O,null,F(v.value,l=>(f(),h(c,{key:l.id,label:l.name,value:l.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue"])]),_:1}),_("",!0),_("",!0),_("",!0),t(r,{label:"教室",prop:"classroom"},{default:o(()=>[t(g,{modelValue:a.value.classroom,"onUpdate:modelValue":e[7]||(e[7]=l=>a.value.classroom=l)},null,8,["modelValue"])]),_:1}),_("",!0)]),_:1},8,["model"])]),_:1},8,["modelValue","title"])}}});export{G as _};
