import React, { Component } from 'react';
import {
Alert,
Steps,
Upload,
message,
Button,
Modal,
Table,
Spin
} from 'antd';
import { connect } from 'dva';
import { withRouter } from 'dva/router';
import store from 'store';
import moment from 'moment';
import './less/batch.less';
import {
host,
systemComDepartImportDepart,
enterpriseInsComInsGetOnlineInsBlbPreservationLink, //生成保全,
systemComVaseInfoGet, //获取部门信息
findUninsuredPerList
} from '../../../services/api';
import axios from 'axios';
import $nModal from '../../../utils/modal/nModal';
import ExcelButtonOline from "../../../components/ExcelButtonOline";
const { Step } = Steps;
let newwin;
@connect(
state => ({
profile: state.profile,
global: state.global
})
)
// 批量导入-新建组织机构
@withRouter
export default class BatchImport extends Component {
constructor(props, context) {
super(props, context);
this.state = {
addpeoplevisible: false,
addpeoplevisible1: false,
dataSource: [],
perIds: [],
//导入人员
visible: false,
visibleFormat: false,
uploadResponse: [], //格式正确后返回的json字符串
dataFormat: '', //格式错误提示内容
comId: '', //企业Id
faileDisabled: 'none', //上传文件失败显示下载失败文件
failData: '', //上传文件失败返回的数据
loading: false,
blackNameList:[],//上传文件成功有黑名单人员列表
};
}
componentWillMount() {
this.systemComVaseInfoGet();
}
systemComVaseInfoGet = () => {
systemComVaseInfoGet({}).then(
response => {
this.setState({
comId: response.data.comId
});
},
err => {
console.log(err, 'systemComVaseInfoGet-err-获取企业详情');
}
);
};
//批量导入组织架构
systemComDepartImportDepart = () => {
systemComDepartImportDepart({
data: JSON.stringify(this.state.uploadResponse)
}).then(
data => {
if (data.msg !== '') {
data.msg = data.msg.replace(/
/, '').trim();
}
message.success(data.msg);
const perIds = data.data.map(val => val.perId);
this.setState({ perIds });
if (this.state.dataSource.length > 0) {
this.setState({
addpeoplevisible: true
});
}
},
err => {
console.log(err, 'systemComDepartImportDepart-err-批量导入组织架构');
}
);
};
showModal = () => {
this.setState({
visible: true
});
};
handleOk = ifError => {
this.setState({
visible: false
});
if (!ifError) {
this.systemComDepartImportDepart();
}
};
handleCancel = e => {
this.setState({
visible: false
});
};
//保险选择
renderTable = () => {
const rowSelection = {
type: 'radio',
selectedRowKeys: this.state.selectedRowKeys,
onChange: selectedRowKeys => {
this.setState({ selectedRowKeys });
},
getCheckboxProps: record => ({
disabled: record.name === 'Disabled User' // Column configuration not to be checked
})
};
const columns = [
{
title: '订单号',
dataIndex: 'blbOrderId',
key: 'blbOrderId'
},
{
title: '保险产品',
dataIndex: 'insComName',
key: 'insComName'
},
{
title: '人数',
dataIndex: 'perNum',
key: 'perNum'
},
{
title: '购买时间',
dataIndex: 'effectStartDate',
key: 'effectStartDate'
}
];
return (
);
};
//保全链接生成
enterpriseInsComInsGetOnlineInsBlbPreservationLink = () => {
enterpriseInsComInsGetOnlineInsBlbPreservationLink({
orderId: this.state.selectedRowKeys,
perIds: this.state.perIds.join(','),
reviseType: '1'
})
.then(res => {
this.setState({ addpeoplevisible1: false });
newwin.location.href = res.data;
})
.catch(err => {
newwin.close();
this.setState({ addpeoplevisible1: false });
});
};
//格式错误提示框
handleFormatOk = () => {
this.setState({ visibleFormat: false });
};
//下载
handleClickLink = () => {
return (
//
);
};
//上传
handleClickUpload = () => {
const uploadExcel = {
name: 'xfile',
// action: `${host}/system/com-depart/get-import-depart-json`,
action: `${host}/system/com-depart/import-excel-per`,
headers: {
authorization: 'Basic c2Fhc3dlYjp3ZWI=',
access_token: store.get('saas')['access_token'],
Accesstoken: store.get('saas')['access_token']|| sessionStorage.userV5Token,
},
showUploadList: false,
// responseType:'blob',
data: {}
};
const beforeUpload = file => {
this.setState({
loading: true
});
let ifError = true;
if (file.name.indexOf('xls') === -1 && file.name.indexOf('xlsx') === -1) {
this.setState({
loading: false
});
message.error('请上传xls或xlsx文件!');
return false
}
console.log(file.size)
if(file.size/1024/1024 > 1.5){
this.setState({
loading: false
});
message.error('请上传小于1.5M文件!');
ifError = false;
}
return ifError;
};
//上传文件
const UploadChange = async info => {
this.setState({
faileDisabled: 'none',
// loading: true
});
if (info.file.status === 'uploading') {
return;
}
if (info.file.status === 'done') {
const { data, msg, retType } = info.file.response;
this.setState({
blackNameList:data?data.blackList:[]
})
//"retType":"-1"为错误,data会有相应的路径值
//"retType":"0"为正确,data为空
if (retType === '-1') {
message.error(msg);
this.setState({
faileDisabled: 'block',
failData: data
});
} else if (retType === '0') {
const unInsureNumRes = await findUninsuredPerList({
perType: '', //人员类型
keyword: '', //关键字
departId: '', //部门id
pageNumber: '1', // 页
pageSize: '10' //条目
});
const nowTimeStamp = moment().valueOf();
const preTimeStamp = store.get('addPersonModalTime');
let canShow = false;
if (!preTimeStamp) {
canShow = true;
} else {
if (nowTimeStamp - preTimeStamp > 2 * 60 * 1000) {
canShow = true;
}
}
let successCount = 0;
const matchInfo = msg.match(/【\d+】/g);
if (matchInfo && matchInfo[1]) {
successCount = matchInfo[1].replace(/^【/, '').replace(/】$/, '');
}
// 未投保人数
const unInsureNum = unInsureNumRes.data.other;
// 存在未投保人数并且距离上一次弹窗时间大于2分钟并且是服务公司的时候弹窗
if (unInsureNum > 0 &&
canShow &&
(this.props.global.companyInfo.institutionType == '0102' || this.props.global.companyInfo.institutionType == '0104')
) {
store.set('addPersonModalTime', nowTimeStamp);
$nModal({
title: '保险增员提示',
destroyOnClose: true,
okText: "马上办理",
cancelText: '取消',
content:
*保险产品的新增、减员等操作可通过【人员投保管理】-【未投保】【已投保】选择相应人员进行保全增减操作!
本次新增人员 {successCount} 位,还存在 {unInsureNum} 位人员未投保,执行任务存在风险,请及时为其投保,以减轻企业负担!
,
onOk: close => {
close();
this.props.history.push('/insurancemanagement/insurance-management?tab=1');
}
});
// this.props.dispatch({
// type: 'insurance/showQuitModal',
// payload: {
// title: '保险增员提示',
// type: 'add',
// warningText: '*保险产品的新增、减员等操作可通过【人员投保管理】-【未投保】【已投保】选择相应人员进行保全增减操作!',
// contentText: `本次新增人员 ${successCount} 位,还存在 ${unInsureNum} 位人员未投保,执行任务存在风险,请及时为其投保,以减轻企业负担!`,
// okCallBack: () => {
// this.props.history.push('/insurancemanagement/insurance-management?tab=1');
// }
// }
// });
} else {
message.success(msg);
}
} else {
message.error(msg);
}
this.setState({
loading: false
});
}
};
const columns = [
{
title: '序号',
dataIndex: 'index',
key: 'index',
render:(text,record,index)=>{
return {index+1}
}
},
{
title: '姓名',
dataIndex: 'name',
key: 'name'
},
{
title: '身份证号',
dataIndex: 'idCardNo',
key: 'idCardNo',
render:(text)=> {
return{text}
}
},
{
title: '手机号',
dataIndex: 'mobilePhone',
key: 'mobilePhone',
render:(text)=> {
return{text}
}
},
{
title: '入单原因',
dataIndex: 'reason',
key: 'reason',
}
];
return (
{
return (
系统正在为您识别并导入数据内容...
若数据量较大,导入时间相对偏长,请耐心等待
);
})()}
/>
{
this.state.blackNameList.length>0&&
本次成功导入入职的人员中以下人员为行业黑名单人员,若有疑问请咨询监管机构进行了解。
}
);
};
//导入通讯录
// renderUploadResult = () => {
// const columns = [
// {
// title: '姓名',
// dataIndex: 'name',
// key: 'name',
// // fixed: 'left',
// width: '120'
// },
// {
// title: '证件类型',
// dataIndex: 'idCardType',
// key: 'idCardType'
// },
// {
// title: '证件号码',
// dataIndex: 'idCardNo',
// key: 'idCardNo'
// },
// {
// title: '手机号',
// dataIndex: 'mobilePhone',
// key: 'mobilePhone'
// },
// {
// title: '部门名称',
// dataIndex: 'departName',
// key: 'departName',
// width: '140px'
// },
// {
// title: '角色',
// dataIndex: 'roleName',
// key: 'roleName',
// width: '130px'
// },
// {
// title: '入职时间',
// dataIndex: 'entryDate',
// key: 'entryDate'
// },
// {
// title: '校验提示',
// dataIndex: 'errorMsg',
// key: 'errorMsg'
// }
// ];
// //格式错误列展示
// let uploadResponse = JSON.parse(JSON.stringify(this.state.uploadResponse));
// //后台的为null 统一转""
// uploadResponse = uploadResponse.map(val => {
// Object.keys(val).forEach(v => {
// if (v === 'entryDate') {
// val[v] = val[v].slice(0, 10);
// }
// if (!val[v]) {
// val[v] = '';
// }
// });
// return val;
// });
// //过滤,包含错误信息的数组
// const errorLength = uploadResponse.filter(
// val => val.errorMsg.trim() !== ''
// );
// const ifError = errorLength.length !== 0; //判断是否包含错误信息
// let alert = '';
// if (ifError) {
// //上传失败
// uploadResponse = uploadResponse.map(val => {
// if (val.errorMsg !== '') {
// val.errorMsg = val.errorMsg.replace(/
/, '').trim();
// }
// return val;
// });
// alert = (
//
// );
// } else {
// //上传成功
// alert = (
//
// );
// columns.pop();
// }
// return (
//
// {alert}
//
//
// );
// };
//加载格式错误提示框
// renderUploadFormat = () => {
// const columnsFormat = [
// {
// title: '序号',
// dataIndex: 'index',
// key: 'index'
// },
// {
// title: '错误提示',
// dataIndex: 'info',
// key: 'info'
// }
// ];
// const { dataFormat } = this.state;
// const [total, ...errorInfo] = dataFormat.split('
');
// if (errorInfo.length !== 1) {
// errorInfo.pop();
// }
// const errorInfos = errorInfo.map((val, key) => {
// return {
// index: key + 1,
// info: val,
// key
// };
// });
// return (
//
//
//
//
// );
// };
render() {
return (
{/* */}
{/* 导入通讯录弹窗 */}
{/* {this.renderUploadResult()} */}
{/*格式错误提示框*/}
{/* {this.renderUploadFormat()} */}
this.setState({ addpeoplevisible: false })}
footer={[
,
]}
>
本次新增人员共
{this.state.perIds.length}
位,企业目前已购买团意险产品[产品名称](订单号:[订单编号]),企业可对新增人员办理保险保全的增员操作。
this.setState({ addpeoplevisible1: false })}
footer={[
,
]}
>
{this.renderTable()}
);
}
}
const pageInitStudent = {
defaultPageSize: 10,
showQuickJumper: true,
pageSizeOptions: ['10', '20', '50'],
showSizeChanger: true
};