<template>
	<view>
		<uni-nav-bar statusBar backgroundColor="#fff" fixed title="查看好友" left-icon="left" @clickLeft="utils.navigateBack()">
		</uni-nav-bar>
		
		<view class="info fx-r fd-ac fx-bc" v-if="data != null">
			<view class="avatar">
				<image :src="data.img == '' ? '/static/img/user-avatar1.png'  : data.img" mode="aspectFill"></image>
			</view>
			<view class="user-info">
				<view class="nickname fx-r fx-bc">
					{{data.name}}
				</view>
			</view>
		</view>
		
		<view class="pannel">
			<view class="item fx-r fx-bc fx-ac">
				<view class="label">来源</view>
				<view class="fx-g1"></view>
				<view class="value">{{data.source}}</view>
			</view>
			
			<view class="item fx-r fx-bc">
				<view class="label">认证方式</view>
				<view class="value">{{data.content}}</view>
			</view>
			
		</view>
		
		<view class="btn" @tap="tapCheck" v-if="data.status == 0">通过验证</view>
		<view class="btn" @tap="tapRefused" v-if="data.status == 0" style="color: red;">拒绝通过</view>
		
		
		<view class="btn" style="color: #ccc;" v-if="data.status == 1">已通过验证</view>
		
		<view class="btn" style="color: #ccc;" v-if="data.status == 2">已拒绝</view>
		
		<view class="btn" style="color: #ccc;" v-if="data.status == -1">已过时</view>
		
		<view class="btn" style="color: #ccc;" v-if="data.status == -2">已忽略</view>
		
	</view>	
</template>

<script>
	import {mapState,mapMutations } from 'vuex';
	export default {
	    data() {
	        return {
				data : {},
				id : 0,
				isPop:false
	        }  
	    },
		
		onLoad(option){
			this.id = option.id || "0";
		},
		
		onShow() {
			this.getData();
		},
		
	    methods: {
			getData:function(){
				uni.showLoading({	title: '获取数据中..'});
				this
					.request
					.post("verificationInfo",{id:this.id})
					.then(res => {
							uni.hideLoading();
							if(res.code == 200) {
								this.data = res.data;
							} else {
								uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
							}
						})
						.catch(res=>{
							console.log(res);
							uni.hideLoading();
							uni.showModal({title: '系统提示',content: '加载失败，重新点击尝试！',showCancel: false});
						});
				},
				/**
				 * checkBox
				 */
				tapCheck:function(){
					uni.showLoading({title: '验证中..'});
					this
						.request
						.post("FriendVerificationSub",{id:this.id,type:1})
						.then(res => {
								uni.hideLoading();
								if(res.code == 200) {
									this.getData();
									uni.$emit('checkInvite',{type:1,id:this.id});
									uni.navigateBack();
								} else {
									uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
								}
							})
							.catch(res=>{
								console.log(res);
								uni.hideLoading();
								uni.showModal({title: '系统提示',content: '加载失败，重新点击尝试！',showCancel: false});
							});
				},
				
				tapRefused:function(){
					uni.showLoading({title: '验证中..'});
					this
						.request
						.post("FriendVerificationSub",{id:this.id,type:2})
						.then(res => {
								uni.hideLoading();
								if(res.code == 200) {
									this.getData();
									uni.$emit('checkInvite',{type:2,id:this.id});
								} else {
									uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
								}
							})
							.catch(res=>{
								console.log(res);
								uni.hideLoading();
								uni.showModal({title: '系统提示',content: '加载失败，重新点击尝试！',showCancel: false});
							});
				},
				
				/**
				 * 添加好友
				 */
				tapAddBtn:function(){
					uni.showLoading({	title: '获取数据中..'});
					this
						.request
						.post("FriendAdd",{usercode:this.usercode})
						.then(res => {
							uni.hideLoading();
							if(res.code == 200) {
								if(res.data.stats == 1) {
									this.utils.Tip("加入成功");
									this.getData();
								} else {
									uni.navigateTo({
										url:"checkAdd?userCode=" + this.usercode
									})
								}
							} else {
								uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
							}
						})
						.catch(res=>{
							console.log(res);
							uni.hideLoading();
							uni.showModal({title: '系统提示',content: '加载失败，重新点击尝试！',showCancel: false});
						});
					
				}
	    }
	}
</script>

<style lang="scss">
	.info{background: #fff;padding: 10px;}
	.info .avatar{}
	.info .avatar image{width: 60px;height: 60px;border-radius: 60px;}
	.user-info{margin-left: 10px;width: calc(100% - 70px);}
	.user-info .nickname{font-size: 16px;}
	.user-info .nickname image{width: 15px;}
	.info-name{color: $ic-default-text;font-size: 12px;margin-top: 6px;}
	.info-qm{padding: 10px;background: #fff;}
	.info-qm .label{color:$ic-default-text;font-size: 14px;}
	.info-qm .mono{color:$ic-default-text;font-size: 14px;padding: 20px;}
	.pannel{background: #fff;padding: 10px;margin-top:10px;}
	.pannel .item{padding: 16px 0;border-bottom: 1px solid #f1f1f1;}  
	.pannel .item:last-child{border-bottom: 0;}
	.pannel .item .label{margin-right: 10px}
	.pannel .value{color:$ic-default-text}
	.btn{background: #fff;padding: 10px;margin-top: 10px;text-align: center;}
</style>