import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { getTown, dict } from '/@/api/common/api'
import { dictName } from '/@/utils/domUtils';

// import { transformArray } from '/@/utils/modifFiled'
// import { ref } from 'vue';
// import { rules } from '/@/utils/helper/validator';
// import { render } from '/@/utils/common/renderUtils';

export const columns: BasicColumn[] = [
  {
    title: '市',
    dataIndex: 'cityName',
    resizable: true,
    key: 'cityName'
  },
  {
    title: '县',
    dataIndex: 'countryName',
    key: 'countryName'
  },
  {
    title: '地块名称',
    dataIndex: 'wrdkmc',
  },
  {
    title: '地块编码',
    dataIndex: 'wrdkbm',
  },
  {
    title: '行业类别',
    dataIndex: 'hylb',
    key: 'hylb'
  },
  {
    title: '政策依据',
    dataIndex: 'faliYiju',
    resizable: true,
    key: 'faliYiju'
  },
  {
    title: '政策依据条款',
    dataIndex: 'faliErji',
    resizable: true,
    key: 'faliErji'
  },

  {
    title: '地块类型',
    dataIndex: 'dklx',
    key: 'dklx',
  },

  {
    title: '所处阶段',
    dataIndex: 'mlbs',
    customRender: ({ record }: any) => {
      return dictName('dk_scqd', record.mlbs)
    },
  },
  {
    title: '登录账号',
    dataIndex: 'userId',
    key: 'userId'
  },
  {
    title: '创建地块时间',
    dataIndex: 'createTsamp',
    key: 'createTsamp'
  },
];

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: 'faliYiju',
    component: 'ApiSelect',
    componentProps: {
      api: dict,
      params: { key: 'dk_zcyj' },
      labelField: 'text',
      valueField: 'value',
    },
  },
  {
    label: '政策依据二级',
    field: 'faliYijuerji',
    component: 'ApiSelect',
    ifShow: ({ values }) => {
      return values?.faliYiju == 1
    },
    componentProps: {
      api: dict,
      params: { key: 'dk_zcyjej' },
      labelField: 'text',
      valueField: 'value'
    },
  },
  {
    label: '地块类型',
    field: 'dklx',
    component: 'ApiSelect',
    componentProps: {
      api: dict,
      params: { key: 'dk_dklx' },
      labelField: 'text',
      valueField: 'value'
    },
  },
  {
    label: '行业分类',
    field: 'isSuspect',
    component: 'ApiSelect',
    slot: 'suspect',
  },
  {
    label: '行业类别',
    field: 'hylb',
    component: 'TreeSelect',
    slot: 'category',
  },
  {
    label: '地块名称或编码',
    field: 'wrdkbm',
    component: 'Input',
  },
  {
    label: '是否超标',
    field: 'pollueted',
    component: 'JSearchSelect',
    componentProps: {
      dict: 'qd_sfcb',
    },
  },
  // {
  //   label: '阶段',
  //   field: 'mlbs',
  //   component: 'ApiSelect',
  //   componentProps: {
  //     api: dict,
  //     params: { key: 'dk_scqd' },
  //     labelField: 'text',
  //     valueField: 'value'
  //   },
  // },

];

export const formSchema: FormSchema[] = [
  // TODO 主键隐藏字段，目前写死为ID
  { label: '', field: 'id', component: 'Input', show: false },
  {
    label: '地块名称',
    field: 'wrdkid',
    component: 'Input',
    required: true,
  },
  {
    label: '行业归属',
    field: 'wrdkbm',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '男', value: 1 },
        { label: '女', value: 2 },
        { label: '未知', value: 3 },
      ],
    },
  },
  {
    label: '行业类别',
    field: 'wrdkmc',
    required: true,
    component: 'TreeSelect',
    componentProps: {
      //是否显示下拉框，默认false
      //标题
      title: '下拉树',
      treeCheckAble: false,
      //下拉树
      treeData: [
        {
          label: '洗衣机',
          value: '0',
          children: [
            {
              label: '滚筒洗衣机',
              value: '0-1',
            },
          ],
        },
        {
          label: '电视机',
          value: '1',
          children: [
            {
              label: '平板电视',
              value: '1-1',
              disabled: true,
            },
            {
              label: 'CRT电视机',
              value: '1-2',
            },
            {
              label: '投影电视',
              value: '1-3',
            },
          ],
        },
      ]
    },
  },
  {
    label: '地块类型',
    field: 'pollueted',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '男', value: 1 },
        { label: '女', value: 2 },
        { label: '未知', value: 3 },
      ],
    },
  },
  {
    label: '政策依据',
    field: 'provinceCode',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '男', value: 1 },
        { label: '女', value: 2 },
        { label: '未知', value: 3 },
      ],
    },
  },
  {
    label: '涉及的专项工作',
    field: 'cityCode',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '男', value: 1 },
        { label: '女', value: 2 },
        { label: '未知', value: 3 },
      ],
    },

  },
  {
    label: '涉及的重点区域',
    field: 'countryCode',
    component: 'Select',
    required: true,
    componentProps: {
      options: [
        { label: '男', value: 1 },
        { label: '女', value: 2 },
        { label: '未知', value: 3 },
      ],
    },
  },
  {
    label: '备注',
    field: 'type',
    component: 'InputTextArea',
    required: true,
  },
];

