import { BasicColumn, FormSchema } from '/@/components/Table';
import { dict, getTown, getHylb } from '/@/api/common/api'
import { useUserStore } from '/@/store/modules/user';
import { convertTreeData } from '/@/utils/modifFiled';
import { ref } from 'vue';

const userStore: any = useUserStore();
export const useSuspectsData = () => {
    const suspects = ref([]);
    // 获取行业分类
    const getIsSuspect = async () => {
        suspects.value = await dict({ key: 'dk_hyfl' });
    };
    getIsSuspect();
    return { data: suspects };
};

export const useCategoryData = () => {
    let allCategory = [];
    const treeData = ref([]);
    // 获取行业类别
    const getData = async () => {
        allCategory = await getHylb({});
        // allCategory = convertTreeData(allCategory); // 只显示前2级
        // allCategory.forEach((item: any) => {
        //     item.disabled = true; // 第1层级不能选中
        // });
        treeData.value = allCategory;
    };
    getData();
    // 改变行业分类
    function changeIsSuspect(v) {
        if (v == 1) {
            // 只显示42号类
            treeData.value = allCategory.filter((item) => item['is42']);
        } else {
            treeData.value = allCategory;
        }
    }
    return { data: treeData, changeIsSuspect };
};
// 获取等级
const userIdent = ref<any>([])
export const getUserLevel = () => {
    const getIsSuspect = async () => {
        if (userStore?.userInfo?.userIdentity == '1') {
            userIdent.value = [{
                text: '市级',
                value: '1'

            }, {
                text: '区县',
                value: '2'
            }
            ]
        }
    };
    getIsSuspect();

    return { data: userIdent };
}

//地块阶段情况统计
export const Columns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '县',
        dataIndex: 'countryName',
        resizable: true,
    },
    {
        title: '地块名称',
        dataIndex: 'wrdkmc',
        resizable: true,
    },
    {
        title: '地块编码',
        dataIndex: 'wrdkbm',
        resizable: true,
    },
    {
        title: '地块调查填报方式',
        dataIndex: 'dkdctbfs',
        resizable: true,
    },
    {
        title: '地块是否超标',
        dataIndex: 'dksfcb',
        resizable: true,
    },
    {
        title: '所处阶段',
        dataIndex: 'scjd',
        resizable: true,
    },
]
export const searchFormSchema: FormSchema[] = [
    {
        label: '市',
        field: 'cityCode',
        component: 'ApiSelect',
        ifShow: () => {
            return userStore?.userInfo?.userIdentity == '1' ? true : false
        },
        componentProps: ({ formModel, formActionType }) => {
            return {
                api: getTown,
                params: 440000, // 行政区划编码
                labelField: 'name',
                valueField: 'id',
                onChange: (val: any) => {
                    const { updateSchema } = formActionType;
                    formModel.countryCode = undefined;
                    if (val) {
                        updateSchema({
                            field: 'countryCode',
                            componentProps: {
                                api: getTown,
                                params: val,
                                labelField: 'name',
                                valueField: 'id',
                            },
                        });
                    } else {
                        updateSchema({
                            field: 'countryCode',
                            componentProps: {
                                api: undefined,
                                labelField: 'name',
                                valueField: 'id',
                            },
                        });
                    }
                },
            };
        },
    },
    {
        label: '县',
        field: 'countryCode',
        component: 'ApiSelect',
        ifShow: () => {
            return (userStore?.userInfo?.userIdentity == '2' || userStore?.userInfo?.userIdentity == '1') ? true : false
        },
        componentProps: ({ formModel, formActionType }) => {
            if (userStore?.userInfo?.userIdentity == '2') {
                const { updateSchema } = formActionType;
                updateSchema({
                    label: '县',
                    field: 'countryCode',
                    ifShow: true,
                    componentProps: {
                        api: getTown,
                        params: userStore?.userInfo?.codeRegion,
                        labelField: 'name',
                        valueField: 'id',
                    },
                });
            }
            return {
                labelField: 'name',
                valueField: 'id',
            }
        },
    },
    {
        label: '地块调查填报方式',
        field: 'dclx',
        component: 'ApiSelect',
        componentProps: {
            api: dict,
            params: { key: 'dk_dclx' },
            labelField: 'text',
            valueField: 'value',
        }
    },
    {
        label: '是否超标',
        field: 'sfcb',
        component: 'ApiSelect',
        componentProps: {
            api: dict,
            params: { key: 'qd_sfcb' },
            labelField: 'text',
            valueField: 'value',
        }
    },
    // {
    //     label: '政策依据',
    //     field: 'faliyiju',
    //     component: 'JSearchSelect',
    //     componentProps: {
    //         dict: 'dk_zcyj',
    //     },
    // },
    {
        label: '地块名称',
        field: 'wrdkbm',
        component: 'Input',
        componentProps: {
            placeholder: '地块名称或地块编码'
        }
    },
]

// 公用的搜索
export const DKdcsearchFormSchema: FormSchema[] = [
    {
        label: '等级',
        field: 'level',
        component: 'ApiSelect',
        show: () => {
            return userStore?.userInfo?.userIdentity == '1' ? true : false
        },
        slot: 'userLevle'
    },
    {
        label: '市',
        field: 'cityCode',
        component: 'ApiSelect',
        show: ({ values }) => {
            return values.level == '2' ? true : false
        },
        componentProps: () => {
            return {
                api: getTown,
                params: 440000, // 行政区划编码
                labelField: 'name',
                valueField: 'id',

            };
        },
    },

    // {
    //     label: '政策依据',
    //     field: 'faliyiju',
    //     component: 'JSearchSelect',
    //     componentProps: {
    //         dict: 'dk_zcyj',
    //     },
    // },
    {
        label: '地块添加日期',
        field: 'data',
        component: 'RangeDate',
        componentProps: {
            format: 'YYYY-MM-DD',
            //范围文本描述用集合
            placeholder: ['请选择开始日期', '请选择结束日期']
        },
    },

]
//地块调查阶段业务情况统计
export const DKdcColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '调查地块总数',
        dataIndex: 'dcdkzs',
        resizable: true,
    },
    {
        title: '完成调查的地块数（包括已移出调查名录的地块）',
        dataIndex: 'wcdcddks',
        resizable: true,
        ellipsis: true,
        slots: { customRender: 'wcdcddks' }
    },
    {
        title: '（评审）进入风险评估地块数',
        dataIndex: 'psjrfxpgdks',
        resizable: true,
    },
    {
        title: '（未评审）进入风险评估地块数',
        dataIndex: 'wpsjrfxpgdks',
        resizable: true,
    },
    {
        title: '（评审）进入移除调查名录清单地块数',
        dataIndex: 'psjrycdc',
        resizable: true,
    },
    {
        title: '（未评审）进入移除调查名录清单地块数',
        dataIndex: 'wpsjrycdc',
        resizable: true,
    },
    {
        title: '调查中地块数',
        dataIndex: 'dczdks',
        resizable: true,
    },
]
// 风险评估阶段业务情况统计
export const FxpgColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },

    {
        title: '风险评估地块数',
        dataIndex: 'fxpgdks',
        resizable: true,
    },
    {
        title: '（评审）无需采取措施地块数',
        dataIndex: 'pswxcqcsdk',
        resizable: true,
    },
    {
        title: '（评审）需风险管控地块数',
        dataIndex: 'psxfxgkdks',
        resizable: true,
    },
    {
        title: '（评审）需修复地块数',
        dataIndex: 'psxxfdks',
        resizable: true,
    },
    {
        title: '（评审）需管控及修复地块数',
        dataIndex: 'psxgkjxfdks',
        resizable: true,
    },
    {
        title: '（未评审）无需采取措施地块数',
        dataIndex: 'wpswxcqcsdk',
        resizable: true,
    },
    {
        title: '（未评审）需风险管控地块数',
        dataIndex: 'wpsxfxgkdks',
        resizable: true,
    },
    {
        title: '（未评审）需修复地块数',
        dataIndex: 'wpsxxfdks',
        resizable: true,
    },
    {
        title: '（未评审）需管控及修复地块数',
        dataIndex: 'wpsxgkjxfdks',
        resizable: true,
    },
    {
        title: '正在评估中地块数',
        dataIndex: 'zzpgzdks',
        resizable: true,
    },
]
//管控修复阶段业务情况统计
export const GkxfColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },

    {
        title: '风险管控',
        resizable: true,
        children: [
            {
                title: '正在开展',
                dataIndex: 'fxgkzzkz',
            },
            {
                title: '已完成',
                dataIndex: 'fxgkwc',
            },
            {
                title: '未开展',
                dataIndex: 'fxgkwkz',
            },
        ]
    },
    {
        title: '修复',
        resizable: true,
        children: [
            {
                title: '正在开展',
                dataIndex: 'xfzzkz',
            },
            {
                title: '已完成',
                dataIndex: 'xfwc',
            },
            {
                title: '未开展',
                dataIndex: 'xfwkz',
            },
        ]
    },
    {
        title: '管控及修复',
        resizable: true,
        children: [
            {
                title: '正在开展',
                dataIndex: 'gkjxfzzkz',
            },
            {
                title: '已完成',
                dataIndex: 'gkjxfwc',
            },
            {
                title: '未开展',
                dataIndex: 'gkjxfwkz',
            },
        ]
    },

]
//效果评估阶段业务情况统计
export const XgpgColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '效果评估地块',
        dataIndex: 'xgpgdk',
        resizable: true,
    },

    {
        title: '风险管控效果评估',
        resizable: true,
        children: [
            {
                title: '完成效果评估',
                dataIndex: 'fxgkwc',
            },
            {
                title: '移除风险管控与修复名录',
                dataIndex: 'fxgkyc',
            },
            {
                title: '正在开展效果评估',
                dataIndex: 'fxgkzz',
            },
        ]
    },
    {
        title: '修复效果评估',
        resizable: true,
        children: [
            {
                title: '完成效果评估',
                dataIndex: 'xfwc',
            },
            {
                title: '移除风险管控与修复名录',
                dataIndex: 'xfyc',
            },
            {
                title: '正在开展效果评估',
                dataIndex: 'xfzz',
            },
        ]
    },
    {
        title: '管控及修复效果评估',
        resizable: true,
        children: [
            {
                title: '完成效果评估',
                dataIndex: 'gkjxfwc',
            },
            {
                title: '移除风险管控与修复名录',
                dataIndex: 'gkjxfyc',
            },
            {
                title: '正在开展效果评估',
                dataIndex: 'gkjxfzz',
            },
        ]
    },

]
// 污染地块各阶段汇总情况统计
export const WrdkColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '总地块',
        dataIndex: 'zdk',
        resizable: true,
    },

    {
        title: '地块调查',
        resizable: true,
        children: [
            {
                title: '评审超标地块数',
                dataIndex: 'cb',
                resizable: true,
            },
            {
                title: '评审未超标地块数',
                dataIndex: 'wcb',
                resizable: true,
            },
            {
                title: '未开展调查地块',
                dataIndex: 'wkzdc',
                resizable: true,
            },
            {
                title: '调查中地块',
                dataIndex: 'dcz',
                resizable: true,
            },
        ]
    },
    {
        title: '风险评估',
        resizable: true,
        children: [
            {
                title: '评审需管控修复地块数',
                dataIndex: 'xgkxfdks',
                resizable: true,
            },
            {
                title: '评审无需采取措施地块数',
                dataIndex: 'wxcqcs',
                resizable: true,
            },
            {
                title: '风险评估中地块数',
                dataIndex: 'pgz',
                resizable: true,
            },
        ]
    },
    {
        title: '管控及修复地块数',
        dataIndex: 'gkxfdks',
        resizable: true,
    },
    {
        title: '风险管控地块',
        resizable: true,
        children: [
            {
                title: '正在开展地块',
                dataIndex: 'fxgkzzkz',
                resizable: true,
            },
            {
                title: '已完成地块',
                dataIndex: 'fxgkywc',
                resizable: true,
            },
            {
                title: '未开展地块',
                dataIndex: 'fxgkwkz',
                resizable: true,
            },
        ]
    },
    {
        title: '修复地块',
        resizable: true,
        children: [
            {
                title: '正在开展地块',
                dataIndex: 'xfzzkz',
                resizable: true,
            },
            {
                title: '已完成地块',
                dataIndex: 'xfywc',
                resizable: true,
            },
            {
                title: '未开展地块',
                dataIndex: 'xfwkz',
                resizable: true,
            },
        ]
    },
    {
        title: '管控及修复地块',
        resizable: true,
        children: [
            {
                title: '正在开展地块',
                dataIndex: 'gkjxfzzkz',
                resizable: true,
            },
            {
                title: '已完成地块',
                dataIndex: 'gkjxfywc',
                resizable: true,
            },
            {
                title: '未开展地块',
                dataIndex: 'gkjxfwkz',
                resizable: true,
            },
        ]
    },
    {
        title: '效果评估地块数',
        dataIndex: 'xgpgdks',
        resizable: true,
    },
    {
        title: '风险管控效果评估',
        resizable: true,
        children: [
            {
                title: '完成效果评估',
                dataIndex: 'fxgkwc',
                resizable: true,
            },
            {
                title: '移除风险管控与修复名录',
                dataIndex: 'fxgkyc',
                resizable: true,
            },
            {
                title: '正在开展效果评估',
                dataIndex: 'fxgkzz',
                resizable: true,
            },
        ]
    },
    {
        title: '修复效果评估',
        resizable: true,
        children: [
            {
                title: '完成效果评估',
                dataIndex: 'xfwc',
                resizable: true,
            },
            {
                title: '移除风险管控与修复名录',
                dataIndex: 'xfyc',
                resizable: true,
            },
            {
                title: '正在开展效果评估',
                dataIndex: 'xfzz',
                resizable: true,
            },
        ]
    },
    {
        title: '管控及修复效果评估',
        resizable: true,
        children: [
            {
                title: '完成效果评估',
                dataIndex: 'gkjxfwc',
                resizable: true,
            },
            {
                title: '移除风险管控与修复名录',
                dataIndex: 'gkjxfyc',
                resizable: true,
            },
            {
                title: '正在开展效果评估',
                dataIndex: 'gkjxfzz',
                resizable: true,
            },
        ]
    },
]

// 区域创建地块月情况统计
export let MonthColumns: BasicColumn[] = [
    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },

]
export const MonthsearchFormSchema: FormSchema[] = [
    {
        label: '等级',
        field: 'level',
        component: 'ApiSelect',
        show: () => {
            return userStore?.userInfo?.userIdentity == '1' ? true : false
        },
        slot: 'userLevle'
    },
    {
        label: '市',
        field: 'cityCode',
        component: 'ApiSelect',
        show: ({ values }) => {
            return values.level == '2' ? true : false
        },
        componentProps: () => {
            return {
                api: getTown,
                params: 440000, // 行政区划编码
                labelField: 'name',
                valueField: 'id',

            };
        },
    },

    {
        label: '开始月份',
        field: 'startMonth',
        component: 'MonthPicker',
        componentProps: {
            format: 'YYYYMM',
            //范围文本描述用集合
            valueFormat: 'YYYYMM',

        },
    },
    {
        label: '结束月份',
        field: 'endMonth',
        component: 'MonthPicker',
        componentProps: {
            format: 'YYYYMM',
            //范围文本描述用集合
            valueFormat: 'YYYYMM',

        },
    },

]

// 地块评审
export const DkpsFormSchema: FormSchema[] = [
    {
        label: '地块编码',
        field: 'wrdkbm',
        component: 'Input',
        componentProps: {
            placeholder: '请输入地块编码'
        }
    },
]
export const DkpsColumns: BasicColumn[] = [
    {
        title: '地块名称',
        dataIndex: 'wrdkmc',
        resizable: true,
        width: 220,
    },
    {
        title: '地块编码',
        dataIndex: 'wrdkbm',
        width: 220,
        resizable: true,
    },
    {
        title: '当前所处阶段',
        dataIndex: 'szjd',
        width: 220,
        resizable: true,
    },
    {
        title: '调查阶段',
        dataIndex: 'cityName',
        resizable: true,
        children: [
            {
                title: '是否通过评审',
                dataIndex: 'cdsftg',
            },
            {
                title: '评审次数',
                dataIndex: 'dcpscs',
            },
            {
                title: '通过率(%)',
                dataIndex: 'cdtgl',
            },

        ]
    },
    {
        title: '风评阶段',
        dataIndex: 'cityName',
        resizable: true,
        children: [
            {
                title: '是否通过评审',
                dataIndex: 'fxpgsftg',
            },
            {
                title: '评审次数',
                dataIndex: 'fxpgpscs',
            },
            {
                title: '通过率(%)',
                dataIndex: 'fxpgtgl',
            },

        ]
    },
    {
        title: '风险管控及修复阶段',
        dataIndex: 'cityName',
        resizable: true,
        children: [
            {
                title: '是否通过评审',
                dataIndex: 'gkxfsftg',
            },
            {
                title: '评审次数',
                dataIndex: 'gkxfpscs',
            },
            {
                title: '通过率(%)',
                dataIndex: 'gkxftgl',
            },

        ]
    },
    {
        title: '风险管控及修复效果评估阶段',
        dataIndex: 'cityName',
        resizable: true,
        children: [

            {
                title: '是否通过评审',
                dataIndex: 'xgpgsftg',
            },
            {
                title: '评审次数',
                dataIndex: 'xgpgpscs',
            },
            {
                title: '通过率(%)',
                dataIndex: 'xgpgtgl',
            },

        ]
    },
]
// 地块评审
export const ZjpsFormSchema: FormSchema[] = [
    {
        label: '专家名称',
        field: 'zjxm',
        component: 'Input',
        componentProps: {
            placeholder: '请输入专家名称'
        }
    },
]
export const ZjpsColumns: BasicColumn[] = [
    {
        title: '序号',
        dataIndex: 'index',
        key: 'index',
        width: 150,
        customRender: ({ index }) => {
            return index + 1;
          },
      },
    {
        title: '专家名称',
        dataIndex: 'zjxm',
        resizable: true,
        width: 220,
    },
    {
        title: '参与项目',
        dataIndex: 'cyxm',
        resizable: true,
    },

    {
        title: '是否通过评审',
        dataIndex: 'sftg',
        resizable: true,
        width: 220,
    },
    {
        title: '项目时间(评审会时间)',
        dataIndex: 'hysj',
        width: 220,
        resizable: true,
    },
]
