<template>
    <div class="evaluationReportPanel">
        <h1>评价报告</h1>
        <div class="evaluationInfo">
            <div class="evaluationBox">
                <div class="box">
                    <span>算法名称:</span>
                    <b>{{ info.algorithmName }}</b>
                </div>
                <div class="box">
                    <span>算法得分:</span>
                    <b>{{ info.algorithmScore }}</b>
                </div>
                <div class="box">
                    <span>测试等级:</span>
                    <b>{{ info.evaluationLevel }}</b>
                </div>
            </div>
            <div class="desBox">
                <span>算法描述:</span>
                <b>{{ info.algorithmDescribe }}</b>
            </div>
            <div class="evaBox">
                <span>算法简评:</span>
                <b>{{ info.algorithmEvaluation }}</b>
            </div>
        </div>

        <div class="tableBox tableBoxA">
            <div class="title">测试得分表</div>
            <tableList :columns="columns" :getDataWay="getDataWay"> </tableList>
        </div>

        <div class="tableBox tableBoxB">
            <div class="title">评价等级</div>
            <tableList
                :columns="columnsA"
                :getDataWay="getDataWayA"
                class="colorfulTable"
            >
            </tableList>
        </div>

        <div class="tableBox tableBoxC">
            <div class="title">算法测试评分细则</div>
            <tableList
                :columns="columnsB"
                :getDataWay="getDataWayB"
                :span-method="arraySpanMethod"
            >
            </tableList>
        </div>

        <div class="tableBox tableBoxD">
            <div class="title">详情得分情况</div>
            <tableList
                :columns="columnsC"
                :getDataWay="getDataWayC"
                :row-class-name="errRow"
            >
            </tableList>
        </div>
    </div>
</template>

<script>
import tableList from "@/components/grid/TableList";

export default {
    name: "evaluationReport", // 评价报告
    components: { tableList },
    data() {
        return {
            id: "",
            columns: [
                {
                    label: "测试项目",
                    prop: "projectName",
                },
                {
                    label: "场景数量",
                    prop: "sceneNum",
                },
                {
                    label: "测试权重%",
                    prop: "weight",
                },
                {
                    label: "测试得分",
                    prop: "score",
                },
                {
                    label: "得分率%",
                    prop: "scoreRatio",
                },
            ],
            pagination: {
                //分页使用
                currentPage: 1,
                pageSize: 10,
                position: "right",
                pageSizes: [10, 30, 50, 100, 200],
                layout: "sizes, total, prev, pager, next, jumper",
            },
            getDataWay: {
                //加载表格数据
                dataType: "data",
                type: "post",
                firstRequest: false,
                data: [],
                param: {},
            },
            columnsA: [
                {
                    label: "测试项目",
                    prop: "name",
                },
                {
                    label: "90<总分<100",
                    prop: "levelA",
                },
                {
                    label: "80<总分<90",
                    prop: "levelB",
                },
                {
                    label: "70<总分<80",
                    prop: "levelC",
                },
                {
                    label: "0<总分<70",
                    prop: "levelD",
                },
            ],
            getDataWayA: {
                //加载表格数据
                dataType: "data",
                type: "post",
                firstRequest: false,
                data: [
                    {
                        index: 1,
                        name: "评价等级",
                        levelA: "优秀(G)",
                        levelB: "良好(A)",
                        levelC: "一般(M)",
                        levelD: "较差(P)",
                    },
                    {
                        index: 2,
                        name: "评价等级",
                        levelA: "++++++",
                        levelB: "+++++",
                        levelC: "++++",
                        levelD: "+++",
                    },
                ],
                param: {},
            },
            columnsB: [],
            getDataWayB: {
                //加载表格数据
                dataType: "data",
                type: "post",
                data: [],
                param: {},
            },
            columnsC: [],
            getDataWayC: {
                //加载表格数据
                dataType: "data",
                type: "post",
                data: [],
                param: {},
            },
            info: {},
            sublistNameObj1: {}, // 存储一级指标名称对应的次数
            sublistNameObj2: {}, // 存储二级指标名称对应的次数
            sublistNameObj3: {}, // 存储三级指标名称对应的次数
            sublistNameObj4: {}, // 存储四级指标名称对应的次数
            sublistNameObj5: {}, // 存储五级指标名称对应的次数
            sublistNameObj6: {}, // 存储六级指标名称对应的次数
            subIndexArr1: [], // 存储一级指标名称第一次出现对应的下标
            subIndexArr2: [], // 存储二级指标名称第一次出现对应的下标
            subIndexArr3: [], // 存储三级指标名称第一次出现对应的下标
            subIndexArr4: [], // 存储四级指标名称第一次出现对应的下标
            subIndexArr5: [], // 存储五级指标名称第一次出现对应的下标
            subIndexArr6: [], // 存储六级指标名称第一次出现对应的下标
        };
    },

    computed: {},

    methods: {
        arraySpanMethod({ row, column, rowIndex, columnIndex }) {
            if (columnIndex === 0 || columnIndex === this.columnsB.length - 1) {
                if (this.subIndexArr1.includes(rowIndex)) {
                    return [this.sublistNameObj1[row.sublistName1], 1];
                } else {
                    return [0, 0];
                }
            } else if (columnIndex === 1) {
                if (this.subIndexArr2.includes(rowIndex)) {
                    return [this.sublistNameObj2[row.sublistName2], 1];
                } else {
                    if (row.sublistName2) {
                        return [0, 0];
                    } else {
                        return [1, 1];
                    }
                }
            } else if (columnIndex === 2) {
                if (this.subIndexArr3.includes(rowIndex)) {
                    return [this.sublistNameObj3[row.sublistName3], 1];
                } else {
                    if (row.sublistName3) {
                        return [0, 0];
                    } else {
                        return [1, 1];
                    }
                }
            } else if (columnIndex === 3) {
                if (this.subIndexArr4.includes(rowIndex)) {
                    return [this.sublistNameObj4[row.sublistName4], 1];
                } else {
                    if (row.sublistName4) {
                        return [0, 0];
                    } else {
                        return [1, 1];
                    }
                }
            } else if (columnIndex === 4) {
                if (this.subIndexArr5.includes(rowIndex)) {
                    return [this.sublistNameObj5[row.sublistName5], 1];
                } else {
                    if (row.sublistName5) {
                        return [0, 0];
                    } else {
                        return [1, 1];
                    }
                }
            } else if (columnIndex === 5) {
                if (this.subIndexArr6.includes(rowIndex)) {
                    return [this.sublistNameObj6[row.sublistName6], 1];
                } else {
                    if (row.sublistName6) {
                        return [0, 0];
                    } else {
                        return [1, 1];
                    }
                }
            }
        },
        errRow({ row, rowIndex }) {
            if (row.runState === "Failed") {
                return "errColor";
            }
        },
        // 处理数据，通关于配合表格进行合并单元行
        dataHandle(data) {
            let arr = data;

            let lastRowSublistName1 = "";
            let lastRowSublistName2 = "";
            let lastRowSublistName3 = "";
            let lastRowSublistName4 = "";
            let lastRowSublistName5 = "";
            let lastRowSublistName6 = "";

            let sublistNameObj1 = {};
            let sublistNameObj2 = {};
            let sublistNameObj3 = {};
            let sublistNameObj4 = {};
            let sublistNameObj5 = {};
            let sublistNameObj6 = {};

            arr.forEach((item, i) => {
                let sublistName1 = item.sublistName1;
                if (sublistName1 === lastRowSublistName1) {
                    sublistNameObj1[sublistName1]++;
                } else {
                    lastRowSublistName1 = sublistName1;
                    this.subIndexArr1.push(i);
                    sublistNameObj1[sublistName1] = 1;
                }

                if (item.sublistName2) {
                    // 一级后的指标名称可能不存在
                    let sublistName2 = item.sublistName2;
                    if (sublistName2 === lastRowSublistName2) {
                        sublistNameObj2[sublistName2]++;
                    } else {
                        lastRowSublistName2 = sublistName2;
                        this.subIndexArr2.push(i);
                        sublistNameObj2[sublistName2] = 1;
                    }
                }

                if (item.sublistName3) {
                    let sublistName3 = item.sublistName3;
                    if (sublistName3 === lastRowSublistName3) {
                        sublistNameObj3[sublistName3]++;
                    } else {
                        lastRowSublistName3 = sublistName3;
                        this.subIndexArr3.push(i);
                        sublistNameObj3[sublistName3] = 1;
                    }
                }

                if (item.sublistName4) {
                    let sublistName4 = item.sublistName4;
                    if (sublistName4 === lastRowSublistName4) {
                        sublistNameObj4[sublistName4]++;
                    } else {
                        lastRowSublistName4 = sublistName4;
                        this.subIndexArr4.push(i);
                        sublistNameObj4[sublistName4] = 1;
                    }
                }

                if (item.sublistName5) {
                    let sublistName5 = item.sublistName5;
                    if (sublistName5 === lastRowSublistName5) {
                        sublistNameObj5[sublistName5]++;
                    } else {
                        lastRowSublistName5 = sublistName5;
                        this.subIndexArr5.push(i);
                        sublistNameObj5[sublistName5] = 1;
                    }
                }

                if (item.sublistName6) {
                    let sublistName6 = item.sublistName6;
                    if (sublistName6 === lastRowSublistName6) {
                        sublistNameObj6[sublistName6]++;
                    } else {
                        lastRowSublistName6 = sublistName6;
                        this.subIndexArr6.push(i);
                        sublistNameObj6[sublistName6] = 1;
                    }
                }
            });

            this.sublistNameObj1 = sublistNameObj1;
            this.sublistNameObj2 = sublistNameObj2;
            this.sublistNameObj3 = sublistNameObj3;
            this.sublistNameObj4 = sublistNameObj4;
            this.sublistNameObj5 = sublistNameObj5;
            this.sublistNameObj6 = sublistNameObj6;
        },
    },

    mounted() {
        if (this.$route.query.id) {
            this.id = this.$route.query.id;

            if (this.id) {
                this.$axios({
                    method: "post",
                    url: this.$api.workManagement.selectProjectReportById,
                    data: {
                        id: this.id,
                    },
                }).then((res) => {
                    if (res.code == 200 && res.info) {
                        this.info = res.info;
                        this.getDataWay.data = res.info.algorithmScoreList;
                        this.columnsB = res.info.subListScoreLiTitle;
                        this.dataHandle(res.info.subListScoreLi);
                        this.getDataWayB.data = res.info.subListScoreLi;
                        this.columnsC = res.info.sceneScoreLiTitle;
                        this.getDataWayC.data = res.info.sceneScoreLi;
                    } else {
                        this.$message.error(res.message || "获取信息失败");
                    }
                });
            }
        }
    },
};
</script>

<style lang='less' scoped>
.evaluationReportPanel {
    min-width: 900px;
    width: 60%;
    margin: 0 auto;

    h1 {
        padding: 40px 0 60px;
        font-size: 36px;
        color: @themeColor;
        text-align: center;
    }

    .evaluationInfo {
        font-size: 16px;

        span,
        b {
            display: block;
            font-weight: normal;
        }

        span {
            width: 80px;
            color: @gray;
        }

        b {
            flex: 1;
        }
    }

    .evaluationBox {
        display: flex;
        justify-content: space-between;

        .box {
            display: flex;
            width: 30%;

            span {
                padding-right: 10px;
                // color: @color;
            }

            b {
                padding-bottom: 3px;
                border-bottom: 1px solid @gray;
                text-align: center;
            }
        }
    }

    .desBox,
    .evaBox {
        display: flex;

        b {
            padding: 12px;
            border: 1px solid @gray;
        }
    }

    .desBox {
        padding: 40px 0;
    }

    .tableBox {
        padding: 60px 0;
        .title {
            padding-bottom: 20px;
            font-size: 18px;
            text-align: center;
            font-weight: bold;
        }
    }

    .tableBoxB,
    .tableBoxC,
    .tableBoxD {
        padding: 0 0 60px;
    }

    .colorfulTable {
        /deep/ .el-table__body {
            .el-table__row:nth-child(2) {
                td:nth-child(2) {
                    background-color: #c1db69;
                }
                td:nth-child(3) {
                    background-color: #faf54a;
                }
                td:nth-child(4) {
                    background-color: #ff9d33;
                }
                td:last-child {
                    background-color: #f56c6c;
                }
            }
        }
    }

    /deep/ .el-table .errColor td {
        color: red;
    }
}
</style>