<template>
	<view class="content" :style="{height:nowHeight}">
		
		<view class="self-title-box">
			<image :src='userHeadUrl' mode="aspectFit"></image>
			<text>{{userName}}</text>
		</view>
		<button class="login-button-pos" v-if="isShowAuthBtn" open-type="getUserInfo" @getuserinfo="getUserInfo">
			<image src="/static/icon/power-head.png" class="power-head-img" />未授权,请点击获取信息
		</button>
		<view class="self-search-box">
			<view class="search-content">
				<view class="search-content-value">{{userTime}}</view>
				<view class="search-content-text">剩余查询（次）</view>
			</view>
			<view class="line"></view>
			<view class="search-content">
				<view class="search-content-value">{{userTotalTime}}</view>
				<view class="search-content-text">累计查询（次）</view>
			</view>
			<view class="share-detail" @click.stop="goShareDetail">
				<text>明细></text>
			</view>
		</view>
		
		<!-- <view class="self-pay-box" v-if='!isIos'> 
			<view class="search-content">
				<view class="search-content-value" style="color:#000;font-size: 38upx;margin-left: -11%;">查询套餐</view>
				<view class="search-content-text">限时优惠进行中</view>
			</view>
			<view class="search-content" style="width: 33%;height: 180rpx;" @click.stop="goPayPage()">
				<image src="../../static/payIcon.png" mode=""></image>
				<button type="primary">去购买</button>
			</view>
		</view> -->
		
		<view class="self-setting-box">
			<!-- <view class="setting-content-box" style="border-bottom: 1upx solid #d9d9d9" v-if='!isIos' @click.stop="goRechargePage()"> 
				<view class="setting-content-text">
					<image src="../../static/icon/moneyIcon.png" mode=""></image>
				    <text>充值记录</text>
				</view>
				<view style="margin-right: 2%;margin-top: 2%;">
					<image src="../../static/icon/arrowIcon.png" mode="" style="width: 32upx;height:32upx;"></image>
				</view>
			 </view> -->
			
			<view class="setting-content-box" @click.stop="inviteFriend()">
				<view class="setting-content-text">
					<image src="../../static/icon/askIcon.png" mode="" class="askIcon"></image>
				    <text>邀好友</text>
				</view>
				<view style="margin-right: 2%;margin-top:2%;display: flex;">
					<text style="font-size: 25upx;color:#999999;padding-right: 20rpx;">邀1人得{{shareCounts}}次查询机会</text>
					<image src="../../static/icon/arrowIcon.png" mode="" style="width: 32upx;height:32upx;"></image>
				</view>
			</view>
			
			
			
			<view class="setting-content-box" @click.stop="goMyAskPage()">
				<view class="setting-content-text">
					<image src="../../static/icon/askIcon.png" mode="" class="askIcon"></image>
				    <text>我的咨询</text>
				</view>
				<view style="margin-right: 2%;margin-top: 2%;">
					<image src="../../static/icon/arrowIcon.png" mode="" style="width: 32upx;height:32upx;"></image>
				</view>
			</view>
		</view>
	</view>	
</template>

<script>
	var md5 = require("../../common/md5.js");
	export default {
		data() {
			return {
				title: '个人中心页面',
				nowHeight:getApp().globalData.glbalHeight,
				isShowAuthBtn:true,
				userName:getApp().globalData.user_name,
				userHeadUrl:getApp().globalData.user_headUrl,
				userTime:getApp().globalData.times,
				userTotalTime:getApp().globalData.total_times,
				isIos:getApp().globalData.isIos,
				shareCounts:'10',
			}
		},
		onLoad() {
			this.getShareCounts();
		},
		onShow(){
			this.getUserTimes();
		},
		methods: {
			// 获取用户信息
			getUserInfo(e) {
				console.log(e);
				if (e.detail.errMsg == "getUserInfo:ok") {
					this.userHeadUrl = e.detail.userInfo.avatarUrl;
					this.userName = e.detail.userInfo.nickName;
					getApp().globalData.user_name =e.detail.userInfo.nickName;
					getApp().globalData.user_headUrl = e.detail.userInfo.avatarUrl;
					this.isShowAuthBtn = false;
					this.loginUserInfo()
				} else {
					console.log("用户信息授权失败");
					this.isShowAuthBtn = true;
				}
			},
			getShareCounts(){
				let that = this;
				uni.request({
					url:getApp().globalData.shareUrl, //需要设置为全局
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						method: 'get_invite_rule',
						timestamp: getApp().globalData.globalTimestamp, //Date.now()
						uid:getApp().globalData.user_id,
						sign: md5('get_invite_rule' + getApp().globalData.globalTimestamp),
					},
					success: res => {
						getApp().globalData.globalShareCounts = res.data.msg || 10;
						that.shareCounts = res.data.msg || 10
					} 
				});
			},
			goShareDetail(){
				uni.navigateTo({
					url: '/pages/selfInfo/shareDetail/shareDetail',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			getUserTimes(){
				let that = this;
				uni.request({
					url:getApp().globalData.shareUrl, //需要设置为全局
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						method: 'getUserInfo',
						timestamp: getApp().globalData.globalTimestamp, //Date.now()
						uid:getApp().globalData.user_id,
						sign: md5('getUserInfo' + getApp().globalData.globalTimestamp),
					},
					success: res => {
						 that.isShowAuthBtn = res.data.msg.isauth === '0';
						 that.userTime = res.data.msg.times;
						 that.userTotalTime = res.data.msg.total_times;
						 getApp().globalData.times = res.data.msg.times;
						 getApp().globalData.total_times = res.data.msg.total_times;
					} 
				});
			},
			loginUserInfo(){
				let that = this;
				uni.request({
					url:getApp().globalData.shareUrl, //需要设置为全局
					method: 'POST',
					header: {
						'content-type': 'application/x-www-form-urlencoded'
					},
					data: {
						method: 'auth',
						timestamp: getApp().globalData.globalTimestamp, //Date.now()
						uid:getApp().globalData.user_id,
						sign: md5('auth' + getApp().globalData.globalTimestamp),
						nickname:getApp().globalData.user_name,
						headimg:getApp().globalData.user_headUrl
					},
					success: res => {
						console.log('已授权')
					} 
				});
			},
			goMyAskPage(){
				uni.navigateBack({
					delta:0
				})
			},
			inviteFriend(){
				uni.navigateTo({
					url: '../share/sharePage',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			goRechargePage(){
				uni.navigateTo({
					url: './rechargeRecord/rechargeRecord',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			},
			goPayPage(){
				uni.navigateTo({
					url: './payList/payList',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: flex-start;
		background: #f4f5f7;
	}

	
	.self-title-box {
		height: 120upx;
		width: 100%;
		background: #27BCEF;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		color: #fff;
		position: relative;
	}
	.login-button-pos{
		position: absolute;
		height: 120upx;
		line-height: 120upx;
		width: 100%;
		background:#27BCEF;
		color:#fff;
		display: flex;
		align-items: center;
		font-size: 28upx;
		padding-left: 50upx;

	}
	.power-head-img {
		width: 85upx;
		height: 85upx;
        margin-right: 3%;
	}
	.self-title-box image {
		width: 90rpx;
		height:90rpx;
		border-radius: 45rpx;
		margin-left: 7%;
		margin-right: 5%;
	}
	
	.self-search-box {
		height: 230upx;
		width: 85%;
		background: #fff;
		margin-top: 5%;
		display: flex;
		justify-content: space-around;
		align-items: center;
		position: relative;
	}
	
	.share-detail {
		position: absolute;
		top: 175upx;
		right: 10upx;
	}
	.share-detail text {
		font-size: 26upx;
		text-decoration: underline;
		color: #999;
	}
	.line {
		height: 150rpx;
		width: 1rpx;
		background: #D9D9D9;

	}
	.search-content {
		height: 150upx;
		width: 45%;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		align-items: center;
	}
	.search-content-value {
		color:  #27BCEF;
		font-weight: bold;
		font-size: 42rpx;
	}
	.search-content-text {
		color:#000;
		font-size: 26rpx;
		margin-top: -10%;
	}
	.self-pay-box {
		height: 200upx;
		width: 85%;
		background: #fff;
		margin-top: 5%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	.search-content image {
		width: 120rpx;
		height:90rpx;
	}
	.search-content button {
		width: 120rpx;
		height:60rpx;
		line-height: 60rpx;
		font-size: 26rpx;
		color: #fff;
		background-color: #27BCEF!important;
		padding-left: 0;
		padding-right: 0;
	}
	
	.self-setting-box {
		/* height: 200upx; */
		width: 90%;
		background: #fff;
		margin-top: 5%;
	}
	.setting-content-box {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 100upx;
	}
	.setting-content-text {
		display: flex;
		align-items: center;
		width: 50%;
	}
	.setting-content-text image {
		width: 60upx;
		height:60upx;
		margin-left: 5%;
		margin-right: 3%;
	}
	.askIcon{
		width: 45rpx!important;
		height: 45rpx!important;
		margin-left: 8%!important;
		margin-right: 5%!important;
	}
	.setting-content-text text {
		font-size:30rpx;
	}
	
</style>
