import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import Icon from '@/components/Icon/Icon.vue';
import { getPosGroupList, getPositionsTree } from '@/api/demo/system';

export const columns: BasicColumn[] = [
  {
    title: '职级名称',
    dataIndex: 'name',
  },
];

const isDir = (type: string) => type === '0';
const isMenu = (type: string) => type === '1';
const isButton = (type: string) => type === '2';

export const searchFormSchema: FormSchema[] = [
  // {
  //   field: 'key',
  //   label: '关键字',
  //   component: 'Input',
  //   colProps: { span: 8 },
  // },
];

export const formSchema: FormSchema[] = [
  {
    field: 'type',
    label: '类型',
    component: 'RadioButtonGroup',
    defaultValue: '1',
    componentProps: {
      options: [
        // { label: '目录', value: '0' },
        { label: '职级组', value: '1' },
        { label: '职级', value: '2' },
      ],
    },
    colProps: { lg: 24, md: 24 },
  },
  {
    field: 'id',
    label: '名称',
    component: 'Input',
    required: true,
    ifShow:false
  },
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'groupId',
    component: 'ApiSelect',
    label: '职级组',
    required: true,
    componentProps: ({ formActionType, formModel }) => {
      return {
        api: getPosGroupList, // 接口
        // 接口参数
        params: {
          site: formModel.site || '',
          placeId: formModel.placeId || '',
        },
        resultField: 'result',
        labelField: 'name',
        valueField: 'id',
        onChange: (e: any) => {
          formModel.parentId = undefined
          async function getList() {
            const treeData = await getPositionsTree({groupId:e})
            const { updateSchema } = formActionType;
            updateSchema({
              field: 'parentId',
              componentProps: {
                treeData,
              },
            });
          }
          getList()
        }
      };
    },
    ifShow: ({ values }) => isButton(values.type),
  },
  {
    field: 'parentId',
    label: '上级',
    component: 'TreeSelect',
    componentProps: {
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
      getPopupContainer: () => document.body,
    },
    ifShow: ({ values }) => isButton(values.type),
  },
  {
    field: 'remark',
    label: '备注',
    component: 'Input',
    ifShow: ({ values }) => isButton(values.type),
  },
];
