// 不动产管理
import { useEffect, useImperativeHandle, useRef, useState } from "react";
import LeftSelectTree from "@/components/leftSelectTree/leftSelectTree";
import { ActionType, FormInstance, ProForm, ProFormDatePicker, ProFormDateRangePicker, ProFormDigitRange, ProFormSelect, ProFormText, ProFormTextArea, ProTable } from "@ant-design/pro-components";
import { handleDeleteREALESTATE, handleGetREALESTATEList, handleSynchroREALESTATE } from "./service";
import moment from "moment";
import { encryptAES } from "@/utils/handleAes";
import { Button, Col, ConfigProvider, DatePicker, message, Modal, Row } from "antd";
import zhCN from 'antd/locale/zh_CN';
import ModalFooter from "./components/modalFooter";
import { handleGetPassportInfoById } from "../DigitalElectronics/service";
// 引入地址解析工具
import { handleAddressChange, parseAddress } from "@/utils/addressParser";
import { handleGetServerpartDDL, handleGetServerpartInfo, handleGetServerpartTree } from "../serverpartAssets/service";
import { handleGetSERVERPARTDetail } from "../operationReport/service";
import dayjs from "dayjs";
import 'dayjs/locale/zh-cn';
import weekday from "dayjs/plugin/weekday";
import localeData from "dayjs/plugin/localeData";
import customParseFormat from 'dayjs/plugin/customParseFormat';
import updateLocale from 'dayjs/plugin/updateLocale';
dayjs.extend(updateLocale);
dayjs.updateLocale('zh-cn', {
    weekStart: 0,
});
dayjs.extend(weekday);
dayjs.extend(localeData);
dayjs.extend(customParseFormat);



const RealEstate = ({ serverPartId, isComponent, onRef, selectRealEstateId, parentRow }: { serverPartId: string, isComponent: boolean, onRef?: any, selectRealEstateId?: any, parentRow?: any }) => {
    const actionRef = useRef<ActionType>();
    const formRef = useRef<FormInstance>();
    const modalFormRef = useRef<FormInstance>();
    const { RangePicker } = DatePicker;
    // 树相关的属性和方法
    const [selectedId, setSelectedId] = useState<string>()
    const [collapsible, setCollapsible] = useState<boolean>(false)
    // 添加不动产内容的悬浮框
    const [showDetail, setShowDetail] = useState<boolean>(false)
    // 当前行数据
    const [currentRow, setCurrentRow] = useState<any>()
    // 判断是不是第一次进入到页面
    const [isFirst, setIsFirst] = useState<boolean>(true)
    // 获取用户信息
    const [userInfo, setUserInfo] = useState<any>()
    // 拿到服务区列表
    const [serverPartList, setServerPartList] = useState<any>()
    // 悬浮框点击确认的按钮加载效果
    const [confirmLoading, setConfirmLoading] = useState<boolean>(false)
    // 选中的行数据详情
    const [selectRowKey, setSelectRowKey] = useState<any>()
    const [selectRowDetail, setSelectRowDetail] = useState<any>()
    // 当前服务区下的方位
    const [SERVERPARTREGION, setSERVERPARTREGION] = useState<any>()
    // 表格数据
    const [tableData, setTableData] = useState<any>()
    // 服务区列表
    const [searchServerPartList, setSearchServerPartList] = useState<any>()
    const [columnsState, setColumnsState] = useState<any>({
        PROVINCE_NAME: { show: false },
        CITY_NAME: { show: false },
        SPECIALINDUSTRY_NUMBER: { show: false },
    })
    // 当前组件的可以选择的全部服务区
    const [currentServerPartList, setCurrentServerPartList] = useState<any>()

    // 列表配置
    const columns: any = [
        // {
        //     title: "统计日期",
        //     dataIndex: "staticDate",
        //     hideInTable: true,
        //     valueType: "dateRange",
        //     initialValue: [moment().startOf('M'), moment()],
        //     search: {
        //         transform: (value: any) => {
        //             return {
        //                 START_LEASEDATE_End: moment().startOf('y').format('YYYY-MM-DD'),
        //                 END_LEASEDATE_Start: moment().format('YYYY-MM-DD')
        //             };
        //         },
        //     }, 
        //     fieldProps: {
        //         picker: "day",
        //         format: 'YYYY-MM-DD',
        //     },
        //     hideInSearch: isComponent
        // },
        {
            title: "服务区",
            dataIndex: "serverPartId",
            ellipsis: true,
            width: 180,
            align: 'center',
            hideInTable: true,
            valueType: 'select',
            fieldProps: {
                options: searchServerPartList,
                showSearch: true,
                filterOption: (input: string, option: any) => {
                    return option?.label?.toLowerCase().includes(input.toLowerCase())
                }
            },
            hideInSearch: !isComponent
        },
        {
            title: "服务区名称",
            dataIndex: "SERVERPART_NAME",
            hideInSearch: true,
            ellipsis: true,
            width: 180,
            align: 'center'
        },
        {
            title: "租赁期限",
            dataIndex: "LEASEDATE",
            hideInSearch: true,
            ellipsis: true,
            width: 250,
            align: 'center',
            render: (_: any, record: any) => {
                return isComponent ?
                    <ConfigProvider locale={zhCN}>
                        <RangePicker
                            value={[record?.START_LEASEDATE ? dayjs(record.START_LEASEDATE) : null, record?.END_LEASEDATE ? dayjs(record.END_LEASEDATE) : null]}
                            onChange={(e: any) => {
                                console.log('eee', e);
                                let [start, end] = [moment(e[0].$d).format('YYYY-MM-DD'), moment(e[1].$d).format('YYYY-MM-DD')]
                                console.log('2321321', [start, end]);
                                console.log('tableDatatableData', tableData);
                                let list: any = JSON.parse(JSON.stringify(tableData))
                                list.forEach((item: any) => {
                                    if (item.REALESTATE_ID === record.REALESTATE_ID) {
                                        item.START_LEASEDATE = start
                                        item.END_LEASEDATE = end
                                    }
                                })
                                setTableData(list)
                            }}
                        />
                    </ConfigProvider>
                    // <ProForm
                    //     submitter={false}
                    //     initialValues={{ LEASEDATE: [moment(record?.START_LEASEDATE).format('YYYY-MM-DD'), moment(record?.END_LEASEDATE).format('YYYY-MM-DD')] }}
                    // >
                    //     <ProFormDateRangePicker name="LEASEDATE" fieldProps={{
                    //         format: 'YYYY-MM-DD',
                    //         onChange: (e: any) => {
                    //             console.log('eee', e);
                    //             let [start, end] = [moment(e[0].$d).format('YYYY-MM-DD'), moment(e[1].$d).format('YYYY-MM-DD')]
                    //             console.log('2321321', [start, end]);
                    //         }
                    //     }} />
                    // </ProForm>
                    : `${record?.START_LEASEDATE || ""}${record?.END_LEASEDATE ? `-${record?.END_LEASEDATE}` : ''}`
            }
        },

        {
            title: "查询内容",
            dataIndex: "searchText",
            hideInTable: true,
            fieldProps: {
                placeholder: "请输入省份名称/城市名称",
            },
            hideInSearch: isComponent
        },
        {
            title: "省份名称",
            dataIndex: "PROVINCE_NAME",
            hideInSearch: true,
            ellipsis: true,
            width: 150,
            align: 'center'
        },
        {
            title: "城市名称",
            dataIndex: "CITY_NAME",
            hideInSearch: true,
            ellipsis: true,
            width: 150,
            align: 'center'
        },
        {
            title: "详细地址",
            dataIndex: "REALESTATE_ADDRESS",
            hideInSearch: true,
            ellipsis: true,
            width: 380,
            align: 'center'
        },
        {
            title: "是否跨地",
            dataIndex: "CROSS_CITYSIGN",
            hideInSearch: true,
            ellipsis: true,
            width: 120,
            align: 'center',
            render: (_: any, record: any) => {
                return record?.CROSS_CITYSIGN ? "是" : "否"
            }
        },
        {
            title: "面积单位",
            dataIndex: "AREA_UNIT",
            hideInSearch: true,
            ellipsis: true,
            width: 120,
            align: 'center',
            valueType: "select",
            valueEnum: {
                1: "平方千米",
                2: "平方米",
                3: "公顷",
                4: "亩",
                5: "h㎡",
                6: "k㎡",
                7: "㎡"
            }
        },

        {
            title: "产权证号",
            dataIndex: "ESTATE_IDENTITY",
            hideInSearch: true,
            ellipsis: true,
            width: 150,
            align: 'center',
            render: (_, record) => {
                return record?.ESTATE_IDENTITY ? <a onClick={() => {
                    setCurrentRow(record)
                    setShowDetail(true)
                }}>
                    {record?.ESTATE_IDENTITY}
                </a> : ""
            }
        },
        {
            title: "资料编码",
            dataIndex: "SPECIALINDUSTRY_NUMBER",
            hideInSearch: true,
            ellipsis: true,
            width: 150,
            align: 'center',
            render: (_, record) => {
                return record?.SPECIALINDUSTRY_NUMBER ? <a onClick={() => {
                    setCurrentRow(record)
                    setShowDetail(true)
                }}>
                    {record?.SPECIALINDUSTRY_NUMBER}
                </a> : ""
            }
        },
        {
            title: "不动产类型",
            dataIndex: "REALESTATE_TYPE",
            width: 150,
            valueType: "select",
            align: 'center',
            valueEnum: {
                1000: "房屋租赁",
                2000: "车辆资产",
            },
            hideInSearch: isComponent
        },
    ]

    // 获取当前用户信息的方法 
    const handleGetUserInfo = async () => {
        const search = window.location.search;
        const addressParams: any = Object.fromEntries(new URLSearchParams(search).entries());
        const req: any = {
            UserIdEncrypted: addressParams.UserIdEncrypted
        }
        const data = await handleGetPassportInfoById(req)
        console.log('dsajikajds', data);

        setUserInfo(data)
    }

    // 新增和同步不动产的方法
    const handleAddOrUpdate = async (values: any) => {
        // 准备入参
        let req: any = {}
        console.log('valuesvalues', values);

        let [start, end] = [moment(values?.LEASEDATE[0].$d).format('YYYY-MM-DD HH:mm:ss'), moment(values?.LEASEDATE[1].$d).format('YYYY-MM-DD HH:mm:ss')]

        if (currentRow?.REALESTATE_ID) {
            req = {
                ...currentRow,
                ...values,
                LEASEDATE: "",
                START_LEASEDATE: start || "",
                END_LEASEDATE: end || "",
                REALESTATE_STATE: 1,
                STAFF_ID: userInfo?.ID,
                STAFF_NAME: userInfo?.Name,
                OPERATE_DATE: moment().format('YYYY-MM-DD HH:mm:ss')
            }
        } else {
            req = {
                ...values,
                LEASEDATE: "",
                REALESTATE_STATE: 1,
                START_LEASEDATE: start || "",
                END_LEASEDATE: end || "",
                STAFF_ID: userInfo?.ID,
                STAFF_NAME: userInfo?.Name,
                OPERATE_DATE: moment().format('YYYY-MM-DD HH:mm:ss')
            }
        }
        console.log('reqreqreqreq', req);

        let reqData: any = {
            name: "",
            value: encryptAES(JSON.stringify(req))
        }
        const data: any = await handleSynchroREALESTATE(reqData)
        setConfirmLoading(false)
        if (data?.Result_Code === 100) {
            message.success('添加成功！');
            setCurrentRow(undefined)
            setShowDetail(false)
            actionRef.current?.reload()
        } else {
            message.error(data?.Result_Desc || '添加失败')
        }
    }

    // 删除不动产
    const handleDeleteOrUpdate = async (id: string) => {
        const req: any = {
            REALESTATEId: id
        }
        let reqData: any = {
            name: "",
            value: encryptAES(JSON.stringify(req))
        }
        const data: any = await handleDeleteREALESTATE(reqData)
        setConfirmLoading(false)
        if (data?.Result_Code === 100) {
            message.success('删除成功！');
            setCurrentRow(undefined)
            setShowDetail(false)
            actionRef.current?.reload()
        } else {
            message.error(data?.Result_Desc || '删除失败')
        }
    }

    // 获取到服务区方位的方法
    const handleGetSERVERPARTREGION = async (id: string) => {
        setSERVERPARTREGION([])
        const req: any = {
            SERVERPARTId: id
        }
        const data = await handleGetServerpartInfo(req)
        let list: any = []
        if (data.RegionInfo && data.RegionInfo.length > 0) {
            data.RegionInfo.forEach((item: any) => {
                list.push({ label: item.SERVERPART_REGIONNAME, value: item.SERVERPART_REGION })
            })
        }

        setSERVERPARTREGION(list)
        return data
    }

    // 获得服务区列表
    const handleGetServerPartList = async () => {
        const req: any = {
            ProvinceCode: "530000",
        }
        const data = await handleGetServerpartDDL(req)
        setSearchServerPartList(data)
    }

    // 遍历找出全部type为1 的
    const collectTypeOne = (list: any) => {
        const result: any = [];

        function dfs(arr: any) {
            if (!Array.isArray(arr)) return;

            arr.forEach(item => {
                if (item && item.type === 1) {
                    result.push(item);
                }

                // 关键：层级不确定，递归遍历
                if (Array.isArray(item?.children)) {
                    dfs(item.children);
                }
            });
        }

        dfs(list);
        return result;
    }

    useEffect(() => {
        if (!isComponent) {
            if (isFirst) {
                handleGetUserInfo()
                setIsFirst(false)
                handleGetServerPartList()
            }
        }
    }, [])


    useImperativeHandle(onRef, () => ({
        selectRowKey,
        selectRowDetail,
        tableData
    }));

    return <div style={{ height: isComponent ? '600px' : 'calc(100vh - 100px)', backgroundColor: '#fff', display: 'flex' }}>
        {
            isComponent ? '' :
                <LeftSelectTree setSelectedId={setSelectedId} setCollapsible={setCollapsible} collapsible={collapsible} serverPartType={'1000'} ServerpartSiteType={'1000,1010,3000'} />
        }

        <div style={{
            width: isComponent ? 'calc(100%)' : !collapsible ? 'calc(100% - 300px)' : 'calc(100% - 60px)',
            paddingTop: 0,
            paddingBottom: 0,
            paddingRight: 0
        }}>

            <ProTable
                actionRef={actionRef}
                formRef={formRef}
                columns={columns}
                bordered
                rowKey={'REALESTATE_ID'}
                scroll={{ x: '100%', y: isComponent ? '370px' : 'calc(100vh - 450px)' }}
                headerTitle={'不动产列表'}
                // search={isComponent && Number(serverPartId) !== 1269 ? false : { span: 6 }}
                // search={isComponent ? false : { span: 6 }}
                search={{ span: 6 }}
                dataSource={tableData}
                request={async (params) => {
                    // 如果是组件的话 它下面的服务区 可能是单个服务区 或者是 一个片区下面的全部服务区
                    let isComponentSelect = ''
                    // 服务区详情的信息
                    let detail: any = {}
                    console.log('paramsparamsparamsparams', params);

                    if (!isComponent) {
                        if (!selectedId) {
                            return []
                        }
                    } else {
                        console.log('selectRealEstateIdselectRealEstateId', selectRealEstateId);
                        console.log('paramsparamsparamsparams', params);
                        console.log('serverPartIdserverPartIdserverPartId', serverPartId);
                        setSelectRowKey(selectRealEstateId)
                        if (isFirst) {
                            // 先调用一下服务区详情 判断是管理单元 还是服务区 
                            detail = await handleGetSERVERPARTDetail({ SERVERPARTId: serverPartId })
                            console.log('detaildetaildetaildetail', detail);
                            let nowShowSelectServerPartList: any = []
                            // 先判断一下 是服务区还是管理单元  1000 说明是服务区  那么直接去请求即可 
                            if (Number(detail.STATISTICS_TYPE) === 1000) {
                                isComponentSelect = serverPartId
                                nowShowSelectServerPartList.push({
                                    label: detail.SERVERPART_NAME,
                                    value: Number(detail.SERVERPART_ID)
                                })
                            } else {
                                // 如果不是 那么就拿它的片区id 去请求下面的全部服务区 当作选择了的服务区id
                                const serverPart: any = await handleGetServerpartTree({
                                    ProvinceCode: "530000",
                                    SPRegionType_ID: detail.SPREGIONTYPE_ID,
                                    ServerpartType: "1000,1001,1010,2000,3000,4000,5000",
                                    StatisticsType: 1000
                                })
                                console.log('serverPartserverPartserverPart', serverPart);
                                if (serverPart && serverPart.length > 0) {
                                    const selectedIds = collectTypeOne(serverPart)
                                    console.log('selectedIdsselectedIds', selectedIds);
                                    isComponentSelect = selectedIds.map((n: any) => n?.value)?.toString() || ''
                                    setSelectedId(isComponentSelect)

                                    if (selectedIds && selectedIds.length > 0) {
                                        selectedIds.forEach((item: any) => {
                                            nowShowSelectServerPartList.push({
                                                label: item.label,
                                                value: Number(item.value)
                                            })
                                        })
                                    }
                                }
                            }
                            console.log('isComponentSelectisComponentSelectisComponentSelect', isComponentSelect);

                            formRef.current?.setFieldsValue({ serverPartId: Number(detail.SERVERPART_ID) })
                            setSearchServerPartList(nowShowSelectServerPartList)
                            setIsFirst(false)
                            setCurrentServerPartList(isComponentSelect)
                        }

                    }

                    console.log('isComponentSelectisComponentSelect', isComponentSelect);

                    const req: any = {
                        searchParameter: {
                            REALESTATE_TYPE: isComponent ? '' : params?.REALESTATE_TYPE || "",// 不动产类型
                            // 当不是组件的时候 就根据左侧选择的服务区 selectedId
                            // 是组件的时候  如果选择的服务区里面有值 那就按照选择的走  没有值的话 就按照 当前片区的默认权限请求服务区  isComponentSelect是仅第一次生效  currentServerPartList是存好了的 之后生效
                            SERVERPART_IDS: isComponent ? params?.serverPartId ? params?.serverPartId : isComponentSelect ? isComponentSelect : currentServerPartList : selectedId,
                            // START_LEASEDATE_End: isComponent ? '' : params?.END_LEASEDATE_Start || "",
                            // END_LEASEDATE_Start: isComponent ? '' : params?.START_LEASEDATE_End || "",
                            REALESTATE_STATE: 1,
                            // REALESTATE_IDS: isComponent ? Number(serverPartId) === 1269 ? params?.serverPartId ? '' : selectRealEstateId ? selectRealEstateId.toString() : "" : '' : ''
                        },
                        PageIndex: 1,
                        PageSize: 999999,
                        keyWord: {
                            Key: "PROVINCE_NAME,CITY_NAME",
                            Value: params?.searchText || ""
                        }
                    }
                    let newReq: any = {
                        name: "",
                        value: encryptAES(JSON.stringify(req))
                    }
                    console.log('req', req);

                    const data: any = await handleGetREALESTATEList(newReq)
                    console.log('datadatadata', data);
                    if (data && data.length > 0) {
                        console.log('parentRowparentRow', parentRow);
                        if (parentRow) {
                            let NewData: any = []
                            data.forEach((item: any) => {
                                if (Number(item.REALESTATE_ID) === Number(parentRow.REALESTATE_ID)) {
                                    item = {
                                        ...item,
                                        ...parentRow,
                                        REALESTATE_ID: Number(parentRow.REALESTATE_ID)
                                    }
                                    NewData.push(item)
                                } else {
                                    NewData.push(item)
                                }
                            })
                            console.log('NewDataNewData', NewData);
                            setTableData(NewData)
                            return { data: NewData, success: true }
                        } else {
                            setTableData(data)
                            return { data, success: true }
                        }
                    }
                    setTableData([])
                    return { data: [], success: true }
                }}
                rowSelection={isComponent ? {
                    type: 'radio',
                    defaultSelectedRowKeys: selectRealEstateId || [],
                    onChange: (_, row) => {
                        console.log('__', _);
                        console.log('row', row);
                        setSelectRowKey(_)

                        // // 确保取最新的数据  不拿row 拿tableData
                        // let list: any = JSON.parse(JSON.stringify(tableData))
                        // let newRow: any = {}
                        // list.forEach((item: any) => {
                        //     if (item.REALESTATE_ID === row[0].REALESTATE_ID) {
                        //         newRow = item
                        //     }
                        // })
                        // console.log('newRownewRow', newRow);

                        // setSelectRowDetail(newRow)
                    }
                } : false}
                toolbar={{
                    actions: isComponent ? [] : [
                        <Button type="primary" onClick={() => {
                            setShowDetail(true)
                        }}>添加不动产</Button>
                    ]
                }}
                columnsState={{
                    value: columnsState,
                    onChange: (value) => {
                        setColumnsState(value)
                    }
                }}
            />
        </div>

        <Modal
            title={currentRow?.REALESTATE_ID ? '编辑不动产' : '添加不动产'}
            destroyOnClose
            width={1200}
            open={showDetail}
            className="realEstateModalBox"
            onCancel={() => {
                setCurrentRow(undefined)
                setShowDetail(false)
            }}
            confirmLoading={confirmLoading}
            footer={
                isComponent ? false :
                    <ModalFooter
                        confirmLoading={confirmLoading}
                        hideDelete={!currentRow?.REALESTATE_ID}
                        handleDelete={async () => {
                            setConfirmLoading(true)
                            await handleDeleteOrUpdate(currentRow?.REALESTATE_ID)
                        }}
                        handleCancel={() => {
                            setCurrentRow(undefined)
                            setShowDetail(false)
                        }}
                        handleOK={() => {
                            modalFormRef.current?.validateFields().then(async (res) => {
                                setConfirmLoading(true)
                                await handleAddOrUpdate(res)
                            })
                        }}
                    />
            }
        >
            <ProForm
                formRef={modalFormRef}
                submitter={false}
                request={async () => {
                    if (currentRow?.REALESTATE_ID) {
                        handleGetSERVERPARTREGION(currentRow?.SERVERPART_ID)
                        return {
                            ...currentRow,
                            SERVERPART_ID: currentRow?.SERVERPART_ID.toString(),
                            LEASEDATE: [moment(currentRow?.START_LEASEDATE), moment(currentRow?.END_LEASEDATE)]
                        }
                    } else {
                        console.log('selectedIdselectedIdselectedId', selectedId);
                        if (selectedId) {
                            let defaultSeverPartId: any = selectedId.split(',') && selectedId.split(',').length > 0 ? selectedId.split(',')[0] : ""
                            console.log('defaultSeverPartIddefaultSeverPartIddefaultSeverPartId', defaultSeverPartId);
                            let detailObj: any = {}
                            if (defaultSeverPartId) {
                                detailObj = await handleGetSERVERPARTREGION(defaultSeverPartId)
                            }
                            console.log('detailObjdetailObjdetailObj', detailObj);

                            return {
                                SERVERPART_ID: defaultSeverPartId,
                                SERVERPART_NAME: detailObj.SERVERPART_NAME
                            }
                        }
                        return {

                        }
                    }
                }}
                onFinish={() => {
                }}
            >
                <Row gutter={16}>
                    <Col span={8}>
                        <ProFormSelect
                            label={'不动产类型'}
                            name={'REALESTATE_TYPE'}
                            options={[
                                { label: "房屋租赁", value: 1000 },
                                { label: "车辆资产", value: 2000 },
                            ]}
                            rules={[{
                                required: true,
                                message: '请选择不动产类型!'
                            }]}
                            readonly={isComponent}
                        />
                    </Col>

                    <Col span={8}>
                        <ProFormSelect
                            label={'服务区'}
                            name={'SERVERPART_ID'}
                            options={[
                                { label: "房屋租赁", value: 1000 },
                                { label: "车辆资产", value: 2000 },
                            ]}
                            request={async () => {
                                if (serverPartList && serverPartList.length > 0) {
                                    return serverPartList
                                } else {
                                    const req: any = {
                                        ProvinceCode: "530000",
                                    }
                                    let list: any = []
                                    const data = await handleGetServerpartDDL(req)
                                    if (data && data.length > 0) {
                                        list = data
                                        setServerPartList(list)
                                    } else {
                                        setServerPartList([])
                                    }
                                    return list
                                }
                            }}
                            fieldProps={{
                                showSearch: true,
                                filterOption: (input, option) =>
                                    (option?.label ?? '').toLowerCase().includes(input.toLowerCase()),
                                optionFilterProp: 'label',
                                onChange: async (value: any, option: any) => {
                                    handleGetSERVERPARTREGION(value)
                                    modalFormRef.current?.setFieldsValue({ SERVERPART_NAME: option.title })
                                    // 顺便拿个 服务区详情 
                                    let detail: any = await handleGetSERVERPARTDetail({ SERVERPARTId: value })
                                    // 从地址里面 解出 城市(市区)
                                    let address: any = parseAddress(detail?.SERVERPART_ADDRESS);

                                    modalFormRef.current?.setFieldsValue({ PROVINCE_NAME: detail?.PROVINCE_NAME, CITY_NAME: address?.city, REALESTATE_ADDRESS: detail?.SERVERPART_ADDRESS })
                                }
                            }}
                            rules={[{
                                required: true,
                                message: '请选择服务区!'
                            }]}
                            readonly={isComponent}
                        />
                    </Col>
                    <Col span={8} style={{ display: 'none' }}>
                        <ProFormText
                            label={'服务区'}
                            name={'SERVERPART_NAME'}
                            readonly={isComponent}
                        />
                    </Col>
                    <Col span={8}>
                        <ProFormSelect
                            label={'服务区方位'}
                            name={'SERVERPART_REGION'}
                            // rules={[{
                            //     required: true,
                            //     message: '请选择服务区方位!'
                            // }]}
                            options={SERVERPARTREGION}
                            readonly={isComponent}
                        />
                    </Col>
                    <Col span={8}>
                        <ProFormDateRangePicker
                            label={'租赁日期'}
                            name={"LEASEDATE"}
                            style={{ width: '100%' }}
                            rules={[{ required: true, message: '请选择租赁日期!' }]}
                            readonly={isComponent}
                        />
                    </Col>

                    <Col span={8} >
                        <ProFormText
                            label={'省份名称'}
                            name={'PROVINCE_NAME'}
                            rules={[{ required: true, message: '请输入省份名称!' }]}
                            readonly={isComponent}
                        />
                    </Col>
                    <Col span={8} >
                        <ProFormText
                            label={'城市名称'}
                            name={'CITY_NAME'}
                            rules={[{ required: true, message: '请输入城市名称!' }]}
                            readonly={isComponent}
                        />
                    </Col>
                    <Col span={8} >
                        <ProFormSelect
                            label={'跨地标志'}
                            name={'CROSS_CITYSIGN'}
                            options={[
                                { label: "是", value: 1 },
                                { label: "否", value: 0 },
                            ]}
                            readonly={isComponent}
                        />
                    </Col>
                    <Col span={24} >
                        <ProFormTextArea
                            label={'详细地址'}
                            name={'REALESTATE_ADDRESS'}
                            rules={[{ required: true, message: '请输入详细地址!' }]}
                            readonly={isComponent}
                        />
                    </Col>
                    <Col span={8} >
                        <ProFormSelect
                            label={'面积单位'}
                            name={'AREA_UNIT'}
                            options={[
                                { label: "平方千米", value: 1 },
                                { label: "平方米", value: 2 },
                                { label: "公顷", value: 3 },
                                { label: "亩", value: 4 },
                                { label: "h㎡", value: 5 },
                                { label: "k㎡", value: 6 },
                                { label: "㎡", value: 7 }
                            ]}
                            rules={[{ required: true, message: '请选择面积单位!' }]}
                            readonly={isComponent}
                        />
                    </Col>
                    <Col span={8} >
                        <ProFormText
                            label={'产权证号'}
                            name={'ESTATE_IDENTITY'}
                            rules={[
                                ({ getFieldValue }) => ({
                                    validator(_: any, value: any) {
                                        if (value || getFieldValue('SPECIALINDUSTRY_NUMBER')) {
                                            return Promise.resolve();
                                        }
                                        return Promise.reject(new Error('产权证号和资料编码至少填写一个'));
                                    },
                                }),
                            ]}
                            readonly={isComponent}
                        />
                    </Col>
                    <Col span={8} >
                        <ProFormText
                            label={'资料编码'}
                            name={'SPECIALINDUSTRY_NUMBER'}
                            rules={[
                                ({ getFieldValue }) => ({
                                    validator(_: any, value: any) {
                                        if (value || getFieldValue('ESTATE_IDENTITY')) {
                                            return Promise.resolve();
                                        }
                                        return Promise.reject(new Error('产权证号和资料编码至少填写一个'));
                                    },
                                }),
                            ]}
                            readonly={isComponent}
                        />
                    </Col>


                </Row>
            </ProForm>


        </Modal>

    </div >
}


export default RealEstate         