import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import { getChildrenTree } from '@/api/demo/system';
import { getLoad } from '@/api/sys/sysDataItemDetail';
export const columns: BasicColumn[] = [
  {
    title: '原始图斑编号',
    dataIndex: 'original_case_no',
    width: 200,
  },
  {
    title: '图斑编号',
    dataIndex: 'case_no',
    width: 200,
  },
  {
    title: '图斑描述',
    dataIndex: 'case_description',
    width: 300,
  },
  {
    title: '图斑类型',
    dataIndex: 'typename',
  },
  {
    title: '县',
    dataIndex: 'countyname',
  },
  {
    title: '镇',
    dataIndex: 'streetname',
  },
  {
    title: '判读人',
    dataIndex: 'identification_user',
  },
  {
    title: '判读时间',
    dataIndex: 'createtime',
  },
  {
    title: '状态',
    dataIndex: 'checkstatus',
    customRender: ({ record }) => {
      const { checkstatus } = record;
      if(checkstatus == '待审核'){
        return h(Tag, { color: 'yellow' }, () => checkstatus);
      }else if(checkstatus == '已审核'){
        return h(Tag, { color: 'green' }, () => checkstatus);
      }
      return h(Tag, {}, () => checkstatus);
    }
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'originalCaseNo',
    label: '原始图斑编号',
    component: 'Input',
    colProps: { span: 5 },
    componentProps: {
      placeholder: '请输入原始编号',
    },
  },
  {
    field: 'caseNo',
    label: '图斑编号',
    component: 'Input',
    colProps: { span: 5 },
    componentProps: {
      placeholder: '请输入图斑编号',
    },
  },
  {
    field: 'typename',
    label:'图斑类型',
    component: 'ApiSelect',
    colProps: { span: 4 },
    componentProps: ({formModel}) => {
      return {
        api: getLoad,
        params: { code: 'kctubanleixing' },
        // 接口参数
        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',
      };
    },
  }
];