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.

181 lines
4.7 KiB
TypeScript

2 years ago
import Constants from '@/constants';
import {
pbcUsersPageUsingPost,
updateMemberRecordStateUsingGet,
} from '@/services/pop-b2b2c/pbcUsersController';
import { gradeListUsingPost } from '@/services/pop-b2b2c/pbcVipGradeController';
2 years ago
import { handlePageQuery } from '@/utils/utils';
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
import { PageContainer } from '@ant-design/pro-layout';
2 years ago
import { Access, useAccess } from '@umijs/max';
import { message, Switch } from 'antd';
import React, { useRef } from 'react';
2 years ago
/**
*
* @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: number, state: number) => {
2 years ago
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: 'pbcUserType',
valueEnum: Constants.pbcUserType
},
2 years ago
{
title: '会员昵称',
dataIndex: 'pbcUserNickName',
},
{
title: '手机号',
dataIndex: 'pbcUserMobile',
},
{
title: '入口',
dataIndex: 'pbcUserSourceType',
search: false,
valueEnum: Constants.pbcUserSourceType
2 years ago
},
2 years ago
{
title: '分享人昵称',
dataIndex: 'pbcUserSourceUserNickName',
},
2 years ago
{
title: '分享人店铺',
dataIndex: 'pbcBusinessInfo',
search: false,
render: (text, record) => {
return record.pbcBusinessInfo?.pbcBusinessName
}
},
2 years ago
{
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,
2 years ago
},
{
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 || 0, value ? 1 : 2);
2 years ago
if (success) {
if (actionRef.current) {
actionRef.current.reload();
}
}
}}
/>
</Access>
);
},
},
2 years ago
];
return (
<PageContainer
header={{
title: '',
breadcrumb: {},
}}
>
<ProTable<API.PbcUsers>
columns={columns}
actionRef={actionRef}
request={(param: any) => {
console.log(param)
let hasUserType = false
if (param.pbcUserType) {
param.pbcUserType = parseInt(param.pbcUserType)
hasUserType = true
}
2 years ago
const queryParam = handlePageQuery(param);
if (!hasUserType && queryParam.filters) {
2 years ago
queryParam.filters.push({
key: 'pbcUserType'.replace(/([A-Z])/g, '_$1').toLowerCase(),
value: 1,
action: '<=',
});
2 years ago
}
return fetchData(queryParam);
}}
rowKey="pbcId"
size="small"
bordered
search={{
labelWidth: 'auto',
span: 6,
2 years ago
}}
pagination={{
pageSize: 20,
showSizeChanger: true,
}}
scroll={{
y: 'calc(100vh - 320px)',
}}
dateFormatter="string"
options={false}
toolBarRender={() => []}
/>
</PageContainer>
);
};
export default TableList;