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

const userStore: any = useUserStore();

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

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

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

export const searchFormSchema: FormSchema[] = [
  {
    label: '行政区(市)',
    field: 'cityCode',
    component: 'ApiSelect',
    ifShow: () => {
      return userStore?.userInfo?.userIdentity == '1' ? true : false
    },
    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,
                labelField: 'name',
                valueField: 'id',
              },
            });
          } else {
            updateSchema({
              field: 'countryCode',
              componentProps: {
                api: undefined,
                labelField: 'name',
                valueField: 'id',
              },
            });
          }
        },
      };
    },
  },
  {
    label: '区县',
    field: 'countryCode',
    component: 'ApiSelect',
    ifShow: () => {
      return (userStore?.userInfo?.userIdentity == '2' || userStore?.userInfo?.userIdentity == '1') ? true : false
    },
    componentProps: ({ formModel, formActionType }) => {
      if (userStore?.userInfo?.userIdentity == '2') {
        const { updateSchema } = formActionType;
        updateSchema({
          label: '区县',
          field: 'countryCode',
          ifShow: true,
          componentProps: {
            api: getTown,
            params: userStore?.userInfo?.codeRegion,
            labelField: 'name',
            valueField: 'id',
          },
        });
      }
      return {
        labelField: 'name',
        valueField: 'id',
      }
    },
  },
  {
    label: '政策依据',
    field: 'faliYiju',
    component: 'ApiSelect',
    componentProps: {
      api: dict,
      params: { key: 'dk_zcyj' },
      labelField: 'text',
      valueField: 'value',
    },
  },
  // {
  //   label: '政策依据二级',
  //   field: 'faliErji',
  //   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,
  },
];

