<script>
import { getTechnicianToken } from "@/api/newLogin";

export default {
	globalData: {
		couponSelected: {}
	},
	data() {
		return {
		}
	},
	onLaunch() {
		this.getTechnicianTokenFun()
		console.log('App Launch')


	},
	onShow() {
		console.log('App Show')
	},
	methods: {
		//存入openid
		getTechnicianTokenFun() {
			let isWechat = navigator.userAgent.toLowerCase().includes('micromessenger');
			// 非微信环境直接跳过
			//if (!isWechat) return;//guo
			let openid = uni.getStorageSync('wx_copenid')
			const code = this.$utils.getQueryStr('code');
			if (openid) {
				this.checkMerchantStatus()
			} else {
				// // 1. 没有code → 跳转微信静默授权
				// if (!code && isWechat) {
				// 	let appid = 'wx9dc677bd41e82569'
				// 	//https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx9dc677bd41e82569&redirect_uri=https://city.baoxianzhanggui.com/fragrance/wxcode/&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect
				// 	let ruri = encodeURIComponent('https://city.baoxianzhanggui.com/fragrance/');
				// 	const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${ruri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`
				// 	window.location.href = authUrl
				// }

				let params = {
					//code: this.$utils.('code') //guo
					code: '031VMh000FD7zW1OwB200nJFjM1VMh0q'
				}
				getTechnicianToken(params).then(res => {
					if (res.data.code == 200) {
						uni.setStorageSync('wx_copenid', res.data.data.copenid);
						this.checkMerchantStatus()
					}
				})
			}



		},
		//查询商户注册和入驻信息   auditStatus 审核状态：-1-申请入住,0-待入驻，1-待审核，2-审核通过，3-审核驳回"

		async checkMerchantStatus() {
			const openid = uni.getStorageSync('wx_copenid')
			const merchantInfo = await this.$utils.checkMerchantStatus(openid)
			if (!merchantInfo) return
			//merchantInfo.merchant.auditStatus = 2  //guo
			if (merchantInfo.merchant.auditStatus == -1) {//未注册
				uni.navigateTo({
					url: '/pages/join/staff'
				})
				return

			} else if (merchantInfo.merchant.auditStatus == 0 || merchantInfo.merchant.auditStatus == 1 || merchantInfo.merchant.auditStatus == 2 || merchantInfo.merchant.auditStatus == 3) {
				if (merchantInfo.merchant.auditStatus == 0) { //待入驻
					if (!this.$utils.checkLogin({ type: 'navigate' })) return;
					uni.switchTab({
						url: '/pages/index/index'
					})
					return
				}
				if (merchantInfo.merchantAuditFile.length) {//已有入驻信息
					if (!this.$utils.checkLogin({ type: 'navigate' })) return;
					uni.switchTab({
						url: '/pages/index/index?merchantInfo=' + encodeURIComponent(JSON.stringify(merchantInfo))
					})

				} else {//无入驻信息
					if (merchantInfo.merchant.auditStatus == 1 || merchantInfo.merchant.auditStatus == 3) {
						uni.navigateTo({
							url: '/pages/join/staff?merchantInfo=' + encodeURIComponent(JSON.stringify(merchantInfo))
						})
					} if (merchantInfo.merchant.auditStatus == 2) {
						uni.switchTab({
							url: '/pages/index/index'
						})
					}
				}
			}

		},


	},
	onHide() {
		console.log('App Hide')
	}
}
</script>

<style lang="scss">
@import 'uview-ui/index.scss';
@import "common/common.scss";

html,
body {
	height: 100vh;
	overflow-x: hidden;

	&::-webkit-scrollbar {
		display: none;
	}
}

page {
	--theme-color: #03C8BE;
	--theme-color-gradient: linear-gradient(131deg, #00DAAB 0%, #07CDC4 100%);
	;
}

// 弹窗
.modal-wrap {
	width: 590rpx;
	//height: 314rpx;
	background: #fff;
	border-radius: 16rpx;

	.title {
		font-weight: 600;
		font-size: 32rpx;
		color: #1D2129;
		text-align: center;
		margin-top: 32rpx;
	}

	.content {
		padding: 32rpx 48rpx;
		font-weight: 400;
		font-size: 30rpx;
		color: #4E5969;
	}

	.btn-box {
		display: flex;
		border-top: 1rpx solid #E7E7E7;
	}

	.btn {
		flex: 1;
		height: 90rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size: 30rpx;
		color: #1D2129;
		font-weight: 400;
	}

	.left {
		font-weight: 400;
		font-size: 30rpx;
		color: #86909C;
		text-align: center;
		border-right: 1rpx solid #E7E7E7;
	}

	.right {
		font-weight: 400;
		font-size: 30rpx;
		color: #1D2129;
		text-align: center;
	}

}
</style>
