<script>
	export default {
		//全局变量
		globalData: {
			baseUrl: 'https://qingyujiankang.baomihua222.top/api',
			imageUrl: 'https://qingyujiankang.baomihua222.top/storage/',
			is_auth: '',
			b_minute_money: '',
			ab_minute_money: '',
			a_minute_money: '',
			modelList: []
		},
		onLaunch: function() {
			let that = this
			setTimeout(function() {
				uni.request({
					url: that.globalData.baseUrl + '/common/maps',
					method: 'GET',
					header: {
						'content-type': 'application/json',
						'Accept': 'application/json',
					},

					success(res) {
						console.log(res.data.data.PayStatusEnum, '所有状态')
						console.log(res.data, '所有状态')
					}
				})
			}, 500)
			console.log('App Launch')
			this.tokens()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			tokens: function() {
				let that = this
				uni.login({
					success(res) {
						console.log(res, '888888888')
						if (res.code) {
							uni.request({
								url: that.globalData.baseUrl + '/auth/weapp-login',
								method: 'POST',
								header: {
									'content-type': 'application/x-www-form-urlencoded',
								},
								data: {
									code: res.code,
								},
								success(res) {
									console.log(res, '-----------')
									console.log(res, '-----------')
									uni.setStorageSync('token', res.data.data.token),
										uni.setStorageSync('session_key', res.data.data.session_key)
									// uni.setStorageSync('is_auth', res.data.data.is_auth)
									that.globalData.is_auth = res.data.data.is_auth
								}
							})
						}
					}
				})
			},
			request(api, params, method) {
				var that = this;
				return new Promise((resolve, reject) => {
					uni.request({
						url: that.globalData.baseUrl + api,
						data: params,
						header: {
							'Accept': 'application/json',
							'content-type': 'application/json',
							'Authorization': uni.getStorageSync('token'),
						},
						method: method,
						success: (res) => {
							resolve(res)
							// console.log(res)
							if (res.statusCode == 450) {
								return;
							}
							if (res.statusCode != 200) {
								if (res.statusCode == 401) {
									uni.removeStorageSync('token')
									this.tokens();
									uni.showToast({
										title: '登录过期，重试',
										icon: 'none',
										mask: true,
										success: function() {
											uni.switchTab({
												url: "pages/order/order"
											})
										}
									})
								} else {


									if (res.message != undefined) {
										uni.showModal({
											showCancel: false,
											title: '提示',
											content: res.message
										})

									} else if (res.data.message != undefined) {
										uni.showModal({
											showCancel: false,
											title: '提示',
											content: res.data.message
										})

									}
								}
							}
						},
						fail: (err) => {
							reject("请求失败")
						}
					})
				})
			},

		}
	}
</script>

<style>
	/* #02B7CA */
	page {
		height: 100vh;
		background-color: #f6f6f6;

	}

	@font-face {
		font-family: "iconfont";
		src: url('~@/static/font/iconfont.eot?t=1618301166239');
		/* IE9 */
		src: url('~@/static/font/iconfont.eot?t=1618301166239#iefix') format('embedded-opentype'),
			/* IE6-IE8 */
			url('data:application/x-font-woff2;charset=utf-8;base64,d09GMgABAAAAAAK4AAsAAAAABmAAAAJuAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHEIGVgCCcApgbAE2AiQDCAsGAAQgBYRtBzobnAUR1Ytjsr8kcBMGbh21zElHLWZZtWb2Nay/eEDoCGVSodH5r61OpFilgscEIazpJZ8RgFv9AEgTqQnFqMgT+gmFvp0EErpEsWu2DU4x9EAC8Cf+BihY4LL/m/ZrEaY2XZYl+zyojmmZCezQEHp3ymxhT8rT1xM8gPZ65JK5Ww+M8P7LByL3AMghCAEDLqc/gR5k1AHltieNNXlMwMDSAPfCKE6khDJuGLvAJdyHAIGkKiZVQVMXg2EtE0Amq5E+JhfGMJbzR/Ct2WvINuKvKxqGrfD78oufAcXHwWpoo+pBzr9vF/C87RNEQECHfQAHKAYG0lWbbjFFGOcQmN5kYl+1Ah/++y5kr3aE/XVWdTAAyVBxT0pXdavVCoDF4/EgddRbQeNyP8SDWHp/ODmOwXx/+nQtrpg7n33jZk3uznpzH39tlyV5nk2bv2uYRTaUoZ+pWw8gEDz/9h7x988AcP88Dm1GPy/89+QR+CPKnn2mqy2nmqqs9Srxo5YqEEgg4MX+SO9jLTGnzwv+xNyE14+UFA7+ZJPGFsOHIFzwxZ9SBFKk9nAQUaZMEQsACi0ACOGuoYTyCIdwT6SxHvgQ6x++hKcIpGfGmUHkxqosgoliDukbVBn35LjVimrPWExtIll1yN9RxioGnu0WcyH2KHNsGJ+Fr0pAwh0E4DFsW4ZBuMZM7VJ12DoO1b3IzrgzFoKJYg7pG1QZ9+SPVqv0+TMWU5tIS1NN9o4yVpODZ7s9yNDQ92q6l2fGZ+GrEpBwBwGYhW3LMNTPqjFTuxyRHLaOPYz6Guz1Td0HlLM2LGuxffWdT6mrpFeefGMA') format('woff2'),
			url('~@/static/font/iconfont.woff?t=1618301166239') format('woff'),
			url('~@/static/font/iconfont.ttf?t=1618301166239') format('truetype'),
			/* chrome, firefox, opera, Safari, Android, iOS 4.2+ */
			url('~@/static/font/iconfont.svg?t=1618301166239#iconfont') format('svg');
		/* iOS 4.1- */
	}

	.iconfont {
		font-family: "iconfont" !important;
		font-size: 16px;
		font-style: normal;
		-webkit-font-smoothing: antialiased;
		-moz-osx-font-smoothing: grayscale;
	}

	.icon-iconfontjiantou2:before {
		content: "\e632";
	}
</style>
