import store from '@/store'

// 获取当前用户详情
export function getUserData() {
	return store.getters.user_info || JSON.parse(localStorage.getItem('user_info'))
}
export function getIsCreator (key) {
	 let is=false;
	 let getUserdatas = getUserData().employee_detail.role_list
	 for(let i in getUserdatas){
		//  console.log(getUserdatas[i])
		 if(key == getUserdatas[i].name){
			is=true;
		 }
	 }
	//  getUserData().forEach(item=>{ 
	// 	 if(key==item.name){
	// 		 is=true;
	// 	 }
	//  })
	 return is
}
export function supremeAuthority () {
	if(getIsCreator('creator')){
		return 'creator'
	}else if(getIsCreator('admin')){
		return 'admin'
	}else if(getIsCreator('point_manager')){
		return 'point_manager'
	}else if(getIsCreator('dept_manager')){
		return 'dept_manager'
	}else if(getIsCreator('employee')){
		return 'employee'
	}
}
export function authoritys (key) {//判断是否为某项权限：this.$authoritys('dept_manager')
	return supremeAuthority() == key
}

// 获取积分类型
export function getTyps(id) {
	if (id) {
		var arr = JSON.parse(localStorage.getItem('SET_POINT_TYPES'))
		var item = arr.filter(element => {
		return typeof (id) === 'string' ? element.code == id : element.id == id
		})
		return item[0]
	} else {
		return JSON.parse(localStorage.getItem('SET_POINT_TYPES'))
	}
}
// 获取积分类型名称
export function getTypsName(id) {
	return getTyps(id).name
}

// 防抖
//用法
// _debounce(this.XXX(),1000)
export function _debounce (fn, delay) {
	if(!delay)delay=500
    let timer = null
    return function () {
        let arg = arguments
        clearTimeout(timer)
        timer = setTimeout(() => {
            fn.apply(this, arg)
        }, delay)
    }
}
