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 typenameKey = {
  '违法用地': 'wfydtblx',
  '非法采矿': 'kctubanleixing',
  '卫片下发': 'kctubanleixing',
  '耕地非粮化': 'gdflhtblx',
  '重点问题Ⅰ类': 'zd1tblx',
  '重点问题Ⅱ类': 'zd2tblx',
  '巡察审计': 'xcsjtblx',
  '生态保护红线监管': 'stbhhxjgtblx',
  '生态修复': 'stxftblx',
}
export const SubjectKeyObj = {
  '巡察审计': 'Subject_XCSJ', //巡查审计
  '违法用地': 'Subject_WFYD', // 违法用地
  '非法采矿': 'Subject_FFCK', //非法采矿
  '卫片下发': 'Subject_WPCK', //非法采矿(卫片)
  '耕地非粮化': 'Subject_GDFLH', //耕地非粮化
  '重点问题Ⅰ类': 'Subject_ZDWT1', //重点问题Ⅰ类
  '重点问题Ⅱ类': 'Subject_ZDWT2', //重点问题Ⅱ类
  '生态保护红线监管': 'Subject_STHX',  //生态保护红线监管
  '生态修复': 'Subject_STXF',  //生态修复
}
export const codeObj = {
  '违法用地': '0000001',
  '巡察审计': '0000002',
  '非法采矿': '100001',
  '卫片下发': '0000003',
  '耕地非粮化': '0000004',
  '重点问题Ⅰ类': '0000005',
  '重点问题Ⅱ类': '0000006',
  '生态保护红线监管': '0000007',
  '生态修复': '0000008',
}
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 searchFormSchemaFunction:(type:string, audit:boolean) => FormSchema[] = (type, audit=false) => {
  return [
    {
      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: typenameKey[type] },
          // 接口参数
          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',
        };
      },
    },
    audit && {
      field: 'nowStatus',
      label: '状态',
      component: 'Select',
      colProps: { span: 4 },
      componentProps: {
        options: [
          { label: '待审核', value: '待审核'},
          { label: '复提', value: '复提'},
        ],
      },
      defaultValue: '待审核',
    },
  ];
}