import React, { useRef } from 'react';
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 { pbcUserMessagePageUsingPost } from '@/services/pop-b2b2c/pbcUserMessageController';

/**
 * 查询表格
 * @param param0
 */
const fetchData = async (params: API.PageVO) => {
  const msg = await pbcUserMessagePageUsingPost(params);
  return {
    data: msg.data?.records,
    total: msg.data?.total,
    success: msg.retcode,
  } as any;
};

// eslint-disable-next-line @typescript-eslint/ban-types
const TableList: React.FC<{}> = () => {
  const actionRef = useRef<ActionType>();

  const columns: ProColumns<API.PbcUserMessage>[] = [
    {
      title: '会员昵称',
      dataIndex: 'pbcUserNickName',
    },
    {
      title: '手机号',
      dataIndex: 'pbcUserMobile',
    },
    {
      title: '商户名称',
      dataIndex: 'pbcBusinessName'
    },
    {
      title: '留言时间',
      dataIndex: 'pbcCreateAt',
      valueType: 'dateTime',
      search: false
    },
    {
      title: '回复状态',
      dataIndex: 'pbcReplyState',
      valueEnum: Constants.pbcReplyState
    },
  ];
  return (
    <PageContainer
      header={{
        title: '',
        breadcrumb: {},
      }}
    >
      <ProTable<API.PbcUserMessage>
        columns={columns}
        actionRef={actionRef}
        request={(param: any) => {
          const queryParam = handlePageQuery(param);
          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;
