import Mock from "mockjs";
//处理路径传参
import { parameteUrl } from "@/utils/query-param"

function ArrSet(Arr: any[], id: string): any[] {
    let obj: any = {}
    const arrays = Arr.reduce((setArr, item) => {
        obj[item[id]] ? '' : (obj[item[id]] = true && setArr.push(item))
        return setArr
    }, [])
    return arrays
}
/**
* @description: min ≤ r ≤ max  随机数
* @param {*} Min
* @param {*} Max
* @return {*}
*/
function RandomNumBoth(Min: any, Max: any) {
    var Range = Max - Min;
    var Rand = Math.random();
    var num = Min + Math.round(Rand * Range); //四舍五入
    return num;
}
//左中
export default [
    {
        url: "/bigscreen/countUserNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    offlineNum: '@integer(50, 100)',
                    alarmNum: '@integer(20, 100)',
                    lockNum: '@integer(10, 50)',
                    totalNum: 368
                }
            })
            a.data.onlineNum = a.data.totalNum - a.data.offlineNum - a.data.lockNum - a.data.alarmNum
            return a
        },
    },
    {
        url: "/bigscreen/countDeviceNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    alarmNum: '@integer(100, 1000)',
                    offlineNum: '@integer(0, 50)',
                    totalNum: 698
                }
            })
            a.data.onlineNum = a.data.totalNum - a.data.offlineNum
            return a
        }
    },
    //左下
    {
        url: "/bigscreen/leftBottom",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    "list|20": [
                        {
                            provinceName: "@province()",
                            cityName: '@city()',
                            countyName: "@county()",
                            createTime: "@datetime('yyyy-MM-dd HH:mm:ss')",
                            deviceId: "6c512d754bbcd6d7cd86abce0e0cac58",
                            "gatewayno|+1": 10000,
                            "onlineState|1": [0, 1],

                        }
                    ]
                }
            })
            return a
        }
    },
    //右上
    {
        url: "/bigscreen/alarmNum",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    dateList: ['2021-11', '2021-12', '2022-01', '2022-02', '2022-03', "2022-04"],
                    "numList|6": [
                        '@integer(0, 1000)'
                    ],
                    "numList2|6": [
                        '@integer(0, 1000)'
                    ]
                }
            })
            return a
        }
    },
    //右中
    {
        url: "/bigscreen/ranking",
        type: "get",
        response: () => {
            let num = Mock.mock({ "list|80": [{ value: "@integer(50,1000)", name: "@city()" }] }).list
            //   console.log("ranking",num);
            let newNum: any = [], numObj: any = {}
            num.map((item: any) => {
                if (!numObj[item.name] && newNum.length < 8) {
                    numObj[item.name] = true
                    newNum.push(item)
                }
            })
            let arr = newNum.sort((a: any, b: any) => {
                return b.value - a.value
            })
            let a = {
                success: true,
                data: arr
            }
            return a
        }
    },
    //右下
    {
        url: "/bigscreen/rightBottom",
        type: "get",
        response: () => {
            const a = Mock.mock({
                success: true,
                data: {
                    "list|40": [{
                        alertdetail: "@csentence(5,10)",
                        "alertname|1": ["水浸告警", "各种报警"],
                        alertvalue: "@float(60, 200)",
                        createtime: "2022-04-19 08:38:33",
                        deviceid: null,
                        "gatewayno|+1": 10000,
                        phase: "A1",
                        sbInfo: "@csentence(10,18)",
                        "terminalno|+1": 100,
                        provinceName: "@province()",
                        cityName: '@city()',
                        countyName: "@county()",
                    }],

                }
            })
            return a
        }
    },
    //安装计划
    {
        url: "/bigscreen/installationPlan",
        type: "get",
        response: () => {

            let num = RandomNumBoth(26, 32);
            const a = Mock.mock({
                ["category|" + num]: ["@city()"],
                ["barData|" + num]: ["@integer(10, 100)"],
            })
            let lineData = [], rateData = [];
            for (let index = 0; index < num; index++) {
                let lineNum = Mock.mock('@integer(0, 100)') + a.barData[index]
                lineData.push(lineNum)
                let rate = a.barData[index] / lineNum;
                rateData.push((rate * 100).toFixed(0))
            }
            a.lineData = lineData
            a.rateData = rateData
            return {
                success: true,
                data: a
            }
        }
    },
    {
        url: "/bigscreen/centerMap",
        type: "get",
        response: (options: any) => {
            let params = parameteUrl(options.url)
            //不是中国的时候
            if (params.regionCode && !["china"].includes(params.regionCode)) {
                const a = Mock.mock({
                    success: true,
                    data: {
                        "dataList|100": [
                            {
                                name: "@city()",
                                value: '@integer(1, 1000)'
                            }
                        ],
                        regionCode: params.regionCode,//-代表中国
                    }
                })
                return a
            } else {
                const a = Mock.mock({
                    success: true,
                    data: {
                        "dataList|12": [
                            {
                                name: "@province()",
                                value: '@integer(1, 1100)'
                            }
                        ],
                        regionCode: 'china',
                    }
                })
                // 去重
                a.data.dataList = ArrSet(a.data.dataList, "name")
                return a
            }
        }
    },
     // 添加咨询人数趋势图接口
     {
        url: "/bigscreen/consultationTrend",
        type: "get",
        response: () => {
            const dateList = ['7/1', '7/2', '7/3', '7/4', '7/5', '7/6', '7/7'];
            // 生成趋势数据，符合图中的走势
            const valueList = [150, 300, 580, 680, 900, 800, 300];
            
            return {
                success: true,
                data: {
                    dateList,
                    valueList
                }
            };
        }
    },
    // 教师咨询数据统计
    {
        url: "/bigscreen/teacherConsultStats",
        type: "get",
        response: () => {
            return {
                success: true,
                data: {
                    consultCount: 12452,
                    replyCount: 12452,
                    messageCount: 2231
                }
            };
        }
    },
    // 学生用户属考生分布统计
    {
        url: "/bigscreen/studentDistribution",
        type: "get",
        response: () => {
            return {
                success: true,
                data: {
                    years: ['2022', '2023', '2024', '2025', '2026', '2027'],
                    values: [320, 400, 350, 500, 450, 380],
                    totalCount: 24680,
                    growthRate: 12.5
                }
            };
        }
    },
    // 用户量属高中排行
    {
        url: "/bigscreen/highSchoolRanking",
        type: "get",
        response: () => {
            return {
                success: true,
                data: [
                    { rank: 1, school: '杭州第二中学', count: 3954 },
                    { rank: 2, school: '杭州第一中学', count: 2360 },
                    { rank: 3, school: '杭州学军中学', count: 1025 },
                    { rank: 4, school: '杭州高级中学', count: 998 },
                    { rank: 5, school: '杭州师范大学附属中学', count: 874 }
                ]
            };
        }
    },
    // 平均时长趋势
    {
        url: "/bigscreen/averageDuration",
        type: "get",
        response: () => {
            return {
                success: true,
                data: {
                    days: ['7/1', '7/2', '7/3', '7/4', '7/5', '7/6', '7/7'],
                    durations: [65, 80, 45, 68, 80, 55, 60]
                }
            };
        }
    },
    // 用户量属专业排行
    {
        url: "/bigscreen/majorRanking",
        type: "get",
        response: () => {
            return {
                success: true,
                data: [
                    { rank: 1, major: '计算机科学与技术', count: 3954 },
                    { rank: 2, major: '软件工程', count: 2360 },
                    { rank: 3, major: '人工智能', count: 1025 },
                    { rank: 4, major: '数据科学与大数据技术', count: 998 },
                    { rank: 5, major: '电子信息工程', count: 874 },
                    { rank: 6, major: '通信工程', count: 3954 },
                    { rank: 7, major: '网络工程', count: 2360 },
                    { rank: 8, major: '信息安全', count: 1025 },
                    { rank: 9, major: '物联网工程', count: 998 },
                    { rank: 10, major: '自动化', count: 874 }
                ]
            };
        }
    },
    // 常见咨询问题
    {
        url: "/bigscreen/commonQuestions",
        type: "get",
        response: () => {
            return {
                success: true,
                data: [
                    {
                        id: 1,
                        question: '学校有哪些奖学金政策和申请条件？',
                        count: 3948
                    },
                    {
                        id: 2,
                        question: '我的高考成绩能报考哪些学校和专业？',
                        count: 2249
                    },
                    {
                        id: 3,
                        question: '大学生实习和就业有哪些资源？',
                        count: 900
                    },
                    {
                        id: 4,
                        question: '如何申请转专业以及需要满足什么条件？',
                        count: 600
                    },
                    {
                        id: 5,
                        question: '如何申请休学、复学或者退学？',
                        count: 380
                    },
                    {
                        id: 6,
                        question: '如果高考分数不理想，有哪些复读或者其他选择？',
                        count: 20
                    }
                ]
            };
        }
    }
];

