import { connect } from "umi";
import type { ConnectState } from "@/models/connect";
import { PageContainer } from "@ant-design/pro-layout";
import type { FormInstance } from "antd";
import { message } from "antd";
import { Button, Col, Descriptions, Row, Tooltip } from "antd";
import moment from 'moment'
import { contractType } from "@/pages/contract/emun";
import session from "@/utils/session";
import ProTable from "@ant-design/pro-table";
import numeral from 'numeral'
import { useImperativeHandle, useRef, useState } from "react";
import CorrectTable from "./correctTable";
import { handleGetPeriodSupplementList } from "../service";
import ProForm, { ProFormDigit, ProFormSelect, ProFormTextArea, ProFormUploadButton } from "@ant-design/pro-form";
import { handleGetAPPROVALROUTEDetail, handleGetProjectPeriodAccount } from "../../ShopExpenseDetail/service";
import ReviewProcess from "../../revenueConfirmation/components/ReviewProcess";
import { getMoney } from "@/services/options";
import { wrapTreeNode } from "@/utils/format";
import { handleGetBUSINESSAPPROVALDetail } from "@/pages/examine/monthSettlement/service";
import HistoricalProjects from "./HistoricalProjects";

type DetailProps = {
    parentRow: any
    dataRef: any // 可以通过这个拿到选中的数据
    onShow: boolean // 组件是否显示
    setIsFinishCalibration?: any
    onRef: any
    currentUser?: any
    readonly: boolean // 判断是否显示按钮和 精算表单
}
const AfterSettlement = ({ parentRow, dataRef, onShow, setIsFinishCalibration, onRef, currentUser, readonly }: DetailProps) => {
    const SETTLEMENTMODESOBJ: any = session.get('SETTLEMENT_MODESObj')
    const settlementRef = useRef<FormInstance>();
    const HistoricalProjectsRef = useRef<any>()

    // 表格数据
    const [tableData, setTableData] = useState<any>()
    // 表格的加载效果
    const [tableLoading, setTableLoading] = useState<boolean>(false)
    // 日结冲正信息表的表格数据
    const [correctTableData, setCorrectTableData] = useState<any>()
    // 校验表单的加载效果
    const [proFormLoading, setProFormLoading] = useState<boolean>(false)
    // 附件
    const [fileList, setFileList] = useState<any>()
    // 当前是否为指定重新申请
    const [currentREJECTTYPE, setCurrentREJECT_TYPE] = useState<boolean>(false)
    // 指定的下一个状态
    const [nextState, setNextState] = useState<any>()
    const columns: any = [
        {
            title: <div style={{ textAlign: 'center' }}>期限</div>,
            dataIndex: 'PeriodDesc',
            align: 'left',
            width: 300,
            fixed: 'left',
            hideInSearch: true,
            render: (_, record) => {
                return record?.PeriodDesc === '合计' ?
                    <span style={{ color: '#9A3D1A', fontWeight: 600 }}>合计</span> :
                    record?.level === 1 ?
                        <span>{`${record?.PeriodDesc}`}</span> :
                        <>
                            <span>{`${record?.PeriodDesc}`}</span>
                            {
                                record?.EarlySettlement ?
                                    <span style={{ color: 'red', marginLeft: '4px' }}>【提前结算】</span> : ''
                            }
                        </>
            }
        },
        {
            title: '租金信息',
            dataIndex: '',
            hideInSearch: true,
            children: [
                {
                    title: <div style={{ textAlign: 'center' }}>保底/固定租金</div>,
                    dataIndex: 'MinturnOver',
                    valueType: 'digit',
                    align: 'right',
                    width: 130,
                    hideInSearch: true,
                },
                {
                    title: <div style={{ textAlign: 'center' }}>提成比率</div>,
                    dataIndex: 'GuaranteeRatio',
                    hideInSearch: true,
                    align: 'right',
                    width: 100,
                    render: (_, record) => {
                        return record?.GuaranteeRatio ? `${record?.GuaranteeRatio}%` : ''
                    }
                }
            ]
        },
        {
            title: '营业额',
            dataIndex: '',
            hideInSearch: true,
            children: [
                {
                    title: <div style={{ textAlign: 'center' }}>现金</div>,
                    dataIndex: 'CashAmount',
                    valueType: 'digit',
                    align: 'right',
                    width: 80,
                    hideInSearch: true,
                },
                {
                    title: <div style={{ textAlign: 'center' }}>微支付</div>,
                    dataIndex: 'MobilePayAmount',
                    valueType: 'digit',
                    align: 'right',
                    width: 100,
                    hideInSearch: true,
                },
                {
                    title: <div style={{ textAlign: 'center' }}>小计</div>,
                    dataIndex: 'RevenueAmount',
                    valueType: 'digit',
                    align: 'right',
                    width: 150,
                    hideInSearch: true,
                    render: (_, record) => {
                        return <span style={{ color: '#1890ff' }}>
                            {record?.RevenueAmount ?
                                `${numeral(getMoney(record?.RevenueAmount)).format('0,0.00')}${record?.addRevenueMoney ? `（${record?.addRevenueMoney > 0 ? '+' : record?.addRevenueMoney < 0 ? '' : ''}${record?.addRevenueMoney}）`
                                    : ''
                                }`
                                : '0'}</span>
                    }
                }
            ]
        },
        {
            title: <div style={{ textAlign: 'center' }}>业主收款</div>,
            dataIndex: 'RoyaltyAmount',
            valueType: 'digit',
            width: 100,
            align: 'right',
            hideInSearch: true,
        },
        {
            title: '应收费用',
            dataIndex: '',
            hideInSearch: true,
            children: [
                {
                    title: <div style={{ textAlign: 'center' }}>合计</div>,
                    dataIndex: 'ReceivableAmount',
                    valueType: 'digit',
                    align: 'right',
                    width: 100,
                    hideInSearch: true,
                    render: (_, record) => {
                        const str: string = `租金(${numeral(record?.GuaranteeFee).format('0.00')}) + 物业费(${numeral(record?.PropertyFee).format('0.00')}) + 房租(${numeral(record?.HouseRent).format('0.00')}) + 罚款(${numeral(record?.BreachPenalty).format('0.00')}) + 电费(${numeral(record?.ElectricityCharge).format('0.00')}) + 水费(${numeral(record?.WaterCharge).format('0.00')}) + 其他(${numeral(record?.OtherFee).format('0.00')})`
                        return record?.ReceivableAmount ?
                            <Tooltip title={str}>
                                <span>
                                    {numeral(record?.ReceivableAmount).format('0,0.00')}
                                </span>
                            </Tooltip>
                            : ''
                    }
                },
                {
                    title: <div style={{ textAlign: 'center' }}>租金</div>,
                    dataIndex: 'GuaranteeFee',
                    valueType: 'digit',
                    align: 'right',
                    width: 120,
                    hideInSearch: true,
                    render: (_, record) => {
                        const str: string = `租金(${numeral(record?.MinturnOver).format('0.00')}) ${record?.MinturnOver > (record?.RevenueAmount * (record?.GuaranteeRatio) / 100) ? '>' : '<'} 营业额(${record?.RevenueAmount || 0}) * 提成比率(${record?.GuaranteeRatio ? `${record?.GuaranteeRatio}%` : ''})`
                        return record?.GuaranteeFee ?
                            <Tooltip title={record?.PeriodDesc === '合计' ? '' : str}>
                                <span>{numeral(record?.GuaranteeFee).format('0,0.00')}</span>
                            </Tooltip>
                            : ''
                    }
                },
                {
                    title: <div style={{ textAlign: 'center' }}>物业费</div>,
                    dataIndex: 'PropertyFee',
                    valueType: 'digit',
                    align: 'right',
                    width: 100,
                    hideInSearch: true,
                    render: (_, record) => {
                        return record?.PropertyFee ?
                            numeral(record?.PropertyFee).format('0,0.00')
                            : record?.PropertyFee === 0 ? <span style={{ color: 'red' }}>0</span> : ''
                    }
                },
                {
                    title: <div style={{ textAlign: 'center' }}>房租</div>,
                    dataIndex: 'HouseRent',
                    valueType: 'digit',
                    align: 'right',
                    width: 80,
                    hideInSearch: true,
                },
                {
                    title: <div style={{ textAlign: 'center' }}>罚款</div>,
                    dataIndex: 'BreachPenalty',
                    valueType: 'digit',
                    align: 'right',
                    width: 80,
                    hideInSearch: true,
                },
                {
                    title: <div style={{ textAlign: 'center' }}>电费</div>,
                    dataIndex: 'ElectricityCharge',
                    valueType: 'digit',
                    align: 'right',
                    width: 80,
                    hideInSearch: true,
                    render: (_, record) => {
                        return record?.ElectricityCharge ?
                            numeral(record?.ElectricityCharge).format('0,0.00')
                            : record?.ElectricityCharge === 0 ? <span style={{ color: 'red' }}>0</span> : ''
                    }
                },
                {
                    title: <div style={{ textAlign: 'center' }}>水费</div>,
                    dataIndex: 'WaterCharge',
                    valueType: 'digit',
                    align: 'right',
                    width: 80,
                    hideInSearch: true,
                    render: (_, record) => {
                        return record?.WaterCharge ?
                            numeral(record?.WaterCharge).format('0,0.00')
                            : record?.WaterCharge === 0 ? <span style={{ color: 'red' }}>0</span> : ''
                    }
                },
                {
                    title: <div style={{ textAlign: 'center' }}>其他</div>,
                    dataIndex: 'OtherFee',
                    valueType: 'digit',
                    align: 'right',
                    width: 80,
                    hideInSearch: true,
                }
            ]
        },
        {
            title: '已缴费用',
            dataIndex: '',
            align: 'center',
            hideInSearch: true,
            children: [
                {
                    title: <div style={{ textAlign: 'center' }}>合计</div>,
                    dataIndex: 'PaidFee',
                    valueType: 'digit',
                    align: 'right',
                    width: 100,
                    hideInSearch: true,
                    render: (_, record) => {
                        const str: string = `水费(${numeral(record?.SHOPEXPENSE_AMOUNT_1000).format('0.00')}) + 电费(${numeral(record?.SHOPEXPENSE_AMOUNT_2000).format('0.00')}) + 房租(${numeral(record?.SHOPEXPENSE_AMOUNT_3000).format('0.00')})
                + 物业费(${numeral(record?.SHOPEXPENSE_AMOUNT_5000).format('0.00')})`


                        return record?.PaidFee
                            ?
                            <Tooltip title={str}>
                                <span>{numeral(record?.PaidFee).format('0,0.00')}</span>
                            </Tooltip>
                            : ''
                    }
                },
                {
                    title: <div style={{ textAlign: 'center' }}>水费</div>,
                    dataIndex: 'SHOPEXPENSE_AMOUNT_1000',
                    valueType: 'digit',
                    align: 'right',
                    width: 80,
                    hideInSearch: true,
                    render: (_, record) => {
                        return record?.SHOPEXPENSE_AMOUNT_1000 ?
                            numeral(record?.SHOPEXPENSE_AMOUNT_1000).format('0,0.00')
                            : record?.SHOPEXPENSE_AMOUNT_1000 === 0 ? <span style={{ color: 'red' }}>0</span> : ''
                    }
                },
                {
                    title: <div style={{ textAlign: 'center' }}>电费</div>,
                    dataIndex: 'SHOPEXPENSE_AMOUNT_2000',
                    valueType: 'digit',
                    align: 'right',
                    width: 80,
                    hideInSearch: true,
                    render: (_, record) => {
                        return record?.SHOPEXPENSE_AMOUNT_2000 ?
                            numeral(record?.SHOPEXPENSE_AMOUNT_2000).format('0,0.00')
                            : record?.SHOPEXPENSE_AMOUNT_2000 === 0 ? <span style={{ color: 'red' }}>0</span> : ''
                    }
                },
                {
                    title: <div style={{ textAlign: 'center' }}>房租</div>,
                    dataIndex: 'SHOPEXPENSE_AMOUNT_3000',
                    valueType: 'digit',
                    align: 'right',
                    width: 80,
                    hideInSearch: true,
                },
                {
                    title: <div style={{ textAlign: 'center' }}>物业费</div>,
                    dataIndex: 'SHOPEXPENSE_AMOUNT_5000',
                    valueType: 'digit',
                    align: 'right',
                    width: 100,
                    hideInSearch: true,
                    render: (_, record) => {
                        return record?.SHOPEXPENSE_AMOUNT_5000 ?
                            numeral(record?.SHOPEXPENSE_AMOUNT_5000).format('0,0.00')
                            : record?.SHOPEXPENSE_AMOUNT_5000 === 0 ? <span style={{ color: 'red' }}>0</span> : ''
                    }
                }
            ]
        },
        {
            title: <div style={{ textAlign: 'center' }}>退补款</div>,
            dataIndex: 'RefundSupplement',
            valueType: 'digit',
            align: 'right',
            fixed: 'right',
            width: 100,
            hideInSearch: true,
            render: (_, record) => {
                const str: string = `业主收款(${record?.RoyaltyAmount || 0}) - 应收费用(${record?.ReceivableAmount || 0}) + 已缴费用(${record?.PaidFee || 0})`
                return record?.RefundSupplement ?
                    <Tooltip title={str}>
                        <span style={{ color: '#9A3D1A', fontWeight: 600 }}>{numeral(record?.RefundSupplement).format('0,0.00')}</span>
                    </Tooltip>
                    : ''
            }
        },

    ]

    const descirption = () => {
        return <>
            <Descriptions column={3}>
                <Descriptions.Item label="开始日期">{parentRow?.STARTDATE ? moment(parentRow?.STARTDATE).format('YYYY-MM-DD') : ''}</Descriptions.Item>
                <Descriptions.Item label="截止日期">{parentRow?.ENDDATE ? moment(parentRow?.ENDDATE).format('YYYY-MM-DD') : ''}</Descriptions.Item>
                <Descriptions.Item label="经营商户">{parentRow?.MERCHANTS_NAME}</Descriptions.Item>
            </Descriptions>
            <Descriptions column={3}>
                <Descriptions.Item label="经营模式">{parentRow?.BUSINESS_TYPE ? contractType[parentRow?.BUSINESS_TYPE] : '-'}</Descriptions.Item>
                <Descriptions.Item label="结算模式">{parentRow?.SETTLEMENT_MODES ? SETTLEMENTMODESOBJ[parentRow?.SETTLEMENT_MODES] : '-'}</Descriptions.Item>
                {/* <Descriptions.Item label="项目税率">{}</Descriptions.Item> */}
                <Descriptions.Item label="经营门店">{parentRow?.SERVERPARTSHOP_NAME}</Descriptions.Item>
            </Descriptions>


            {/* <Descriptions column={3}> */}
            {/* </Descriptions> */}
        </>
    }

    // 重新校准
    const handleRecalibrate = (money?: any) => {

        if (tableData && tableData.length > 0) {
            // 避免重复添加重新精算的数据 把原本重新精算的数据 先给筛选掉
            const newReqList: any = []
            tableData.forEach((item: any) => {
                if (item.PeriodDesc !== '精算数据' && item.PeriodDesc !== '合计') {
                    newReqList.push(item)
                }
                if (item.PeriodDesc === '合计' && item.children && item.children.length > 0) {
                    item.children.forEach((subItem: any) => {
                        newReqList.push(subItem)
                    })
                }
            })
            console.log('tableData', tableData);

            // 最近的一条数据
            const newObj: any = JSON.parse(JSON.stringify(newReqList[newReqList.length - 1]))
            // 重新校准点击拿到的值
            const res = settlementRef.current?.getFieldsValue()
            newObj.RevenueAmount += (res?.CORRECT_AMOUNT || money || 0)
            newObj.addRevenueMoney = (res?.CORRECT_AMOUNT || money || 0)
            let isBig: boolean = false
            // 判断现在新的小计乘以提升比率 是否大于租金
            if ((newObj.RevenueAmount * (newObj.GuaranteeRatio / 100)) > newObj.GuaranteeFee) {
                isBig = true
            }
            // 如果新小计大于租金 那么租金就变成小计乘以比率 反之就是原本的值
            newObj.GuaranteeFee = isBig ? getMoney(newObj.RevenueAmount * (newObj.GuaranteeRatio / 100)) : newObj.GuaranteeFee
            if (isBig) {
                // 算出合计
                newObj.ReceivableAmount = newObj.GuaranteeFee + newObj.PropertyFee + newObj.HouseRent + newObj.BreachPenalty + newObj.ElectricityCharge + newObj.WaterCharge + newObj.OtherFee
                // 算出退补款
                newObj.RefundSupplement = newObj.RoyaltyAmount - newObj.ReceivableAmount + newObj?.PaidFee
            }
            const list = JSON.parse(JSON.stringify(newReqList))
            newObj.PeriodDesc = '精算数据'
            newObj.children = null

            // 根据新要求 冲正了多少钱应该显示在第二条记录里面 即精算数据的上面一行 精算数据 直接显示结果既可
            list.forEach((item: any, index: number) => {
                if (index === list.length - 1) {
                    item.addRevenueMoney = newObj.addRevenueMoney
                }
            })
            newObj.addRevenueMoney = null
            list.push(newObj)
            console.log('list', list);

            setTableData(list)
        }
    }

    useImperativeHandle(onRef, () => ({
        settlementRef,
        tableData,
        fileList,
        nextState,
        HistoricalProjectsRef
    }));


    return (
        <div>
            <PageContainer
                style={{ width: '100%', height: '100%', background: '#ffffff' }}
                header={{
                    title: parentRow?.BUSINESSPROJECT_NAME,
                    breadcrumb: {},
                }}
            >
                <>
                    <>
                        {descirption()}
                    </>
                    <>
                        <ProTable
                            rowKey={(record) => {
                                return `${record?.ShopRoyalty_Id}-${record?.PeriodIndexStr}-${record?.PeriodDesc}`
                            }}
                            columns={columns}
                            bordered
                            search={false}
                            pagination={false}
                            scroll={{ x: 'max-content' }}
                            loading={tableLoading}
                            request={async () => {
                                setTableLoading(true)
                                console.log('dataRef', dataRef);
                                const res: any = dataRef.current?.YearExamineDetailTableRef?.current?.selectDetailList
                                setTableData(res)
                                console.log('res', res);
                                // 拿最小的开始  最大的结束
                                let startTime: string = ''
                                let endTime: string = ''
                                let ShopRoyaltyIdStr: string = ''
                                if (res && res.length > 0) {
                                    res.forEach((item: any, index: number) => {
                                        if (item.PeriodDesc !== '合计') {
                                            if (ShopRoyaltyIdStr) {
                                                ShopRoyaltyIdStr += `,${item.ShopRoyalty_Id}`
                                            } else {
                                                ShopRoyaltyIdStr = `${item.ShopRoyalty_Id}`
                                            }


                                            if (startTime) {
                                                if (new Date(moment(item.StartDate).format('YYYY-MM-DD')).getTime() < new Date(startTime).getTime()) {
                                                    startTime = moment(item.StartDate).format('YYYY-MM-DD')
                                                }
                                            } else {
                                                startTime = moment(item.StartDate).format('YYYY-MM-DD')
                                            }

                                            if (endTime) {
                                                if (new Date(moment(item.EndDate).format('YYYY-MM-DD')).getTime() > new Date(endTime).getTime()) {
                                                    endTime = moment(item.EndDate).format('YYYY-MM-DD')
                                                }
                                            } else {
                                                endTime = moment(item.EndDate).format('YYYY-MM-DD')
                                            }
                                        } else {
                                            if (item.children && item.children.length > 0) {
                                                item.children.forEach((subItem) => {
                                                    if (ShopRoyaltyIdStr) {
                                                        ShopRoyaltyIdStr += `,${subItem.ShopRoyalty_Id}`
                                                    } else {
                                                        ShopRoyaltyIdStr = `${subItem.ShopRoyalty_Id}`
                                                    }


                                                    if (startTime) {
                                                        if (new Date(moment(subItem.StartDate).format('YYYY-MM-DD')).getTime() < new Date(startTime).getTime()) {
                                                            startTime = moment(subItem.StartDate).format('YYYY-MM-DD')
                                                        }
                                                    } else {
                                                        startTime = moment(subItem.StartDate).format('YYYY-MM-DD')
                                                    }

                                                    if (endTime) {
                                                        if (new Date(moment(subItem.EndDate).format('YYYY-MM-DD')).getTime() > new Date(endTime).getTime()) {
                                                            endTime = moment(subItem.EndDate).format('YYYY-MM-DD')
                                                        }
                                                    } else {
                                                        endTime = moment(subItem.EndDate).format('YYYY-MM-DD')
                                                    }
                                                })
                                            }
                                        }
                                    })
                                }
                                console.log('parentRow', parentRow);

                                // 调新接口 拿数据
                                const newReq: any = {
                                    BusinessProjectId: parentRow?.BUSINESSPROJECT_ID,
                                    ShopRoyaltyId: ShopRoyaltyIdStr,
                                    ServerpartShopId: parentRow?.SERVERPARTSHOP_ID,
                                    StartDate: startTime,
                                    EndDate: endTime,
                                }

                                const newData = await handleGetPeriodSupplementList(newReq)
                                console.log('newDatanewDatanewDatanewData', newData);
                                setCorrectTableData(newData)
                                if (!(parentRow?.APPLY_PROCCESS && parentRow?.BUSINESSAPPROVAL_ID)) {
                                    settlementRef.current?.setFieldsValue({ CORRECT_AMOUNT: newData && newData.length > 0 ? newData[0].CorrectAmount : '' })
                                }
                                setTableLoading(false)

                                // 如果是重新申请的话 再调用这个接口
                                if (parentRow?.APPLY_PROCCESS && parentRow?.BUSINESSAPPROVAL_ID) {
                                    const req: any = {
                                        BUSINESSPROJECT_ID: parentRow?.BUSINESSPROJECT_ID,
                                        SHOPROYALTY_ID: parentRow?.SHOPROYALTY_ID,
                                        BUSINESSAPPROVAL_ID: parentRow?.BUSINESSAPPROVAL_ID
                                    }
                                    const data = await handleGetProjectPeriodAccount(req)
                                    if (data.ProjectPeriodList && data.ProjectPeriodList.length > 0) {
                                        const list: any = wrapTreeNode(data.ProjectPeriodList)
                                        console.log('dskdjaskldjas', list);
                                        if (list && list.length > 0) {
                                            list.forEach((item: any) => {
                                                if (item.PeriodIndex > 0) {
                                                    settlementRef.current?.setFieldsValue({ CORRECT_AMOUNT: item.CorrectAmount })
                                                }
                                            })
                                        }

                                    }

                                }
                            }}
                            dataSource={tableData}
                        />
                    </>
                    {/* <HistoricalProjects parentRow={parentRow} onRef={HistoricalProjectsRef} /> */}
                    <>
                        {
                            tableLoading ? '' :
                                <CorrectTable data={correctTableData} show={false} currentRow={parentRow} money={parentRow?.CORRECT_AMOUNT} />
                        }
                    </>
                    {
                        readonly ? '' :
                            <div style={{ marginTop: '16px' }}>
                                <ProForm
                                    formRef={settlementRef}
                                    submitter={{
                                        render: () => {
                                            return []
                                        }
                                    }}
                                // loading={proFormLoading ? {
                                //     spinning: proFormLoading,
                                //     tip: '正在为您查询结算年度内，服务区管理员校验冲正数据...'
                                // } : false}
                                // request={() => {
                                //     setProFormLoading(true)
                                //     if (correctTableData && correctTableData.length > 0) {
                                //         const obj: any = correctTableData[0]
                                //         setProFormLoading(false)
                                //         return { CORRECT_AMOUNT: obj?.CorrectAmount || 0 }
                                //     }
                                //     setProFormLoading(false)
                                //     return {}
                                // }}
                                >
                                    <Row gutter={16}>
                                        <Col span={6}>
                                            <ProFormDigit
                                                name={'CORRECT_AMOUNT'}
                                                label={'冲正金额'}
                                                fieldProps={{
                                                    min: -9999999999
                                                }}
                                            />
                                        </Col>

                                        <Col span={6}>
                                            <ProFormSelect
                                                name="APPROVALSTAFF_ID"
                                                label="审批人"
                                                rules={[
                                                    {
                                                        required: true,
                                                        message: '请选择审批人'
                                                    }
                                                ]}
                                                disabled={currentREJECTTYPE}
                                                request={async () => {
                                                    console.log('currentRow请选择审批人', parentRow);

                                                    const req = {
                                                        OperationType: 11,
                                                        CurState: 1000,
                                                        IsValid: 1,
                                                        ShowApprovalUser: true,
                                                        ServerpartIds: parentRow?.SERVERPART_ID || '',
                                                        ShopIds: parentRow?.SERVERPARTSHOP_ID || ''
                                                    }
                                                    const data = await handleGetAPPROVALROUTEDetail(req)

                                                    const detailReq: any = {
                                                        BUSINESSAPPROVALId: parentRow?.BUSINESSAPPROVAL_ID
                                                    }
                                                    console.log('req', req);
                                                    let detailData: any = []
                                                    if (parentRow?.BUSINESSAPPROVAL_ID) {
                                                        detailData = await handleGetBUSINESSAPPROVALDetail(detailReq)
                                                    }
                                                    const list: any = []
                                                    if (detailData.REJECT_TYPE === 2) {
                                                        const nowPersonList: any = detailData.approveList[detailData.approveList.length - 1]
                                                        const list: any = [{ label: nowPersonList.REJECT_STAFF, value: `${nowPersonList.REJECT_STAFF}-${nowPersonList.REJECT_ID}` }]
                                                        settlementRef.current?.setFieldsValue({ APPROVALSTAFF_ID: `${nowPersonList.REJECT_STAFF}-${nowPersonList.REJECT_ID}` })
                                                        setNextState(nowPersonList?.REJECT_TYPE)
                                                        setCurrentREJECT_TYPE(true)
                                                        return list
                                                    }
                                                    setCurrentREJECT_TYPE(false)
                                                    setNextState(undefined)
                                                    if (data.UserList && data.UserList.length > 0) {
                                                        data.UserList.forEach((item: any) => {
                                                            list.push({ label: item.USER_NAME, value: `${item.USER_NAME}-${item.USER_ID}` })
                                                        })
                                                    }
                                                    if (list && list.length > 0 && list.length === 1) {
                                                        settlementRef.current?.setFieldsValue({ APPROVALSTAFF_ID: list[0].value })
                                                    }
                                                    if (currentUser?.ID === 2785) {
                                                        list.push({ label: '严琅杰', value: `严琅杰-2785` })
                                                    }

                                                    return list


                                                }}
                                            />
                                        </Col>

                                    </Row>

                                    <ProFormTextArea
                                        label={"结算备注"}
                                        name={"BUSINESSAPPROVAL_DESC"}
                                        rules={[
                                            {
                                                required: true,
                                                message: '请输入结算备注'
                                            }
                                        ]}
                                    />

                                    <ProFormUploadButton
                                        label={"上传年度结算单"}
                                        name="files"
                                        fileList={fileList}
                                        fieldProps={{
                                            beforeUpload: () => false,
                                            onChange: async (info: any) => {
                                                console.log('info', info);
                                                // setFileList(info.fileList)
                                                const { fileList: newFileList } = info;

                                                // 过滤出有效的图片文件
                                                const validFileList = newFileList.filter(file => {
                                                    if (file.type.startsWith('image/')) {
                                                        return true;
                                                    }
                                                    message.error(`${file.name} 不是图片文件，已被移除.`);
                                                    return false;

                                                });
                                                // 更新文件列表
                                                setFileList(validFileList);


                                                // console.log('parentRow', parentRow);


                                                // const formData = new FormData();
                                                // info.fileList.forEach((item: any) => {
                                                //     if (item.status !== "done") {
                                                //         console.log('item', item);
                                                //         formData.append('files[]', item.originFileObj);
                                                //         formData.append('ImageName', item.name);
                                                //     }
                                                // })
                                                // formData.append('TableType', '1130');
                                                // formData.append('TableId', );
                                            }
                                        }}
                                        buttonProps={{
                                            children: '上传年度结算单'
                                        }}
                                    />

                                    <div style={{ width: '100%', display: 'flex', justifyContent: 'flex-end' }}>
                                        <Button type="primary" onClick={() => {
                                            handleRecalibrate()
                                            setIsFinishCalibration(true)
                                        }}>
                                            精算金额
                                        </Button>
                                    </div>

                                </ProForm>
                            </div>
                    }

                    {
                        readonly ? '' :
                            <div style={{ paddingBottom: '16px', paddingTop: '16px' }}>
                                <ReviewProcess showReviewProcess={onShow} compareCurrent={{
                                    ...parentRow,
                                    BusinessApprovalId: parentRow?.BUSINESSAPPROVAL_ID
                                }} changeDesc={settlementRef} />
                            </div>
                    }



                </>
            </PageContainer>
        </div>
    )
}

export default connect(({ user, }: ConnectState) => ({
    currentUser: user.currentUser,
}))(AfterSettlement);
