import { BasicColumn, FormSchema } from '/@/components/Table';
import { getTown, dict, categoryList } from '/@/api/common/api'
import { useUserStore } from '/@/store/modules/user';

const userStore: any = useUserStore();

export const columns: BasicColumn[] = [
    {
        title: '开发利用信息（自然资源部门提供）',
        dataIndex: 'bz',
        resizable: true,
        width: 150,
        children: [
            // {
            //     title: '省',
            //     dataIndex: 'provinceName',
            //     resizable: true,
            //     width: 50,
            // },
            {
                title: '市',
                dataIndex: 'cityName',
                resizable: true,
                width: 100,
            },
            {
                title: '区',
                dataIndex: 'countryName',
                resizable: true,
                width: 150,
            },
            {
                title: '项目名称',
                dataIndex: 'xmmc',
                resizable: true,
                width: 200,
            },
            // {
            //     title: '年度',
            //     dataIndex: 'nd',
            //     resizable: true,
            //     width: 120,
            // },
            {
                title: '国有建设用地划拨决定书或国有建设用地使用权出让合同编号',
                dataIndex: 'htbm',
                resizable: true,
                width: 220,
            },
            {
                title: '供地日期',
                dataIndex: 'gdrq',
                resizable: true,
                width: 120,
            },
            {
                title: '用地位置',
                dataIndex: 'ydwz',
                resizable: true,
                width: 200,
            },
            {
                title: '地块原用途（一级类）',
                dataIndex: 'dkyytYl',
                width: 200,
                resizable: true,
            },
            {
                title: '地块原用途（二级类）',
                dataIndex: 'dkyytEl',
                width: 200,
                resizable: true,
            },
            {
                title: '现土地用途（一级类）',
                dataIndex: 'xtdytYl',
                width: 200,
                resizable: true,
            },
            {
                title: '现土地用途（二级类）',
                dataIndex: 'xtdytEl',
                width: 200,
                resizable: true,
            },
        ],
    },
    {
        title: '基础信息（生态环境部门提供）',
        resizable: true,
        width: 150,
        children: [
            {
                title: '地块名称',
                dataIndex: 'dkmc',
                resizable: true,
                width: 251,
            },
            {
                title: '地块编码',
                dataIndex: 'dkbm',
                resizable: true,
                width: 150,
            },
        ]
    },
    {
        title: '管控修复信息（生态环境部门提供）',
        resizable: true,
        width: 150,
        children: [
            {
                title: '是否落实土壤污染状况调查及报告评审制度',
                dataIndex: 'sflstrwrztdcjbgpszd',
                resizable: true,
                width: 120,
                customRender: ({ record }) => {
                    return (record.sflstrwrztdcjbgpszd || record.sflstrwrztdcjbgpszd === 0) ? (record.sflstrwrztdcjbgpszd == 1 ? '是' : '否') : '';
                },
            },
            {
                title: '是否落实土壤污染风险评估及报告评审制度',
                dataIndex: 'sflstrwrfxpgjbgpszd',
                resizable: true,
                width: 120,
                customRender: ({ record }) => {
                    return (record.sflstrwrfxpgjbgpszd || record.sflstrwrfxpgjbgpszd === 0) ? (record.sflstrwrfxpgjbgpszd == 1 ? '是' : '否') : '';
                },
            },
            {
                title: '是否落实土壤污染风险管控和修复及报告评审制度',
                dataIndex: 'sflstrwrfxgkhxfjbgpszd',
                resizable: true,
                width: 140,
                customRender: ({ record }) => {
                    return (record.sflstrwrfxgkhxfjbgpszd || record.sflstrwrfxgkhxfjbgpszd === 0) ? (record.sflstrwrfxgkhxfjbgpszd == 1 ? '是' : '否') : '';
                },
            },
            {
                title: '是否明确土壤污染风险管控和修复责任主体（前一列为“否”填写，为“是”无需填）',
                dataIndex: 'sfmqtrwrfxgkhxfzrzt',
                resizable: true,
                width: 200,
                customRender: ({ record }) => {
                    return (record.sfmqtrwrfxgkhxfzrzt || record.sfmqtrwrfxgkhxfzrzt === 0) ? (record.sfmqtrwrfxgkhxfzrzt == 1 ? '是' : '否') : '';
                },
            },
            {
                title: '是否落实建设用地土壤污染风险管控和修复名录制度',
                dataIndex: 'sflsjsydtrwrfxgkhxfmlzd',
                resizable: true,
                width: 140,
                customRender: ({ record }) => {
                    return (record.sflsjsydtrwrfxgkhxfmlzd || record.sflsjsydtrwrfxgkhxfmlzd === 0) ? (record.sflsjsydtrwrfxgkhxfmlzd == 1 ? '是' : '否') : '';
                },
            },
            {
                title: '是否落实信息上报制度',
                dataIndex: 'sflsxxsbzd',
                resizable: true,
                width: 120,
                customRender: ({ record }) => {
                    return (record.sflsxxsbzd || record.sflsxxsbzd === 0) ? (record.sflsxxsbzd == 1 ? '是' : '否') : '';
                },
            },
            {
                title: '结论:是否依法落实土壤污染风险管控和修复措施',
                dataIndex: 'sfyflstrwrfxgkhxfcs',
                resizable: true,
                width: 180,
                customRender: ({ record }) => {
                    return (record.sfyflstrwrfxgkhxfcs || record.sfyflstrwrfxgkhxfcs === 0) ? (record.sfyflstrwrfxgkhxfcs == 1 ? '是' : '否') : '';
                },
            },

        ]
    },
    {
        title: '处罚和整改信息',
        resizable: true,
        width: 150,
        children: [
            {
                title: '是否存在违规开发利用情况',
                dataIndex: 'sfczwgkflyqk',
                resizable: true,
                width: 200,
                customRender: ({ record }) => {
                    return (record.sfczwgkflyqk || record.sfczwgkflyqk === 0) ? (record.sfczwgkflyqk == 1 ? '是' : '否') : '';
                },
            },
            {
                title: '处罚或整改措施',
                dataIndex: 'cfhzgcs',
                resizable: true,
                width: 200,
                customRender: ({ record }) => {
                    return (record.cfhzgcs || record.cfhzgcs === 0) ? (record.cfhzgcs == 1 ? '整改' : '处罚') : '';
                },
            },
            {
                title: '中央、部领导批示',
                dataIndex: 'zybldps',
                resizable: true,
                width: 200,

            },
            {
                title: '中央、地方环保督察',
                dataIndex: 'zydfhbdc',
                resizable: true,
                width: 200,
            },
            {
                title: '舆情报道',
                dataIndex: 'yqbd',
                resizable: true,
                width: 200,
            },
        ]
    },
    {
        title: '备注',
        dataIndex: 'bz',
        width: 150,
        resizable: true,
    },
];

export const searchFormSchema: FormSchema[] = [
    {
        label: '市',
        field: 'cityCode',
        component: 'ApiSelect',
        ifShow: () => {
            return userStore?.userInfo?.userIdentity == '1' ? true : false
        },
        // slot: 'form-city',
        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,
                            },
                        });
                    }
                },
            };
        },
    },
    {
        label: '区县',
        field: 'countryCode',
        ifShow: () => {
            return (userStore?.userInfo?.userIdentity == '2' || userStore?.userInfo?.userIdentity == '1') ? true : false
        },
        component: 'ApiSelect',
        componentProps: ({ formModel, formActionType }) => {
            console.log(formModel, 'formModel');
            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: 'xmmc',
        component: 'Input',

    },
    {
        label: '合同编号',
        field: 'htbm',
        component: 'Input',

    },
    {
        label: '供地日期',
        field: 'gdrq',

        component: 'DatePicker',
        componentProps: {
            //日期格式化，页面上显示的值
            format: 'YYYY-MM-DD',
            //返回值格式化（绑定值的格式）
            valueFormat: 'YYYY-MM-DD',
        },
    },
    {
        label: '地块名称',
        field: 'wrdkmc',
        component: 'Input',

    },
    {
        label: '地块名称',
        field: 'wrdkbm',
        component: 'Input',

    },
    {
        label: '是否依法落实土壤污染风险管控和修复措施',
        field: 'sfyflstrwrfxgkhxfcs',
        component: 'Select',

        componentProps: {
            options: [
                { label: '否', value: 0 },
                { label: '是', value: 1 },
            ],
        },
    },
];
export const searchFormSchemalyl: FormSchema[] = [
    {
        label: '年度',
        field: 'nd',
        component: 'DatePicker',
        componentProps: {
            //日期格式化，页面上显示的值
            format: 'YYYY',
            //返回值格式化（绑定值的格式）
            valueFormat: 'YYYY',
            picker: 'year'
        },
    },
    
];
export const formSchema: FormSchema[] = [
    // TODO 主键隐藏字段，目前写死为ID
    { label: '', field: 'id', component: 'Input', show: false },
    { label: '', field: 'showFooter', component: 'Input', show: false }, //用来查看的时候禁用的
    {
        label: '备注',
        field: 'bz',
        component: 'InputTextArea',
        dynamicDisabled: ({ values }) => {
            return !values.showFooter;
        },
        colProps: { span: 24 },
        componentProps: {
            maxlength: 5000,
            minRows: 6, maxRows: 20
        }
    },
];
