import { MyColumns, MyProTableProps, useCurrentPermissions } from '@/common';
import { Apis } from '@/gen/Apis';
import {
  BillPaymentsStatusEnum,
  HouseOrdersPaymentMethodEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import Review from './modals/Review';

export default function Index() {
  const getCurrentPermissions = useCurrentPermissions();
  let tableRender = (item: any, action: any) => {
    return getCurrentPermissions(
      {
        audit: <Review item={item} reload={action?.reload} title="审核" />,
      },
      'AllBillsAudit',
    );
  };
  return (
    <ProTable<Record<any, any>>
      {...MyProTableProps.props}
      request={async (params, sort) =>
        MyProTableProps.request(params, sort, Apis.Bill.BillPayments.List)
      }
      params={{
        status: 'Pending',
      }}
      headerTitle="账单审核列表"
      columns={[
        MyColumns.ID({
          search: false,
        }),
        {
          title: '支付账单ID',
          dataIndex: 'bills_id',
        },
        MyColumns.EnumTag({
          title: '状态',
          dataIndex: 'status',
          search: false,
          valueEnum: BillPaymentsStatusEnum,
        }),
        MyColumns.EnumTag({
          title: '支付方式',
          dataIndex: 'payment_method',
          valueEnum: HouseOrdersPaymentMethodEnum,
        }),
        {
          title: '收款金额',
          dataIndex: 'actual_amount',
          render: (_, item: any) => `${item?.amount}元`,
          search: false,
        },
        {
          title: '支付时间',
          dataIndex: 'paid_time',
          search: false,
        },
        {
          title: '收款帐号',
          search: false,
          render: (_, item: any) => {
            return `${item?.accept_account_name}:${item?.accept_account_number}`;
          },
          // search: false,
        },
        {
          title: '收款单号',
          dataIndex: 'payment_no',
          search: false,
        },
        MyColumns.CreatedAt(),
        MyColumns.Option({
          render: (_, item: any, index, action) => (
            <Space key={index}>{tableRender(item, action)}</Space>
          ),
        }),
      ]}
    />
  );
}
