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

export const columns: BasicColumn[] = [
  {
    title: '编码',
    dataIndex: 'codeName',
    width: 120,
  },
  {
    title: '名称',
    dataIndex: 'name',
    width: 100,
  },
  {
    title: '授权类型',
    dataIndex: 'objectType',
    width: 100,
    customRender: ({ record }) => {
      let color = '';
      let text = '';
      const formType = record.objectType;
      if (formType == 2 || formType == '2') {
        color = 'green';
        text = '角色';
      }
      if (formType == 1 || formType == '1') {
        color = 'yellow';
        text = '用户';
      }
      if (formType == 3 || formType == '3') {
        color = 'orange';
        text = '所有用户';
      }
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '授权对象',
    dataIndex: 'objectName',
    width: 100,
  },
  {
    title: '类型',
    dataIndex: 'type',
    width: 100,
    customRender: ({ record }) => {
      let color = '';
      let text = '';
      const formType = record.type;
      if (formType == 2 || formType == '2') {
        color = 'green';
        text = '自定义表单';
      }
      if (formType == 1 || formType == '1') {
        color = 'yellow';
        text = '普通';
      }
      return h(Tag, { color: color }, () => text);
    },
  },
  {
    title: '创建人',
    dataIndex: 'createUserName',
    width: 100,
  },
  {
    title: '创建时间',
    dataIndex: 'createDate',
    width: 120,
  },
];

const colProps = {
  span: 24,
};

export const searchFormSchema: FormSchema[] = [
  {
    field: 'key',
    label: '关键字',
    component: 'Input',
    colProps: { span: 8 },
    componentProps: {
      placeholder: '请输入名称/编号',
    },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'itemDetailId',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'itemId',
    label: '项目ID',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'parentId',
    label: '上级',
    component: 'TreeSelect',
    componentProps: {
      fieldNames: {
        label: 'itemName',
        key: 'itemId',
        value: 'itemValue',
      },
      getPopupContainer: () => document.body,
    },
    colProps,
  },
  {
    field: 'itemCode',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'itemName',
    label: '项目名',
    component: 'Input',
    required: true,
    colProps,
  },
  {
    field: 'itemValue',
    label: '项目值',
    component: 'Input',
    required: true,
    colProps,
  },
  {
    field: 'quickQuery',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'simpleSpelling',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'isDefault',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'sortCode',
    label: '排序',
    component: 'InputNumber',
    required: true,
    colProps,
  },
  {
    field: 'deleteMark',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'enabledMark',
    label: '状态',
    component: 'Switch',
    colProps,
    ifShow: false,
    render: (scope) => {
      return h('Switch', {
        props: {
          value: scope.model?.enabledMark === 1,
        },
      });
    },
  },
  {
    field: 'description',
    label: '备注',
    component: 'InputTextArea',
    colProps,
  },
  {
    field: 'createDate',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'createUserId',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'createUserName',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'modifyDate',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'modifyUserId',
    component: 'Input',
    ifShow: false,
  },
  {
    field: 'modifyUserName',
    component: 'Input',
    ifShow: false,
  },
];
