/*
* @Author: your name
* @Date: 2021-07-26 10:13:13
* @LastEditTime: 2021-08-12 19:19:17
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: /TracerMethodology_PC/src/pages/UserMana/index.js
*/
import { PlusOutlined } from '@ant-design/icons';
import { Button, Popconfirm} from 'antd';
import React, { useState, useRef} from 'react';
import { useModel } from 'umi';
import { PageContainer } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import { ModalForm, ProFormText, ProFormSelect } from '@ant-design/pro-form';
import UpdateForm from './updateForm';
import CAUpload from '@/components/CAUpload';
import { getUserList, addUser, editUser, delUser,importExcel } from './service';
const UserMana = () => {
const columns = [
{
title: 'Id',
dataIndex: 'id',
key: 'id',
hideInSearch: true,
},
{
title: '姓名',
dataIndex: 'name',
key: 'name',
},
{
title: '用户名',
dataIndex: 'account',
key: 'account',
hideInSearch: true,
},
{
title: '在职状态',
dataIndex: 'hospitalStatus',
key: 'hospitalStatus',
hideInSearch: true,
render: (text) => <>{text == 1 ? '在职' : '离职'}>,
},
{
title:'操作',
dataIndex: 'option',
valueType: 'option',
render: (_, record) => [
{
handleUpdateModalVisible(true);
setCurrentRow(record);
}}
>
编辑
,
{
setCurrentRow(record);
delUserHandler(record);
}}
>
删除
,
],
},
];
const [createModalVisible, handleModalVisible] = useState(false);
const [updateModalVisible, handleUpdateModalVisible] = useState(false);
const actionRef = useRef();
const [currentRow, setCurrentRow] = useState({});
const { initialState, setInitialState } = useModel('@@initialState');
const {currentUser:{token}} = initialState;
// const [shareParamsSetting,setShareParamsSetting] = useState(false); //是否分摊参数设置
/**
*
* @param {Boolean} bool 弹窗展示状态
*/
const updateModalVisibleChange = (bool) => {
handleUpdateModalVisible(bool);
if (!bool) setCurrentRow(undefined);
};
//获取用户列表
const getUserlist = async (params = {}, sort, filter) => {
const res = await getUserList(params);
return {
data: res.data.list,
total: res.data.totalCount,
success: res.success,
};
};
/**
*
* @param {Object} value 删除项数据
*/
const delUserHandler = async (value) => {
const resp = await delUser(value);
if(resp.msg){
if (actionRef.current) {
actionRef.current.reload();
}
}
};
//自定义上传回调
const customRequestCallback = async (formData)=>{
const resp = await importExcel({formData},{
'content-type':'multipart/form-data',
})
const {status} = resp;
if(status==200){
if (actionRef.current) {
actionRef.current.reload();
}
}
}
return (
[
}
type="primary"
onClick={() => {
handleModalVisible(true);
}}
>
新增
,
{}}
token={token}
type='normal'
customRequestCallback={customRequestCallback}
/>
]}
pagination={{
pageSize: 10,
}}
search={{
defaultCollapsed: false,
labelWidth: 'auto',
}}
/>
{
const success = await addUser(value);
// console.log({ success });
if (success) {
handleModalVisible(false);
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
>
{/* 更新 */}
{
// console.log({value});
const success = await editUser(value);
if (success) {
handleUpdateModalVisible(false);
setCurrentRow(undefined);
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
onCancel={() => {
handleUpdateModalVisible(false);
setCurrentRow(undefined);
}}
updateModalVisible={updateModalVisible}
updateModalVisibleChange={updateModalVisibleChange}
values={currentRow || {}}
/>
);
};
export default UserMana;