function loginMsg(res) {
	wx.removeStorageSync('auth')
	wx.removeStorageSync('userauth');
	wx.removeStorageSync('siteP');
	wx.removeStorageSync('banner_list');
	wx.removeStorageSync('templetList');
	wx.setStorageSync('account_list', res.account_list);
	if (res.account_list.length == 1) {
		wx.setStorageSync('userrole', res.account_list[0].usertype == 1 ? '业务员' : '经销商');
		wx.removeStorageSync('userMsg')
		wx.setStorageSync('userMsg', res.account_list[0])
		init();
	} else {
		wx.redirectTo({
			url: './selectSite',
		})
	}
}

function init() {
	const _Http = getApp().globalData.http;
	Promise.all([{
		"classname": "sysmanage.develop.userauth.userauth",
		"method": "query_userauth", //获取用户权限
		content: {
			nocache: true
		}
	}, {
		"classname": "webmanage.site.site",
		"method": "querySite_Parameter", //查询站点数据
		content: {
			nocache: true
		}
	}, {
		"classname": "common.adspace.adspace",
		"method": "query_adspacelist", //查询轮播图
		content: {
			nocache: true
		}
	}, {
		"classname": "sysmanage.develop.querytemplet.querytemplet",
		"method": "query",
		"content": {}
	}].map(v => _Http.basic(v))).then(list => {
		console.log("登录初始化", list)
		if (list.some(res => res.msg != '成功')) return list.filter(res => {
			if (res.msg != '成功') wx.showToast({
				title: res.msg,
				icon: "none",
				mask: true
			})
		})
		wx.setStorageSync('userauth', list[0].data);
		wx.setStorageSync('siteP', list[1].data);
		wx.setStorageSync('banner_list', list[2].data)
		if (!getApp().globalData.socketEstablish) getApp().initSocket();
		let pages = getCurrentPages();
		let prevPage = pages[pages.length - 2];
		if (prevPage && prevPage.__route__ == 'pages/tabbar/home/index') prevPage.refreshData();

		let data = list[3].data.find(v => v.templetname == '站点全部');
		if (data) {
			list[3].data = list[3].data.filter(v => v.templetname != '站点全部')
			list[3].data.unshift(data)
		}
		wx.setStorageSync('templetList', list[3].data)
		wx.switchTab({
			url: '/pages/tabbar/home/index'
		})
	})
}

/* 站点数据查询 */
module.exports = {
	loginMsg,
	init
}