import { connect } from "umi";
import type { ConnectState } from "@/models/connect";
import { useImperativeHandle, useState } from "react";
import ProTable from "@ant-design/pro-table";
import { getLinkManList } from "../../Merchats/service";

type DetailProps = {
    selectRowDetail: any
    onRef: any
}
const SelectPerson = ({ selectRowDetail, onRef }: DetailProps) => {

    // 选择的人
    const [selectPersonDetail, setSelectPersonDetail] = useState<any>()

    const columns: any = [
        {
            title: '联系人',
            width: 200,
            ellipsis: true,
            dataIndex: 'LINKER_NAME'
        },
        {
            title: '手机号码',
            width: 200,
            ellipsis: true,
            dataIndex: 'LINKER_MOBILEPHONE'
        }
    ]

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

    return (
        <div>
            <ProTable
                columns={columns}
                request={async () => {
                    console.log('selectRowDetail', selectRowDetail);
                    const data = await getLinkManList(selectRowDetail?.COOPMERCHANTS_ID)
                    console.log('data', data);
                    if (data && data.length > 0) {
                        return { data, success: true }
                    }
                    return { data: [], success: true }
                }}
                search={false}
                options={false}
                rowKey={"COOPMERCHANTS_LINKER_ID"}
                pagination={false}
                rowSelection={{
                    type: "radio",
                    onChange: (_, selectedRows) => {
                        // setSelectRow
                        console.log('_', _);
                        console.log('selectedRows', selectedRows);
                        if (selectedRows && selectedRows.length > 0) {
                            setSelectPersonDetail(selectedRows)
                        } else {
                            setSelectPersonDetail(undefined)
                        }
                    }
                }}
            />

        </div>
    )
}

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