import Store from '@/store'

export default {
  //专利数据库权限
  hasRole(projectId, roles){
    if (!projectId) {
      return true
    }
    const permissions = Store.getters && Store.getters.permissions
    const p = permissions[projectId]
    return p === 0 || roles.indexOf(p) !== -1
  },
  //专利数据库权限
  hasPermission(sign){
    return (Store.state.admin.permission).indexOf(sign) !== -1
  },
  //报告权限
  reportPermission(reportId, roles){
    if(!reportId){
        return true
    }
  const role = Store.state.user.userinfo
    if(role.roleType === 1){
        return true
    }
    const permissions = Store.getters && Store.getters.permissions
    if(Object.keys(permissions).length==0){
        return true
    }
    const reportRole = permissions[reportId]
    if(!reportRole){
        return true
    }
        var result = false
        for(var item of reportRole){
            if(roles.includes(item)){
                result = true
                break
            }
        }
    return result
  }
}
