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 TrwrsearchFormSchema: 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: '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',
    //     },
    // },
]
// 土壤受污染程度情况统计
export const TrwrColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '地块数',
        dataIndex: 'dks',
        resizable: true,
    },
    {
        title: '超过管制值地块',
        dataIndex: 'cggzz',
        resizable: true,
    },
    {
        title: '超过筛选值地块',
        dataIndex: 'cgsxz',
        resizable: true,
    },
    {
        title: '超过管制及筛选值地块',
        dataIndex: 'cgsxzgzz',
        resizable: true,
    },
    {
        title: '未超出地块',
        dataIndex: 'wcb',
        resizable: true,
    },
    {
        title: '未确定地块',
        dataIndex: 'wqddk',
        resizable: true,
    },
]
// 地下水污染情况统计
export const DxsColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '地块数',
        dataIndex: 'dks',
        resizable: true,
    },
    {
        title: '地下水污染地块',
        dataIndex: 'wrdk',
        resizable: true,
    },
    {
        title: '地下水未污染地块',
        dataIndex: 'wwrdk',
        resizable: true,
    },
    {
        title: '未确定地下水是否污染地块',
        dataIndex: 'wqdwrdk',
        resizable: true,
    },
    {
        title: '地下水作为饮用水源地块',
        dataIndex: 'yysy',
        resizable: true,
    },
    {
        title: '地下水未作为饮用水源地块',
        dataIndex: 'fyysy',
        resizable: true,
    },
    {
        title: '未确定地下水是否作为饮用水源地块',
        dataIndex: 'wqdyysy',
        resizable: true,
    },
    {
        title: '地下水污染且作为饮用水源地块',
        dataIndex: 'wrdkyysy',
        resizable: true,
    },
]

// 地块调查-区域污染物超标情况统计
export const AreaColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '地块数',
        dataIndex: 'dks',
        resizable: true,
    },
    {
        title: '未超出地块',
        dataIndex: 'wccdk',
        resizable: true,
    },
    {
        title: '未确认地块',
        dataIndex: 'wqddk',
        resizable: true,
    },
    {
        title: '超出地块',
        dataIndex: 'ccdk',
        resizable: true,
    },
    {
        title: '六六六',
        dataIndex: 'sxzLiull',
        resizable: true,
    },
    {
        title: '滴滴涕',
        dataIndex: 'sxzDdd',
        resizable: true,
    },
    {
        title: '多氯联苯',
        dataIndex: 'sxzDllb',
        resizable: true,
    },
    {
        title: '二噁英',
        dataIndex: 'sxzEry',
        resizable: true,
    },
    {
        title: '其他POPs',
        dataIndex: 'sxzQtpop',
        resizable: true,
    },
    {
        title: '镉',
        dataIndex: 'sxzGe',
        resizable: true,
    },
    {
        title: '铬',
        dataIndex: 'sxzKe',
        resizable: true,
    },
    {
        title: '砷',
        dataIndex: 'sxzShen',
        resizable: true,
    },
    {
        title: '铅',
        dataIndex: 'sxzQian',
        resizable: true,
    },
    {
        title: '汞',
        dataIndex: 'sxzGong',
        resizable: true,
    },
    {
        title: '重金属其他',
        dataIndex: 'sxzZjsQt',
        resizable: true,
    },
]

// 地块区域敏感受体情况统计
export const MgstColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '地块数',
        dataIndex: 'dks',
        resizable: true,
    },
    {
        title: '幼儿园',
        dataIndex: 'mgdYey',
        resizable: true,
    },
    {
        title: '学校',
        dataIndex: 'mgdSchool',
        resizable: true,
    },
    {
        title: '居民区',
        dataIndex: 'mgdJmq',
        resizable: true,
    },
    {
        title: '医院',
        dataIndex: 'mgdYy',
        resizable: true,
    },
    {
        title: '食用农产品产地',
        dataIndex: 'mgdSyncpcd',
        resizable: true,
    },
    {
        title: '地表水体',
        dataIndex: 'mgdDbst',
        resizable: true,
    },
    {
        title: '集中式饮用水水源地',
        dataIndex: 'mgdJzsyyssyd',
        resizable: true,
    },
    {
        title: '自然保护区',
        dataIndex: 'mgdZrbhq',
        resizable: true,
    },
    {
        title: '无',
        dataIndex: 'mgdNone',
        resizable: true,
    },
    {
        title: '其他',
        dataIndex: 'mgdOther',
        resizable: true,
    },
]

// 地块土壤环境风险信息查询
export const TrhjColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '县级',
        dataIndex: 'countryName',
        resizable: true,
    },
    {
        title: '地块名称',
        dataIndex: 'wrdkmc',
        resizable: true,
    },
    {
        title: '地块编码',
        dataIndex: 'wrdkbm',
        resizable: true,
    },
    {
        title: '需要风险管控修复土壤污染面积(m2)',
        dataIndex: 'wrmj',
        resizable: true,
    },
    {
        title: '主要风险',
        dataIndex: 'zyfx',
        resizable: true,
    },
    {
        title: '风险管控、修复要求',
        dataIndex: 'gkxflx',
        resizable: true,
    },
    {
        title: '评审情况',
        dataIndex: 'psqk',
        resizable: true,
    },
]
export const TrhjsearchFormSchema: 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: 'hylb',
    //     component: 'TreeSelect',
    //     slot: 'category',
    // },
    // {
    //     label: '政策依据',
    //     field: 'faliyiju',
    //     component: 'JSearchSelect',
    //     componentProps: {
    //         dict: 'dk_zcyj',
    //     },
    // },
    {
        label: '地块名称',
        field: 'wrdkbm',
        component: 'Input',
        componentProps: {
            placeholder: '地块名称或地块编码'
        }
    },
]

// 风险评估需要风险管控修复土壤污染面积统计
export const FxgkColumns: BasicColumn[] = [

    {
        title: '市',
        dataIndex: 'cityName',
        resizable: true,
    },
    {
        title: '0~5000',
        dataIndex: 'five',
        resizable: true,
    },
    {
        title: '5000~10000',
        dataIndex: 'ten',
        resizable: true,
    },
    {
        title: '10000~15000',
        dataIndex: 'fifth',
        resizable: true,
    },
    {
        title: '15000~20000',
        dataIndex: 'twenty',
        resizable: true,
    },
    {
        title: '20000以上',
        dataIndex: 'twentyMore',
        resizable: true,
    },

]
export const FxgksearchFormSchema: FormSchema[] = [
    {
        label: '等级',
        field: 'userIdentity',
        component: 'ApiSelect',
        show: () => {
            return userStore?.userInfo?.userIdentity == '1' ? true : false
        },
        slot: 'userLevle'
    },
    {
        label: '行政区(市)',
        field: 'cityCode',
        component: 'ApiSelect',
        show: ({ values }) => {
            return values.userIdentity == '2' ? true : false
        },
        componentProps: () => {
            return {
                api: getTown,
                params: 440000, // 行政区划编码
                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',
        },
    },

]