import React, { Fragment, useEffect, useState } from 'react';
import styles from '../Evaluation/BiddingDocumentsDecrypt/index.less';
import logo from '@/images/opening/logo.svg';
import { Descriptions, Spin, Typography } from 'antd';
import EquityRelation from '@/components/EquityRelation';
import ProTable, { ProColumns } from '@ant-design/pro-table';
import { getSuspectedViolation } from '../Evaluation/BidControl/BidControlManager/service';
import { getProjectDataById, getSectionDataById } from '@/services/common';
import { getURLInformation } from '@/utils/CommonUtils';
import { updateRead } from './service';
const SupplierRelation: React.FC<{}> = () => {
    const title_style = { color: "#b30000", fontWeight: 700 };
    const { Paragraph, Text } = Typography;
    //loading
    const [loading, setLoading] = useState<boolean>(true);
    //查询的供应商股权关系数据，确认数据。
    const [warningsData, setWarningsData] = useState<any>();
    //项目数据
    const [projectData, setProjectData] = useState<any>();
    //标段数据
    const [sectionData, setSectionData] = useState<any>();
    //专家组长填写的表格的供应商
    const [supplierTableData, setSupplierTableData] = useState<any[]>([]);
    //获取url参数
    const tpId = getURLInformation("tpId");
    const sectionId = getURLInformation("sectionId");
    const roomId = getURLInformation("roomId");
    const readOnlyColumns: ProColumns<any>[] = [
        {
            title: <Text strong>供应商A</Text>,
            render: (_: any, record: any) => (
                <span>{record?.supplierA.name}</span>
            ),
        },
        {
            title: <Text strong>供应商B</Text>,
            render: (_: any, record: any) => (
                <span>{record?.supplierB.name}</span>
            ),
        },
        {
            title: <Text strong>关系类型</Text>,
            editable: false,
            render: (_: any, record: any) => (
                <span>{record.typeDesc}关系</span>
            ),
        },
        {
            title: <Text strong>关联信息是否准确（专家评审）</Text>,
            dataIndex: 'relationFlag',
            key: 'relationFlag',
            render: (_: any, record: any) => warningsData?.headmanConfirmStatus == "1" ? (<span style={{ color: record.relationFlag == 1 ? "" : "red" }}>{record.relationFlag == 1 ? "是" : record.relationFlag == 0 ? "否" : "-"}</span>) : (<span>-</span>),
        },
        {
            title: <Text strong>是否被认定为风险（专家评审）</Text>,
            dataIndex: 'riskFlag',
            key: 'riskFlag',
            render: (_: any, record: any) => warningsData?.headmanConfirmStatus == "1" ? (<span style={{ color: record.riskFlag == 1 ? "" : "red" }}>{record.riskFlag == 1 ? "是" : record.riskFlag == 0 ? "否" : "-"}</span>) : (<span>-</span>),
        },
        {
            title: <Text strong>说明（专家评审）</Text>,
            dataIndex: 'memo',
            key: 'memo',
            render: (_: any, record: any) => warningsData?.headmanConfirmStatus == "1" ? _ : (<span>-</span>)
        },
    ];
    //获取数据
    const getData = async () => {
        let params = {
            "tpId": tpId,
            "sectionId": sectionId,
            "assessRoomId": roomId,
        }
        // let params = { "tpId": "1626032810108956672", "sectionId": "1626032810125733888", "assessRoomId": "1626032965674401792" };
        if (tpId && sectionId && roomId) {
            setLoading(true);
            const riskResponse = await getSuspectedViolation(params);//获取风险数据
            const projectResponse = await getProjectDataById(params.tpId);//获取项目数据
            const sectionResponse = await getSectionDataById(params.sectionId);//获取标段数据
            if (riskResponse && riskResponse.success) {
                setSupplierTableData(riskResponse?.data?.riskSupplier != null ? riskResponse?.data?.riskSupplier?.map((item: any) => { item.riskFlag = String(item.riskFlag); item.relationFlag = String(item.relationFlag); return item }) : []);
                setWarningsData(riskResponse?.data);
                updateRead(roomId, riskResponse?.data.readingCode);
            }
            if (projectResponse && projectResponse.success) {
                setProjectData(projectResponse?.data);
            }
            if (sectionResponse && sectionResponse.success) {
                setSectionData(sectionResponse?.data);
            }
            setLoading(false);
        }
    }

    useEffect(() => {
        getData();
    }, [])

    return (
        <Fragment>
            <div className={styles.headerView}>
                <div className={styles.headerAlignView}
                    style={{ position: "absolute", left: "0", fontSize: "16px", fontWeight: 600, top: '15px' }}>
                    <img src={logo} style={{ height: "30px", marginRight: "10px", position: 'relative', top: '-2px' }} />中国联通智慧供应链平台 ｜ 招标采购中心
                </div>
            </div>
            <div style={{ height: "calc(100vh - 56px)", overflow: "auto", padding: "24px" }}>
                <Spin spinning={loading}>
                    <h2 style={{ fontWeight: "bold", textAlign: "center", lineHeight: "60px" }}>
                        供应商疑似关联关系情况
                    </h2>
                    <h3 className="first-title" style={title_style}>基本信息</h3>
                    <Descriptions column={4}>
                        <Descriptions.Item label="项目名称">{projectData?.projectName ?? "-"}</Descriptions.Item>
                        <Descriptions.Item label="项目编号">{projectData?.ebpProjectNumber ?? "-"}</Descriptions.Item>
                        <Descriptions.Item label="代理机构业务经理">{projectData?.appManagerName ?? "-"}</Descriptions.Item>
                        <Descriptions.Item label="采购经理">{projectData?.ownerContactName ?? "-"}</Descriptions.Item>
                        <Descriptions.Item label="标段名称">{sectionData?.bidSectName ?? "-"}</Descriptions.Item>
                    </Descriptions>
                    <h3 className="first-title" style={title_style}>供应商疑似关联关系图</h3>
                    <div style={{ display: "flex", justifyContent: "flex-start", alignItems: "flex-start" }}>
                        <div style={{ width: "50vw" }}>
                            <EquityRelation result={warningsData?.riskData} />
                        </div>
                        <div style={{ width: "calc(50vw - 60px)", paddingLeft: "40px", paddingTop: "42px" }}>
                            <Paragraph>
                                <Text strong>《中华人民共和国招标投标法》第三十二条规定：”投标人不得相互串通投标报价，不得排挤其他投标人的公平竞争，损害招标人或者其他投标人的合法权益。投标人不得与招标人串通投标，损害国家利益、社会公共利益或者他人的合法权益。”</Text>
                            </Paragraph>
                            <Paragraph>
                                <Text strong>《中华人民共和国招标投标法实施条例》第三十四条规定：“与招标人存在利害关系可能影响招标公正性的法人、其它组织或者个人，不得参加投标。单位负责人为同一人或者存在控股关系、管理关系的不同单位，不得参加同一标段投标或者未划分标段的同一招标项目投标。违反前两款规定的，相关投标无效。”</Text>
                            </Paragraph>
                            <Paragraph>
                                <Text strong>控股超过51%或股权关系分散的占股最大的股东都属于控股，请项目经理与评委给予注意!</Text>
                            </Paragraph>
                        </div>
                    </div>
                    <div style={{ margin: "10px 0" }}>
                        <h3 className="first-title" style={title_style}>相关供应商关联情况汇总（参考）</h3>
                        <ProTable
                            rowKey="id"
                            pagination={false}
                            search={false}
                            options={false}
                            columns={readOnlyColumns}
                            dataSource={supplierTableData}
                        />
                    </div>
                </Spin>
            </div>
        </Fragment>
    );
};

export default SupplierRelation;
