import { BasicColumn, FormSchema } from '@/components/Table';
import { getChildrenTree } from '@/api/demo/system';
import { getLoad } from '@/api/sys/sysDataItemDetail';
import { asyncGetOptions } from '@/utils/global'
import dayjs from 'dayjs';
import { getAppEnvConfig } from '@/utils/env';

const {  VITE_GLOB_GEOSERVER_PREFECTURE_CITY } = getAppEnvConfig();

export const typenameOptions = await asyncGetOptions('rcxjxslx');
export const tubanlaiyuanOptions = await asyncGetOptions('rcxjxsly');

export const columns: BasicColumn[] = [
  {
    title: '线索来源',
    dataIndex: 'tubanlaiyuan',
  },
  {
    title: '线索编号',
    dataIndex: 'case_no',
    width: 240
  },
  {
    title: '县区',
    dataIndex: 'countyname',
    width: 100
  },
  {
    title: '乡镇',
    dataIndex: 'streetname',
    width: 100
  },
  {
    title: '社区/村',
    dataIndex: 'communityname',
  },
  {
    title: '线索类型',
    dataIndex: 'typename',
  },
  {
    title: '线索描述',
    dataIndex: 'case_description',
  },
  {
    title: '线索状态',
    dataIndex: 'biaozhu',
  },

  {
    title: '上报时间',
    dataIndex: 'createtime',
  },
  {
    title: '经度',
    dataIndex: 'lng',
  },
  {
    title: '纬度',
    dataIndex: 'lat',
  },

];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'typename',
    component: 'ApiSelect',
    colProps: { span: 5 },
    label: '线索类型',
    componentProps: ({ formModel }) => {
      return {
        api: getLoad,
        params: { code: 'rcxjxslx' },
        resultField: 'result',
        labelField: 'itemName',
        valueField: 'itemValue',
      };
    },
  },
  {
    field: 'tubanlaiyuan',
    component: 'ApiSelect',
    colProps: { span: 5 },
    label: '线索来源',
    componentProps: ({ formModel }) => {
      return {
        api: getLoad,
        params: { code: 'rcxjxsly' },
        resultField: 'result',
        labelField: 'itemName',
        valueField: 'itemValue',
      };
    },
  },
  
  {
    field: 'countyid',
    label: '区县',
    component: 'ApiSelect',
    colProps: { span: 5 },
    componentProps: ({ formModel }) => {
      return {
        api: getChildrenTree,
        params: { parentId: VITE_GLOB_GEOSERVER_PREFECTURE_CITY },
        // 接口参数
        resultField: 'result',
        labelField: 'name',
        valueField: 'id',
        onChange: () => {
          formModel.streetid = '';
        },
      };
    },
  },
  {
    field: 'streetid',
    label: '乡镇',
    component: 'ApiSelect',
    colProps: { span: 5 },
    componentProps: ({ formModel }) => {
      return {
        api: formModel.countyid && getChildrenTree,
        params: { parentId: formModel.countyid },
        // 接口参数
        resultField: 'result',
        labelField: 'name',
        valueField: 'id',
        placeholder: '请先选择区县',
      };
    },
  },
  {
    field: 'biaozhu',
    label: '线索状态',
    component: 'Select',
    colProps: { span: 4 },
    componentProps: {
      options: [
        { label: '未确认', value: 0},
        { label: '已确认', value: 1},
      ],
    },
  },
  {
    field: '[synchronoustimebegin, synchronoustimeend]',
    label: '上报时间',
    component: 'RangePicker',
    colProps: { span: 5 },
    componentProps: {
      format: 'YYYY-MM-DD',
      placeholder: ['开始日期', '结束日期'],
    },
  },
  {
    field: 'case_no',
    label: '线索编号',
    component: 'Input',
    colProps: { span: 5 },
  },
];
