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 BzsearchFormSchema: 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: 'data',
        component: 'RangeDate',
        componentProps: {
            format: 'YYYY-MM-DD',
            //范围文本描述用集合
            placeholder: ['请选择开始日期', '请选择结束日期']
        },
    },
    {
        label: '单位名称',
        field: 'dwmcdm',
        component: 'Input',
        componentProps: {
            placeholder: '单位名称或信用代码'
        }
    },


]
// 报告编制单位业务开展情况统计
export const BzColumns: BasicColumn[] = [

    {
        title: '单位名称',
        dataIndex: 'dwmc',
        resizable: true,
    },
    {
        title: '统一社会信用代码',
        dataIndex: 'tyshxydm',
        resizable: true,
    },
    {
        title: '参与地块数量',
        dataIndex: 'zdks',
        resizable: true,
    },
    {
        title: '阶段参与地块',
        resizable: true,
        children: [
            {
                title: '地块调查',
                dataIndex: 'dkdcs',
            },
            {
                title: '风险评估',
                dataIndex: 'fxpgs',
            },
            {
                title: '管控修复',
                dataIndex: 'gkxfs',
            },
            {
                title: '效果评估',
                dataIndex: 'xgpgs',
            },
        ]
    },

]
//报告编制单位业务开展区域情况表
export const BzqyColumns: BasicColumn[] = [
    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '县',
        dataIndex: 'countryName',
        resizable: true,
    },
    {
        title: '单位名称',
        dataIndex: 'dwmc',
        resizable: true,
    },
    {
        title: '统一社会信用代码',
        dataIndex: 'tyshxydm',
        resizable: true,
    },

    {
        title: '参与地块数量',
        dataIndex: 'zdks',
        resizable: true,
    },
    {
        title: '阶段参与地块',
        resizable: true,
        children: [
            {
                title: '地块调查',
                dataIndex: 'dkdcs',
            },
            {
                title: '风险评估',
                dataIndex: 'fxpgs',
            },
            {
                title: '管控修复',
                dataIndex: 'gkxfs',
            },
            {
                title: '效果评估',
                dataIndex: 'xgpgs',
            },
        ]
    },

]
// 检测单位业务开展情况
export const JcColumns: BasicColumn[] = [

    {
        title: '单位名称',
        dataIndex: 'dwmc',
        resizable: true,
    },
    {
        title: '统一社会信用代码',
        dataIndex: 'tyshxydm',
        resizable: true,
    },
    {
        title: '参与地块数量',
        dataIndex: 'zdks',
        resizable: true,
    },
    {
        title: '阶段参与地块',
        resizable: true,
        children: [
            {
                title: '地块调查',
                dataIndex: 'dkdcs',
            },
            {
                title: '风险管控效果评估',
                dataIndex: 'fxgkxgpgs',
            },
            {
                title: '修复效果评估',
                dataIndex: 'xfxgpgs',
            },
            {
                title: '管控及修复效果评估',
                dataIndex: 'gkjxfxgpgs',
            },
        ]
    },

]

// 单位信息统计
export const dwtjFormSchema: FormSchema[] = [
    {
        label: '地块名称',
        field: 'wrdkbm',
        component: 'Input',
        componentProps: {
            placeholder: '请输入地块名称或者编码'
        }
    },
    {
        label: '从业单位名称',
        field: 'dwmcdm',
        component: 'Input',
        componentProps: {
            placeholder: '单位名称或信用代码'
        }
    },


]
export const dwtjColumns: BasicColumn[] = [

    {
        title: '从业单位名称',
        dataIndex: 'syqdwmc',
        width: 220,
        resizable: true,
    },
    {
        title: '从业单位统一社会信用代码',
        dataIndex: 'gsyyzzh',
        width: 220,
        resizable: true,
    },
    {
        title: '地块名称',
        dataIndex: 'wrdkmc',
        width: 220,
        resizable: true,
    },
    {
        title: '地块编码',
        dataIndex: 'wrdkbm',
        width: 220,
        resizable: true,
    },
    {
        title: '当前所处阶段',
        dataIndex: 'szjd',
        width: 220,
        resizable: true,
    },
    {
        title: '调查阶段',
        resizable: true,
        children: [
            {
                title: '阶段类型',
                dataIndex: 'dcscjd',
            },
            {
                title: '单位类型',
                dataIndex: 'dclx',
            },
            {
                title: '评审次数',
                dataIndex: 'dcpscs',
            },
            {
                title: '通过率（%）',
                dataIndex: 'cdtgl',
            },
        ]
    },
    {
        title: '风评阶段',
        resizable: true,
        children: [

            {
                title: '单位类型',
                dataIndex: 'fxpglx',
            },
            {
                title: '评审次数',
                dataIndex: 'fxpgpscs',
            },
            {
                title: '通过率（%）',
                dataIndex: 'fxpgtgl',
            },
        ]
    },
    {
        title: '风险管控及修复阶段',
        resizable: true,
        children: [
            {
                title: '阶段类型',
                dataIndex: 'gkxfscjd',
            },

            {
                title: '单位类型',
                dataIndex: 'gkxflx',
            },
            {
                title: '评审次数',
                dataIndex: 'gkxfpscs',
            },
            {
                title: '通过率（%）',
                dataIndex: 'gkxftgl',
            },
        ]
    },
    {
        title: '风险管控及修复效果评估阶段',
        resizable: true,
        children: [
            {
                title: '阶段类型',
                dataIndex: 'xgpgscjd',
            },

            {
                title: '单位类型',
                dataIndex: 'xgpglx',
            },
            {
                title: '评审次数',
                dataIndex: 'xgpgpscs',
            },
            {
                title: '通过率（%）',
                dataIndex: 'xgpgtgl',
            },
        ]
    },

]