import { connect } from "umi";
import type { ConnectState } from "@/models/connect";
import { Button, Card, Col, FormInstance, Input, message, Modal, Popconfirm, Row, Space, Steps, Tooltip } from "antd";
import { useImperativeHandle, useRef, useState } from "react";
import ProForm, { ProFormSelect, ProFormTextArea } from "@ant-design/pro-form";
import { handleApproveCommodityProInst, handleCreateCommodityProInst, handleDeleteCOMMODITY_RUNNING, handleGetApprovalCommodityList, handleGetBUSINESSAPPROVALDetail, handleGetCOMMODITYRUNNINGList, handleReapplyCommodityProInst, handleRejectCommodityProInst } from "../../ProductApprovalProcess/service";
import session from "@/utils/session";
import { handleGetAPPROVALROUTEList } from "@/pages/Setting/serviceConfig/service";
import ProTable from "@ant-design/pro-table";

type DetailProps = {
    modalType: number // 1 新增商品申请  2 商品调价申请 3 信息修改审批
    parentRow: any // 父级传入的基本信息
    tableRef: any // 表格的实例
    onShow: any // 控制组件是否显示
    handleCencel: any // 悬浮框取消显示的效果
    currentUser: any // 公参
    showDetailType: any // 显示的类型
    InitiateApplication: any // 有无发起的权限
    shopData: any // 商品数据
    handleChangeShopData: any // 改变shopData的方法
    ApprovalType: any // 审批还是驳回的判断
    setCurrentShopRow: any // 当前的商品行
    setShowAddShopModal: any // 新增商品的悬浮框
    setShowEditShopModal?: any // 打开编辑 调价的时候可以出现
    setSelectRowList?: any // 关于选择行 调价的时候可以出现
    setSelectedOrderRowKeys?: any// 关于选择行 调价的时候可以出现
    onRef?: any // 子组件实例
    setEditSelectRow?: any // 编辑的商品行  修改信息的时候才会有
    setEditShopModal?: any // 打开编辑商品的悬浮框  修改信息的时候 才会有
}
const NewApplicationModal = ({ modalType, parentRow, tableRef, onShow, handleCencel, currentUser, showDetailType, InitiateApplication, shopData, handleChangeShopData,
    ApprovalType, setCurrentShopRow, setShowAddShopModal, setShowEditShopModal, setSelectRowList, setSelectedOrderRowKeys, onRef, setEditSelectRow, setEditShopModal }: DetailProps) => {
    const { Step } = Steps

    const modalApproveFormRef = useRef<FormInstance>();
    const modalFormRef = useRef<FormInstance>();

    // 审批记录详情
    const [BUSINESSAPPROVALDETAIL, setBUSINESSAPPROVALDETAIL] = useState<any>()
    // 还有几个环节 拼在流程进度后面
    const [nextStepsList, setNextStepsList] = useState<any>()
    // 下一个审批流程
    const [nextApproval, setNextApproval] = useState<any>()
    // 下一审批流程的审批人
    const [nextApprovalPerson, setNextApprovalPerson] = useState<any>()
    // 新增申请的加载效果
    const [addApprovalLoading, setAddApprovalLoading] = useState<boolean>(false);
    // 确认按钮的加载效果
    const [confirmLoading, setConfirmLoading] = useState<boolean>(false);

    const modalColumns: any = [
        {
            title: "序号",
            width: 70,
            dataIndex: "index",
            valueType: "index",
            align: 'center',
            ellipsis: true,
        },
        {
            title: "名称",
            width: 300,
            dataIndex: "COMMODITY_NAME",
            ellipsis: true,
            align: 'center',
        },
        {
            title: "条码",
            width: 150,
            dataIndex: "COMMODITY_BARCODE",
            ellipsis: true,
            align: 'center',
        },
        {
            title: "零售价",
            width: 150,
            dataIndex: "COMMODITY_RETAILPRICE",
            ellipsis: true,
            align: 'center',
        },
        {
            title: "规格",
            width: 150,
            dataIndex: "COMMODITY_RULE",
            ellipsis: true,
            align: 'center',
        },
        {
            title: "单位",
            width: 150,
            dataIndex: "COMMODITY_UNIT",
            ellipsis: true,
            align: 'center',
        },
        {
            dataIndex: 'option',
            title: '操作',
            valueType: 'option',
            align: 'center',
            hideInSearch: true,
            width: 120,
            fixed: "right",
            ellipsis: true,
            render: (_, record) => {
                return (
                    <Space>
                        {
                            parentRow?.BusinessProcess_State > 1000 || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID) ? '' :
                                <>
                                    <a
                                        onClick={() => {
                                            setCurrentShopRow(record)
                                            setShowAddShopModal(true)
                                        }}
                                    >
                                        编辑
                                    </a>
                                    <Popconfirm
                                        title="确认删除该商品管理列表信息吗?"
                                        onConfirm={async () => {
                                            if (parentRow?.BusinessApproval_ID) {
                                                // 申请回到发起时候的真删
                                                const req: any = {
                                                    COMMODITY_RUNNINGId: record?.COMMODITY_ID
                                                }
                                                const data = await handleDeleteCOMMODITY_RUNNING(req)
                                                console.log('datadatadatadata', data);
                                                // actionRef.current?.reload()
                                                if (tableRef) {
                                                    tableRef.current?.reload()
                                                }
                                                // 实现直接删除的效果
                                                let oldData: any = JSON.parse(JSON.stringify(shopData))
                                                let list: any = []
                                                oldData.forEach((item: any) => {
                                                    if (item.COMMODITY_ID !== record?.COMMODITY_ID) {
                                                        list.push(item)
                                                    }
                                                })
                                                if (handleChangeShopData) {
                                                    handleChangeShopData(list)
                                                }
                                            } else {
                                                // 还未发起申请的假删
                                                console.log('record', record);
                                                let oldData: any = JSON.parse(JSON.stringify(shopData))
                                                let list: any = []
                                                oldData.forEach((item: any) => {
                                                    if (item.ADDTIME !== record?.ADDTIME) {
                                                        list.push(item)
                                                    }
                                                })
                                                if (handleChangeShopData) {
                                                    handleChangeShopData(list)
                                                }
                                            }
                                        }}
                                    >
                                        <a>删除</a>
                                    </Popconfirm>
                                </>
                        }

                        {
                            parentRow?.BusinessProcess_State === 9000 ?
                                <a onClick={() => {
                                    setCurrentShopRow(record)
                                    setShowAddShopModal(true)
                                }}>详情</a>
                                : ''
                        }

                    </Space>
                );
            },
        },
    ]


    const modalColumnsPrice: any = [
        {
            title: "序号",
            width: 70,
            dataIndex: "index",
            valueType: "index",
            align: 'center',
            ellipsis: true,
        },
        {
            title: "名称",
            width: 300,
            dataIndex: "COMMODITY_NAME",
            ellipsis: true,
            align: 'center',
            render: (_, record) => {
                return record?.COMMODITY_NAME ? <a onClick={() => {
                    setCurrentShopRow(record)
                    setShowEditShopModal(true)
                }}>
                    {record?.COMMODITY_NAME}
                </a> : "-"
            }
        },
        {
            title: "条码",
            width: 150,
            dataIndex: "COMMODITY_BARCODE",
            ellipsis: true,
            align: 'center',
        },
        {
            title: "原价",
            width: 150,
            dataIndex: "COMMODITY_CURRPRICE",
            ellipsis: true,
            align: 'center',
        },
        {
            title: "现价",
            width: 150,
            dataIndex: "newPrice",
            ellipsis: true,
            align: 'center',
            render: (_, record) => {
                return <Input value={record.newPrice} disabled={parentRow?.BusinessProcess_State > 1000 || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID)} onChange={(e: any) => {
                    let oldData: any = JSON.parse(JSON.stringify(shopData))
                    let list: any = []
                    oldData.forEach((item: any) => {
                        if (item.COMMODITY_ID === record?.COMMODITY_ID) {
                            item.newPrice = e.target.value
                        }
                        list.push(item)
                    })
                    if (handleChangeShopData) {
                        handleChangeShopData(list)
                    }
                    // setShopData(list)
                }} />
            }
        },
        {
            title: "单位",
            width: 150,
            dataIndex: "COMMODITY_UNIT",
            ellipsis: true,
            align: 'center',
        },
        {
            dataIndex: 'option',
            title: '操作',
            valueType: 'option',
            align: 'center',
            hideInSearch: true,
            width: 180,
            fixed: "right",
            ellipsis: true,
            render: (_, record) => {
                return (
                    <Space>
                        {
                            parentRow?.BusinessProcess_State > 1000 || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID) ? '' :
                                <>
                                    <Popconfirm
                                        title="确认删除该商品管理列表信息吗?"
                                        onConfirm={async () => {
                                            if (parentRow?.BusinessApproval_ID) {
                                                // 申请回到发起时候的真删
                                                const req: any = {
                                                    COMMODITY_RUNNINGId: record?.COMMODITY_ID
                                                }
                                                const data = await handleDeleteCOMMODITY_RUNNING(req)
                                                console.log('datadatadatadata', data);
                                                if (tableRef) {
                                                    tableRef.current?.reload()
                                                }
                                                // 实现直接删除的效果
                                                console.log('record', record);
                                                let oldData: any = JSON.parse(JSON.stringify(shopData))
                                                let list: any = []
                                                let rowKeyList: number[] = []
                                                oldData.forEach((item: any) => {
                                                    if (item.COMMODITY_ID !== record?.COMMODITY_ID) {
                                                        list.push(item)
                                                        rowKeyList.push(item.COMMODITY_ID)
                                                    }
                                                })
                                                // setShopData(list)
                                                if (handleChangeShopData) {
                                                    handleChangeShopData(list)
                                                }

                                                console.log('listlist', list);


                                                if (setSelectRowList) {
                                                    setSelectRowList(list)
                                                }
                                                if (setSelectedOrderRowKeys) {
                                                    setSelectedOrderRowKeys(rowKeyList)
                                                }
                                            } else {
                                                console.log('record', record);
                                                let oldData: any = JSON.parse(JSON.stringify(shopData))
                                                let list: any = []
                                                let rowKeyList: number[] = []
                                                oldData.forEach((item: any) => {
                                                    if (item.COMMODITY_ID !== record?.COMMODITY_ID) {
                                                        list.push(item)
                                                        rowKeyList.push(item.COMMODITY_ID)
                                                    }
                                                })

                                                console.log('listlist', list);
                                                if (handleChangeShopData) {
                                                    handleChangeShopData(list)
                                                }
                                                console.log('setSelectRowList', setSelectRowList);
                                                if (setSelectRowList) {
                                                    setSelectRowList(list)
                                                }
                                                if (setSelectedOrderRowKeys) {
                                                    setSelectedOrderRowKeys(rowKeyList)
                                                }
                                            }
                                        }}
                                    >
                                        <a>删除</a>
                                    </Popconfirm>
                                </>
                        }
                    </Space>
                );
            },
        },
    ]

    const modalColumnsInfo: any = [
        {
            title: "序号",
            width: 70,
            dataIndex: "index",
            valueType: "index",
            align: 'center',
            ellipsis: true,
        },
        {
            title: "名称",
            width: 300,
            dataIndex: "COMMODITY_NAME",
            ellipsis: true,
            align: 'center',
            render: (_, record) => {
                return record?.COMMODITY_NAME ? <a onClick={() => {
                    let obj: any = {}
                    if (shopData && shopData.length > 0) {
                        obj = shopData.filter((item: any) => item.COMMODITY_ID === record?.COMMODITY_ID)[0]
                    }
                    setEditSelectRow(obj)
                    setEditShopModal(true)
                }}>
                    {record?.COMMODITY_NAME}
                </a> : "-"
            }
        },
        {
            title: "条码",
            width: 150,
            dataIndex: "COMMODITY_BARCODE",
            ellipsis: true,
            align: 'center',
        },
        {
            title: "零售价",
            width: 150,
            dataIndex: "COMMODITY_RETAILPRICE",
            ellipsis: true,
            align: 'center',
        },
        {
            title: "规格",
            width: 150,
            dataIndex: "COMMODITY_RULE",
            ellipsis: true,
            align: 'center',
        },
        {
            title: "单位",
            width: 150,
            dataIndex: "COMMODITY_UNIT",
            ellipsis: true,
            align: 'center',
        },
        {
            dataIndex: 'option',
            title: '操作',
            valueType: 'option',
            align: 'center',
            hideInSearch: true,
            width: 120,
            fixed: "right",
            ellipsis: true,
            render: (_, record) => {
                return (
                    <Space>
                        {
                            parentRow?.BusinessProcess_State > 1000 || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID) ? '' :
                                <>
                                    <a
                                        onClick={() => {
                                            let obj: any = {}
                                            if (shopData && shopData.length > 0) {
                                                obj = shopData.filter((item: any) => item.COMMODITY_ID === record?.COMMODITY_ID)[0]
                                            }
                                            setEditSelectRow(obj)
                                            setEditShopModal(true)
                                        }}
                                    >
                                        编辑
                                    </a>
                                    <Popconfirm
                                        title="确认删除该商品管理列表信息吗?"
                                        onConfirm={async () => {
                                            if (parentRow?.BusinessApproval_ID) {
                                                // 申请回到发起时候的真删
                                                const req: any = {
                                                    COMMODITY_RUNNINGId: record?.COMMODITY_ID
                                                }
                                                const data = await handleDeleteCOMMODITY_RUNNING(req)
                                                console.log('datadatadatadata', data);
                                                parentRow.current?.reload()
                                                // 实现直接删除的效果
                                                let oldData: any = JSON.parse(JSON.stringify(shopData))
                                                let rowKeyList: number[] = []

                                                let list: any = []
                                                oldData.forEach((item: any) => {
                                                    if (item.COMMODITY_ID !== record?.COMMODITY_ID) {
                                                        list.push(item)
                                                        rowKeyList.push(item.COMMODITY_ID)

                                                    }
                                                })
                                                // setShopData(list)
                                                if (handleChangeShopData) {
                                                    handleChangeShopData(list)
                                                }

                                                if (setSelectRowList) {
                                                    setSelectRowList(list)
                                                }
                                                if (setSelectedOrderRowKeys) {
                                                    setSelectedOrderRowKeys(rowKeyList)
                                                }
                                            } else {
                                                // 还未发起申请的假删
                                                console.log('record', record);
                                                let oldData: any = JSON.parse(JSON.stringify(shopData))
                                                let list: any = []
                                                let rowKeyList: number[] = []
                                                oldData.forEach((item: any) => {
                                                    if (item.ADDTIME !== record?.ADDTIME) {
                                                        list.push(item)
                                                        rowKeyList.push(item.COMMODITY_ID)
                                                    }
                                                })
                                                // setShopData(list)
                                                if (handleChangeShopData) {
                                                    handleChangeShopData(list)
                                                }

                                                if (setSelectRowList) {
                                                    setSelectRowList(list)
                                                }
                                                if (setSelectedOrderRowKeys) {
                                                    setSelectedOrderRowKeys(rowKeyList)
                                                }
                                            }
                                        }}
                                    >
                                        <a>删除</a>
                                    </Popconfirm>
                                </>
                        }

                        {
                            parentRow?.BusinessProcess_State === 9000 ?
                                <a onClick={() => {
                                    // setCurrentShopRow(record)
                                    // setShowAddShopModal(true)
                                    setEditSelectRow(record)
                                    setEditShopModal(true)
                                }}>详情</a>
                                : ''
                        }
                    </Space>
                );
            },
        },
    ]

    useImperativeHandle(onRef, () => ({
        modalFormRef
    }));



    return (
        <div>
            {/* 新增申请的悬浮框 */}
            <Modal
                className="addProductModal"
                width={"70%"}
                title={modalType === 1 ? parentRow?.BusinessApproval_ID ? "商品申请详情" : "新增商品申请" :
                    modalType === 2 ? parentRow?.BusinessApproval_ID ? "商品调价申请详情" : "新增商品调价申请" :
                        modalType === 3 ? parentRow?.BusinessApproval_ID ? "商品信息修改详情" : "新增商品信息修改申请" : ''
                }
                open={onShow}
                destroyOnClose
                onCancel={() => {
                    if (handleCencel) {
                        handleCencel()
                    }
                }}
                // footer={showDetailType === 'detail' || !InitiateApplication || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID) ? false :
                footer={parentRow?.BusinessProcess_State === 9000 || !InitiateApplication || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID) ? false :
                    <div style={{ width: '100%', display: 'flex', alignItems: 'center', justifyContent: 'flex-end', boxSizing: 'border-box', padding: "0 16px" }}>
                        <Button style={{ marginRight: '8px' }} onClick={() => {
                            if (handleCencel) {
                                handleCencel()
                            }
                        }}>取消</Button>

                        <Button loading={confirmLoading} type={"primary"} onClick={() => {
                            if (parentRow?.BusinessProcess_State > 1000) {
                                modalApproveFormRef?.current?.validateFields().then(() => {
                                    modalApproveFormRef?.current?.submit()
                                })
                            } else {
                                if (modalType === 1) {
                                    if (shopData && shopData.length > 0) {
                                        modalFormRef?.current?.validateFields().then(() => {
                                            modalFormRef?.current?.submit()
                                        })
                                    } else {
                                        message.error("请选选择申请的商品！")
                                        return
                                    }
                                } else if (modalType === 2) {
                                    // 判断表格里面的现价 是不是都已经输入了
                                    let allRight: boolean = true
                                    if (shopData && shopData.length > 0) {
                                        shopData.forEach((item: any) => {
                                            if (!item.newPrice) {
                                                allRight = false
                                            }
                                        })
                                    } else {
                                        message.error("请选选择申请的商品！")
                                        return
                                    }
                                    if (!allRight) {
                                        message.error("请先完善表格数据！")
                                        return
                                    }
                                    // formRef?.current?.validateFields().then(() => {
                                    modalFormRef?.current?.submit()
                                    // })
                                } else if (modalType === 3) {
                                    modalFormRef?.current?.validateFields().then(() => {
                                        modalFormRef?.current?.submit()
                                    })
                                }

                            }
                        }}>确认</Button>
                    </div>}
                onOk={() => {
                    if (parentRow?.BusinessProcess_State > 1000) {
                        modalApproveFormRef?.current?.validateFields().then(() => {
                            modalApproveFormRef?.current?.submit()
                        })
                    } else {
                        if (modalType === 1) {
                            modalFormRef?.current?.validateFields().then(() => {
                                modalFormRef?.current?.submit()
                            })
                        } else if (modalType === 2) {
                            // 判断表格里面的现价 是不是都已经输入了
                            let allRight: boolean = true
                            if (shopData && shopData.length > 0) {
                                shopData.forEach((item: any) => {
                                    if (!item.newPrice) {
                                        allRight = false
                                    }
                                })
                            }
                            if (!allRight) {
                                message.error("请先完善表格数据！")
                                return
                            }
                            // formRef?.current?.validateFields().then(() => {
                            modalFormRef?.current?.submit()
                            // })
                        } else if (modalType === 3) {
                            modalFormRef?.current?.validateFields().then(() => {
                                modalFormRef?.current?.submit()
                            })
                        }
                    }
                }}
                bodyStyle={{
                    height: '700px', // 你可以根据需要调整高度
                    overflowY: 'auto',
                }}
            >
                <ProForm
                    // layout={'horizontal'}
                    formRef={modalFormRef}
                    submitter={false}
                    preserve={false}
                    request={async () => {
                        if (parentRow?.BusinessApproval_ID) {
                            const req: any = {
                                BUSINESSAPPROVALId: parentRow?.BusinessApproval_ID,
                            }
                            const data = await handleGetBUSINESSAPPROVALDetail(req)
                            console.log('datadatadata', data);
                            setBUSINESSAPPROVALDETAIL(data.Result_Data)

                            let shopData: any = []

                            if (parentRow?.BusinessProcess_State === 9000) {
                                shopData = await handleGetApprovalCommodityList({
                                    ProvinceCode: currentUser?.ProvinceCode,
                                    // CommodityId: currentUser?.ProvinceCode,
                                    BusinessApprovalId: parentRow?.BusinessApproval_ID,
                                    PageIndex: 1,
                                    PageSize: 999999,
                                })
                            } else {
                                shopData = await handleGetCOMMODITYRUNNINGList({
                                    SearchParameter: {
                                        BUSINESSAPPROVAL_ID: parentRow?.BusinessApproval_ID,
                                    },
                                    PageIndex: 1,
                                    pageSize: 999999,
                                })
                            }


                            console.log('shopDatashopDatashopDatashopData', shopData);
                            if (modalType === 1 || modalType === 3) {
                                // setShopData(shopData.Result_Data.List)
                                if (handleChangeShopData) {
                                    handleChangeShopData(shopData.Result_Data.List)
                                }
                            } else if (modalType === 2) {
                                let shopList: any = shopData.Result_Data.List
                                let list: any = []
                                if (shopList && shopList.length > 0) {
                                    shopList.forEach((item: any) => {
                                        let obj: any = JSON.parse(JSON.stringify(item))
                                        obj.newPrice = item.COMMODITY_CURRPRICE
                                        obj.COMMODITY_RETAILPRICE = item.COMMODITY_ORIPRICE
                                        obj.COMMODITY_CURRPRICE = item.COMMODITY_ORIPRICE
                                        obj.COMMODITY_MEMBERPRICE = item.COMMODITY_ORIPRICE
                                        obj.COMMODITY_ORIPRICE = null
                                        list.push(obj)
                                    })
                                }
                                if (handleChangeShopData) {
                                    handleChangeShopData(list)
                                }
                            }

                            return {
                                reasonForApplication: data.Result_Data.BUSINESSAPPROVAL_DESC,
                                ServerpartId: data.Result_Data.SERVERPART_ID,
                                NextApproveStaffId: data.Result_Data.APPOVED_IDS
                            }
                        } else {
                            return {}
                        }
                    }}
                    onFinish={async (res) => {
                        setConfirmLoading(true)
                        let data: any = {}
                        let list: any = []
                        if (modalType === 2) {
                            if (shopData && shopData.length > 0) {
                                shopData.forEach((item: any) => {
                                    let obj: any = JSON.parse(JSON.stringify(item))
                                    let oldPrice = JSON.parse(JSON.stringify(obj.COMMODITY_RETAILPRICE))
                                    obj.COMMODITY_ORIPRICE = oldPrice
                                    obj.COMMODITY_RETAILPRICE = item.newPrice
                                    obj.COMMODITY_CURRPRICE = item.newPrice
                                    obj.COMMODITY_MEMBERPRICE = item.newPrice

                                    list.push(obj)
                                })
                            }
                        } else if (modalType === 3) {
                            if (shopData && shopData.length > 0) {

                            } else {
                                message.error('请选择要修改的商品！')
                                return
                            }
                        }

                        if (parentRow?.BusinessApproval_ID) {
                            const req: any = {
                                ProinstId: parentRow?.BusinessApproval_ID,
                                ProinstName: res.reasonForApplication,
                                UserId: currentUser?.ID,
                                OperateType: modalType === 1 ? "100100" : modalType === 2 ? '100200' : modalType === 3 ? '100210' : '',
                                ServerpartId: res.ServerpartId,
                                NextApproveStaffId: res.NextApproveStaffId,
                                NextApproveState: 2000,
                                CommodityRunningList: modalType === 1 ? shopData : modalType === 2 ? list : modalType === 3 ? shopData : '',
                            }
                            data = await handleReapplyCommodityProInst(req)
                        } else {
                            const req: any = {
                                ProinstName: res.reasonForApplication,
                                UserId: currentUser?.ID,
                                OperateType: modalType === 1 ? "100100" : modalType === 2 ? '100200' : modalType === 3 ? '100210' : '',
                                ServerpartId: res.ServerpartId,
                                NextApproveStaffId: res.NextApproveStaffId,
                                NextApproveState: 2000,
                                CommodityRunningList: modalType === 1 ? shopData : modalType === 2 ? list : modalType === 3 ? shopData : '',
                            }
                            data = await handleCreateCommodityProInst(req)
                            console.log('dsaidjaskda', data);
                        }
                        setConfirmLoading(false)
                        if (data.Result_Code === 100) {
                            message.success(data.Result_Desc)
                            if (handleCencel) {
                                handleCencel()
                            }

                            if (tableRef) {
                                tableRef.current?.reload()
                            }

                        } else {
                            message.error(data.Result_Desc)
                        }



                    }}
                >
                    <Row gutter={8}>
                        <Col span={24}>
                            <ProFormTextArea
                                label="申请原因"
                                name="reasonForApplication"
                                rules={[{
                                    required: true,
                                    message: "请输入申请原因！"
                                }]}
                                disabled={parentRow?.BusinessProcess_State > 1000 || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID)}
                            />
                        </Col>
                        <Col span={12}>
                            <ProFormSelect
                                label="服务区"
                                name="ServerpartId"
                                rules={[{
                                    required: true,
                                    message: "请选择服务区！"
                                }]}
                                request={async () => {
                                    const ServerpartIdsTree = session.get('ServerpartIdsTree')
                                    return ServerpartIdsTree
                                }}
                                disabled={parentRow?.BusinessProcess_State > 1000 || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID)}
                                fieldProps={{
                                    showSearch: true,  // 启用搜索框
                                    filterOption: (inputValue: any, option: any) => {
                                        // 通过 label 搜索
                                        return option.label.toLowerCase().includes(inputValue.toLowerCase());
                                    }
                                }}

                            />
                        </Col>
                        <Col span={12} style={{ display: parentRow?.BusinessProcess_State > 1000 && ApprovalType !== 0 ? "none" : "" }}>
                            <ProFormSelect
                                label="下一环节审批人"
                                name="NextApproveStaffId"
                                rules={[{
                                    required: true,
                                    message: "请选择下一环节审批人！"
                                }]}
                                request={async () => {
                                    const reqState: any = {
                                        SearchParameter: {
                                            PROVINCE_CODE: currentUser?.ProvinceCode,
                                            APPROVALROUTE_STATES: "",
                                            APPROVALROUTE_VALID: 1,
                                            OPERATION_TYPES: modalType === 1 ? '100100' : modalType === 2 ? '100200' : modalType === 3 ? '100210' : ''
                                        },
                                        PageIndex: 1,
                                        PageSize: 999999
                                    }
                                    const dataState = await handleGetAPPROVALROUTEList(reqState)
                                    if (dataState && dataState.length > 0) {
                                        let obj: any = {}
                                        // 下面的环节
                                        let nextList: any = []
                                        console.log('dataState', dataState);
                                        console.log('parentRowparentRowparentRow', parentRow);

                                        dataState.forEach((item: any) => {
                                            if (item.APPROVALROUTE_STATE === 2000) {
                                                obj = item
                                            }
                                            if (item.APPROVALROUTE_STATE >= parentRow?.BusinessProcess_State) {
                                                if (item.APPROVALROUTE_STATE === parentRow?.BusinessProcess_State) {
                                                    item.status = "process"
                                                }
                                                nextList.push(item)
                                            }
                                        })
                                        setNextStepsList(nextList)
                                        console.log('next', nextList);

                                        let personTotal: number = obj.APPROVALSTAFF_ID.split(',').length || 0
                                        if (personTotal > 0) {
                                            let STAFFIDList: number[] = obj.APPROVALSTAFF_ID.split(',')
                                            let STAFFNAMEList: string[] = obj.APPROVALSTAFF_NAME.split(',')
                                            let list: any = []
                                            for (let i = 0; i < personTotal; i++) {
                                                list.push({ label: STAFFNAMEList[i], value: STAFFIDList[i] })
                                            }
                                            return list
                                        }
                                    }
                                }}
                                disabled={parentRow?.BusinessProcess_State > 1000 || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID)}
                            />
                        </Col>
                    </Row>

                </ProForm>

                {
                    parentRow?.BusinessProcess_State > 1000 && parentRow?.BusinessProcess_State !== 9000 ?
                        <ProForm
                            // layout={'horizontal'}
                            formRef={modalApproveFormRef}
                            submitter={false}
                            preserve={false}
                            request={async () => {
                                const reqState: any = {
                                    SearchParameter: {
                                        APPROVALROUTE_STATES: "",
                                        APPROVALROUTE_VALID: 1,
                                        PROVINCE_CODE: currentUser?.ProvinceCode,
                                        OPERATION_TYPES: modalType === 1 ? '100100' : modalType === 2 ? '100200' : modalType === 3 ? '100210' : ''
                                    },
                                    PageIndex: 1,
                                    PageSize: 999999
                                }
                                console.log('reqStatereqStatereqState', reqState);

                                const dataState = await handleGetAPPROVALROUTEList(reqState)
                                console.log('dataStatedataStatedataState', dataState);
                                let obj: any = {}
                                let currentIndex: number = 0
                                if (dataState && dataState.length > 0) {
                                    dataState.forEach((item: any, index: number) => {
                                        if (item.APPROVALROUTE_STATE === parentRow.BusinessProcess_State) {
                                            obj = item
                                            currentIndex = index
                                        }
                                    })
                                }
                                if (obj) {

                                    // 审批的时候 拿到当前状态 去找下一个状态  
                                    if (ApprovalType === 1) {
                                        // 拿到当前状态的信息 判断下一状态 是不是结束了 结束了 就不显示 下一结算审批人   不是结束 就拿到下一流程的审批人
                                        setNextApproval(obj.NEXT_STATE)
                                        let nextObj: any = currentIndex + 1 <= dataState.length ? dataState[currentIndex + 1] : {}
                                        if (nextObj) {
                                            let personTotal: number = nextObj.APPROVALSTAFF_ID.split(',').length || 0
                                            if (personTotal > 0) {
                                                let STAFFIDList: number[] = nextObj.APPROVALSTAFF_ID.split(',')
                                                let STAFFNAMEList: string[] = nextObj.APPROVALSTAFF_NAME.split(',')
                                                let list: any = []
                                                for (let i = 0; i < personTotal; i++) {
                                                    list.push({ label: STAFFNAMEList[i], value: STAFFIDList[i] })
                                                }
                                                setNextApprovalPerson(list)
                                            }
                                        }
                                    } else {
                                        console.log('dataStatedataStatedataState', dataState);

                                        // 驳回的话 去找历史状态
                                        if (dataState && dataState.length > 0) {
                                            let list: any = []
                                            dataState.forEach((item: any, index: number) => {
                                                if (obj.APPROVALROUTE_STATE > item.APPROVALROUTE_STATE) {
                                                    list.push({ label: item.APPROVALROUTE_NAME, value: item.APPROVALROUTE_STATE })
                                                }
                                            })
                                            setNextApprovalPerson(list)
                                        }

                                    }

                                }
                                return {}
                            }}
                            onFinish={async (res) => {
                                setAddApprovalLoading(true)
                                setConfirmLoading(true)
                                let data: any = {}
                                console.log('ApprovalTypeApprovalTypeApprovalType', ApprovalType);

                                if (ApprovalType === 1) {
                                    // 审批
                                    const req: any = {
                                        businessApprovalId: parentRow?.BusinessApproval_ID,
                                        UserId: currentUser?.ID,
                                        ApproveInfo: res.ApproveInfo,
                                        nextApproveStaffId: res.nextApproveStaffId || "",
                                        nextApproveState: nextApproval || ""
                                    }

                                    data = await handleApproveCommodityProInst(req)
                                } else {
                                    // 驳回
                                    const req: any = {
                                        businessApprovalId: parentRow?.BusinessApproval_ID,
                                        UserId: currentUser?.ID,
                                        RejectInfo: res.ApproveInfo,
                                        nextApproveState: res.nextApproveState || ""
                                    }
                                    console.log('reqreqreqreq', req);

                                    data = await handleRejectCommodityProInst(req)
                                }
                                setAddApprovalLoading(false)
                                setConfirmLoading(false)
                                console.log('datadatadata', data);
                                if (data.Result_Code === 100) {
                                    message.success(data.Result_Desc)

                                    // setShowApplyFor(false)
                                    // setCurrentRow(undefined)
                                    // setShopData([])
                                    // setShowDetailType(null)

                                    // setApprovaType(0)
                                    if (handleCencel) {
                                        handleCencel()
                                    }

                                    setBUSINESSAPPROVALDETAIL(undefined)
                                    // setApproveCurrentRow(undefined)
                                    // setApproveModal(false)
                                    setNextApproval(null)
                                    setNextApprovalPerson(null)
                                    // actionRef.current?.reload()
                                    if (tableRef) {
                                        tableRef.current?.reload()
                                    }
                                } else {
                                    message.error(data.Result_Desc)
                                }

                            }}
                        >
                            {
                                ApprovalType === 1 ?
                                    <Row>
                                        {
                                            nextApproval === 9000 ? '' :
                                                <Col span={6}>
                                                    <ProFormSelect
                                                        label={"下一阶段审批人"}
                                                        name={"nextApproveStaffId"}
                                                        options={nextApprovalPerson}
                                                        rules={[
                                                            {
                                                                required: true,
                                                                message: "请选择下一阶段审批人！"
                                                            }
                                                        ]}
                                                    />
                                                </Col>

                                        }
                                        <Col span={24}>
                                            <ProFormTextArea
                                                label={"审批意见"}
                                                name={"ApproveInfo"}
                                                rules={[
                                                    {
                                                        required: true,
                                                        message: "请输入审批意见！"
                                                    }
                                                ]}
                                            />
                                        </Col>
                                    </Row> : ApprovalType === 2 ?
                                        <Row>
                                            <Col span={6}>
                                                <ProFormSelect
                                                    label={"驳回状态"}
                                                    name={"nextApproveState"}
                                                    options={nextApprovalPerson}
                                                    rules={[
                                                        {
                                                            required: true,
                                                            message: "请选择下一阶段审批人！"
                                                        }
                                                    ]}
                                                />
                                            </Col>

                                            <Col span={24}>
                                                <ProFormTextArea
                                                    label={"驳回意见"}
                                                    name={"ApproveInfo"}
                                                    rules={[
                                                        {
                                                            required: true,
                                                            message: "请输入驳回意见！"
                                                        }
                                                    ]}
                                                />
                                            </Col>
                                        </Row> : ""
                            }
                        </ProForm> : ""
                }

                <ProTable
                    search={false}
                    options={false}
                    pagination={false}
                    columns={modalType === 1 ? modalColumns : modalType === 2 ? modalColumnsPrice : modalType === 3 ? modalColumnsInfo : ''}
                    dataSource={shopData}
                    bordered
                    toolbar={{
                        actions: modalType === 1 ? [
                            parentRow?.BusinessProcess_State > 1000 || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID) ? '' : <Button type={"primary"} onClick={() => {
                                setShowAddShopModal(true)
                            }}>
                                新增商品
                            </Button>
                        ] : modalType === 2 ? [
                            parentRow?.BusinessProcess_State > 1000 || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID) ? '' : <Button type={"primary"} onClick={() => {
                                console.log('shopDatashopDatashopData', shopData);


                                // 判断服务区是否已选择
                                const values = modalFormRef.current?.getFieldsValue();
                                if (!values?.ServerpartId) {
                                    message.error("请先选择服务区！");
                                    return;
                                }
                                setShowAddShopModal(true);
                            }}>
                                选择商品
                            </Button>
                        ] : modalType === 3 ? [
                            parentRow?.BusinessProcess_State > 1000 || (parentRow?.BusinessApproval_ID && parentRow?.ApproveStaff_ID !== currentUser?.ID) ? '' : <Button type={"primary"} onClick={() => {
                                // parentRow
                                const values = modalFormRef.current?.getFieldsValue();
                                if (!values?.ServerpartId) {
                                    message.error("请先选择服务区！");
                                    return;
                                }
                                setShowAddShopModal(true);
                            }}>
                                选择商品
                            </Button>
                        ] : []
                    }}
                />

                {
                    parentRow?.BusinessProcess_State > 1000 ?
                        <Card title="流程进度" bordered className="ProcessProgress">
                            <div style={{ width: '100%' }} className="ProcessProgressBox">
                                <Steps
                                    size="small"
                                    className="multi-line-steps"
                                    direction="horizontal"
                                    progressDot={false}
                                    current={BUSINESSAPPROVALDETAIL?.approveList && BUSINESSAPPROVALDETAIL?.approveList.length ? BUSINESSAPPROVALDETAIL?.approveList.length : 0}
                                >
                                    {
                                        BUSINESSAPPROVALDETAIL?.approveList && BUSINESSAPPROVALDETAIL?.approveList.length > 0 ?
                                            BUSINESSAPPROVALDETAIL?.approveList.map((item: any, index: number) => (
                                                <Step
                                                    key={index}
                                                    style={{ minWidth: 180, maxWidth: 220 }}
                                                    status={"finish"}
                                                    title={item.APPROVED_NAME}
                                                    description={
                                                        <div>
                                                            <Tooltip title={`${item.STAFF_NAME || ''}${item.APPLYAPPROVE_INFO ? `：${item.APPLYAPPROVE_INFO}` : ''}`}>
                                                                <p>{`${item.APPLYAPPROVE_DATE || ''}`}</p>
                                                            </Tooltip>
                                                        </div>}
                                                />
                                            )) : ''
                                    }

                                    {
                                        nextStepsList && nextStepsList.length > 0 ?
                                            nextStepsList.map((item: any, index: number) => (
                                                <Step
                                                    key={index}
                                                    style={{ minWidth: 180, maxWidth: 220 }}
                                                    status={item.status === 'process' ? 'process' : 'wait'}
                                                    title={item.APPROVALROUTE_NAME}
                                                />
                                            )) : ''
                                    }
                                </Steps>
                            </div>
                        </Card>
                        : ''
                }
            </Modal >
        </div>
    )
}

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