import { BasicColumn, FormSchema } from '/@/components/Table';
import { getTown, getHylb, dict } from '/@/api/common/api';
import { convertTreeData } from '/@/utils/modifFiled';
import { ref } from 'vue';

export const useSuspectsData = () => {
  const suspects = ref([]);
  // 获取行业分类
  const getIsSuspect = async () => {
    suspects.value = await dict({ key: 'dk_hyfl' });
  };
  getIsSuspect();
  return { data: suspects };
};

export const useCategoryData = () => {
  let allCategory = [];
  const treeData = ref([]);
  // 获取行业类别
  const getData = async () => {
    allCategory = await getHylb({});
    allCategory = convertTreeData(allCategory); // 只显示前2级
    allCategory.forEach((item) => {
      item.disabled = true; // 第1层级不能选中
    });
    treeData.value = allCategory;
  };
  getData();
  // 改变行业分类
  function changeIsSuspect(v) {
    if (v == 1) {
      // 只显示42号类
      treeData.value = allCategory.filter((item) => item['is42']);
    } else {
      treeData.value = allCategory;
    }
  }
  return { data: treeData, changeIsSuspect };
};

export const columns: BasicColumn[] = [
  {
    title: '地块名称',
    dataIndex: 'wrdkmc',
  },
  {
    title: '地块编码',
    dataIndex: 'wrdkbm',
  },
  {
    title: '监督管理标题',
    dataIndex: 'jdglbt',
  },
  {
    title: '市',
    dataIndex: 'cityName',
  },
  {
    title: '县',
    dataIndex: 'countryName',
  },
  {
    title: '行业类别',
    dataIndex: 'hylb',
  },
  {
    title: '最新监督管理日期',
    dataIndex: 'jdglsj',
  },
  {
    title: '监督管理状态',
    dataIndex: 'jdglzt',
  },
];

// T1：填报中 DSL：待受理 T2：待评审 SH：评审通过 SHBTG：评审不通过 SHHDWS：评审后待完善 BPS：不评审 DKDTC：地块待退出 DKYTC：地块已退出
export const searchFormSchema: FormSchema[] = [
  {
    label: '行政区(市)',
    field: 'cityCode',
    component: 'ApiSelect',
    componentProps: ({ formModel, formActionType }) => {
      return {
        api: getTown,
        params: 440000, // 行政区划编码
        labelField: 'name',
        valueField: 'id',
        onChange: (val: any) => {
          const { updateSchema } = formActionType;
          formModel.countryCode = undefined;
          if (val) {
            updateSchema({
              field: 'countryCode',
              componentProps: {
                api: getTown,
                params: val,
              },
            });
          } else {
            updateSchema({
              field: 'countryCode',
              componentProps: {
                api: undefined,
              },
            });
          }
        },
      };
    },
  },
  {
    label: '区县',
    field: 'countryCode',
    component: 'ApiSelect',
    componentProps: {
      labelField: 'name',
      valueField: 'id',
    },
  },
  {
    label: '行业分类',
    field: 'isSuspect',
    component: 'ApiSelect',
    slot: 'suspect',
  },
  {
    label: '行业类别',
    field: 'hylb',
    component: 'TreeSelect',
    slot: 'category',
  },
  {
    label: '地块类型',
    field: 'dklx',
    component: 'JSearchSelect',
    componentProps: {
      dict: 'dk_dklx',
    },
  },
  {
    label: '地块名称或者编码',
    field: 'wrdkbm',
    component: 'Input',
  },
  {
    label: '监督管理状态',
    field: 'jdglstatus',
    component: 'Select',
    componentProps: {
      options: [
        { value: '1', label: '已监督管理' },
        { value: '0', label: '未监督管理' },
      ],
    },
  }
];

// 方案列表
export const lookDatacolumns: BasicColumn[] = [
  {
    title: '监督管理标题',
    dataIndex: 'jdglbt',
  },
  {
    title: '监督管理单位',
    dataIndex: 'jdgldw',
  },
  {
    title: '督查情况',
    dataIndex: 'bz',
  },
  {
    title: '监督管理时间	',
    dataIndex: 'jdglsj',
  },
  {
    title: '上报人',
    dataIndex: 'createName',
  },
  {
    title: '上报时间	',
    dataIndex: 'createTsamp',
  },
];