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.

152 lines
3.9 KiB
TypeScript

2 years ago
import React, { useRef } from 'react';
import { Switch, message } from 'antd';
import { PageContainer } from '@ant-design/pro-layout';
import Constants from '@/constants';
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
import { handlePageQuery } from '@/utils/utils';
import { Access, useAccess } from '@umijs/max';
import { pbcUsersPageUsingPost, updateMemberRecordStateUsingGet } from '@/services/pop-b2b2c/pbcUsersController';
import { gradeListUsingPost } from '@/services/pop-b2b2c/pbcVipGradeController';
/**
*
* @param param0
*/
const fetchData = async (params: API.PageVO) => {
const msg = await pbcUsersPageUsingPost(params);
return {
data: msg.data?.records,
total: msg.data?.total,
success: msg.retcode,
} as any;
};
const handleUpdateState = async (id: string, state: number) => {
const hide = message.loading('正在保存');
if (!id) return false;
try {
const msg = await updateMemberRecordStateUsingGet({ pbcId: id, state: state });
hide();
if (msg.retcode) {
message.success(!id ? '新增成功!' : '保存成功!');
return true;
}
message.error(msg.retmsg);
return false;
} catch (error) {
hide();
message.error(!id ? '新增失败,请重试!' : '保存失败,请重试!');
return false;
}
};
// eslint-disable-next-line @typescript-eslint/ban-types
const TableList: React.FC<{}> = () => {
const actionRef = useRef<ActionType>();
const access: any = useAccess();
const columns: ProColumns<API.PbcUsers>[] = [
{
title: '会员昵称',
dataIndex: 'pbcUserNickName',
},
{
title: '手机号',
dataIndex: 'pbcUserMobile',
},
{
title: '入口',
dataIndex: 'pbcUserSourceType',
search: false
},
{
title: '会员等级',
dataIndex: 'pbcVipGradeName',
valueType: 'select',
request: async () => {
const msg = await gradeListUsingPost();
if (msg.retcode && msg.data) {
return msg.data.map((e) => {
return {
label: e.pbcVipGradeName,
value: e.pbcVipGradeName,
};
});
}
return [];
},
},
{
title: '注册日期',
dataIndex: 'pbcCreateAt',
valueType: 'dateTimeRange',
render: (text, record) => record.pbcCreateAt
},
{
title: '状态',
dataIndex: 'pbcState',
valueType: 'select',
valueEnum: Constants.state,
render: (_, record) => {
return <Access key="switch" accessible={access.memberUpdateState}>
<Switch
checked={record.pbcState === 1}
onChange={async (value) => {
const success = await handleUpdateState(record.pbcId || '', value ? 1 : 2 );
if (success) {
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
/>
</Access>
}
}
];
return (
<PageContainer
header={{
title: '',
breadcrumb: {},
}}
>
<ProTable<API.PbcUsers>
columns={columns}
actionRef={actionRef}
request={(param: any) => {
const queryParam = handlePageQuery(param);
if (queryParam.filters) {
queryParam.filters.push({
key: 'pbcUserType'.replace(/([A-Z])/g, '_$1').toLowerCase(),
value: 0,
action: '=',
})
}
return fetchData(queryParam);
}}
rowKey="pbcId"
size="small"
bordered
search={{
labelWidth: 'auto',
span: 6
}}
pagination={{
pageSize: 20,
showSizeChanger: true,
}}
scroll={{
y: 'calc(100vh - 320px)',
}}
dateFormatter="string"
options={false}
toolBarRender={() => []}
/>
</PageContainer>
);
};
export default TableList;