import{k as $,E as y,h as H,t as K,y as S,z as W}from"./index.kKfH623w.js";import{G as Q,c as X}from"./crud.B8lt2KqB.js";import{G as Y}from"./api.qlfwJwm4.js";import{h as Z}from"./columnPermission.BxnAQs2L.js";import{a as R,r as w,f as ee,q as le,aj as f,J as s,o as n,K as t,S as d,H as ae,u as oe,c as m,R as v,a9 as h,P as _}from"./vue.D1BjjNmv.js";import"./authFunction.BBmcfwfs.js";const re={key:0,style:{display:"flex",gap:"8px",width:"100%"}},te=R({name:"allusers"}),pe=R({...te,setup(ne,{expose:j}){const p=w(!1),c=w([]),u=w([]),b=ee(()=>{const e=Array.isArray(u.value)?u.value:[],l=[];return e.forEach(r=>{Array.isArray(r==null?void 0:r.children)&&l.push(...r.children)}),l.map(r=>({id:r.id,name:r.name}))});function C(e){if(!e)return;const l=[...u.value||[]];for(;l.length;){const r=l.shift();if((r==null?void 0:r.id)===e)return r;Array.isArray(r==null?void 0:r.children)&&r.children.length&&l.push(...r.children)}}function k(e){const l=C(e);return Array.isArray(l==null?void 0:l.children)?l.children:[]}function x(e){const l=C(e);return Array.isArray(l==null?void 0:l.children)?l.children:[]}function A(e){e.form._major_id=void 0,e.form._grade_id=void 0,e.form.user_type===0?e.form.organization_ref=void 0:e.form.organization_ref=e.form._college_id}function z(e){e.form._grade_id=void 0,e.form.user_type===0&&(e.form.organization_ref=void 0)}function U(e){e.form.user_type===0&&(e.form.organization_ref=e.form._grade_id)}const B=()=>{Y().then(e=>{if(console.log("组织架构API响应:",e),e&&(e.code===200||e.code===2e3||!e.code)){const l=e.data||e.results||e;Array.isArray(l)?(u.value=l,console.log("成功赋值组织架构数据:",u.value)):(console.warn("返回的数据不是数组格式:",l),u.value=[])}else console.error("获取组织架构数据失败:",e),u.value=[]}).catch(e=>{console.error("请求组织架构数据失败:",e),u.value=[]})},{crudBinding:E,crudRef:F,crudExpose:V,crudOptions:G,resetCrudOptions:P,selectedRows:de}=$({createCrudOptions:X}),I=()=>{p.value=!0},T=e=>{c.value=[e.raw]},D=async()=>{if(c.value.length===0){y.warning("请先选择文件");return}const e=c.value[0];if(!e){y.error("文件无效,请重新选择");return}const l=new FormData;l.append("file",e);const r=H.get("token");try{await K({url:"/api/system/app_user/batch_import/",method:"post",data:l,headers:{"Content-Type":"multipart/form-data",Authorization:r?`JWT ${r}`:""}}).then(i=>{console.log("导入resssss:::",i),y.success("导入成功"),p.value=!1,c.value=[],V.doRefresh()})}catch(i){y.error("导入失败,请检查文件格式或内容"),console.error(i)}},M=()=>{S({url:"/api/system/app_user/download_template/",method:"get",filename:"用户导入模板"})},O=()=>{var l;const e=((l=V.selectedIds)==null?void 0:l.value)||[];if(console.log("selectedRows::",e),e.length===0){y.warning("请先选择要导出的用户");return}W({url:"/api/system/app_user/export_selected/",method:"post",data:{user_ids:e},filename:"用户导出"})};return le(async()=>{B();const e=await Z(Q,G);P(e),V.doRefresh()}),j({getMajors:k,getGrades:x,onCollegeChange:A,onMajorChange:z,onGradeChange:U,colleges:b}),(e,l)=>{const r=f("el-button"),i=f("el-option"),g=f("el-select"),L=f("fs-crud"),N=f("el-upload"),q=f("el-dialog"),J=f("fs-page");return n(),s(J,null,{default:t(()=>[d(L,ae({ref_key:"crudRef",ref:F},oe(E)),{"actionbar-right":t(()=>[d(r,{type:"primary",style:{"margin-left":"12px"},onClick:I},{default:t(()=>l[2]||(l[2]=[_("批量导入")])),_:1}),d(r,{type:"primary",onClick:M},{default:t(()=>l[3]||(l[3]=[_("下载模板")])),_:1}),d(r,{type:"primary",onClick:O},{default:t(()=>l[4]||(l[4]=[_("批量导出")])),_:1})]),form_organization_ref:t(a=>[a.form.user_type===0?(n(),m("div",re,[d(g,{style:{flex:"1"},disabled:a.mode=="view",modelValue:a.form._college_id,"onUpdate:modelValue":o=>a.form._college_id=o,placeholder:"请选择学院",filterable:"",clearable:"",onChange:()=>A(a)},{default:t(()=>[(n(!0),m(v,null,h(b.value,o=>(n(),s(i,{key:o.id,label:o.name,value:o.id},null,8,["label","value"]))),128))]),_:2},1032,["disabled","modelValue","onUpdate:modelValue","onChange"])])):a.form.user_type===1||a.form.user_type===3?(n(),s(g,{key:1,disabled:a.mode=="view",modelValue:a.form.organization_ref,"onUpdate:modelValue":o=>a.form.organization_ref=o,placeholder:"请选择学院",filterable:"",clearable:""},{default:t(()=>[(n(!0),m(v,null,h(b.value,o=>(n(),s(i,{key:o.id,label:o.name,value:o.id},null,8,["label","value"]))),128))]),_:2},1032,["disabled","modelValue","onUpdate:modelValue"])):(n(),s(g,{key:2,disabled:a.mode=="view",modelValue:a.form.organization_ref,"onUpdate:modelValue":o=>a.form.organization_ref=o,placeholder:"请选择学院",filterable:"",clearable:""},{default:t(()=>[(n(!0),m(v,null,h(b.value,o=>(n(),s(i,{key:o.id,label:o.name,value:o.id},null,8,["label","value"]))),128))]),_:2},1032,["disabled","modelValue","onUpdate:modelValue"]))]),form_sub_organization:t(a=>[d(g,{style:{flex:"1"},disabled:a.mode=="view"||!a.form._college_id,modelValue:a.form._major_id,"onUpdate:modelValue":o=>a.form._major_id=o,placeholder:"请选择专业",filterable:"",clearable:"",onChange:()=>z(a)},{default:t(()=>[(n(!0),m(v,null,h(k(a.form._college_id),o=>(n(),s(i,{key:o.id,label:o.name,value:o.id},null,8,["label","value"]))),128))]),_:2},1032,["disabled","modelValue","onUpdate:modelValue","onChange"])]),form_grade_or_level:t(a=>[d(g,{style:{flex:"1"},disabled:a.mode=="view"||!a.form._major_id,modelValue:a.form._grade_id,"onUpdate:modelValue":o=>a.form._grade_id=o,placeholder:"请选择年级",filterable:"",clearable:"",onChange:()=>U(a)},{default:t(()=>[(n(!0),m(v,null,h(x(a.form._major_id),o=>(n(),s(i,{key:o.id,label:o.name,value:o.id},null,8,["label","value"]))),128))]),_:2},1032,["disabled","modelValue","onUpdate:modelValue","onChange"])]),_:1},16),d(q,{modelValue:p.value,"onUpdate:modelValue":l[1]||(l[1]=a=>p.value=a),title:"导入用户信息",width:"30%"},{footer:t(()=>[d(r,{onClick:l[0]||(l[0]=a=>p.value=!1)},{default:t(()=>l[6]||(l[6]=[_("取消")])),_:1}),d(r,{type:"primary",onClick:D},{default:t(()=>l[7]||(l[7]=[_("确认导入")])),_:1})]),default:t(()=>[d(N,{ref:"uploadRef","auto-upload":!1,"file-list":c.value,limit:1,"on-change":T,"before-upload":()=>!1,accept:".xls,.xlsx"},{default:t(()=>[d(r,{type:"primary"},{default:t(()=>l[5]||(l[5]=[_("选择文件")])),_:1})]),_:1},8,["file-list"])]),_:1},8,["modelValue"])]),_:1})}}});export{pe as default};