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

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