<script setup>
import ShareReportButton from "./ShareReportButton.vue";
import { splitDWBG8B4DForTabs } from '@/ui/CDWBG8B4D/utils/simpleSplitter.js';
import { splitDWBG6A2CForTabs } from '@/ui/DWBG6A2C/utils/simpleSplitter.js';
import { splitCJRZQ5E9FForTabs } from '@/ui/CJRZQ5E9F/utils/simpleSplitter.js';
import { splitCQYGL3F8EForTabs } from '@/ui/CQYGL3F8E/utils/simpleSplitter.js';

const props = defineProps({
    isShare: {
        type: Boolean,
        default: false,
    },
    orderId: {
        type: String,
        required: false,
        default: "",
    },
    orderNo: {
        type: String,
        default: "",
    },
    feature: {
        type: String,
        required: true,
    },
    reportData: {
        type: Array,
        required: true,
    },
    reportParams: {
        type: Object,
        required: true,
    },
    reportName: {
        type: String,
        required: true,
    },
    reportDateTime: {
        type: [String, null],
        required: false,
        default: null,
    },
    isEmpty: {
        type: Boolean,
        required: true,
    },
    isDone: {
        type: Boolean,
        required: true,
    },
});

// 使用toRefs将props转换为组件内的ref
const {
    feature,
    reportData,
    reportParams,
    reportName,
    reportDateTime,
    isEmpty,
    isDone,
} = toRefs(props);

const active = ref(null);

const reportScore = ref(0); // 默认分数

// 处理数据拆分（支持DWBG8B4D、DWBG6A2C、CJRZQ5E9F和CQYGL3F8E）
const processedReportData = computed(() => {
    let data = reportData.value;

    // 拆分DWBG8B4D数据
    data = splitDWBG8B4DForTabs(data);

    // 拆分DWBG6A2C数据
    data = splitDWBG6A2CForTabs(data);

    // 拆分CJRZQ5E9F数据
    data = splitCJRZQ5E9FForTabs(data);

    // 拆分CQYGL3F8E数据
    data = splitCQYGL3F8EForTabs(data);

    return data;
});

watch(reportData, () => {
    reportScore.value = calculateScore(reportData.value);
});
const featureMap = {
    IVYZ5733: {
        name: "婚姻状态",
        component: defineAsyncComponent(() => import("@/ui/CIVYZ5733.vue")),
        remark: '查询结果为"未婚或尚未登记结婚"时，表示婚姻登记处暂无相关的登记记录。婚姻状态信息由婚姻登记处逐级上报，可能存在数据遗漏或更新滞后。当前可查询的婚姻状态包括：未婚或尚未登记结婚、已婚、离异。如您对查询结果有疑问，请联系客服反馈。',
    },
    JRZQ0A03: {
        name: "借贷申请记录",
        component: defineAsyncComponent(() =>
            import("@/ui/CJRZQ0A03.vue")
        ),
    },
    JRZQ8203: {
        name: "借贷行为记录",
        component: defineAsyncComponent(() =>
            import("@/ui/CJRZQ8203.vue")
        ),
    },
    FLXG3D56: {
        name: "违约失信",
        component: defineAsyncComponent(() => import("@/ui/CFLXG3D56.vue")),
    },

    FLXG0V4B: {
        name: "司法涉诉",
        component: defineAsyncComponent(() =>
            import("@/ui/CFLXG0V4B/index.vue")
        ),
    },
    QYGL3F8E: {
        name: "人企关系加强版",
        component: defineAsyncComponent(() =>
            import("@/ui/CQYGL3F8E/index.vue")
        ),
        remark: '人企关系加强版提供全面的企业关联分析，包括投资企业记录、高管任职记录和涉诉风险等多维度信息。'
    },
    // 人企关系加强版拆分模块
    CQYGL3F8E_Investment: {
        name: "投资企业记录",
        component: defineAsyncComponent(() => import("@/ui/CQYGL3F8E/components/Investment.vue")),
    },
    CQYGL3F8E_SeniorExecutive: {
        name: "高管任职记录",
        component: defineAsyncComponent(() => import("@/ui/CQYGL3F8E/components/SeniorExecutive.vue")),
    },
    CQYGL3F8E_Lawsuit: {
        name: "涉诉风险",
        component: defineAsyncComponent(() => import("@/ui/CQYGL3F8E/components/Lawsuit.vue")),
    },
    CQYGL3F8E_InvestHistory: {
        name: "对外投资历史",
        component: defineAsyncComponent(() => import("@/ui/CQYGL3F8E/components/InvestHistory.vue")),
    },
    CQYGL3F8E_FinancingHistory: {
        name: "融资历史",
        component: defineAsyncComponent(() => import("@/ui/CQYGL3F8E/components/FinancingHistory.vue")),
    },
    CQYGL3F8E_Punishment: {
        name: "行政处罚",
        component: defineAsyncComponent(() => import("@/ui/CQYGL3F8E/components/Punishment.vue")),
    },
    CQYGL3F8E_Abnormal: {
        name: "经营异常",
        component: defineAsyncComponent(() => import("@/ui/CQYGL3F8E/components/Abnormal.vue")),
    },
    CQYGL3F8E_TaxRisk: {
        name: "税务风险",
        component: defineAsyncComponent(() => import("@/ui/CQYGL3F8E/components/TaxRisk/index.vue")),
    },
    QCXG7A2B: {
        name: "名下车辆",
        component: defineAsyncComponent(() => import("@/ui/CQCXG7A2B.vue")),
    },
    BehaviorRiskScan: {
        name: "风险行为扫描",
        component: defineAsyncComponent(() =>
            import("@/ui/CBehaviorRiskScan.vue")
        ),
    },
    JRZQ4AA8: {
        name: "还款压力",
        component: defineAsyncComponent(() => import("@/ui/CJRZQ4AA8.vue")),
    },
    IVYZ9A2B: {
        name: "学历信息查询",
        component: defineAsyncComponent(() => import("@/ui/CIVYZ9A2B.vue")),
    },
    DWBG8B4D: {
        name: "谛听多维报告",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/index.vue")),
    },
    // 谛听多维报告拆分模块
    DWBG8B4D_Overview: {
        name: "报告概览",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/components/ReportOverview.vue")),
    },
    DWBG8B4D_ElementVerification: {
        name: "要素核查",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/components/ElementVerification.vue")),
    },
    DWBG8B4D_Identity: {
        name: "运营商核验",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/components/Identity.vue")),
    },
    DWBG8B4D_RiskWarning: {
        name: "公安重点人员检验",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/components/RiskWarning.vue")),
    },
    DWBG8B4D_OverdueRisk: {
        name: "逾期风险产品",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/components/OverdueRiskSection.vue")),
    },
    DWBG8B4D_CourtInfo: {
        name: "法院曝光台信息",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/components/MultCourtInfoSection.vue")),
    },
    DWBG8B4D_LoanEvaluation: {
        name: "借贷评估",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/components/LoanEvaluationSection.vue")),
    },
    DWBG8B4D_LeasingRisk: {
        name: "租赁风险评估",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/components/LeasingRiskSection.vue")),
    },
    DWBG8B4D_RiskSupervision: {
        name: "关联风险监督",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/components/RiskSupervisionSection.vue")),
    },
    DWBG8B4D_RiskWarningTab: {
        name: "规则风险提示",
        component: defineAsyncComponent(() => import("@/ui/CDWBG8B4D/components/RiskWarningTab.vue")),
    },
    JRZQ4B6C: {
        name: "信贷表现",
        component: defineAsyncComponent(() => import("@/ui/JRZQ4B6C/index.vue")),
        remark: '信贷表现主要为企业在背景调查过程中探查用户近期信贷表现时提供参考，帮助企业对其内部员工、外部业务进行个人信用过滤。数据来源于多个征信机构，可能存在数据延迟或不完整的情况。'
    },
    JRZQ09J8: {
        name: "收入评估",
        component: defineAsyncComponent(() => import("@/ui/JRZQ09J8/index.vue")),
        remark: '基于全国社会保险信息系统的缴费基数数据进行收入水平评估。评级反映相对收入水平，实际收入可能因地区差异而有所不同，建议结合其他收入证明材料进行综合评估。'
    },
    // 司南报告
    DWBG6A2C: {
        name: "司南报告",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/index.vue")),
        remark: '司南报告提供全面的个人信用风险评估，包括身份核验、风险名单、借贷行为、履约情况等多维度分析。'
    },
    // 司南报告拆分模块
    // DWBG6A2C_BaseInfo: {
    //     name: "基本信息",
    //     component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/BaseInfoSection.vue")),
    // },
    DWBG6A2C_StandLiveInfo: {
        name: "身份信息核验",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/StandLiveInfoSection.vue")),
    },
    DWBG6A2C_RiskPoint: {
        name: "命中风险标注",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/RiskPointSection.vue")),
    },
    DWBG6A2C_SecurityInfo: {
        name: "公安重点人员核验",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/SecurityInfoSection.vue")),
    },
    DWBG6A2C_AntiFraudInfo: {
        name: "涉赌涉诈人员核验",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/AntiFraudInfoSection.vue")),
    },
    DWBG6A2C_RiskList: {
        name: "风险名单",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/RiskListSection.vue")),
    },
    DWBG6A2C_ApplicationStatistics: {
        name: "历史借贷行为",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/ApplicationStatisticsSection.vue")),
    },
    DWBG6A2C_LendingStatistics: {
        name: "近24个月放款情况",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/LendingStatisticsSection.vue")),
    },
    DWBG6A2C_PerformanceStatistics: {
        name: "履约情况",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/PerformanceStatisticsSection.vue")),
    },
    DWBG6A2C_OverdueRecord: {
        name: "历史逾期记录",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/OverdueRecordSection.vue")),
    },
    DWBG6A2C_CreditDetail: {
        name: "授信详情",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/CreditDetailSection.vue")),
    },
    DWBG6A2C_RentalBehavior: {
        name: "租赁行为",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/RentalBehaviorSection.vue")),
    },
    DWBG6A2C_RiskSupervision: {
        name: "关联风险监督",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/RiskSupervisionSection.vue")),
    },
    DWBG6A2C_CourtRiskInfo: {
        name: "法院风险信息",
        component: defineAsyncComponent(() => import("@/ui/DWBG6A2C/components/CourtRiskInfoSection.vue")),
    },
    // 贷款风险报告
    JRZQ5E9F: {
        name: "贷款风险评估",
        component: defineAsyncComponent(() => import("@/ui/CJRZQ5E9F/index.vue")),
        remark: '贷款风险评估提供全面的个人贷款风险分析，包括风险概览、信用评分、贷款行为分析、机构分析等多维度评估。'
    },
    // 贷款风险报告拆分模块
    CJRZQ5E9F_RiskOverview: {
        name: "风险概览",
        component: defineAsyncComponent(() => import("@/ui/CJRZQ5E9F/components/RiskOverview.vue")),
    },
    CJRZQ5E9F_CreditScores: {
        name: "信用评分",
        component: defineAsyncComponent(() => import("@/ui/CJRZQ5E9F/components/CreditScores.vue")),
    },
    CJRZQ5E9F_LoanBehaviorAnalysis: {
        name: "贷款行为分析",
        component: defineAsyncComponent(() => import("@/ui/CJRZQ5E9F/components/LoanBehaviorAnalysis.vue")),
    },
    CJRZQ5E9F_InstitutionAnalysis: {
        name: "机构分析",
        component: defineAsyncComponent(() => import("@/ui/CJRZQ5E9F/components/InstitutionAnalysis.vue")),
    },
    CJRZQ5E9F_TimeTrendAnalysis: {
        name: "时间趋势分析",
        component: defineAsyncComponent(() => import("@/ui/CJRZQ5E9F/components/TimeTrendAnalysis.vue")),
    },
    CJRZQ5E9F_RiskIndicators: {
        name: "风险指标详情",
        component: defineAsyncComponent(() => import("@/ui/CJRZQ5E9F/components/RiskIndicators.vue")),
    },
    CJRZQ5E9F_RiskAdvice: {
        name: "专业建议",
        component: defineAsyncComponent(() => import("@/ui/CJRZQ5E9F/components/RiskAdvice.vue")),
    }
};

const maskValue = computed(() => {
    return (type, value) => {
        if (!value) return value;
        if (type === "name") {
            // 姓名脱敏（保留首位）
            if (value.length === 1) {
                return "*"; // 只保留一个字，返回 "*"
            } else if (value.length === 2) {
                return value[0] + "*"; // 两个字，保留姓氏，第二个字用 "*" 替代
            } else {
                return (
                    value[0] +
                    "*".repeat(value.length - 2) +
                    value[value.length - 1]
                ); // 两个字以上，保留第一个和最后一个字，其余的用 "*" 替代
            }
        } else if (type === "id_card") {
            // 身份证号脱敏（保留前6位和最后4位）
            return value.replace(/^(.{6})(?:\d+)(.{4})$/, "$1****$2");
        } else if (type === "mobile") {
            if (value.length === 11) {
                return value.substring(0, 3) + "****" + value.substring(7);
            }
            return value; // 如果手机号不合法或长度不为 11 位，直接返回原手机号
        } else if (type === "bank_card") {
            // 银行卡号脱敏（保留前6位和后4位）
            return value.replace(/^(.{6})(?:\d+)(.{4})$/, "$1****$2");
        } else if (type === "ent_name") {
            // 企业名称脱敏（保留前3个字符和后3个字符，中间部分用 "*" 替代）
            if (value.length <= 6) {
                return value[0] + "*".repeat(value.length - 1); // 少于6个字符时，只保留第一个字符，其他用 * 替代
            } else {
                return (
                    value.slice(0, 3) +
                    "*".repeat(value.length - 6) +
                    value.slice(-3)
                ); // 多于6个字符时保留前3和后3
            }
        } else if (type === "ent_code") {
            // 企业代码脱敏（保留前4个字符和后4个字符，中间部分用 "*" 替代）
            if (value.length <= 8) {
                return value.slice(0, 4) + "*".repeat(value.length - 4); // 长度不超过8时，保留前4个字符，其他用 * 替代
            } else {
                return (
                    value.slice(0, 4) +
                    "*".repeat(value.length - 8) +
                    value.slice(-4)
                ); // 长度超过8时，保留前4个字符和后4个字符
            }
        } else if (type === "car_license") {
            // 车牌号脱敏（保留前2个字符，后2个字符，其他部分用 "*" 替代）
            if (value.length <= 4) {
                return value[0] + "*".repeat(value.length - 1); // 如果车牌号长度小于等于4，只保留首字符
            } else {
                // 如果车牌号较长，保留前2个字符，后2个字符，其余部分用 "*" 替代
                return (
                    value.slice(0, 2) +
                    "*".repeat(value.length - 4) +
                    value.slice(-2)
                );
            }
        }
        return value;
    };
});

// 计算综合评分的函数
const calculateScore = (reportData) => {
    // 从0分开始（0分表示无风险）
    let score = 0;
    // 最高分为90分（90分表示最高风险）
    const maxScore = 90;

    // 定义各接口的相对风险权重比例
    const relativeWeights = {
        // 关键风险指标（高优先级）
        FLXG0V3B: 250, // 不良记录
        FLXG3D56: 100, // 违约异常
        FLXG0V4B: 400, // 司法涉诉
        G35SC01: 20, // 司法涉诉（次要）
        Q23SC01: 50, // 企业涉诉
        FIN019: 100, // 银行卡黑名单

        // 高风险指标（中优先级）
        JRZQ0A03: 40, // 借贷申请记录
        JRZQ8203: 40, // 借贷行为记录
        FLXG54F5: 70, // 手机号码风险

        // 中风险指标（低优先级）
        YYSYF7DB: 50, // 手机二次卡
        YYSY4B37: 50, // 手机在网时长
        QYGLB4C0: 50, // 人企关系
        JRZQ4B6C: 60, // 信贷表现
        JRZQ09J8: 40, // 收入评估

        // 验证指标（最低优先级）
        YYSY6F2E: 25, // 手机三要素
        IVYZ0B03: 25, // 手机号二要素
        KZEYS: 25, // 身份证二要素
        JRZQDCBE: 25, // 银行卡四要素核验
    };

    // 找出当前报告中包含的接口
    const availableAPIs = reportData
        .map((item) => item.data.apiID)
        .filter((id) => relativeWeights[id]);

    // 如果没有可评分的接口，返回默认分数
    if (availableAPIs.length === 0) return 30; // 默认30分（中等风险）

    // 计算当前报告中所有接口的相对权重总和
    let totalWeight = 0;
    availableAPIs.forEach((apiID) => {
        totalWeight += relativeWeights[apiID];
    });

    // 计算每个权重点对应的分数
    const pointValue = maxScore / totalWeight;

    // 基于当前报告中的接口计算实际权重
    const actualWeights = {};
    availableAPIs.forEach((apiID) => {
        // 将相对权重转换为实际分数权重
        actualWeights[apiID] = relativeWeights[apiID] * pointValue;
    });

    // 遍历报告数据进行评分 - 风险越高分数越高
    reportData.forEach((item) => {
        const apiID = item.data.apiID;
        const data = item.data.data;

        // 如果没有定义权重，跳过
        if (!actualWeights[apiID]) return;

        // 根据不同的API ID计算分数（有风险时加分）
        switch (apiID) {
            case "G09SC02": // 婚姻状态
                // 不计入风险
                break;

            case "JRZQ0A03": // 借贷申请记录
                if (data) {
                    // 检查是否有申请记录（有则表示风险）
                    let hasRisk = false;
                    for (const key in data) {
                        if (
                            data[key] !== 0 &&
                            data[key] !== "0" &&
                            key.indexOf("allnum") > -1 &&
                            !isNaN(parseInt(data[key])) &&
                            parseInt(data[key]) > 0
                        ) {
                            hasRisk = true;
                            break;
                        }
                    }
                    if (hasRisk) {
                        score += actualWeights[apiID];
                    }
                }
                break;

            case "JRZQ8203": // 借贷行为记录
                if (data) {
                    // 检查是否有借贷记录（有则表示风险）
                    let hasRisk = false;
                    for (const key in data) {
                        if (
                            data[key] !== 0 &&
                            data[key] !== "0" &&
                            (key.indexOf("lendamt") > -1 ||
                                key.indexOf("num") > -1) &&
                            !isNaN(parseInt(data[key])) &&
                            parseInt(data[key]) > 0
                        ) {
                            hasRisk = true;
                            break;
                        }
                    }
                    if (hasRisk) {
                        score += actualWeights[apiID];
                    }
                }
                break;

            case "FLXG3D56": // 违约异常
                if (data) {
                    // 检查除特定字段外的其他字段是否有异常值（有异常则表示风险）
                    const excludeFields = [
                        "swift_number",
                        "code",
                        "flag_specialList_c",
                    ];
                    let hasRisk = false;

                    for (const key in data) {
                        if (
                            !excludeFields.includes(key) &&
                            data[key] !== 0 &&
                            data[key] !== "0"
                        ) {
                            hasRisk = true;
                            break;
                        }
                    }

                    if (hasRisk) {
                        score += actualWeights[apiID];
                    }
                }
                break;

            case "FLXG0V3B": // 不良记录
                if (data && data.risk_level) {
                    // 根据风险等级加分
                    switch (data.risk_level) {
                        case "A": // 无风险
                            // 不加分
                            break;
                        case "F": // 低风险
                            score += actualWeights[apiID] * 0.3;
                            break;
                        case "C": // 中风险
                        case "D": // 中风险
                            score += actualWeights[apiID] * 0.7;
                            break;
                        case "B": // 高风险
                        case "E": // 高风险
                            score += actualWeights[apiID];
                            break;
                    }
                }
                break;

            case "G35SC01": // 司法涉诉
            case "FLXG0V4B": // 司法涉诉
            case "Q23SC01": // 企业涉诉
                if (data) {
                    let hasRisk = false;

                    // 检查各种涉诉信息 - 处理嵌套数据结构
                    // entout是一个单元素数组，数组中第一个元素是JSON对象，对象中有entout属性
                    if (
                        data.entout &&
                        Array.isArray(data.entout) &&
                        data.entout.length > 0 &&
                        data.entout[0] &&
                        data.entout[0].entout &&
                        ((Array.isArray(data.entout[0].entout) &&
                            data.entout[0].entout.length > 0) ||
                            (typeof data.entout[0].entout === "object" &&
                                Object.keys(data.entout[0].entout).length > 0))
                    ) {
                        hasRisk = true;
                    }

                    // 处理sxbzxr(失信被执行人)嵌套结构
                    if (
                        data.sxbzxr &&
                        Array.isArray(data.sxbzxr) &&
                        data.sxbzxr.length > 0 &&
                        data.sxbzxr[0] &&
                        data.sxbzxr[0].sxbzxr &&
                        ((Array.isArray(data.sxbzxr[0].sxbzxr) &&
                            data.sxbzxr[0].sxbzxr.length > 0) ||
                            (typeof data.sxbzxr[0].sxbzxr === "object" &&
                                Object.keys(data.sxbzxr[0].sxbzxr).length > 0))
                    ) {
                        hasRisk = true;
                    }

                    // 处理xgbzxr(限制高消费被执行人)嵌套结构
                    if (
                        data.xgbzxr &&
                        Array.isArray(data.xgbzxr) &&
                        data.xgbzxr.length > 0 &&
                        data.xgbzxr[0] &&
                        data.xgbzxr[0].xgbzxr &&
                        ((Array.isArray(data.xgbzxr[0].xgbzxr) &&
                            data.xgbzxr[0].xgbzxr.length > 0) ||
                            (typeof data.xgbzxr[0].xgbzxr === "object" &&
                                Object.keys(data.xgbzxr[0].xgbzxr).length > 0))
                    ) {
                        hasRisk = true;
                    }

                    if (hasRisk) {
                        score += actualWeights[apiID];
                    }
                }
                break;

            case "FLXG54F5": // 手机号码风险
                if (data && data.filterType) {
                    // 根据filterType判断风险等级
                    switch (data.filterType) {
                        case "0": // 安全
                            // 不加分
                            break;
                        case "3": // 低危
                            score += actualWeights[apiID] * 0.3;
                            break;
                        case "2": // 中危
                            score += actualWeights[apiID] * 0.7;
                            break;
                        case "1": // 高危
                            score += actualWeights[apiID];
                            break;
                    }
                }
                break;

            case "YYSYF7DB": // 手机二次卡
                if (data && data.is_second_card === true) {
                    score += actualWeights[apiID];
                }
                break;

            case "YYSY4B37": // 手机在网时长
                if (data && data.online_months < 6) {
                    score += actualWeights[apiID];
                }
                break;

            case "YYSY6F2E": // 手机三要素
            case "IVYZ0B03": // 手机号二要素
            case "KZEYS": // 身份证二要素
            case "JRZQDCBE": // 银行卡四要素核验
                if (data && data.is_consistent === false) {
                    score += actualWeights[apiID];
                }
                break;

            case "FIN019": // 银行卡黑名单
                if (data && data.is_blacklisted === true) {
                    score += actualWeights[apiID];
                }
                break;

            case "JRZQ4B6C": // 信贷表现
                if (data) {
                    let riskScore = 0;

                    // 根据结果编码评分
                    switch (data.result_code) {
                        case "1": // A(Overdue) - 逾期，高风险
                            riskScore += 0.8;
                            break;
                        case "3": // B(Delay) - 延迟，中风险
                            riskScore += 0.5;
                            break;
                        case "2": // B(Normal) - 正常，低风险
                            riskScore += 0.1;
                            break;
                        case "4": // U - 未知，中等风险
                            riskScore += 0.3;
                            break;
                    }

                    // 当前逾期机构数
                    const currentlyOverdue = parseInt(data.currently_overdue) || 0;
                    if (currentlyOverdue > 0) {
                        riskScore += Math.min(currentlyOverdue * 0.1, 0.3);
                    }

                    // 异常还款机构数
                    const accExc = parseInt(data.acc_exc) || 0;
                    if (accExc > 0) {
                        riskScore += Math.min(accExc * 0.05, 0.2);
                    }

                    // 应用风险评分
                    score += actualWeights[apiID] * Math.min(riskScore, 1.0);
                }
                break;

            case "JRZQ09J8": // 收入评估
                if (data && data.level) {
                    let riskScore = 0;

                    // 根据收入等级评分（收入越低风险越高）
                    switch (data.level) {
                        case "-": // 无记录，高风险
                            riskScore = 0.9;
                            break;
                        case "A": // A级，中高风险
                            riskScore = 0.7;
                            break;
                        case "B": // B级，中等风险
                            riskScore = 0.5;
                            break;
                        case "C": // C级，中低风险
                            riskScore = 0.3;
                            break;
                        case "D": // D级，低风险
                            riskScore = 0.2;
                            break;
                        case "E": // E级，很低风险
                            riskScore = 0.1;
                            break;
                        case "F": // F级，极低风险
                        case "G": // G级，极低风险
                        case "H": // H级，无风险
                        case "I": // I级，无风险
                        case "J": // J级，零风险
                            riskScore = 0.05;
                            break;
                    }

                    // 应用风险评分
                    score += actualWeights[apiID] * riskScore;
                }
                break;

            default:
                // 未知接口类型不影响评分
                break;
        }
    });

    // 确保分数在0-90范围内并四舍五入
    return Math.max(0, Math.min(maxScore, Math.round(score)));
};
</script>

<template>
    <div class="min-h-full from-blue-100 to-white bg-gradient-to-b">

        <template v-if="isDone">
            <van-tabs v-model:active="active" scrollspy sticky :offset-top="46">
                <div class="flex flex-col gap-y-4 p-4">
                    <LEmpty v-if="isEmpty" />
                    <van-tab title="分析指数">
                        <div id="analysis" class="title mb-4">分析指数</div>
                        <div class="card mb-4">
                            <div class="my-4">
                                <GaugeChart :score="reportScore" />
                            </div>
                        </div>
                    </van-tab>
                    <van-tab title="基本信息">
                        <div id="basic" class="title mb-4">基本信息</div>
                        <div class="card">
                            <div class="flex flex-col gap-y-2">
                                <LTitle title="报告信息" type="blue-green"></LTitle>
                                <div class="flex flex-col gap-2 my-2">
                                    <div class="flex justify-between border-b pb-2 pl-2">
                                        <span class="text-gray-700 font-bold">报告时间：</span>
                                        <span class="text-gray-600">{{
                                            reportDateTime ||
                                            "2025-01-01 12:00:00"
                                        }}</span>
                                    </div>
                                    <div class="flex justify-between border-b pb-2 pl-2" v-if="!isEmpty">
                                        <span class="text-gray-700 font-bold">报告项目：</span>
                                        <span class="text-gray-600">
                                            {{ reportName }}</span>
                                    </div>
                                </div>
                                <template v-if="Object.keys(reportParams).length != 0">
                                    <LTitle title="报告对象" type="blue-green"></LTitle>
                                    <div class="flex flex-col gap-2 my-2">
                                        <div class="flex justify-between border-b pb-2 pl-2" v-if="reportParams?.name">
                                            <span class="text-gray-700 font-bold">姓名</span>
                                            <span class="text-gray-600">{{
                                                maskValue(
                                                    "name",
                                                    reportParams?.name
                                                )
                                            }}</span>
                                        </div>
                                        <div class="flex justify-between border-b pb-2 pl-2"
                                            v-if="reportParams?.id_card">
                                            <span class="text-gray-700 font-bold">身份证号</span>
                                            <span class="text-gray-600">
                                                {{
                                                    maskValue(
                                                        "id_card",
                                                        reportParams?.id_card
                                                    )
                                                }}</span>
                                        </div>
                                        <div class="flex justify-between border-b pb-2 pl-2"
                                            v-if="reportParams?.mobile">
                                            <span class="text-gray-700 font-bold">手机号</span>
                                            <span class="text-gray-600">{{
                                                maskValue(
                                                    "mobile",
                                                    reportParams?.mobile
                                                )
                                            }}</span>
                                        </div>
                                        <div class="flex flex-col gap-4">
                                            <div class="flex items-center bg-blue-100 rounded-xl px-4 py-2 flex-1">
                                                <div
                                                    class="bg-green-500 w-12 h-12 text-white text-xl flex items-center justify-center rounded-full mr-4">
                                                    ✔
                                                </div>
                                                <div>
                                                    <div class="font-bold text-lg">
                                                        身份证检查结果
                                                    </div>
                                                    <div class="text-sm text-gray-600">
                                                        身份证信息核验通过
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="flex items-center bg-blue-100 rounded-xl px-4 py-2 flex-1">
                                                <div
                                                    class="bg-green-500 w-12 h-12 text-white text-xl flex items-center justify-center rounded-full mr-4">
                                                    ✔
                                                </div>
                                                <div>
                                                    <div class="font-bold text-lg">
                                                        手机号检测结果
                                                    </div>
                                                    <div class="text-sm text-gray-600">
                                                        被查询人姓名与运营商提供的一致
                                                    </div>
                                                    <div class="text-sm text-gray-600">
                                                        被查询人身份证与运营商提供的一致
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </template>
                            </div>
                            <ShareReportButton v-if="!isShare" :order-id="orderId" :order-no="orderNo"
                                :is-example="!orderId" />
                        </div>
                        <LRemark content="如查询的姓名/身份证与运营商提供的不一致，可能会存在报告内容不匹配的情况" />
                    </van-tab>
                    <van-tab v-for="(item, index) in processedReportData" :key="index"
                        :title="featureMap[item.data.apiID]?.name">
                        <div :id="item.data.apiID" class="title mb-4">
                            {{ featureMap[item.data.apiID]?.name }}
                        </div>
                        <component :is="featureMap[item.data.apiID]?.component" :data="item.data.data"
                            :params="reportParams">
                        </component>
                        <LRemark v-if="featureMap[item.data.apiID]?.remark"
                            :content="featureMap[item.data.apiID]?.remark" />
                    </van-tab>
                    <ShareReportButton v-if="!isShare" class="mb-4" :order-id="orderId" :order-no="orderNo"
                        :is-example="!orderId" />

                    <div class="card">
                        <div>
                            <div class="text-bold text-blue-500 mb-2">
                                报告说明
                            </div>
                            <div>
                                &nbsp;
                                &nbsp;本报告的数据由用户本人明确授权后，我们才向相关合法存有用户个人数据的机构调取本报告相关内容，本平台只做大数据的获取与分析，仅向用户个人展示参考。
                            </div>
                            <p>
                                &nbsp; &nbsp; 报告有效期<strong class="text-red-500">30天</strong>，过期自动删除。
                            </p>
                            <p>
                                &nbsp; &nbsp;
                                若您的数据不全面，可能是数据具有延迟性或者合作信息机构未获取到您的数据。若数据有错误请联系客服
                            </p>
                            <p>
                                &nbsp;
                                &nbsp;本产品所有数据均来自第三方。可能部分数据未公开、数据更新延迟或信息受到限制，贵司不对数据的准确性、真实性、完整性做任何承诺。用户需根据实际情况，结合报告内容自行判断与决策。
                            </p>
                        </div>
                    </div>
                </div>
            </van-tabs>
        </template>

    </div>
    <div class="disclaimer">
        <div class="flex flex-col items-center">
            <div class="flex items-center">
                <img class="w-4 h-4 mr-2" src="@/assets/images/public_security_record_icon.png" alt="公安备案" />
                <text>琼公网安备46010002000584号</text>
            </div>
            <div>
                <a class="text-blue-500" href="https://beian.miit.gov.cn">
                    琼ICP备2024048057号-2
                </a>
            </div>
        </div>
        <div>海南天远大数据科技有限公司版权所有</div>
    </div>

</template>

<style lang="scss" scoped>
.title {
    @apply mx-auto mt-2 w-64 border rounded-3xl py-2 text-center text-white font-bold;
    background: linear-gradient(135deg, var(--van-theme-primary), var(--van-theme-primary-dark));
}

.a {
    color: #e03131;
}

.disclaimer {
    /* margin-top: 24px; */
    padding: 10px;
    font-size: 12px;
    color: #999;
    text-align: center;
    border-top: 1px solid #e0e0e0;
    padding-bottom: 60px;
    background: #ffffff;
}

:deep(.card) {
    @apply p-3;
}
</style>
