<template>
	<view class="content">
		<view class="top">
			<view class="bg"><image class="imgBg" src="../../static/user/img17.png" mode=""></image></view>
			<view class="title">
				<view class="header">
					<view class="tx"><image src="../../static/error/missing-face.png" mode=""></image></view>
					<view class="dl"><image src="../../static/user/jiedian1.png" mode=""></image></view>
				</view>
				<view class="message">
					<view class="name">{{ userInfo.nickname }}</view>
					<view class="phone">{{ userInfo.phone }}</view>
					<view class="vip-box">
						<view class="vip">会员等级LV.5</view>
						<view class="pintuan">拼团等级LV.2</view>
					</view>
				</view>
			</view>
		</view>
		<view class="box">
			<view class="sweets-box">
				<view class="sweets" @click="nav('/pages/money/award')">
					<view class="limit">{{ userInfo.now_money }}</view>
					<view class="sweets-name">糖果</view>
				</view>
				<view class="jiange"></view>
				<view class="sweets" @click="nav('/pages/money/integralP')">
					<view class="limit">{{ userInfo.integral }}</view>
					<view class="sweets-name">拼团积分</view>
				</view>
				<view class="jiange"></view>
				<view class="sweets" @click="nav('/pages/money/integralShopping')">
					<view class="limit">{{ userInfo.integral }}</view>
					<view class="sweets-name">购物积分</view>
				</view>
				<view class="jiange"></view>
				<view class="sweets" @click="nav('/pages/money/wallet')">
					<view class="limit">{{ userInfo.broken_commission }}</view>
					<view class="sweets-name">佣金</view>
				</view>
			</view>
			<view class="my-order">
				<view class="box-title flex ">
					<view class="title1"><text>我的订单</text></view>
					<view class="link" @click="nav('/pages/order/order?state=0')" hover-class="common-hover"><text class="iconfont iconenter"></text></view>
				</view>
				<view class="order-section">
					<view class="order-item" @click="nav('/pages/order/order?state=0')" hover-class="common-hover" :hover-stay-time="50">
						<view class=" icon1 position-relative">
							<image class="icon-img" src="/static/user/user01.png" mode="aspectFit"></image>
						</view>
						<text>待付款</text>
					</view>
					<view class="order-item" @click="nav('/pages/order/order?state=1')" hover-class="common-hover" :hover-stay-time="50">
						<view class="icon1 position-relative">
							<image class="icon-img" src="/static/user/user02.png" mode="aspectFit"></image>
						</view>
						<text>待发货</text>
					</view>
					<view class="order-item" @click="nav('/pages/order/order?state=2')" hover-class="common-hover" :hover-stay-time="50">
						<view class="icon1 position-relative">
							<image class="icon-img" src="/static/user/user03.png" mode="aspectFit"></image>
						</view>
						<text>待收货</text>
					</view>
					<view class="order-item" @click="nav('/pages/order/order?state=4')" hover-class="common-hover" :hover-stay-time="50">
						<view class=" icon1 position-relative"><image class="icon-img" src="/static/user/user04.png" mode="aspectFit"></image></view>
						<text>已完成</text>
					</view>
				</view>
			</view>
			<view class="my-order">
				<view class="box-title flex ">
					<view class="title1"><text>更多功能</text></view>
					<view class="link" hover-class="common-hover"></view>
				</view>
				<view class="order-section">
					<view class="order-item" @click="nav('/pages/user/extension')" hover-class="common-hover" :hover-stay-time="50">
						<view class=" icon1 position-relative"><image class="icon-img" src="../../static/user/myTeam.png" mode="aspectFit"></image></view>
						<text>我的资产</text>
					</view>
					<view class="order-item" @click="nav('/pages/user/extension')" hover-class="common-hover" :hover-stay-time="50">
						<view class=" icon1 position-relative"><image class="icon-img" src="../../static/user/myTeam.png" mode="aspectFit"></image></view>
						<text>我的团队</text>
					</view>
					<view class="order-item" @click="nav('/pages/user/myjiedian')" hover-class="common-hover" :hover-stay-time="50">
						<view class="icon1 position-relative"><image class="icon-img" src="../../static/user/myTeams.png" mode="aspectFit"></image></view>
						<text>互助团队</text>
					</view>
					<view class="order-item" @click="nav('/pages/user/shareQrCode')" hover-class="common-hover" :hover-stay-time="50">
						<view class="icon1 position-relative"><image class="icon-img" src="../../static/user/myShare.png" mode="aspectFit"></image></view>
						<text>团队邀请</text>
					</view>
					<view class="order-item" @click="nav('/pages/user/extension')" hover-class="common-hover" :hover-stay-time="50">
						<view class=" icon1 position-relative"><image class="icon-img" src="../../static/user/myTeam.png" mode="aspectFit"></image></view>
						<text>银行卡管理</text>
					</view>
					<view class="order-item" @click="nav('/pages/address/address')" hover-class="common-hover" :hover-stay-time="50">
						<view class=" icon1 position-relative"><image class="icon-img" src="../../static/user/myAddress.png" mode="aspectFit"></image></view>
						<text>收货地址</text>
					</view>
					<view class="order-item" @click="server()" hover-class="common-hover" :hover-stay-time="50">
						<view class=" icon1 position-relative"><image class="icon-img" src="../../static/user/myKefu.png" mode="aspectFit"></image></view>
						<text>联系客服</text>
					</view>
					<view class="order-item" @click="nav('/pages/user/about')" hover-class="common-hover" :hover-stay-time="50">
						<view class=" icon1 position-relative"><image class="icon-img" src="../../static/user/myAbout.png" mode="aspectFit"></image></view>
						<text>关于我们</text>
					</view>
					<view class="order-item" @click="nav('/pages/set/set')" hover-class="common-hover" :hover-stay-time="50">
						<view class=" icon1 position-relative"><image class="icon-img" src="../../static/user/mySet.png" mode="aspectFit"></image></view>
						<text>设置</text>
					</view>
				</view>
			</view>
		</view>
		<view class="my-order">
			<view class="box-title flex ">
				<view class="title1"><text>拼购工具</text></view>
				<view class="link" hover-class="common-hover"></view>
			</view>
			<view class="order-section">
				<view class="order-item" @click="nav('/pages/assets/myPing')" hover-class="common-hover" :hover-stay-time="50">
					<view class=" icon1 position-relative"><image class="icon-img" src="../../static/user/myPing.png" mode="aspectFit"></image></view>
					<text>我的拼购</text>
				</view>
				<view class="order-item" @click="nav('/pages/user/myNote')" hover-class="common-hover" :hover-stay-time="50">
					<view class="icon1 position-relative"><image class="icon-img" src="../../static/user/myPoint.png" mode="aspectFit"></image></view>
					<text>我的节点</text>
				</view>
				<view class="order-item" @click="nav('/pages/market/myCalculation')" hover-class="common-hover" :hover-stay-time="50">
					<view class="icon1 position-relative"><image class="icon-img" src="../../static/user/myFu.png" mode="aspectFit"></image></view>
					<text>我的服务器</text>
				</view>
				<view class="order-item" @click="nav('/pages/index/info')" hover-class="common-hover" :hover-stay-time="50">
					<view class=" icon1 position-relative"><image class="icon-img" src="../../static/user/data.png" mode="aspectFit"></image></view>
					<text>汇总数据</text>
				</view>
			</view>
		</view>
		<uni-popup ref="popup" type="center">
			<view class="popup">
				<view class="popup-dox">
					<image class="popup-logo" src="../../static/img/lianxi.png"></image>
					<view class="pop-title">已为您定制专属客服</view>
					<view>{{ weixin }}</view>
					<image class="popup-text" @longtap="bc_code" :src="erweima"></image>
					<view class="btn" @click="copy(weixin)">复制微信号</view>
					<view class="pop-tip flex">
						<view class="weixin"><image src="../../static/img/weixin.png" mode=""></image></view>
						<view>长按保存二维码</view>
					</view>
				</view>
			</view>
			<view class="close_icon" @click="close"><image src="../../static/img/Close.png"></image></view>
		</uni-popup>
	</view>
</template>
<script>
import uniCopy from '@/components/js_sdk/xb-copy/uni-copy.js';
import { mapState, mapMutations } from 'vuex';
import uniList from '@/components/uni-list/uni-list.vue';
import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
import { orderData, getUserInfo, service } from '@/api/user.js';
import { saveUrl, interceptor } from '@/utils/loginUtils.js';
import uniPopup from '@/components/uni-popup/uni-popup.vue';
export default {
	components: {
		uniList,
		uniListItem,
		uniPopup
	},
	data() {
		return {
			erweima: '',
			weixin: ''
		};
	},
	onShow() {
		//判断是否已经登录
		if (this.hasLogin) {
			this.loadBaseData();
		} else {
			uni.showModal({
				title: '登录',
				content: '您未登录，是否马上登陆?',
				success: e => {
					if (e.confirm) {
						interceptor();
					}
				},
				fail: e => {
					console.log(e);
				}
			});
		}
	},
	computed: {
		...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
	},
	methods: {
		...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
		loadBaseData() {
			console.log(this.userInfo);
			getUserInfo({}).then(({ data }) => {
				this.setUserInfo(data);
			});
			service({}).then(({ data }) => {
				this.erweima = data.service_qr;
				this.weixin = data.service_wechat;
			});
		},
		server() {
			this.$refs.popup.open();
		},
		close() {
			this.$refs.popup.close();
		},
		nav(url) {
			// 判断是否已经登录
			// if (this.hasLogin) {
			console.log(url);
			uni.navigateTo({
				url: url,
				fail() {
					uni.switchTab({
						url: url
					});
				}
			});
			// }else {
			// 	uni.showModal({
			// 		title: '登录',
			// 		content: '您未登录，是否马上登陆?',
			// 		success: e => {
			// 			if (e.confirm) {
			// 				interceptor();
			// 			}
			// 		},
			// 		fail: e => {{}
			// 			console.log(e);
			// 		}
			// 	});
			// }
		},
		bc_code() {
			let that = this;
			console.log('保存二维码', this.erweima);
			uni.downloadFile({
				//获得二维码的临时地址
				url: this.erweima,
				success: res => {
					//console.log('获取url',res)
					if (res.statusCode == 200) {
						uni.saveImageToPhotosAlbum({
							filePath: res.tempFilePath, //传入临时地址
							success() {
								that.$api.msg('保存成功'); //封装的提示
							},
							fail() {
								that.$api.msg('保存失败');
							}
						});
					}
				}
			});
		},
		copy(value) {
			let obj = this;
			let content = value; //需要复制的内容
			console.log('复制的内容:', content);
			// content = typeof content === 'string' ? content : content.toString(); // 复制内容，必须字符串，数字需要转换为字符串
			const result = uniCopy(content);
			if (result === false) {
				uni.showToast({
					title: '不支持'
				});
			} else {
				uni.showToast({
					title: '复制成功',
					icon: 'none'
				});
			}
		}
	}
};
</script>
<style lang="scss">
page,
.content {
	height: auto;
	min-height: 100%;
	background-color: #FFFFFF;
	padding-bottom: 44rpx;
}
.top {
	width: 100%;
	height: 530rpx;
	position: relative;

	.bg {
		position: absolute;
		width: 100%;
		height: 530rpx;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.title {
		position: relative;
		display: flex;
		flex-direction: column;
		top: 20%;

		.header {
			display: flex;
			flex-direction: column;
			align-items: center;

			.tx {
				width: 132rpx;
				height: 132rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			.dl {
				position: relative;
				margin-top: -16rpx;
				width: 100rpx;
				height: 32rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}
		}

		.message {
			margin-top: 10rpx;
			display: flex;
			flex-direction: column;
			align-items: center;

			.name {
				font-size: 34rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #ffffff;
			}

			.phone {
				font-size: 26rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #ffffff;
			}
		}

		.vip-box {
			margin-top: 10rpx;
			display: flex;
			align-items: center;

			.vip {
				padding: 6rpx 16rpx;
				text-align: center;
				background: #ffffff;
				border-radius: 24rpx;
				font-size: 20rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #2e58ff;
				margin-right: 10rpx;
			}

			.pintuan {
				padding: 6rpx 16rpx;
				text-align: center;
				background: #ffffff;
				border-radius: 24rpx;
				font-size: 20rpx;
				font-family: PingFang SC;
				font-weight: bold;
				color: #2e58ff;
			}
		}
	}
}

.box {
	display: flex;
	flex-direction: column;
	width: 710rpx;
	position: relative;
	margin: -80rpx 20rpx;
	color: #fefefe;
}

.sweets-box {
	display: flex;
	align-items: center;
	width: 710rpx;
	padding: 48rpx 0;
	background: #ffffff;
	box-shadow: 0px 0px 20px 0px rgba(50, 50, 52, 0.06);
	border-radius: 20rpx;

	.jiange {
		width: 1rpx;
		height: 36rpx;
		background: #999999;
	}

	.sweets {
		width: 25%;
		display: flex;
		flex-direction: column;
		align-items: center;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;

		.limit {
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #666666;
		}
 
		.sweets-name {
			font-size: 28rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #666666;
		}
	}
}

.my-order {
	margin: 80rpx auto 0;
	display: flex;
	justify-content: space-between;
	flex-direction: column;
	width: 710rpx;
	background: #ffffff;
	box-shadow: 0rpx 0rpx 20rpx 0rpx rgba(50, 50, 52, 0.06);
	border-radius: 20rpx;
}

.box-title {
	border-top-left-radius: 20rpx;
	border-top-right-radius: 20rpx;
	background-color: #ffffff;
	line-height: 1;
	padding: 26rpx 34rpx 20rpx;
	border-bottom: 1px solid #F5F5F5;;

	.title1 {
		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}

	.link {
		font-size: $font-base - 2rpx;
		color: $font-color-light;
	}
}

.order-section {
	display: flex;
	flex-wrap: wrap;
	align-items: center;
	text-align: center;
	padding: 34rpx 0 10rpx;
	.order-item {
		display: flex;
		flex-direction: column;
		width: 25%;
		align-items: center;
		height: 140rpx;
		font-size: $font-sm;
		color: $font-color-dark;
	}

	.iconfont {
		font-size: 48rpx;
		margin-bottom: 18rpx;
		color: #fa436a;
	}

	.icon-shouhoutuikuan {
		font-size: 44rpx;
	}

	.icon {
		height: 88rpx;
		width: 90rpx;
		margin-bottom: 18rpx;
		background-size: 100%;
		background-repeat: no-repeat;
		background-position: center;

		.icon-img {
			width: 100%;
			height: 100%;
		}
	}

	.icon1 {
		height: 50rpx;
		width: 48rpx;
		margin-bottom: 18rpx;
		background-size: 100%;
		background-repeat: no-repeat;
		background-position: center;

		.icon-img {
			width: 100%;
			height: 100%;
		}
	}
}
.popup {
	width: 640rpx;
	background-color: #ffffff;
	border-radius: 15rpx;
	text-align: center;
	.popup-dox {
		position: relative;
		top: -60rpx;
		.popup-logo {
			width: 460rpx;
			height: 132rpx;
		}
		.pop-title {
			font-size: 40rpx;
			font-weight: bold;
			color: #333333;
			padding: 25rpx 0rpx;
			margin-bottom: 50rpx;
		}
		.popup-text {
			width: 400rpx;
			height: 400rpx;
			margin-bottom: 50rpx;
		}
		.btn {
			width: 300rpx;
			height: 50rpx;
			line-height: 50rpx;
			background: linear-gradient(90deg, #60bab0, #60bab0, #45969b);
			margin: 0 auto;
			color: #ffffff;
			border-radius: 25rpx;
		}
		.pop-tip {
			font-size: 30rpx;
			font-weight: 500;
			color: #333333;
			justify-content: center;
			margin-top: 20rpx;
			.weixin {
				width: 48rpx;
				height: 40rpx;
				margin-right: 14rpx;
				image {
					width: 48rpx;
					height: 40rpx;
				}
			}
		}
	}
}
.close_icon {
	width: 60rpx;
	height: 60rpx;
	margin: 88rpx auto 0;
	image {
		width: 100%;
		height: 100%;
	}
}
</style>
