import { filterRoutes, generteMenus } from '@/utils/route'

import router from '@/router'

export const handleDisabled = (arr) => {
  arr.forEach((item) => {
    delete item.disabled
    if (item.children.length > 0) {
      handleDisabled(item.children)
    }
  })
}

export const Addrolerules = {
  roleName: [
    { required: true, message: '请填写角色名称', trigger: 'blur' },
    { min: 1, max: 15, message: '长度在1到15个字符', trigger: 'blur' }
  ],
  roleKey: [
    { required: true, message: '请填写角色标识', trigger: 'blur' },
    {
      type: 'string',
      pattern: /^[a-zA-Z]{1,15}$/g,
      message: '请输入1到15位的英文字母',
      trigger: 'blur'
    }
  ],
  remark: [{ message: '请填写角色描述', trigger: 'blur' }]
}

export const columns = (_this) => {
  return [
    {
      prop: 'roleKey',
      label: '角色标识',
      align: 'center'
    },
    {
      prop: 'roleName',
      label: '角色名称'
    },
    {
      prop: 'createTime',
      label: '创建时间'
    },
    {
      button: true,
      label: '操作',
      width: '200px',
      group: [
        {
          name: '配置菜单',
          type: 'text',
          round: false,
          plain: false,
          onClick: (row, index, scope) => {
            _this.menuClick(scope)
          }
        },
        {
          name: '编辑',
          type: 'text',
          round: false,
          plain: false,
          onClick: (row, index, scope) => {
            _this.edit(scope)
          }
        },
        {
          name: '删除',
          type: 'text',
          round: false,
          plain: false,
          onClick: (row, index, scope) => {
            _this.handRemove(row)
          }
        }
      ]
    }
  ]
}

export const options = {
  stripe: false, // 斑马纹
  mutiSelect: false, // 多选框
  index: false, // 显示序号， 多选则 mutiSelect
  loading: false, // 表格动画
  border: true,
  initTable: true, // 是否一挂载就加载数据
  height: 'calc(100vh - 345px)',
  cursor: 'pointer' // 行鼠标形状
}

export const rightColumns = (_this) => {
  return [
    {
      prop: 'nickName',
      label: '用户名称',
      align: 'center'
    },
    {
      prop: 'userName',
      label: '登录账号'
    },
    {
      prop: 'deptName',
      label: '所属部门'
    },
    {
      prop: 'majorName',
      label: '所属专业'
    },
    {
      prop: 'sex',
      label: '性别',
      width: '80px',
      render: (h, params) => {
        if (params.row.sex == 1) {
          return h('span', '男')
        } else {
          return h('span', '女')
        }
      }
    }
  ]
}

export const rightOptions = {
  stripe: false, // 斑马纹
  mutiSelect: true, // 多选框
  index: false, // 显示序号， 多选则 mutiSelect
  loading: false, // 表格动画
  border: true,
  initTable: false, // 是否一挂载就加载数据
  height: 'calc(100vh - 355px)'
}
