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

const userStore: any = useUserStore();

export const columns: BasicColumn[] = [
  {
    title: '市',
    dataIndex: 'cityName',
    resizable: true,
  },
  {
    title: '行政区名称',
    dataIndex: 'xzqmc',
    resizable: true,
  },
  {
    title: '地块名称',
    dataIndex: 'dkmc',
    resizable: true,
  },
  {
    title: '地块编码',
    dataIndex: 'dkdm',
    resizable: true,
  },
  {
    title: '要素代码',
    dataIndex: 'ysdm',
    resizable: true,
  },
  {
    title: '地块面积',
    dataIndex: 'ydmj',
    resizable: true,
  },
  {
    title: '更新时间',
    dataIndex: 'dksjzxgxsj',
    resizable: true,
    customRender: ({ text }) =>{
      if (text) {
        return text.substring(0,4)+'-'+text.substring(4,6)+'-'+text.substring(6,8)
      } else {
        return ''
      }
    }
  },
  {
    title: '备注',
    dataIndex: 'bz',
    resizable: true,
  },
];

// T1：填报中 DSL：待受理 T2：待评审 SH：评审通过 SHBTG：评审不通过 SHHDWS：评审后待完善 BPS：不评审 DKDTC：地块待退出 DKYTC：地块已退出
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.xzqdm = undefined;
            if (val) {
              updateSchema({
                field: 'xzqdm',
                componentProps: {
                  api: getTown,
                  params: val,
                  labelField: 'name',
                  valueField: 'id',
                },
              });
            } else {
              updateSchema({
                field: 'xzqdm',
                componentProps: {
                  api: undefined,
                  labelField: 'name',
                  valueField: 'id',
                },
              });
            }
          },
        };
      },
    },
    {
      label: '区县',
      field: 'xzqdm',
      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: 'xzqdm',
            ifShow: true,
            componentProps: {
              api: getTown,
              params: userStore?.userInfo?.codeRegion,
              labelField: 'name',
              valueField: 'id',
            },
          });
        }
        return {
          labelField: 'name',
          valueField: 'id',
        }
      },
    },
  {
    label: '地块名称或编码',
    field: 'dkdm',
    component: 'Input',
  },
];

export const formSchema: FormSchema[] = [

]