|
|
@ -2,12 +2,12 @@ |
|
|
|
import React, { useState, useEffect } from 'react'; |
|
|
|
import { connect } from 'react-redux'; |
|
|
|
import moment from 'moment'; |
|
|
|
import { Modal, Form, Button, Notification } from '@douyinfe/semi-ui'; |
|
|
|
import { Modal, Form, Button, Notification,Toast } from '@douyinfe/semi-ui'; |
|
|
|
import { IconUpload } from '@douyinfe/semi-icons'; |
|
|
|
import XLSX from 'xlsx' |
|
|
|
//下载模板和上传文件读取 |
|
|
|
const ImportPerformanceSummaryModal = props => { |
|
|
|
const { dispatch, actions, onCancel } = props; |
|
|
|
const { dispatch, actions, onCancel,query } = props; |
|
|
|
const { businessManagement } = actions |
|
|
|
const [msg, setMsg] = useState(''); |
|
|
|
const [loading, setLoading] = useState(''); |
|
|
@ -18,12 +18,11 @@ const ImportPerformanceSummaryModal = props => { |
|
|
|
const confirm = () => { |
|
|
|
if (postData.length) { |
|
|
|
setLoading(true) |
|
|
|
console.log(postData,'-------------------') |
|
|
|
const { postAllPersonalTrainRecord,getPersonalTrainRecord } = actions.humanAffairs |
|
|
|
dispatch(postAllPersonalTrainRecord(postData)).then(res => { |
|
|
|
if (res.success) { |
|
|
|
onCancel() |
|
|
|
dispatch(getPersonalTrainRecord()) |
|
|
|
dispatch(getPersonalTrainRecord(query)) |
|
|
|
} |
|
|
|
setLoading(false) |
|
|
|
}) |
|
|
@ -32,24 +31,6 @@ const ImportPerformanceSummaryModal = props => { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
const dldCsvMb = () => { |
|
|
|
//表头 |
|
|
|
let head = []; |
|
|
|
Object.keys(personalTrainRecord).map(key => { |
|
|
|
head.push(personalTrainRecord[key]); |
|
|
|
}) |
|
|
|
head = head.join(',') + "\n"; |
|
|
|
//数据 |
|
|
|
//let data = 1 + ',' + 2 + ',' + 3 + ',' + 4 + ',' + 5 |
|
|
|
let templateCsv = "data:text/xlsx;charset=utf-8,\ufeff" + head; |
|
|
|
//创建一个a标签 |
|
|
|
let link = document.createElement("a"); |
|
|
|
//为a标签设置属性 |
|
|
|
link.setAttribute("href", templateCsv); |
|
|
|
link.setAttribute("download", "个人培训记录表模板.xlsx"); |
|
|
|
//点击a标签 |
|
|
|
link.click(); |
|
|
|
} |
|
|
|
const download = () => { |
|
|
|
const head = [["姓名", "部门", "培训类型", "课程主题", "培训讲师", "培训时间", "培训时长", "培训方式", "考勤分数","考核形式","考核分数","总分"]]; |
|
|
|
let sheetName = '个人培训'; |
|
|
@ -105,35 +86,12 @@ const ImportPerformanceSummaryModal = props => { |
|
|
|
request.send(); |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 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; |
|
|
|
// } |
|
|
|
|
|
|
|
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 changeTime = (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 a; |
|
|
|
} |
|
|
|
|
|
|
|
return ( |
|
|
@ -183,26 +141,55 @@ const ImportPerformanceSummaryModal = props => { |
|
|
|
obj[key] = d[personalTrainRecord[key]] || null; |
|
|
|
//} |
|
|
|
}) |
|
|
|
// let tValid = judgeTimeValid(obj.recConDate); |
|
|
|
// if (!tValid) { |
|
|
|
// error(`第${i + 2}行【收到合同日期】错误,请填写yyyy/mm/dd格式`) |
|
|
|
// return |
|
|
|
// } |
|
|
|
|
|
|
|
// if (obj.isApproval && ['是', '否'].indexOf(obj.isApproval) == -1) { |
|
|
|
// error(`第${i + 2}行【价格是否特批】错误,请填写是或否`) |
|
|
|
if (!obj.personalName) { |
|
|
|
Toast.error(`第${i + 2}行,姓名为空,请填写`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (!obj.departmentName) { |
|
|
|
Toast.error(`第${i + 2}行,部门为空,请填写`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (!obj.trainingType) { |
|
|
|
Toast.error(`第${i + 2}行,培训类型为空,请填写`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (!obj.topic) { |
|
|
|
Toast.error(`第${i + 2}行,课程主题为空,请填写`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (!obj.trainer) { |
|
|
|
Toast.error(`第${i + 2}行,培训讲师为空,请填写`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (!obj.trainDate) { |
|
|
|
Toast.error(`第${i + 2}行,培训时间为空,请填写`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (!obj.trainTime) { |
|
|
|
Toast.error(`第${i + 2}行,培训时长为空,请填写`) |
|
|
|
return |
|
|
|
} |
|
|
|
if (!obj.trainMethod) { |
|
|
|
Toast.error(`第${i + 2}行,培训方式为空,请填写`) |
|
|
|
return |
|
|
|
} |
|
|
|
// if (!obj.attendanceScore) { |
|
|
|
// error(`第${i + 2}考勤分数为空,请填写`) |
|
|
|
// return |
|
|
|
// } |
|
|
|
// //复购次数 正整数 |
|
|
|
// if (obj.repurchaseCount && !zzsPattern.test(obj.repurchaseCount)) { |
|
|
|
// error(`第${i + 2}行【复购次数】填写错误,需要为非负整数`) |
|
|
|
if (!obj.appraisalMethod) { |
|
|
|
Toast.error(`第${i + 2}考核形式为空,请填写`) |
|
|
|
return |
|
|
|
} |
|
|
|
// if (!obj.appraisalScore) { |
|
|
|
// Toast.error(`第${i + 2}考核分数为空,请填写`) |
|
|
|
// return |
|
|
|
// } |
|
|
|
|
|
|
|
// if (obj.reproducible && ['是', '否'].indexOf(obj.reproducible) == -1) { |
|
|
|
// error(`第${i + 2}行【是否可复制的业务路径】错误,请填写是或否`) |
|
|
|
// if (!obj.totalScore) { |
|
|
|
// Toast.error(`第${i + 2}总分为空,请填写`) |
|
|
|
// return |
|
|
|
// } |
|
|
|
obj.trainDate = changeTime(obj.trainDate) |
|
|
|
postData.push(obj); |
|
|
|
} |
|
|
|
setPostData(postData) |
|
|
|