<template>
	<view class="container">
		<view class="top">
			<view class="bg"><image class="imgBg" src="../../static/img/user-bg.png" mode=""></image></view>
			<view class="user">
				<view class="avtor"><image class="portrait" :src="userInfo.avatar || '/static/img/missing-face.png'"></image></view>
				<view class="">
					<view class="name">{{ userInfo.phone || userInfo.email || '游客' }}</view>
					<view class="id">uid:{{ userInfo.uid }}</view>
					<view class="id-box flex">
						
						<view class="level-box">
							<image class="image" src="../../static/img/img28.png"></image>
							<view class="level" v-if="userInfo.level">{{ userInfo.level_info.name }}</view>
							<view class="level" v-else>
								V0
							</view>
						</view>
						<view class="level-box" v-if="userInfo.point.length !=0">
							<image class="image" src="../../static/img/hehuoren.png"></image>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="main">
			<view class="title">我的工具</view>
			<view class="tt">
				<view class="tt-box" @click="nav('/pages/assets/myPing')">
					<image src="../../static/img/pinggou.png" class="tt-icon1" mode=""></image>
					<view class="tt-txt">我的拼购</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
				<view class="userInfo.point">
					<view class="tt-box" v-if="userInfo.point.length !=0" @click="nav('/pages/user/myNote')">
						<image src="../../static/img/myPoint.png" class="tt-icon1" mode=""></image>
						<view class="tt-txt">我的节点</view>
						<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
					</view>
				</view>
				<view class="tt-box" @click="nav('/pages/market/myCalculation')">
					<image src="../../static/img/myKJ.png" class="tt-icon1" mode=""></image>
					<view class="tt-txt">我的矿机</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
				<view class="tt-box" @click="nav('/pages/index/info')" v-if="userInfo.level >=4"> 
					<image src="../../static/img/data.png" class="tt-icon1" mode=""></image>
					<view class="tt-txt">汇总数据</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
				<view class="tt-box" @click="nav('/pages/user/fulilist')">
					<image src="../../static/img/gift.png" class="tt-icon1" mode=""></image>
					<view class="tt-txt">拼购福利</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
				<view class="tt-box" @click="nav('/pages/user/extension')">
					<image src="../../static/img/myTeam.png" class="tt-icon2" mode=""></image>
					<view class="tt-txt">我的团队</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
				<view class="tt-box" @click="nav('/pages/user/shareQrCode')">
					<image src="../../static/img/share.png" class="tt-icon3" mode=""></image>
					<view class="tt-txt">团队邀请</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
				<view class="tt-box" @click="nav('/pages/money/payment')">
					<image src="../../static/img/zfpwd.png" class="tt-icon4" mode=""></image>
					<view class="tt-txt">交易密码</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
				<view class="tt-box" @click="nav('/pages/set/password')">
					<image src="../../static/img/pwd.png" class="tt-icon1" mode=""></image>
					<view class="tt-txt">登录密码</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
				<view class="tt-box" @click="nav('/pages/user/approve')">
					<image src="../../static/img/real_name.png" class="tt-icon1" mode=""></image>
					<view class="tt-txt">实名认证</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
				<view class="tt-box" @click="server()">
					<image src="../../static/img/kefu.png" class="tt-icon1" mode=""></image>
					<view class="tt-txt">联系客服</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
				<view class="tt-box" @click="nav('/pages/set/userinfo')">
					<image src="../../static/img/set.png" class="tt-icon5" mode=""></image>
					<view class="tt-txt">设置</view>
					<image src="../../static/img/jiantou.png" class="next-icon" mode=""></image>
				</view>
			</view>
			<view class="kb">
				
			</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 {
	height: 100%;
	background: #ffffff;
}
.container {
	height: 100%;
	background: #ffffff;
}
.kb {
	height: 100rpx;
}
.top {
	width: 100%;
	height: 340rpx;
	position: relative;
	.bg {
		position: absolute;
		width: 100%;
		height: 340rpx;
		left: 0;
		top: 0;
		right: 0;
		image {
			width: 100%;
			height: 100%;
		}
	}
	.user {
		position: relative;
		padding-top: 98rpx;
		padding-left: 34rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		z-index: 10;
		.avtor {
			width: 102rpx;
			height: 102rpx;
			border-radius: 50%;
			.portrait {
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
		}
		.name {
			margin-left: 30rpx;
			font-size: 36rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
		}
		.id {
			margin-left: 30rpx;
			font-size: 30rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
		}
		.level-box {
			
			margin-left: 30rpx;
			margin-top: 10rpx;
			position: relative;
			.image {
				width: 128rpx;
				height: 45rpx;
			}
			.level {
				position: absolute;
				top: 0;
				left: 62rpx;
				height: 44rpx;
				line-height: 48rpx;
				font-size: 24rpx;
				color: #826740;
				font-weight: bold;
			}
		}
	}
}
.main {
	position: relative;
	z-index: 11;
	width: 100%;
	height: 100%;
	background: #ffffff;
	margin-top: -70rpx;
	border-top-left-radius: 60rpx;
	border-top-right-radius: 60rpx;
	.title {
		padding-top: 65rpx;
		padding-left: 36rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
	}
	.tt {
		margin: 0 auto;
		width: 750rpx;
		padding: 40rpx 70rpx;
		border-radius: 10rpx;
		background-color: #ffffff;

		.tt-box {
			height: 100rpx;
			display: flex;
			align-items: center;
			border-bottom: 1px solid #f0f0f0;
			.tt-icon1 {
				width: 42rpx;
				height: 42rpx;
			}
			.tt-icon2 {
				width: 49rpx;
				height: 38rpx;
			}
			.tt-icon3 {
				width: 46rpx;
				height: 40rpx;
			}
			.tt-icon4 {
				width: 40rpx;
				height: 42rpx;
			}
			.tt-icon5 {
				width: 44rpx;
				height: 40rpx;
			}

			.tt-txt {
				margin-left: 36rpx;
				font-size: 32rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				flex: 1;
			}

			.next-icon {
				width: 16rpx;
				height: 25rpx;
			}
		}

		.border-b {
			border-bottom: 1px solid #f1f1f1;
		}
	}
}
.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>
