<script>
import store from '@/store'
	import { mapMutations, mapActions, mapGetters } from 'vuex'
	import { setTimeout } from 'timers'
	import { getUser, wxLoginFn } from '@/utils/auth'
	import { getDictionaries } from '@/api/mini'
	import util from "./utils/util";
	export default {
		// 全端，数据共享，还可以解决页面初始化模板访问不到值得
		// 有坑 分包里的页面访问不到
		globalData: {},
		onLaunch() {
			// #ifdef H5
			// H5开发环境无法微信授权，使用固定的用户 shish 2020.4.30
			if (process.env.NODE_ENV == "development") {
				uni.setStorageSync(
					"token",
					"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImp0aSI6IjBfNTIifQ.eyJpc3MiOiJodHRwczpcL1wvYXBpLnNob3AuaHpnaGQuY29tIiwiYXVkIjoiaHR0cHM6XC9cL2FwaS5zaG9wLmh6Z2hkLmNvbSIsImp0aSI6IjBfNTIiLCJpYXQiOjE2MTYxNTc2NjQsIm5iZiI6MTYxNjE1NzY2NCwiZXhwIjoxNjI0Nzk3NjY0LCJ1bmlxdWVJZCI6IjUyIiwic291cmNlSWQiOjB9.VzSekbSwSczMWsfdPVdrm3gZ-v9o3p01NbMVNT4nGZ4"
				);
				uni.setStorageSync("account", "0");
				getDictionaries({ token: uni.getStorageSync('token') }).then(res => {
					if (util.isEmpty(res)) {
						return false
					}
					store.commit('setDictionariesInfo', {
						...res.data.dict,
						...res.data
					})
				})
			}
			// #endif

			// 删除缓存
			if (process.env.NODE_ENV == 'production') {
				uni.removeStorageSync('shopUser')
			}
			// #ifdef MP-WEIXIN
			// wxLoginFn()
			// uni.clearStorage()
			const extConfig = wx.getExtConfigSync ? wx.getExtConfigSync() : {}
			uni.setStorageSync('account', extConfig.account)

			// #endif
			wxLoginFn(true)
				.then(res => {
					//花店员工和未知身份可以访问的地址
					var urlArr = ['admin/shopAdmin/bind', 'pagesClient/official','pagesClient/member/bind','pagesShare/pay'];
					var redirectPage = res.redirectPage;
					var needRedirect = true;
					urlArr.forEach((item, index, array) => {
						if (redirectPage.indexOf(item) != -1) {
							needRedirect = false;
						}
					})
					if (needRedirect === true) {
						//供货商员工
						if (res.data.admin.identity == '2') {
							// this.$util.pageTo({
							// 	url: "/admin/home/workbench",
							// 	type: 4
							// });
						//花店员工
						} else if(res.data.admin.identity == '1'){
							if(redirectPage !== 'admin/billing/customerPlace') {
								this.$util.pageTo({
									url: "/pagesClient/official/latest-shop",
									type: 2,
									query:{
										...this.option
									}
								});
							}
						//未知身份
						}else{
							if(this.option.style != 1){
								this.$util.pageTo({
									url: "/pagesClient/official/index",
									type: 2,
									query: {
										...this.option
									}
								});
							}
						}
					}
					getUser(true)
					//获取门店信息
					this.setUserShopAll()

				})
		},
		onLoad(){
			// const pages = getCurrentPages();
			// const currentPage = pages[pages.length - 1];
			// const url = `/${currentPage.route}`;
			// console.log(1111,url)
		},
		onShow() {
		},
		onHide() {},
		onError(err) {
			console.error(err, '错误捕获')
		},
		methods: {
			...mapActions(['setUserShopAll'])
		}
	}
</script>

<style lang="scss">
	//没有scss变量方法的，主要引入 这样打包的时候就不会所有的组件都打包进去
	@import './static/iconfont/iconfont.css';
	@import './static/css/uni2.css';
	@import './static/css/base.scss';
	@import './static/css/common.scss';
	@import './static/css/reset.scss';
	page {
		height: 100%;
	}
</style>
