import BlueTable from '@/components/BlueTable';
import { useGlobalModalServices } from '@/pages/GlobalModalServices/provider';
import services from '@/services';
import { useRequest } from 'ahooks';
import { useMemo, useState } from 'react';
import Loading from '../../components/Loading';

const AdministPunishList = (props: any) => {
  const [fetchParams, setFetchParams] = useState<any>({
    pageNo: 0,
    pageSize: 10,
  });
  const { dispatch } = useGlobalModalServices();

  const { data, loading } = useRequest(
    () =>
      services.DataBase.getSjdzInfoData({
        typeCode: 'zzcc-xzcf-xzcffylb',
        params: {
          ...fetchParams,
          ...props?.searchTime,
          ajlx: props.wfxw,
          ssqy: props.ssqy,
        },
      }),
    {
      refreshDeps: [fetchParams],
    },
  );


  const columns = useMemo(() => {
    return [
      {
        title: '案件编号',
        dataIndex: 'ajbh',
        key: 'ajbh',
        width: 300,
        ellipsis: true,
      },
      {
        title: '案件类型',
        dataIndex: 'ajlx',
        key: 'ajlx',
        width: 200,
        ellipsis: true,
      },
      {
        title: '案件来源',
        dataIndex: 'ajly',
        key: 'ajly',
        width: 200,
        ellipsis: true,
      },
      {
        title: '违法地点',
        dataIndex: 'wfdd',
        key: 'wfdd',
        width: 400,
        ellipsis: true,
      },
      // {
      //   title: '处罚决定日期',
      //   dataIndex: 'cfjdrq',
      //   key: 'cfjdrq',
      //   width: 150,
      //   ellipsis: true,
      // },
      {
        title: '操作',
        dataIndex: 'c',
        key: 'dictdldj_name',
        width: 100,
        ellipsis: true,
        render: (val: string, record: any) => {
          return (
            <div
              onClick={() => {
                dispatch.push('AdministPunishDetails', {
                  title: '行政处罚详情',
                  props: {
                    id: record?.id,
                  },
                });
              }}
              style={{
                color: 'rgb(36, 164, 255)',
                fontSize: 20,
                fontWeight: 700,
                cursor: 'pointer',
              }}
            >
              详情
            </div>
          );
        },
      },
    ];
  }, [data]);
  return (
    <div>
      <Loading loading={loading}>
        <BlueTable
          //   dataSource={tableData?.data?.data?.records}
          dataSource={data?.data?.data?.records?.[0]?.list || []}
          columns={columns}
          scroll={{ x: 1050, y: 600 }}
          pagination={{
            total: data?.data?.data?.records?.[0]?.page?.total,
            pageSize: fetchParams?.pageSize,
            showQuickJumper: false,
            showSizeChanger: false,
            onChange: (page, pageSize) => {
              setFetchParams({
                ...fetchParams,

                pageNo: page - 1,
                pageSize: pageSize,
              });
            },
            //  hideOnSinglePage: true,
          }}
        />
      </Loading>
    </div>
  );
};
export default AdministPunishList;
