<template>
	<view>
		<!-- #ifdef H5 -->
		<view v-if="showHeader" class="status" :style="{position:headerPosition,top:statusTop}"></view>
		<view v-if="showHeader" class="header" :style="{position:headerPosition,top:headerTop}"></view>
		<!-- 占位 -->
		<view v-if="showHeader" class="place"></view>
		<!-- #endif -->
		<view class="user">
			<!-- 头像 -->
			<view class="left">
				<image :src="imagewxUrl+imgadres" v-if="!user.headerImg"></image>
				<image :src="user.headerImg" v-else></image>
			</view>
			<!-- 昵称,个性签名 -->
			<view class="right">
				<view class="username" v-if="!user.name">请授权登录</view>
				<view class="username" v-else>{{user.name}}</view>
				<view class="font14 fcorfff" v-if="!user.gold">金币: 0</view>
				<view class="font14 fcorfff" v-else>金币: {{user.gold}} 个</view>
				<!-- <view class="signature" @tap="toSetting">{{user.signature}}</view> -->
			</view>
			<!-- 二维码按钮 -->
			<!-- #ifdef MP -->
			<button class="erweima fotct aliitem font14" v-if="user.phone == null" open-type="getPhoneNumber"
				@getphonenumber="getPhoneNumber">
				<image src="../../../static/img/jingbi.png"></image> 充值金额
			</button>
			<button class="erweima fotct aliitem font14" v-else @click="toDeposit">
				<image src="../../../static/img/jingbi.png"></image> 充值金额
			</button>
			<!-- #endif -->
			<!-- #ifdef H5 -->
			<button class="erweima fotct aliitem font14" v-if="user.phone == null" @click="jumpH5Bding">
				<image src="../../../static/img/jingbi.png"></image> 充值金额
			</button>
			<button class="erweima fotct aliitem font14" v-else @click="toDeposit">
				<image src="../../../static/img/jingbi.png"></image> 充值金额
			</button>
			<!-- #endif -->
		</view>
		<!-- 订单-余额 -->
		<view class="order">
			<!-- 订单类型 -->
			<view class="title">我的订单</view>
			<view class="list">
				<view class="box" v-for="(row,index) in orderList" :key="index" @tap="toOrderList(index)">
					<uni-badge style="width: 20px;position: absolute; left: 15%;" v-if="row.text == '待支付' && therrNum "
						:text="therrNum" type="error" size="normal"></uni-badge>
					<view class="img">
						<view class="icon" :class="row.icon"></view>
					</view>
					<view class="text">{{row.text}}</view>
				</view>
			</view>
		</view>
		<!-- 工具栏 -->
		<view class="toolbar">
			<view class="title">卡券中心</view>
			<view class="list">
				<view class="box" v-for="(row,index) in mytoolbarList" :key="index" @tap="toPage(row.url,row.text)">
					<!-- <view style="width: 10px;height: 10px;">
						<uni-badge  text="1" type="error" />
					</view> -->

					<uni-badge style="width: 20px;position: absolute; right: 30%;" v-if="row.text == '我的卡券' && textnum "
						:text="textnum" type="error" size="normal"></uni-badge>
					<uni-badge style="width: 20px;position: absolute; right: 7%;"
						v-if="row.text == '我的优惠券' && textSend " :text="textSend" type="error" size="normal"></uni-badge>
					<view class="img">
						<image :src="imagewxUrl+row.img"></image>
					</view>
					<view class="text">{{row.text}}</view>
				</view>
			</view>
		</view>
		<!-- 我的推广 -->
		<view class="toolbar" style="margin-top: 20px;">
			<view class="title">推广中心</view>
			<view class="list">
				<view class="box" v-for="(row,index) in mytgbarList" :key="index" @tap="toPage(row.url,row.text)">
					<!-- <view style="width: 10px;height: 10px;">
						<uni-badge  text="1" type="error" />
					</view> -->

					<uni-badge style="width: 20px;position: absolute; right: 30%;" v-if="row.text == '我的卡券' && textnum "
						:text="textnum" type="error" size="normal"></uni-badge>
					<uni-badge style="width: 20px;position: absolute; right: 7%;"
						v-if="row.text == '我的优惠券' && textSend " :text="textSend" type="error" size="normal"></uni-badge>
					<view class="img" v-if="row.text != '客服' ">
						<image :src="imagewxUrl+row.img"></image>
					</view>
					<view class="text" v-if="row.text != '客服' ">{{row.text}}</view>
					<button open-type="contact" style="background-color: transparent;" class="img" show-message-card
						session-from send-message-path send-message-title v-if="row.text == '客服' ">
						<image :src="imagewxUrl+row.img"></image>
					</button>
					<view class="text" v-if="row.text == '客服' ">{{row.text}}</view>
				</view>
			</view>
		</view>
		<!-- 占位 -->
		<view class="place-bottom"></view>
		<authorize></authorize>
	</view>
</template>
<script>
	import {
		GetPhoneNumber,
		findUser
	} from "../../../Utils/Api.js";
	import authorize from '../../../components/Authorize';
	import uniBadge from "../../../components/uni-badge/components/uni-badge/uni-badge.vue";
	let app = getApp()
	export default {
		components: {
			authorize,
			uniBadge
		},
		data() {
			return {
				isfirst: true,
				imagewxUrl: app.globalData.imageWxImg,
				imgadres: 'head.png',
				headerPosition: "fixed",
				textnum: '',
				textSend: '',
				therrNum: '',
				headerTop: null,
				statusTop: null,
				showHeader: true,
				//个人信息,
				user: "",
				// 订单类型
				orderList: [{
						text: '待支付',
						icon: "fukuan"
					},
					{
						text: '已支付',
						icon: "fahuo"
					},
					{
						text: '已完成',
						icon: "shouhuo"
					}, {
						text: '已退款',
						icon: "tuihuo"
					}, {
						text: '已取消',
						icon: "pingjia"
					}
				],
				// 工具栏列表
				mytoolbarList: [{
						url: '/pages/goods/recording/recording?id=1',
						text: '充值记录',
						img: 'user/mingxi.png'
					},
					{
						url: '/pages/goods/recording/recording?id=2',
						text: '消费记录',
						img: 'user/quan.png'
					},
					{
						url: '/pages/user/mineCoupons/mineCoupons',
						text: '我的卡券',
						img: 'user/choujiang.png'
					},
					{
						url: '../../user/coupon/coupon',
						text: '我的优惠券',
						img: 'user/momey.png'
					}
				],
				// 推广列表
				mytgbarList: [{
						url: '',
						text: '客服',
						img: 'user/kefu.png'
					},
					{
						url: '../../login/login?id=1',
						text: '商户入口',
						img: 'user/point.png'
					},
					{
						url: '../../login/login?id=2',
						text: '我的推广',
						img: 'user/renw.png'
					}
					// ,
					// {
					// 	url: '/pages/user/Charge/Charge',
					// 	text: '充话费',
					// 	img: 'user/bank.png'
					// }
				]
			}
		},
		//下拉刷新，需要自己在page.json文件中配置开启页面下拉刷新 "enablePullDownRefresh": true
		onPullDownRefresh() {
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		onPageScroll(e) {
			//兼容iOS端下拉时顶部漂移
			this.headerPosition = e.scrollTop >= 0 ? "fixed" : "absolute";
			this.headerTop = e.scrollTop >= 0 ? null : 0;
			this.statusTop = e.scrollTop >= 0 ? null : -this.statusHeight + 'px';
		},
		onLoad() {
			this.statusHeight = 0;
			// #ifdef H5
			this.showHeader = true;
			// this.statusHeight = plus.navigator.getStatusbarHeight();
			// #endif
		},
		onReady() {
			//此处，演示,每次页面初次渲染都把登录状态重置
			uni.setStorage({
				key: 'UserInfo',
				data: false,
				success: function() {},
				fail: function(e) {}
			});
		},
		onShow() {
			if (app.globalData.userInfo) {
				this.findUser();
			}
		},
		methods: {
			findUser() {
				let params;
				findUser(params).then(res => {
					if (res.return_code == '000000') {
						app.globalData.userInfo = res.return_data;
						this.user = res.return_data;
						this.textnum = res.return_data.unusedCouponNum;
						this.textSend = res.return_data.unusedDiscount;
						this.therrNum = res.return_data.unpaid;
						uni.setStorage({
							key: "user",
							data: res.return_data
						})
					}
				});
			},
			getPhoneNumber(PhoneNumber) {
				let params = {
					openId: app.globalData.openId,
					iv: PhoneNumber.detail.iv,
					encryptedData: PhoneNumber.detail.encryptedData
				}
				GetPhoneNumber(params).then(res => {
					if (res.return_code == '000000') {
						app.globalData.userInfo = res.return_data
							.object
							.highUser;
						uni.setStorage({
							key: "user",
							data: res.return_data
								.object
								.highUser
						})
						this.toDeposit();
					}
				});
			},
			// H5获取手机号
			jumpH5Bding() {
				uni.navigateTo({
					url: '/pages/login/register?id=2'
				})
			},
			//扫码
			toScan() {
				uni.scanCode({
					success: function(res) {
						uni.navigateTo({
							url: '../../goods/coupons-info-details/coupons-info-details?id=' + JSON
								.parse(res.result).code
						})
					},
					fail() {
						uni.showToast({
							title: '无法识别二维码',
							icon: 'none',
							duration: 2000
						})
					}
				});

			},
			//消息列表
			toMsg() {
				// uni.navigateTo({
				// 	url:'../../msg/msg'
				// })
				uni.showToast({
					title: '暂未开通',
					icon: 'none'
				});
			},
			toOrderList(index) {
				uni.navigateTo({
					url: '../../user/order_list/order_list?tbIndex=' + index
				})
			},
			// toSetting() {
			// 	uni.navigateTo({
			// 		url: '../../user/setting/setting'
			// 	})
			// },
			toLogin() {
				uni.showToast({
					title: '请登录',
					icon: "none"
				});
				uni.navigateTo({
					url: '../../login/login'
				})
				this.isfirst = false;
			},
			isLogin() {
				//实际应用中,用户登录状态应该用token等方法去维持登录状态.
				const value = uni.getStorageSync('UserInfo');
				if (value) {
					return true;
				}
				return false
			},
			toDeposit() {
				uni.navigateTo({
					url: '../../user/deposit/deposit'
				})
			},
			toPage(url, item) {
				if (item != '客服') {
					uni.navigateTo({
						url: url
					})
				}

			}
		}
	}
</script>
<style lang="scss">
	page {
		position: relative;
		background-color: #fff;
	}

	.status {
		width: 100%;
		height: 0;
		position: fixed;
		z-index: 10;
		background-color: #0083f5;
		top: 0;
		/*  #ifdef  APP-PLUS  */
		height: var(--status-bar-height); //覆盖样式
		/*  #endif  */

	}

	.header {
		width: 92%;
		padding: 0 4%;
		height: 100upx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		position: fixed;
		top: 0;
		z-index: 10;
		background-color: #0083f5;
		/*  #ifdef  APP-PLUS  */
		top: var(--status-bar-height);

		/*  #endif  */
		.icon-btn {
			width: 120upx;
			height: 60upx;
			flex-shrink: 0;
			display: flex;

			.icon {
				color: #fff;
				width: 60upx;
				height: 60upx;
				display: flex;
				justify-content: flex-end;
				align-items: center;
				font-size: 42upx;
			}
		}
	}

	button::after {
		border: none
	}

	.status {
		width: 100%;
		height: 0;
		position: fixed;
		z-index: 10;
		background-color: #0083f5;
		top: 0;
		/*  #ifdef  APP-PLUS  */
		height: var(--status-bar-height); //覆盖样式
		/*  #endif  */

	}

	.header {
		width: 92%;
		padding: 0 4%;
		height: 100upx;
		display: flex;
		justify-content: flex-end;
		align-items: center;
		position: fixed;
		top: 0;
		z-index: 10;
		background-color: #0083f5;
		/*  #ifdef  APP-PLUS  */
		top: var(--status-bar-height);

		/*  #endif  */
		.icon-btn {
			width: 120upx;
			height: 60upx;
			flex-shrink: 0;
			display: flex;

			.icon {
				color: #fff;
				width: 60upx;
				height: 60upx;
				display: flex;
				justify-content: flex-end;
				align-items: center;
				font-size: 42upx;
			}
		}
	}

	.place {
		background-color: #0083f5;
		padding-left: 20px;
		padding-right: 20px;
		text-align: right;
		height: 100upx;
		/*  #ifdef  APP-PLUS  */
		margin-top: var(--status-bar-height);

		/*  #endif  */
		image {
			width: 30px;
			height: 30px;
		}
	}

	.place-bottom {
		height: 300upx;
	}

	.user {
		width: 96%;
		padding: 0 4%;
		display: flex;
		align-items: center;
		// position: relative;
		background-color: #0083f5;
		padding-bottom: 40rpx;

		.left {
			width: 20vw;
			height: 20vw;
			flex-shrink: 0;
			margin-right: 20upx;
			border: solid 1upx #fff;
			border-radius: 100%;

			image {
				width: 20vw;
				height: 20vw;
				border-radius: 100%;
			}

		}

		.right {
			width: 100%;

			.username {
				font-size: 36upx;
				color: #fff;
			}

			.signature {
				color: #eee;
				font-size: 28upx;
			}
		}

		.erweima {
			flex-shrink: 0;
			width: 100px;
			height: 30px;
			border-radius: 15px 0px 0px 15px;
			padding: 0;
			margin-left: 5vw;
			background-color: #1391f6;
			color: #FFFFFF;
			display: flex;
			justify-content: center;
			align-items: center;

			image {
				width: 30rpx;
				height: 30rpx;
			}

			.icon {
				color: #7b6335;
				font-size: 42upx;
			}
		}
	}

	.order {
		.title {
			padding-top: 10upx;
			margin: 0 0 10upx 3%;
			font-size: 30upx;
			height: 80upx;
			display: flex;
			align-items: center;
		}

		width: 92%;
		margin: 30rpx 4% 30rpx 4%;
		padding: 0rpx 0% 20rpx 0%;
		background-color: #fff;
		box-shadow: 0rpx 0rpx 25rpx rgba(0, 0, 0, 0.1);
		border-radius: 15rpx;

		.list {
			display: flex;
			padding-bottom: 10upx;

			.box {
				width: 25%;

				.img {
					width: 100%;
					display: flex;
					justify-content: center;

					.icon {
						font-size: 50upx;
						color: #464646;
					}
				}

				.text {
					width: 100%;
					display: flex;
					justify-content: center;
					font-size: 28upx;
					color: #3d3d3d;
				}
			}
		}

		.balance-info {
			display: flex;
			padding: 10upx 0;

			.left {
				width: 75%;
				display: flex;

				.box {
					width: 50%;
					font-size: 28upx;

					.num {
						width: 100%;
						height: 50upx;
						display: flex;
						justify-content: center;
						align-items: flex-end;
						color: #f9a453;
					}

					.text {
						width: 100%;
						display: flex;
						justify-content: center;
						color: #3d3d3d;
						font-size: 28upx;
					}
				}
			}

			.right {
				border-left: solid 1upx #17e6a1;
				width: 25%;

				.box {

					.img {
						width: 100%;
						height: 50upx;
						display: flex;
						justify-content: center;
						align-items: flex-end;

						.icon {
							font-size: 45upx;
							color: #e78901;
						}
					}

					.text {
						width: 100%;
						display: flex;
						justify-content: center;
						font-size: 28upx;
						color: #3d3d3d;
					}
				}
			}
		}
	}

	.VIP {
		width: 84%;
		margin: -65upx auto 20upx auto;
		padding: 30upx 4%;
		background: linear-gradient(to left, #dea96d 0%, #f6d59b 100%);
		box-shadow: 0upx 0upx 25upx rgba(0, 0, 0, 0.2);
		border-radius: 15upx;
		display: flex;
		align-items: center;

		.img {
			flex-shrink: 0;
			width: 60upx;
			height: 60upx;

			image {
				width: 60upx;
				height: 60upx;
			}
		}

		.title {
			width: 100%;
			color: #796335;
			font-size: 30upx;
		}

		.tis {
			width: 100%;
			display: flex;
			justify-content: flex-end;
			color: #fcf0d0;
			font-size: 26upx;
		}
	}

	.toolbar {
		width: 92%;
		margin: 0 4% 0 4%;
		padding: 0 0 20upx 0;
		background-color: #fff;
		box-shadow: 0upx 0upx 25upx rgba(0, 0, 0, 0.1);
		border-radius: 15upx;

		.title {
			padding-top: 10upx;
			margin: 0 0 10upx 3%;
			font-size: 30upx;
			height: 80upx;
			display: flex;
			align-items: center;
		}

		.list {
			display: flex;
			flex-wrap: wrap;

			.box {
				width: 25%;
				margin-bottom: 30upx;

				.img {
					width: 23vw;
					height: 10.5vw;
					display: flex;
					justify-content: center;

					image {
						width: 9vw;
						height: 9vw;
					}
				}

				.text {
					width: 100%;
					display: flex;
					justify-content: center;
					font-size: 26upx;
					color: #3d3d3d;
				}
			}
		}
	}
</style>
