You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

370 lines
9.4 KiB
TypeScript

2 years ago
import React, { useState, useRef } from "react";
import { message, Button, Popconfirm, FormInstance } from "antd";
import { TableListItem, TableListPagination } from "./data";
import { queryRule, updateRule, removeRule, addRule, getAllInfoSettingValueBySettingName, exportEmployee } from "./service";
import UpdateForm, { FormValueType } from './components/UpdateForm';
import ProTable, { ActionType, ProColumns } from "@ant-design/pro-table";
import Import from "@/components/Import/Import";
/**
*
* @param fields
*/
const handleUpdate = async (fields: FormValueType) => {
const hide = message.loading('正在保存');
if (!fields.id) {
// eslint-disable-next-line no-param-reassign
delete fields.id
try {
const msg = await addRule({...fields});
hide();
if (msg.retcode) {
message.success('添加成功');
} else {
message.error('添加失败请重试!');
}
return true;
} catch (error) {
hide();
message.error('添加失败请重试!');
return false;
}
} else {
try {
const msg = await updateRule({...fields});
hide();
if (msg.retcode) {
message.success('保存成功');
} else {
message.error('保存失败请重试!');
}
return true;
} catch (error) {
hide();
message.error('保存失败请重试!');
return false;
}
}
};
/**
*
* @param selectedRows
*/
const handleExportEmployee = async ({ ...params }: any) => {
const hide = message.loading('正在导出');
try {
await exportEmployee(params);
hide();
return true;
} catch (error) {
hide();
message.error('处理失败,请重试');
return false;
}
};
/**
*
* @param id
*/
const handleRemove = async (id?: number) => {
const hide = message.loading('正在删除');
if (!id) return false;
try {
const msg = await removeRule({
id
});
hide();
if (msg.retcode) {
message.success('删除成功,即将刷新');
} else {
message.error('删除失败,请重试');
}
return true;
} catch (error) {
hide();
message.error('删除失败,请重试');
return false;
}
};
const fetchData = async ({ ...params }: any) => {
const msg = await queryRule(params);
console.log(msg)
return {
data: msg.data?.list || [],
total: msg.data?.total || 0,
success: msg.retcode,
};
};
const UserList: React.FC<{}> = () => {
const actionRef = useRef<ActionType>();
const [updateModalVisible, handleUpdateModalVisible] = useState<boolean>(false);
const [currentRow, setCurrentRow] = useState({});
const ref = useRef<FormInstance<TableListItem>>();
const columns: ProColumns<TableListItem>[] = [
{
title: '姓名',
dataIndex: 'employeeName',
},
{
title: '员工编号',
dataIndex: 'employeeNo',
},
{
title: '手机号',
dataIndex: 'mobile',
},
{
title: '单位',
dataIndex: 'unitId',
valueType: 'select',
request: async () => {
const msg = await getAllInfoSettingValueBySettingName({settingName: '单位'})
if (msg.retcode && msg.data) {
return msg.data.map((e: any) => {
return {
label: e.settingValue,
value: e.id
}
})
}
return []
}
},
{
title: '现岗位',
dataIndex: 'postId',
valueType: 'select',
request: async () => {
const msg = await getAllInfoSettingValueBySettingName({settingName: '岗位'})
if (msg.retcode && msg.data) {
return msg.data.map((e: any) => {
return {
label: e.settingValue,
value: e.id
}
})
}
return []
}
},
{
title: '班组',
dataIndex: 'groupsId',
valueType: 'select',
request: async () => {
const msg = await getAllInfoSettingValueBySettingName({settingName: '班组'})
if (msg.retcode && msg.data) {
return msg.data.map((e: any) => {
return {
label: e.settingValue,
value: e.id
}
})
}
return []
}
},
{
title: '最高学历',
dataIndex: 'highestEducationId',
valueType: 'select',
request: async () => {
const msg = await getAllInfoSettingValueBySettingName({settingName: '学历'})
if (msg.retcode && msg.data) {
return msg.data.map((e: any) => {
return {
label: e.settingValue,
value: e.id
}
})
}
return []
}
},
{
title: '专业技术资格',
dataIndex: 'ptqId',
valueType: 'select',
fieldProps: {
mode: "multiple"
},
formItemProps: {
name: 'ptqIds'
},
request: async () => {
const msg = await getAllInfoSettingValueBySettingName({settingName: '专业技术资格'})
if (msg.retcode && msg.data) {
return msg.data.map((e: any) => {
return {
label: e.settingValue,
value: e.id
}
})
}
return []
}
},
{
title: '技能等级',
dataIndex: 'skillLevelId',
valueType: 'select',
request: async () => {
const msg = await getAllInfoSettingValueBySettingName({settingName: '技能等级'})
if (msg.retcode && msg.data) {
return msg.data.map((e: any) => {
return {
label: e.settingValue,
value: e.id
}
})
}
return []
}
},
{
title: '奖惩等级',
dataIndex: 'honorLevel',
valueType: 'select',
hideInTable: true,
request: async () => {
const msg = await getAllInfoSettingValueBySettingName({settingName: '奖惩等级'})
if (msg.retcode && msg.data) {
return msg.data.map((e: any) => {
return {
label: e.settingValue,
value: e.settingValue
}
})
}
return []
}
},
{
title: '奖惩内容',
dataIndex: 'honorDescription',
hideInTable: true,
},
{
title: "操作",
dataIndex: "option",
hideInSearch: true,
render: (text: any, record: TableListItem) => (
<span>
<a style={{ marginRight: 8 }} onClick={()=>{
handleUpdateModalVisible(true);
setCurrentRow(record);
}}></a>
<Popconfirm title="确定删除?" onConfirm={async () => {
const success = await handleRemove(record.id)
if (success) actionRef.current?.reload()
}}>
<a style={{color: 'red'}}></a>
</Popconfirm>
</span>
)
}
];
return (
<>
<ProTable<TableListItem, TableListPagination>
headerTitle={null}
actionRef={actionRef}
rowKey="id"
options={false}
formRef={ref}
toolBarRender={() => [
<Button
type="primary"
key="primary"
onClick={() => {
handleUpdateModalVisible(true);
setCurrentRow({
id: undefined,
});
}}
>
</Button>,
<Import
api={'/api/employee/importEmployee'}
text="批量导入员工基本信息"
uploaded={() => {
actionRef.current?.reload();
}}
/>,
<Import
api={'/api/educationResume/importEducationResume'}
text="批量导入员工教育履历"
uploaded={() => {
actionRef.current?.reload();
}}
/>,
<Import
api={'/api/familyMembers/importFamilyMembers'}
text="批量导入员工家庭成员"
uploaded={() => {
actionRef.current?.reload();
}}
/>,
<Import
api={'/api/workExperience/importWorkExperience'}
text="批量导入员工工作经历记录"
uploaded={() => {
actionRef.current?.reload();
}}
/>,
<Import
api={'/api/honor/importHonor'}
text="批量导入员工奖惩记录"
uploaded={() => {
actionRef.current?.reload();
}}
/>,
<Button
key="export"
type="primary"
onClick={() => {
const values = ref.current?.getFieldsValue();
handleExportEmployee(values);
}}
>
</Button>,
]}
request={fetchData}
columns={columns}
/>
{currentRow && Object.keys(currentRow).length ? (
<UpdateForm
onSubmit={async value => {
const success = await handleUpdate(value);
if (success) {
handleUpdateModalVisible(false);
setCurrentRow({});
actionRef.current?.reload()
}
}}
onCancel={() => {
handleUpdateModalVisible(false);
setCurrentRow({});
}}
updateModalVisible={updateModalVisible}
values={currentRow}
/>
) : null}
</>
)
}
export default UserList;