import { Apis } from '@/gen/Apis';
import { ProFormSelect, QueryFilter } from '@ant-design/pro-components';
import { Form } from 'antd';
import { useState } from 'react';
type Props = {
  onChange?: (value: any) => void;
};
export default function Search(props: Props) {
  const [form] = Form.useForm();
  const [assetProjectsId, setAssetProjectsId] = useState<any>();
  const [assetBuildingsId, setAssetBuildingsId] = useState<any>();
  const [assetUnitsId, setAssetUnitsId] = useState<any>();
  return (
    <QueryFilter
      style={{ backgroundColor: '#fff' }}
      defaultCollapsed
      split
      form={form}
      span={6}
      onFinish={props?.onChange}
      onReset={() => {
        props?.onChange?.(form?.getFieldsValue() || {});
      }}
    >
      <ProFormSelect
        name="asset_projects_id"
        label="选择项目"
        request={async (params) => {
          let res = await Apis.Asset.AssetProjects.Select({
            keywords: params?.keyWords,
            ...params,
          });
          return res?.data;
        }}
        fieldProps={{
          showSearch: true,
        }}
        onChange={(e: any) => {
          console.log(e, 'e');
          setAssetProjectsId(e);
        }}
        placeholder="请选择项目"
      />
      <ProFormSelect
        name="asset_buildings_id"
        label="选择楼栋"
        params={{
          asset_projects_id: assetProjectsId,
        }}
        fieldProps={{
          showSearch: true,
        }}
        onChange={(e: any) => {
          setAssetBuildingsId(e);
        }}
        request={async (params) => {
          let res = await Apis.Asset.AssetBuildings.Select({
            keywords: params?.keyWords,
            ...params,
          });
          return res?.data;
        }}
        placeholder="请选择楼栋"
      />
      <ProFormSelect
        name="asset_units_id"
        label="选择单元"
        params={{
          asset_projects_id: assetProjectsId,
          asset_buildings_id: assetBuildingsId,
        }}
        fieldProps={{
          showSearch: true,
        }}
        onChange={(e: any) => {
          setAssetUnitsId(e);
        }}
        request={async (params) => {
          let res = await Apis.Asset.AssetUnits.Select({
            keywords: params?.keyWords,
            ...params,
          });
          return res?.data;
        }}
        placeholder="请选择单元"
      />
      <ProFormSelect
        name="asset_houses_id"
        label="选择房屋"
        params={{
          asset_projects_id: assetProjectsId,
          asset_buildings_id: assetBuildingsId,
          asset_units_id: assetUnitsId,
        }}
        fieldProps={{
          showSearch: true,
        }}
        request={async (params) => {
          let res = await Apis.Asset.AssetHouses.Select({
            keywords: params?.keyWords,
            ...params,
          });
          return res?.data;
        }}
        placeholder="请选择房屋"
      />
    </QueryFilter>
  );
}
