<template>
	<view>
		<image class="width90 mart10" mode="widthFix" src="../../../static/img/unionimg/hsg4.jpg"
			@click="jumprecharge(1)"></image>
		<image class="width90 mart5" mode="widthFix" src="../../../static/img/unionimg/hsg2.jpg"
			@click="jumprecharge(2)"></image>
		<image class="width90 mart5" mode="widthFix" src="../../../static/img/unionimg/hsg1.jpg"
			@click="jumprecharge(3)"></image>
		<image class="width90 mart5" mode="widthFix" src="../../../static/img/unionimg/hsg3.jpg"
			@click="jumprecharge(4)"></image>
	</view>
</template>

<script>
	import {
		getCacheParam
	} from '../../../Utils/Api.js';
	let app = getApp();
	export default {
		data() {
			return {}
		},
		onLoad() {
			let that = this;
			uni.getStorage({
				key: "user",
				success(e) {
					app.globalData.userInfo = e.data; //这就是你想要取的token
					uni.getStorage({
						key: 'token',
						success(e) {
							app.globalData.token = e.data;
						},
						fail() {
							uni.navigateTo({
								url: '../../userLogin/userLogin'
							})
						}
					})
					if (!app.globalData.userInfo.phone) {
						uni.navigateTo({
							url: '../../userLogin/userLogin'
						})
						return;
					}
					that.getCacheParam();
				},
				fail: res => {
					uni.navigateTo({
						url: '../../userLogin/userLogin'
					})
				}
			})

		},
		methods: {
			//获取卡券ID
			getCacheParam() {
				let params = {
					key: app.globalData.userInfo.phone
				}
				getCacheParam(params).then(res => {
					if (res.return_code == '000000' && res.return_data) {
						uni.navigateTo({
							url: '../../goods/externalCoupon/externalCoupon?id=' + res.return_data
						})
					}
				})
			},
			//跳转充值
			jumprecharge(item) {
				if (app.globalData.userInfo) {
					if (!app.globalData.latitude) {
						this.hqaddress(item);
						return;
					}
					this.jumpsValue(item);
				} else {
					uni.navigateTo({
						url: '../../userLogin/userLogin'
					})
				}
			},
			//获取定位				
			//定位信息
			hqaddress(item) {
				let that = this;
				upsdk.pluginReady(function() {
					upsdk.getLocationCity({
						success: function(cityCd) {
							app.globalData.cityId = cityCd;
						},
						fail: function(err) {}
					});
					upsdk.getLocationGps({
						success: function(res) {
							switch (uni.getSystemInfoSync().platform) {
								case 'android':
									let zuob = JSON.parse(res);
									app.globalData.latitude = zuob.latitude;
									app.globalData.longitude = zuob.longitude;
									that.jumpsValue(item);
									break;
								case 'ios':
									app.globalData.latitude = res.latitude;
									app.globalData.longitude = res.longitude;
									that.jumpsValue(item);
									break;
							}

						},
						fail: function() {}
					});
				});
			},
			//跳转
			jumpsValue(item) {
				if (item == 1) {
					uni.navigateTo({
						url: '../../goods/goods-list/goods-list?id=3'
					})
					return;
				}
				if (item == 2) {
					uni.navigateTo({
						url: '../../goods/refuel/refuel'
					})
					return;
				}
				if (item == 3) {
					uni.navigateTo({
						url: '../recharge/recharge'
					})
					return;
				}
				if (item == 4) {
					uni.navigateTo({
						url: '../../tabBar/user/user'
					})
					return;
				}
			}
		}
	}
</script>

<style>

</style>
