import { h } from 'vue';
import { Tag, Avatar } from 'ant-design-vue';

export const columns = [
  {
    title: 'ID',
    dataIndex: 'id',
    fixed: 'left',
    width: 50,
  },
  {
    title: '登录账号',
    dataIndex: 'username',
    key: 'username',
    width: 100,
  },
  {
    title: '用户姓名',
    dataIndex: 'realname',
    key: 'realname',
    width: 100,
  },
  {
    title: '头像',
    dataIndex: 'avatar',
    key: 'avatar',
    width: 80,
    customRender({ record }) {
      return h(Avatar, {
        size: 48,
        src: record.avatar,
        shape: 'square',
        fit: 'fill',
      });
    },
  },
  {
    title: '性别',
    dataIndex: 'gender',
    key: 'gender',
    width: 80,
    customRender({ record }) {
      let typeText = '';
      let color = '';
      switch (record.gender) {
        case 1:
          typeText = '男';
          color = 'processing';
          break;
        case 2:
          typeText = '女';
          color = 'error';
          break;
        case 3:
          typeText = '保密';
          color = 'warning';
          break;
        default:
          break;
      }
      return h(
        Tag,
        {
          color: color,
        },
        {
          default: () => typeText,
        },
      );
    },
  },
  {
    title: '手机号',
    dataIndex: 'mobile',
    key: 'mobile',
    width: 120,
  },
  {
    title: '用户角色',
    dataIndex: 'role',
    key: 'role',
    width: 250,
    customRender({ record }) {
      let roleNames = '';
      if (record.roles.length > 0) {
        roleNames = record.roles.map((role) => role.name).join(',');
      }
      // return h('span', roleNames || '-');
      return h(
        Tag,
        {
          color: 'processing',
        },
        {
          default: () => roleNames,
        },
      );
    },
  },
  {
    title: '职级',
    prop: 'levelName',
    dataIndex: 'levelName',
    width: 100,
  },
  {
    title: '岗位',
    prop: 'positionName',
    dataIndex: 'positionName',
    width: 100,
  },
  {
    title: '部门',
    prop: 'deptName',
    dataIndex: 'deptName',
    width: 100,
  },
  {
    title: '状态',
    dataIndex: 'status',
    key: 'status',
    width: 100,
    customRender({ record }) {
      return h(
        Tag,
        {
          color: record.status == 1 ? 'success' : 'error',
        },
        {
          default: () => (record.status == 1 ? '正常' : '禁用'),
        },
      );
    },
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    width: 180,
  },
  {
    title: '操作',
    fixed: 'right',
    dataIndex: 'action',
    key: 'action',
    width: 400,
  },
];
