import React, { useState, useRef } from "react"; import { message, Button, Popconfirm, FormInstance, InputNumber, Input } 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); return { data: msg.data?.list || [], total: msg.data?.total || 0, success: msg.retcode, }; }; const UserList: React.FC<{}> = () => { const actionRef = useRef(); const [updateModalVisible, handleUpdateModalVisible] = useState(false); const [currentRow, setCurrentRow] = useState({}); const ref = useRef>(); const columns: ProColumns[] = [ { title: '姓名', dataIndex: 'employeeName', }, { title: '员工编号', dataIndex: 'employeeNo', }, { title: '手机号', dataIndex: 'mobile', }, { title: '出生日期', dataIndex: 'birthday', search: false }, { title: '性别', dataIndex: 'sex', valueType: 'select', fieldProps: { mode: "multiple" }, formItemProps: { name: 'sexes' }, valueEnum: { 1: '男', 2: '女' } }, { title: '年龄', dataIndex: 'age', fieldProps: { mode: "multiple" }, formItemProps: { name: 'ages' }, renderFormItem: (_, { type }, form) => { if (type === 'form') { return null; } let value1 = form.getFieldValue('ages') ? form.getFieldValue('ages')[0] : ''; let value2 = form.getFieldValue('ages') ? form.getFieldValue('ages')[1] : ''; return ( { value1 = e; const newValues: any = {}; newValues.ages = [value1, value2]; form.setFieldsValue(newValues); }, }} style={{ width: 100, textAlign: 'center' }} /> { value2 = e; const newValues: any = {}; newValues.ages = [value1, value2]; form.setFieldsValue(newValues); }, }} style={{ width: 100, textAlign: 'center', }} /> ); }, }, { title: '部门', dataIndex: 'departmentId', valueType: 'select', fieldProps: { mode: "multiple" }, formItemProps: { name: 'departmentIds' }, 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: 'unitId', valueType: 'select', fieldProps: { mode: "multiple" }, formItemProps: { name: 'unitIds' }, 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', fieldProps: { mode: "multiple" }, formItemProps: { name: 'postIds' }, 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', fieldProps: { mode: "multiple" }, formItemProps: { name: 'groupsIds' }, 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', fieldProps: { mode: "multiple" }, formItemProps: { name: 'highestEducationIds' }, 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', fieldProps: { mode: "multiple" }, formItemProps: { name: 'skillLevelIds' }, 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', fieldProps: { mode: "multiple" }, formItemProps: { name: 'honorLevels' }, 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) => ( { handleUpdateModalVisible(true); setCurrentRow(record); }}>编辑 { const success = await handleRemove(record.id) if (success) actionRef.current?.reload() }}> 删除 ) } ]; return ( <> headerTitle={null} actionRef={actionRef} rowKey="id" options={false} formRef={ref} scroll={{ x: 'max-content' }} pagination={{ pageSize: 10 }} search={{ labelWidth: 'auto' }} toolBarRender={() => [ , { actionRef.current?.reload(); }} />, { actionRef.current?.reload(); }} />, { actionRef.current?.reload(); }} />, { actionRef.current?.reload(); }} />, { actionRef.current?.reload(); }} />, , ]} request={fetchData} columns={columns} /> {currentRow && Object.keys(currentRow).length ? ( { 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;