import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  usePageTabs,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { Space } from 'antd';

export default function Index({ title = '房屋账单' }) {
  const navigate = useNavigate();
  // 注册当前页面为标签页
  usePageTabs({
    tabKey: 'summary',
    tabLabel: title,
  });

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="summary"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Bill.HouseBills.SummaryBillList,
          )
        }
        columns={[
          {
            title: '房屋ID',
            dataIndex: 'asset_houses_id',
          },
          {
            title: '房屋',
            dataIndex: ['asset_house', 'full_name'],
            search: {
              transform: (value) => {
                return { full_name: value };
              },
            },
          },
          {
            title: '账单金额合计',
            dataIndex: 'payable_amount_sum',
            search: false,
          },
          {
            title: '滞纳金合计',
            dataIndex: 'late_fee_sum',
            search: false,
          },
          {
            title: '优惠金额合计',
            dataIndex: 'discount_amount_sum',
            search: false,
          },
          {
            title: '应付合计',
            dataIndex: 'total_payable_sum',
            search: false,
          },
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <MyButtons.View
                  title="查看"
                  onClick={() => {
                    navigate(`/bills/summary/show/${item.asset_houses_id}`);
                  }}
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
