import { h } from 'vue';
import { ElAvatar, ElTag } from 'element-plus';

export const columns = [
  {
    type: 'selection',
  },
  {
    label: 'ID',
    prop: 'id',
    fixed: 'left',
    width: 50,
  },
  {
    label: '登录账号',
    prop: 'username',
    minWidth: 100,
  },
  {
    label: '用户姓名',
    prop: 'realname',
    minWidth: 100,
  },
  {
    label: '头像',
    prop: 'avatar',
    minWidth: 100,
    render(record) {
      return h(ElAvatar, {
        size: 48,
        src: record.row.avatar,
        shape: 'square',
        fit: 'fill',
      });
    },
  },
  {
    label: '性别',
    prop: 'gender',
    minWidth: 100,
    render(record) {
      let typeText = '';
      let color = '';
      switch (record.row.gender) {
        case 1:
          typeText = '男';
          color = 'primary';
          break;
        case 2:
          typeText = '女';
          color = 'danger';
          break;
        case 3:
          typeText = '保密';
          color = 'warning';
          break;
        default:
          break;
      }
      return h(
        ElTag,
        {
          type: color,
        },
        {
          default: () => typeText,
        },
      );
    },
  },
  {
    label: '手机号',
    prop: 'mobile',
    minWidth: 160,
  },
  {
    label: '用户角色',
    prop: 'role',
    minWidth: 100,
    render(record) {
      let roleNames = '';
      if (record.row.roles.length > 0) {
        roleNames = record.row.roles.map((role) => role.name).join(',');
      }
      return h('span', roleNames || '-');
    },
  },
  {
    label: '职级',
    prop: 'levelName',
    minWidth: 100,
  },
  {
    label: '岗位',
    prop: 'positionName',
    minWidth: 100,
  },
  {
    label: '部门',
    prop: 'deptName',
    minWidth: 160,
  },
  {
    label: '状态',
    prop: 'status',
    minWidth: 100,
    render(record) {
      return h(
        ElTag,
        {
          type: record.row.status == 1 ? 'success' : 'danger',
        },
        {
          default: () => (record.row.status == 1 ? '正常' : '禁用'),
        },
      );
    },
  },
  {
    label: '创建人',
    prop: 'createUser',
    minWidth: 100,
  },
  {
    label: '创建时间',
    prop: 'createTime',
    width: 180,
  },
];
