import Constants from '@/constants';
import { listAdminTreeUsingGet } from '@/services/pop-b2b2c/pbcCategoryController';
import {
  pbcUsersPageUsingPost,
} from '@/services/pop-b2b2c/pbcUsersController';
import { ActionType, ProColumns, ProTable } from '@ant-design/pro-components';
import { PageContainer } from '@ant-design/pro-layout';
import React, { useRef } from 'react';

/**
 * 查询表格
 * @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;
};

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

  const columns: ProColumns<API.PbcProduct>[] = [
    {
      title: '商品类目',
      dataIndex: 'pbcProductCategoryId',
      hideInTable: true,
      valueType: 'cascader',
      fieldProps: {
        fieldNames: { label: 'pbcCategoryName', value: 'pbcId', children: 'children' },
      },
      request: async () => {
        const msg = await listAdminTreeUsingGet({ type: 2 });
        if (msg.retcode && msg.data) {
          return msg.data;
        }
        return [];
      },
    },
    {
      title: '商品大类',
      dataIndex: 'pbcProductTopCategoryName',
      search: false,
    },
    {
      title: '商品中类',
      dataIndex: 'pbcProductParentCategoryName',
      search: false,
    },
    {
      title: '商品小类',
      dataIndex: 'pbcProductCategoryName',
      search: false,
    },
    {
      title: '商品名称',
      dataIndex: 'pbcProductTitle',
    },
    {
      title: '价格',
      dataIndex: 'pbcProductPrice',
      search: false,
    },
    {
      title: '所属商户',
      dataIndex: 'pbcBusinessName',
      search: false,
    },
    {
      title: '状态',
      dataIndex: 'pbcState',
      valueType: 'select',
      search: false,
      valueEnum: Constants.pbcProductState,
    },
  ];
  return (
    <PageContainer
      header={{
        title: '',
        breadcrumb: {},
      }}
    >
      <ProTable<API.PbcBusiness>
        columns={columns}
        actionRef={actionRef}
        request={fetchData}
        rowKey="pbcId"
        size="small"
        bordered
        search={{
          labelWidth: 'auto',
          span: 6,
        }}
        pagination={{
          defaultPageSize: 20,
          showSizeChanger: true,
        }}
        scroll={{
          y: 'calc(100vh - 320px)',
        }}
        dateFormatter="string"
        options={false}
        toolBarRender={() => []}
      />
    </PageContainer>
  );
};

export default TableList;
