import { BasicColumn, FormSchema } from '@/components/Table';
import { getChildrenTree } from '@/api/demo/system';
import { getLoad } from '@/api/sys/sysDataItemDetail';
import {
  patchSourceOptions,
  yearOptions,
  markTypeOptions,
  mapTypeOptions,
} from '@/utils/global';
import { asyncGetOptions } from '@/utils/global'

export const nowStatusOptions = await asyncGetOptions('gdflhdqzt');

export const columns: BasicColumn[] = [
  {
    title: '图斑来源',
    dataIndex: 'tubanlaiyuan',
  },
  {
    title: '区县',
    dataIndex: 'countyname',
    width: 100,
  },
  {
    title: '乡镇',
    dataIndex: 'streetname',
  },
  {
    title: '社区/村',
    dataIndex: 'communityname',
  },
  {
    title: '图斑编号',
    dataIndex: 'caseno',
    width: 200,
  },
  {
    title: '图斑类型',
    dataIndex: 'typename',
  },
  {
    title: '图斑面积',
    dataIndex: 'area',
    width: 110,
  },
  {
    title: '农用地面积',
    dataIndex: 'nongyongdiarea',
    width: 110,
  },
  {
    title: '耕地面积',
    dataIndex: 'gengdiarea',
    width: 110,
  },
  {
    title: '永农面积',
    dataIndex: 'yongjiujibennongtianarea',
    width: 110,
  },
  {
    title: '当前状态',
    dataIndex: 'handlestatusname',
    width: 80,
  },
  {
    title: '下发时间',
    dataIndex: 'identificationtime',
  },
  {
    title: '发生时间',
    dataIndex: 'fashengshijian',
  },
  {
    title: '填报类型',
    dataIndex: 'tianbaoleixingname',
  },
  {
    title: '现场情况',
    dataIndex: 'pandingyijushuoming',
  },
  {
    title: '整改措施',
    dataIndex: 'measurename',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'year',
    component: 'Select',
    colProps: { span: 4 },
    label: '年份',
    componentProps: {
      options: yearOptions,
    },
  },
  {
    field: 'tubanlaiyuan',
    label: '图斑来源',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: ({ formModel }) => {
      return {
        api: getLoad,
        params: { code: 'gdflhbly' },
        // 接口参数
        resultField: 'result',
        labelField: 'itemName',
        valueField: 'itemValue',
        mode: 'multiple',
        maxTagCount: 1
      };
    },
  },
  {
    field: 'typename',
    label: '图斑类型',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: ({ formModel }) => {
      return {
        api: getLoad,
        params: { code: 'gdflhblx' },
        // 接口参数
        resultField: 'result',
        labelField: 'itemName',
        valueField: 'itemValue',
      };
    },
  },
  {
    field: 'tianbaoleixing',
    label: '填报类型',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: ({ formModel }) => {
      return {
        api: getLoad,
        params: { code: 'gdflhtianbaolx' },
        // 接口参数
        resultField: 'result',
        labelField: 'itemName',
        valueField: 'itemValue',
      };
    },
  },
  {
    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: formModel.countyid && getChildrenTree,
        params: { parentId: formModel.countyid },
        // 接口参数
        resultField: 'result',
        labelField: 'name',
        valueField: 'id',
      };
    },
  },

  {
    field: 'nowStatus',
    label: '当前状态',
    // component: 'ApiSelect',
    // componentProps: ({ formModel }) => {
    //   return {
    //     api: getLoad,
    //     params: { code: 'gdflhdqzt' },
    //     // 接口参数
    //     resultField: 'result',
    //     labelField: 'itemName',
    //     valueField: 'itemValue',
    //   };
    // },
    colProps: { span: 4 },
    slot: 'dangqianzhuangtai',
  },
  {
    field: 'measureName',
    label: '整改措施',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: ({ formModel }) => {
      return {
        api: getLoad,
        params: { code: 'gdflhzgcs' },
        // 接口参数
        resultField: 'result',
        labelField: 'itemName',
        valueField: 'itemValue',
      };
    },
  },

  // 增加图斑面积、耕地面积、永农面积的筛选项；
  {
    field: 'tubanmianji',
    label: '图斑面积',
    colProps: { span: 4 },
    slot: 'tubanmianji',
  },
  {
    field: 'gengdimianji',
    label: '耕地面积',
    colProps: { span: 4 },
    slot: 'gengdimianji',
  },
  {
    field: 'jibennongtianmianji',
    label: '永农面积',
    colProps: { span: 4 },
    slot: 'jibennongtianmianji',
  },
  {
    field: '[startTime, endTime]',
    label: '下发时间',
    component: 'RangePicker',
    colProps: { span: 5 },
    componentProps: {
      format: 'YYYY-MM-DD',
      placeholder: ['开始日期', '结束日期'],
    },
  },
  {
    field: 'caseNo',
    label: '图斑编号',
    component: 'Input',
    colProps: { span: 5 },
  },
];
