import{p as B,r as d,A as P,t as F,u as V,j as r,B as m,h as H,a_ as q,v as G,cj as b,ck as J,cl as K}from"./index-CKIL6d0V.js";import{r as w,u as N}from"./xlsx-DPk0xC4-.js";const v=""+new URL("template-Dk3Sgd3j.xls",import.meta.url).href,O=B.div`
  width: 100%; 
  height: 100%;
  background-color: ${t=>t.theme.colorBgContainer};
  .topBtns {
    height: 60px;
    padding: 0 20px;
    border-radius: 5px;
    margin-bottom: 15px;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    .btn {
      margin-left: 20px;
    }
    .uploads {
      position: relative;
      .uploadStyle {
        width: 100%;
        height: 100%;
        display: flex;
        justify-content: center;
        align-items: center;
        span {
          width: 88px;
          height: 32px;
          font-size: 14px;
          line-height: 32px;
          text-align: center;
          border-radius: ${t=>t.theme.borderRadius}px;
          color: ${t=>t.theme.colorLink};
          border: 1px solid ${t=>t.theme.colorBorder};
        }
      }
      
      .upload {
        position: absolute;
        width: 100%;
        height: 100%;
        cursor: pointer;
        top: 0;
        left: 0;
        opacity: 0;
        height: 30px;
        line-height: 30px;
        text-align: center;
      }

    }
  }
  .bottomTable {
    height: calc(100% - 75px);
    border-radius: 5px;
    overflow: auto;
    
    border-top: 1px solid ${t=>t.theme.colorBorder};
    background-color: ${t=>t.theme.colorBgContainer};
    .row {
      line-height: 40px;
      display: flex;
      font-size: 16px;
      border-bottom: 1px solid ${t=>t.theme.colorBorder};
      span {
        flex: 1;
        display: flex;
        justify-content: center;
        align-items: center;
        border-right: 1px solid ${t=>t.theme.colorBorder};
        &:nth-last-child(1) {
        border: none;
        padding: 0 10px;
      }
      }
    }
    .title {
      font-weight: 700;
      background-color: ${t=>t.theme.colorBgLayout};
    }
    .none {
      font-size: 18px;
      font-weight: 700;
      height: 50px;
      line-height: 50px;
      justify-content: center;
    }
  }
`,Q=B.div`
  width: 100%;
  height: 100%;
  overflow: auto;
  ul {
    border-radius: 5px;
    border: 1px solid ${t=>t.theme.colorBorder};
    li {
      height: 36px;
      display: flex;
      border-bottom: 1px solid ${t=>t.theme.colorBorder};
      &:nth-last-child(1) {
        border: none;
      }
      &:nth-child(2n) {
        background-color: ${t=>t.theme.colorBgLayout};
      }
      &:nth-child(1) {
        font-size: 16px;
        font-weight: 700;

      }
      span {
        flex: 1;
        display: flex;
        justify-content: center;
        align-items: center;
        border-right: 1px solid ${t=>t.theme.colorBorder};
        &:nth-last-child(1) {
        border: none;
      }
      }
    }
  }
`,W=d.memo(()=>{const{message:t}=P.useApp(),{token:D}=F.useToken(),k=V(),[S,g]=d.useState(!1),[f,$]=d.useState(null),[p,j]=d.useState(null);d.useEffect(()=>{(async()=>{const o=await(await fetch(v)).arrayBuffer(),s=w(o,{type:"array"}),h=s.SheetNames[0],u=s.Sheets[h],c=N.sheet_to_json(u,{header:1});$(c)})()},[]);const y=d.useRef(null),C=()=>{const e=document.createElement("a");e.href=v,e.download="template.xls",e.style.display="none",document.body.appendChild(e),e.click(),e.remove()},A=()=>{g(!0)},E=()=>{g(!1)},R=e=>{let n=!0;for(let o=0;o<e.length;o++){const s=b(e[o].pNum),h=b(e[o].pName),u=J(e[o].pSex),c=K(e[o].pBirthDate);if(e[o].pDepartment){const l=e[o].pDepartment.split("|");for(let i=0;i<l.length;i++)for(let x=i+1;x<l.length;x++)if(l[i]===l[x]){t.warning(`编号: ${e[o].pNum} &nbsp; 组织机构: ${l[x]} 重复, 请检查后再导入`,5),n=!1;return}}else{t.warning(`编号 ${e[o].pNum}的组织机构不符合格式,组织机构必填且只能依据顺序填写, 请检查后再导入`,5),n=!1;return}if(!s){t.warning(`编号 ${e[o].pNum} 不符合格式,编号由字母数字汉字组成,请检查后再导入`),n=!1;return}if(!h){t.warning(`编号 ${e[o].pNum}的姓名 ${e[o].pName} 不符合格式,姓名由字母数字汉字组成,请检查后再导入`),n=!1;return}if(!u){t.warning(`编号 ${e[o].pNum}的性别 ${e[o].pSex} 不符合格式,性别只能是由'男'或者'女',请检查后再导入`),n=!1;return}if(!c){t.warning(`编号 ${e[o].pNum}的出生日期 ${e[o].pBirthDate} 不符合格式,出生日期标准格式为'yyyy-MM-dd',请检查后再导入`),n=!1;return}n=!0}return n},T=e=>{let n=1;return e==="男"?n=1:e==="女"?n=2:n=0,n},z=e=>{let n=[];const o=e.target.files[0];if(o!==void 0){const s=new FileReader;s.onload=h=>{const u=new Uint8Array(h.target.result),c=w(u,{type:"array"}),l=c.SheetNames[0],i=c.Sheets[l];N.sheet_to_json(i,{header:1}).forEach((a,U)=>{const _=[a[4],a[5],a[6],a[7],a[8],a[9],a[10],a[11],a[12],a[13]],M=L(_);U>0&&a.length>0&&n.push({pNum:String(a[0]),pName:String(a[1]),pSex:String(a[2]),pBirthDate:String(a[3]),pDepartment:M})}),R(n)&&j(n)},s.readAsArrayBuffer(o),y.current.value=null}else{j(null);return}},I=async()=>{if(p&&p.length>0){const e=p.map(n=>(n.pSex=T(n.pSex),n));try{const n=await G("/api/Person/BatchAdd",e);n.code===200?(t.success(n.msg,3),k("/layout/everyman")):t.error(n.msg,3)}catch(n){t.error(n)}}else t.error("请选择要上传的数据",3)},L=e=>{let n=e[0],o=!1;for(let s=1;s<e.length;s++)e[s]&&(n=n+"|"+e[s]),e[s]===void 0&&e[s+1]&&(o=!0);return o&&(n=void 0),n};return r.jsxs(O,{theme:D,children:[r.jsxs("div",{className:"topBtns",children:[r.jsx("div",{className:"btn",children:r.jsx(m,{onClick:A,children:"模板预览"})}),r.jsx("div",{className:"btn",children:r.jsx(m,{onClick:C,children:"模板下载"})}),r.jsxs("div",{className:"btn uploads",children:[r.jsx("div",{className:"uploadStyle",children:r.jsx("span",{children:"上传文件"})}),r.jsx("input",{className:"upload",ref:y,type:"file",onChange:z})]}),r.jsx("div",{className:"btn",children:r.jsx(m,{onClick:I,children:"提交文件"})})]}),r.jsxs("div",{className:"bottomTable",children:[r.jsxs("div",{className:"row title",children:[r.jsx("span",{children:"编号"}),r.jsx("span",{children:"姓名"}),r.jsx("span",{children:"年龄"}),r.jsx("span",{children:"生日"}),r.jsx("span",{children:"组织机构"})]}),p?p.map(e=>r.jsxs("div",{className:"row",children:[r.jsx("span",{children:e.pNum}),r.jsx("span",{children:e.pName}),r.jsx("span",{children:e.pSex}),r.jsx("span",{children:e.pBirthDate}),r.jsx("span",{children:e.pDepartment})]},e.pNum)):r.jsx("div",{className:"row none",children:"暂无数据"})]}),r.jsx(H,{text:r.jsxs("span",{style:{fontSize:"24px"},children:[r.jsx(q,{})," 模板预览"]}),width:"70%",open:S,onCancel:E,footer:null,children:r.jsx(Q,{children:r.jsxs("ul",{children:[f&&f.filter(e=>e[0]).map((e,n)=>r.jsx("li",{children:f[0].map((o,s)=>r.jsx("span",{children:e[s]},s))},n)),r.jsx("li",{})]})})})]})});W.displayName="UserImport";export{W as default};
