import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import {
  HouseOrdersOrderStatusEnum,
  HouseOrdersPaymentMethodEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import Payments from './modals/Payments';

export default function Index({ title = '支付订单' }) {
  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="pay_orders"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        headerTitle="支付订单"
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.HouseOrder.HouseOrders.List,
          )
        }
        // toolBarRender={(action) => [
        //   <MyImportModal
        //     key="ImportHouse"
        //     title="批量导入"
        //     type="danger"
        //     size="middle"
        //     templateApi={Apis.Bill.HouseBills.DownloadTemplate}
        //     importApi={Apis.Bill.HouseBills.Import}
        //     reload={action?.reload}
        //   />,
        // ]}
        columns={[
          MyColumns.ID({
            search: false,
          }),

          {
            title: '订单号',
            dataIndex: 'order_code',
            search: false,
          },
          MyColumns.EnumTag({
            title: '支付方式',
            dataIndex: 'payment_method',
            valueEnum: HouseOrdersPaymentMethodEnum,
          }),
          MyColumns.EnumTag({
            title: '支付状态',
            dataIndex: 'order_status',
            valueEnum: HouseOrdersOrderStatusEnum,
          }),
          {
            title: '应收金额',
            dataIndex: 'amount',
            search: false,
          },
          {
            title: '实收金额',
            dataIndex: 'actual_paid_amount',
            search: false,
          },
          {
            title: '退款金额',
            dataIndex: 'refund_amount',
            search: false,
          },

          {
            title: '收款账号',
            dataIndex: ['house_order_items', 'receipt_account'],
            render: (text, item) =>
              `${
                item?.receipt_account?.company_bank
              } ${item?.receipt_account?.company_account?.slice(-4)}`,
          },
          {
            title: '支付时间',
            dataIndex: 'paid_time',
            search: false,
          },
          {
            title: '关联机构',
            dataIndex: ['company', 'name'],
            search: false,
          },
          {
            title: '关联项目',
            dataIndex: ['asset_project', 'name'],
            search: false,
          },

          // MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <Payments item={item} title="查看" reload={action?.reload} />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.HouseOrder.HouseOrders.Delete({ id: item.id }).then(
                      () => action?.reload(),
                    )
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
