<template>
	<view class="we-run-page">
		<view class="contant">
			<image src="../../static/img/run/bg.png" class="bg" mode="widthFix"></image>
			<view class="we-run-container">
				<image src="../../static/img/run/runBg.png" class="run-logo" mode="widthFix"></image>
				<view class="run-step-number">
					<text class="title">今日步数</text>
					<view class="steps" v-if="todayNum">
						<text class="num">{{todayNum}}</text>
						<text>步</text>
					</view>
					<view v-else class="steps-empower">
						<u-button type="primary" size="mini" color="#00c791" :plain="true" text="授权查看"></u-button>
					</view>
				</view>
				<image src="../../static/img/run/ranking_btn.png" class="ranking_btn" mode="widthFix"></image>
				<!-- open-type="getPhoneNumber" @getphonenumber="getPhoneNumber" -->
				<!-- <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">1111</button> -->
			</view>
		</view>
		<u-tabbar :value="tabBarVal" @change="changeTabBar" :fixed="true" :placeholder="true" activeColor="#00c791" :safeAreaInsetBottom="true">
			<u-tabbar-item text="步数" name="步数">
				<image class="u-page__item__slot-icon" slot="active-icon" src="../../static/img/run/tabbar_Index1.png">
				</image>
				<image class="u-page__item__slot-icon" slot="inactive-icon" src="../../static/img/run/tabbar_Index.png">
				</image>
			</u-tabbar-item>
			<u-tabbar-item text="商城"  name="商城">
				<image class="u-page__item__slot-icon" slot="active-icon" src="../../static/img/run/tabbar_shop1.png">
				</image>
				<image class="u-page__item__slot-icon" slot="inactive-icon" src="../../static/img/run/tabbar_shop.png">
				</image>
			</u-tabbar-item>
		</u-tabbar>
	</view>
</template>
<script>
	import http from '@/shopro/request/index';
	import store from '@/shopro/store';
	import {
		mapActions,
		mapGetters
	} from 'vuex'
	export default {
		data() {
			return {
				todayNum: 0,
				tabBarVal: '步数',
				registerPopup:true,
				form:{name:'xxx'},
				tips: '获取',
				seconds: 10
			}
		},
		computed: {
			...mapGetters(['userInfo'])
		},
		methods: {
			...mapActions([]),
			// 获取步数
			getWeRunData() {
				let wRunEncryptedData = {}
				let that = this;
				uni.getWeRunData({
					success: function(res) {
						wRunEncryptedData.encryptedData = res.encryptedData
						wRunEncryptedData.iv = res.iv
						http('user.wxRun', wRunEncryptedData).then(res => {
							if (!res.code && res.data) {
								// that.todayNum = res.data.todayNum;
								that.todayNum = 0;
								console.log(that.todayNum)
							} else {
								that.todayNum = 0;
								// that.$u.toast(res.msg);
							}
						})
					}
				})
			},
			changeTabBar(name){
				this.tabBarVal = name;
				console.log(name)
				if(name == '商城') {
					// let fsCode =  uni.getStorageSync('token');
					// http('user.miniCode', {fsCode:fsCode}).then(res => {
					// 	if (!res.code && res.data) {
							uni.navigateTo({
								url: '/pages/h5/index',
							})
					// 	} else {
					// 		that.todayNum = 0;
					// 	}
					// })
					
					
				} 
			},
			getPhoneNumber (e) {
				if(!e.detail.code){
					this.$u.toast(e.detail.code);
				}
			},
			
		},
		onHide(){
		},
		onShow() {
			this.tabBarVal = "步数";
			// uni.hideTabBar();
		},
		onReady() {
			// this.geAauthorizeWeRun()
			let token = uni.getStorageSync('token');
			// 如果有缓存信息
			if (token) {

				let authCheck = store.dispatch('authCheck');
				authCheck.then(resolve => {
					this.getWeRunData()

				}).catch(errCode => {
					console.log(errCode)
					if (errCode == 2001) {
						// 手机号输入
						console.log(this.userInfo)
						console.log("信息是--------------")
						this.registerInfo = {
							companyId: '999999998', //开放式传
							mobile: '15501156151', //封闭式传
							empcardno: '', //封闭式传
							registerType: 'register' //注册时的类型为普通注册
						}
						console.log(this.registerInfo)
						http('user.register', this.registerInfo).then(res => {
							if (!res.code) {
								// this.getWeRunData()
							} else {
								// that.$u.toast(res.msg);
							}
						})
					}
				})
			} else {
				let getUserInfo = store.dispatch('getUserInfo');
				getUserInfo.then(resolve => {

				}).catch(errCode => {

				})
			}
		}
	}
</script>
<style lang="scss" scoped>
	.we-run-page {
		background-color: #fff;

		.contant {
			height: calc(100% - 100px - env(safe-area-inset-bottom));
			box-sizing: border-box;
			position: relative;

			.bg {
				width: 100%;
			}

			.we-run-container {
				position: absolute;
				top: 250rpx;
				text-align: center;
				width: 100%;

				.run-logo {
					width: 425rpx;

				}

				.run-step-number {
					position: absolute;
					transform: translateX(-50%);
					left: 50%;
					top: 175rpx;

					.title {
						font-size: 25rpx;
					}

					.steps {
						font-size: 25rpx;

						.num {
							font-size: 57rpx;
							font-weight: bold;
						}
					}

					.steps-empower {
						margin-top: 30rpx;
						font-size: 20rpx;
					}
				}

				.ranking_btn {
					margin-top: 100rpx;
					height: 120rpx;
				}
			}
		}

		.registre-popup{
			margin:60rpx 0;
			padding:0 40rpx;
			.btn{
				
			}
		}
	}

	.u-page__item__slot-icon {
		width: 40rpx;
		height: 40rpx;
	}
</style>
