import { BasicColumn, FormSchema } from '@/components/Table';
import { getChildrenTree } from '@/api/demo/system';
import {
  resultNameOptions,
  patchSourceOptions,
  nowStatusOptions,
  markTypeOptions,
} from '@/utils/global';

const getYearList = () => {
  const num = 10;
  const currentYear = new Date().getFullYear();
  // 存储年份数据的数组
  const list: any = [];
  // 获取当前年份
  // year.value = Number(`${currentYear}`);
  list.push({
    value: Number(`${currentYear}`),
    label: Number(`${currentYear}`),
  });
  // 获取后面几年的数据
  for (let i = 1; i <= num; i++) {
    list.push({
      value: Number(`${currentYear - i}`),
      label: Number(`${currentYear - i}`),
    });
  }
  return list;
};
export const columns: BasicColumn[] = [
  {
    title: '区县',
    dataIndex: 'countyname',
  },
  {
    title: '乡镇',
    dataIndex: 'streetname',
  },
  {
    title: '图斑编号',
    dataIndex: 'caseno',
    width: 200,
  },
  {
    title: '下发时间',
    dataIndex: 'identificationtime',
  },
  {
    title: '图斑面积',
    dataIndex: 'area',
  },
  {
    title: '耕地面积',
    dataIndex: 'gengdiarea',
  },
  {
    title: '判定结果',
    dataIndex: 'isillegal',
  },
  {
    title: '当前状态',
    dataIndex: 'handlestatusname',
  },
  {
    title: '项目名称',
    dataIndex: 'xiangmumc',
  },
  {
    title: '项目主体',
    dataIndex: 'xiangmuzhuti',
  },
  {
    title: '违法类型',
    dataIndex: 'weifaleixing',
  },
  {
    title: '整改措施',
    dataIndex: 'measurename',
  },
  {
    title: '处理方式',
    dataIndex: 'resultname',
    editRow: true,
    editComponent: 'Select',
    editComponentProps: {
      options: resultNameOptions,
    },
    fixed: 'right',
  },
  {
    title: '立案号',
    dataIndex: 'registrnumber',
    editRow: true,
    editComponent: 'Input',
    fixed: 'right',
  },
  {
    title: '违法联系人',
    dataIndex: 'illegalcontact',
    editRow: true,
    editComponent: 'Input',
    fixed: 'right',
  },
  {
    title: '违法人身份证号',
    dataIndex: 'illegalshenfenzhenghao',
    editRow: true,
    editComponent: 'Input',
    fixed: 'right',
    width: 160,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'year',
    component: 'Select',
    colProps: { span: 4 },
    label: '年份',
    componentProps: {
      options: getYearList(),
    },
  },
  {
    field: 'tubanlaiyuan',
    label: '图斑来源',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: patchSourceOptions,
    },
  },
  {
    field: 'picihao',
    label: '批次',
    component: 'Input',
    colProps: { span: 4 },
  },
  {
    field: 'isBuildName',
    label: '标注类型',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: markTypeOptions,
    },
  },
  {
    field: 'nowStatus',
    label: '当前状态',
    component: 'Select',
    componentProps: {
      options: nowStatusOptions,
    },
    colProps: { span: 4 },
  },
  {
    field: 'countyid',
    label: '区县',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: ({ tableAction, formModel }) => {
      return {
        api: getChildrenTree,
        params: { parentId: 371300 },
        // 接口参数
        resultField: 'result',
        labelField: 'name',
        valueField: 'id',
        onChange: () => {
          formModel.streetid = '';
        },
      };
    },
  },
  {
    field: 'streetid',
    label: '乡镇',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: ({ formModel }) => {
      return {
        api: getChildrenTree,
        params: { parentId: formModel.countyid },
        // 接口参数
        resultField: 'result',
        labelField: 'name',
        valueField: 'id',
      };
    },
  },
  {
    field: 'caseNo',
    label: '图斑编号',
    component: 'Input',
    colProps: { span: 4 },
  },
];
