|
|
@ -1,4 +1,5 @@ |
|
|
|
'use strict'; |
|
|
|
import moment from 'moment'; |
|
|
|
import React, { useState } from 'react'; |
|
|
|
import { connect } from 'react-redux'; |
|
|
|
import { Modal, Form, Button, Notification } from '@douyinfe/semi-ui'; |
|
|
@ -10,7 +11,7 @@ import ExportJsonExcel from 'js-export-excel'; |
|
|
|
import { rule } from './table-input-rule' |
|
|
|
//下载模板和上传文件读取
|
|
|
|
const ImportMembersModal = props => { |
|
|
|
const { dispatch, onCancel } = props |
|
|
|
const { dispatch, onCancel, xqMembers } = props |
|
|
|
const [msg, setMsg] = useState('') |
|
|
|
const [loading, setLoading] = useState('') |
|
|
|
const [postData, setPostData] = useState([]) |
|
|
@ -20,13 +21,13 @@ const ImportMembersModal = props => { |
|
|
|
setLoading(true) |
|
|
|
dispatch(membersBulkAdd(postData)).then(res => { |
|
|
|
if (res.success) { |
|
|
|
Notification.success('导入员工信息成功') |
|
|
|
//Notification.success({ content: '导入员工信息成功', duration: 2 })
|
|
|
|
onCancel() |
|
|
|
} |
|
|
|
setLoading(false) |
|
|
|
}) |
|
|
|
} else { |
|
|
|
Notification.warn('没有数据可以提交,请上传数据文件') |
|
|
|
Notification.warning({ content: '没有数据可以提交,请上传数据文件', duration: 2 }) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -110,6 +111,9 @@ const ImportMembersModal = props => { |
|
|
|
|
|
|
|
const judgePlace = (place) => { |
|
|
|
let valid = true; |
|
|
|
if (!place) {//可以不填
|
|
|
|
return valid; |
|
|
|
} |
|
|
|
if (place.split('-').length == 1) {//判断籍贯
|
|
|
|
if (['北京市', '上海市', '天津市', '重庆市'].indexOf(place) == -1) { |
|
|
|
valid = false; |
|
|
@ -132,10 +136,35 @@ const ImportMembersModal = props => { |
|
|
|
return valid; |
|
|
|
} |
|
|
|
|
|
|
|
const judgeTimeValid = (time) => { |
|
|
|
let valid = true; |
|
|
|
if (!time) { |
|
|
|
return valid;//可以不填
|
|
|
|
} |
|
|
|
const ymd = /^((19|20)[0-9]{2})[\/\-]((0[1-9])|(1[0-2]))[\/\-]((0[1-9])|((1|2)[0-9])|(3[0-1]))$/;//年月日
|
|
|
|
if (time instanceof Date) { |
|
|
|
let timeStr = moment(time).format('YYYY/MM/DD'); |
|
|
|
if (!ymd.test(timeStr)) { |
|
|
|
valid = false; |
|
|
|
} |
|
|
|
} else { |
|
|
|
valid = false; |
|
|
|
} |
|
|
|
return valid; |
|
|
|
} |
|
|
|
|
|
|
|
const judgeNull = (value) => { |
|
|
|
return value ? String(value).trim().replace(/\s*/g, "") : null; |
|
|
|
} |
|
|
|
|
|
|
|
const judgeNullTime = (v) => { |
|
|
|
//注意的点:xlsx将excel中的时间内容解析后,会小一天
|
|
|
|
//如2020/8/1,xlsx会解析成 Fri Jul 31 2020 23:59:17 GMT+0800 小了43秒
|
|
|
|
let a = new Date(v); |
|
|
|
a.setTime(a.getTime() + 43 * 1000); |
|
|
|
return v ? a : null; |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
|
<Modal |
|
|
|
title="导入信息" visible={true} |
|
|
@ -154,6 +183,10 @@ const ImportMembersModal = props => { |
|
|
|
label={'员工信息'} labelPosition='left' |
|
|
|
action={'/'} accept={fileLimit} |
|
|
|
maxSize={200} limit={1} |
|
|
|
onRemove={(currentFile, fileList, fileItem) => { |
|
|
|
setMsg(''); |
|
|
|
setPostData([]); |
|
|
|
}} |
|
|
|
customRequest={(data) => { |
|
|
|
const { file, onSuccess, onError } = data |
|
|
|
getFileBlob(file.url).then(res => { |
|
|
@ -173,7 +206,7 @@ const ImportMembersModal = props => { |
|
|
|
const zmsz = /^[A-Za-z0-9]+$/;//字母数字组合
|
|
|
|
const pattern = /^1[3|4|5|6|7|8|9]\d{9}$/; |
|
|
|
const sfz = /^[1-9]\d{5}(18|19|([23]\d))\d{2}((0[1-9])|(10|11|12))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;//身份证
|
|
|
|
const ymd = /^((19|20)[0-9]{2})[\/\-]((0[1-9])|(1[0-2]))[\/\-]((0[1-9])|((1|2)[0-9])|(3[0-1]))$/;//年月日
|
|
|
|
//const ymd = /^((19|20)[0-9]{2})[\/\-]((0[1-9])|(1[0-2]))[\/\-]((0[1-9])|((1|2)[0-9])|(3[0-1]))$/;//年月日
|
|
|
|
const num0 = /^\d+$/;//正整数+0
|
|
|
|
for (let i = 0; i < res.length; i++) { |
|
|
|
let d = res[i]; |
|
|
@ -182,7 +215,7 @@ const ImportMembersModal = props => { |
|
|
|
let name = judgeNull(d['姓名']); |
|
|
|
let idNumber = judgeNull(d['证件号']); |
|
|
|
let gender = judgeNull(d['性别(男/女)']); |
|
|
|
let birthday = judgeNull(d['出生年月日(例2022/02/01)']); |
|
|
|
let birthday = judgeNullTime(d['出生年月日(例2022/02/01)']);//-------判断时间
|
|
|
|
let nativePlace = judgeNull(d['籍贯']); |
|
|
|
let marital = judgeNull(d['婚育状态(已婚/未婚/已婚已育)']); |
|
|
|
|
|
|
@ -192,12 +225,12 @@ const ImportMembersModal = props => { |
|
|
|
let graduatedFrom = judgeNull(d['毕业院校']); |
|
|
|
let educationBackground = judgeNull(d['学历']); |
|
|
|
let specialty = judgeNull(d['专业']); |
|
|
|
let graduationDate = judgeNull(d['毕业时间']); |
|
|
|
let graduationDate = judgeNullTime(d['毕业时间']);//-------------------判断时间
|
|
|
|
|
|
|
|
let hiredate = judgeNull(d['入职时间']); |
|
|
|
let turnProbationPeriod = judgeNull(d['转试用期时间']); |
|
|
|
let regularDate = judgeNull(d['转正时间']); |
|
|
|
let dimissionDate = judgeNull(d['离职日期']); |
|
|
|
let hiredate = judgeNullTime(d['入职时间']);//-------------------------判断时间
|
|
|
|
let turnProbationPeriod = judgeNullTime(d['转试用期时间']);//-----------判断时间
|
|
|
|
let regularDate = judgeNullTime(d['转正时间']);//----------------------判断时间
|
|
|
|
let dimissionDate = judgeNullTime(d['离职日期']);//---------------------判断时间
|
|
|
|
let experienceYear = judgeNull(d['工作经验(年)']); |
|
|
|
let occupationalHistory = judgeNull(d['历史工作经历与职务']); |
|
|
|
|
|
|
@ -217,18 +250,20 @@ const ImportMembersModal = props => { |
|
|
|
error(`第${i + 1}行姓名为空,请填写`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (!sfz.test(idNumber)) { |
|
|
|
if (idNumber && !sfz.test(idNumber)) { |
|
|
|
error(`第${i + 1}行证件号错误`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (['男', '女'].indexOf(gender) == -1) { |
|
|
|
if (gender && ['男', '女'].indexOf(gender) == -1) { |
|
|
|
error(`第${i + 1}行性别错误`) |
|
|
|
return |
|
|
|
} |
|
|
|
// if (!ymd.test(birthday)) {
|
|
|
|
// error(`第${i + 1}行出生年月日错误,请填写yyyy/mm/dd格式`)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
|
|
|
|
let bsdValid = judgeTimeValid(birthday); |
|
|
|
if (!bsdValid) { |
|
|
|
error(`第${i + 1}行出生年月日错误,请填写yyyy/mm/dd格式`) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
let jgValid = judgePlace(nativePlace); |
|
|
|
if (!jgValid) { |
|
|
@ -236,15 +271,15 @@ const ImportMembersModal = props => { |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
if (['已婚', '未婚', '已婚已育'].indexOf(marital) == -1) { |
|
|
|
if (marital && ['已婚', '未婚', '已婚已育'].indexOf(marital) == -1) { |
|
|
|
error(`第${i + 1}行婚育状态错误`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (['群众', '党员'].indexOf(politicsStatus) == -1) { |
|
|
|
if (politicsStatus && ['群众', '党员'].indexOf(politicsStatus) == -1) { |
|
|
|
error(`第${i + 1}行政治面貌错误`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (!pattern.test(phoneNumber)) { |
|
|
|
if (phoneNumber && !pattern.test(phoneNumber)) { |
|
|
|
error(`第${i + 1}行联系方式错误`) |
|
|
|
return |
|
|
|
} |
|
|
@ -253,43 +288,49 @@ const ImportMembersModal = props => { |
|
|
|
error(`第${i + 1}行工作地点错误`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (['小学', '初中', '高中', '大专', '本科', '研究生', '博士'].indexOf(educationBackground) == -1) { |
|
|
|
if (educationBackground && ['小学', '初中', '高中', '大专', '本科', '研究生', '博士'].indexOf(educationBackground) == -1) { |
|
|
|
error(`第${i + 1}行学历错误`) |
|
|
|
return |
|
|
|
} |
|
|
|
// if (!ymd.test(graduationDate)) {
|
|
|
|
// error(`第${i + 1}行毕业时间错误,请填写yyyy/mm/dd格式`)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// if (!ymd.test(hiredate)) {
|
|
|
|
// error(`第${i + 1}行入职时间错误,请填写yyyy/mm/dd格式`)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// if (!ymd.test(turnProbationPeriod)) {
|
|
|
|
// error(`第${i + 1}行转试用期时间错误,请填写yyyy/mm/dd格式`)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// if (!ymd.test(regularDate)) {
|
|
|
|
// error(`第${i + 1}行转正时间错误,请填写yyyy/mm/dd格式`)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
// if (!ymd.test(dimissionDate)) {
|
|
|
|
// error(`第${i + 1}行离职日期错误,请填写yyyy/mm/dd格式`)
|
|
|
|
// return
|
|
|
|
// }
|
|
|
|
if (!num0.test(experienceYear)) { |
|
|
|
let byValid = judgeTimeValid(graduationDate); |
|
|
|
if (!byValid) { |
|
|
|
error(`第${i + 1}行毕业时间错误,请填写yyyy/mm/dd格式`) |
|
|
|
return |
|
|
|
} |
|
|
|
let rzhValid = judgeTimeValid(hiredate); |
|
|
|
if (!rzhValid) { |
|
|
|
error(`第${i + 1}行入职时间错误,请填写yyyy/mm/dd格式`) |
|
|
|
return |
|
|
|
} |
|
|
|
let shyValid = judgeTimeValid(turnProbationPeriod); |
|
|
|
if (!shyValid) { |
|
|
|
error(`第${i + 1}行转试用期时间错误,请填写yyyy/mm/dd格式`) |
|
|
|
return |
|
|
|
} |
|
|
|
let zhzhValid = judgeTimeValid(regularDate); |
|
|
|
if (!zhzhValid) { |
|
|
|
error(`第${i + 1}行转正时间错误,请填写yyyy/mm/dd格式`) |
|
|
|
return |
|
|
|
} |
|
|
|
let lzhValid = judgeTimeValid(dimissionDate); |
|
|
|
if (!lzhValid) { |
|
|
|
error(`第${i + 1}行离职日期错误,请填写yyyy/mm/dd格式`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (experienceYear && !num0.test(experienceYear)) { |
|
|
|
error(`第${i + 1}行工作经验(年)错误,请填写非负整数`) |
|
|
|
return |
|
|
|
} |
|
|
|
postData.push({//人员编号 待办todotodo
|
|
|
|
pepUserId: 555, name, idNumber, gender, birthday, nativePlace, marital, |
|
|
|
politicsStatus, phoneNumber, workPlace, graduatedFrom, educationBackground, specialty, graduationDate, |
|
|
|
hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory |
|
|
|
hiredate, turnProbationPeriod, regularDate, dimissionDate, experienceYear, occupationalHistory, |
|
|
|
del: false |
|
|
|
}) |
|
|
|
} |
|
|
|
if (postData.length) { |
|
|
|
setPostData(postData) |
|
|
|
} |
|
|
|
//if (postData.length) {
|
|
|
|
setPostData(postData) |
|
|
|
//}
|
|
|
|
let msg = '文件解析完成,点击确定按钮上传保存!' |
|
|
|
setMsg(msg) |
|
|
|
onSuccess({ message: msg }) |
|
|
|