/**
 *  data {
	 * code:string;
	 * headUrl:string;
	 * hiId:number;
	 * hospName:string;
	 * id:number;
	 * name:string
	 * nowPermission:number;
	 * permissions:number[];
	 * token:string;
 }
 */
export const loginAfterHandle = (data,hospSign) => {
	const rolList = [{
			permission: 1,
			name: '管理员',
			pagePath: 'pages/situationsCenter/situationsCenter'
		}, // targetIndexs：targetList种对应的下标
		{
			permission: 2,
			name: '查核组长',
			pagePath: 'pages/situationsCenter/situationsCenter'
		},
		{
			permission: 3,
			name: '查核组员',
			pagePath: 'pages/situationsCenter/situationsCenter'
		},
		{
			permission: 4,
			name: '单位负责人',
			pagePath: 'pages/mission/mission'
		},
		{
			permission: 5,
			name: '改善者',
			pagePath: 'pages/mission/mission'
		}
	]

	/**
	 * nowPermission:number
	 */
	//角色和对应的跳转页面
	const rolToTarget = (nowPermission) => {
		if (nowPermission != 0) {
			let current = rolList.find(item => item.permission == nowPermission);
			if (current) {
				// 页面跳转
				uni.redirectTo({
					url: `/${current.pagePath}`
				});
			}
		}
	}

	if (data) {
		uni.setStorageSync('hiId', data.hiId);
		uni.setStorageSync('permissions', data.permissions);
		uni.setStorageSync('token', data.token);
		uni.setStorageSync('code', data.code);
		uni.setStorageSync('nowPermission', data.nowPermission);
		uni.setStorageSync('id', data.id);
		uni.setStorageSync('name', data.name);
		uni.setStorageSync('hospSign',hospSign);

		rolToTarget(data.nowPermission)
	}
}
