<template>
	<view class="dashan">
		<view class="list">
			<view class="item" v-for="(a,i) in list" :key="i" @click="toUser(a.userid)">
				<view class="pic">
					<image :src="a.faceImage?a.faceImage:a.img" v-if="userInfo.memberflag>=1"></image>
					<image src="@/static/avatar.png" v-else></image>
				</view>
				<view class="content">
					<view class="info">
						<view class="name" v-if="userInfo.memberflag>=1">{{a.nickname}}</view>
						<view class="name" v-else><image src="@/static/name.png"></image></view>
						<view class="desc">{{a.declaration}}</view>
					</view>
					<view class="btn" v-if="pageType == 1" @click.stop="toDash(a.userid)">搭讪</view>
				</view>
			</view>
			<view class="empty" v-if="isShow">
				<image src="@/static/empty.png"></image>
				<view class="txt">暂无数据</view>
			</view>
		</view>
		<unverified :isPopup="isPopup" />
		<insufficient :isCoins="isCoins" />
		<dashan :isDashan="isDashan" :info="info"></dashan>
	</view>
</template>


<script>
	export default {
		data() {
			return {
				isCoins: false,
				isPopup: false,
				isDashan: false,
				isShow: false,
				list: [],
				userInfo: {},
				info: {},
				pageType: -1
			};
		},
		onLoad() {
			const that = this;
			uni.$on("closeSharePopup",res=>{
				that.isPopup = false;
				that.isDashan=  false;
				that.isCoins=  false;
			})
			
			uni.$on("openCoinsPopup",res=>{
				that.isCoins = res
			})
			that.getList();
			that.userInfo = uni.getStorageSync("userInfo")
		},
		onShow() {
			if(uni.getSystemInfoSync().platform == 'ios'){
				this.pageType = (uni.getStorageSync("pageType")?uni.getStorageSync("pageType"):1)
			}else{
				this.pageType = 1
			}
		},
		methods: {
			async getList() {
				const { code, data } = await this.$api.friendList({
					userId: uni.getStorageSync("userInfo").id,
					type: 4 //1关注 2黑名单 3粉丝 4访客 5好友
				})
				if(code == 200){
					this.list = data;
					this.isShow = data.length == 0?true:false
				}
			},
			toUser(id) {
				if(uni.getStorageSync("userInfo").realnameFlag == 0){
					this.isPopup = true;
					return ;
				}
				if(this.userInfo.memberflag>=1){
					uni.navigateTo({
						url: "/pages/peiwan/detail?id="+id
					})
				}
			},
			toDash(id) {
				if(uni.getStorageSync("userInfo").realnameFlag == 0){
					this.isPopup = true;
					return ;
				}
				if(uni.getStorageSync("userInfo").memberflag == 0){
					uni.showModal({
						title: "温馨提示",
						content: "开通会员才能搭讪?",
						confirmColor: "#000000",
						success(res){
							if(res.confirm){
								uni.navigateTo({
									url: "/pages/users/center/index"
								})
							}
						},
					})
					return ;
				}
				this.info.userid = id;
				this.isDashan = true;
			},
			//去聊天
			async toChat(id) {
				const { code, data } = await this.$api.findZegoToken({
					userId: uni.getStorageSync("userInfo").id,
					sellerId: id
				})
				if(code == 200){
					uni.setStorageSync("chatToken",data.token);
					uni.navigateTo({
						url: "/pages/users/chat/index?id="+this.id+"&roomId="+data.roomId
					})
				}
			},
		}
	}
</script>

<style scoped lang="scss">
.dashan{
	padding: 0 25rpx;
	min-height: 100vh;
	background-color: #fff;
	overflow: hidden;
	.empty{
		padding: 150rpx 0;
		text-align: center;
		font-weight: 500;
		font-size: 28rpx;
		color: #222222;
		image{
			display: block;
			width: 460rpx;
			height: 400rpx;
			margin: 0 auto;
		}
	}
	.item{
		display: flex;
		align-items: center;
		.pic{
			width: 90rpx;
			height: 90rpx;
			margin-right: 20rpx;
			position: relative;
			image{
				width: 100%;
				height: 100%;
				border-radius: 50%;
			}
		}
		.content{
			padding: 30rpx 0;
			flex: 1;
			border-bottom: 1px solid #EAEAEA;
			display: flex;
			align-items: center;
			justify-content: space-between;
			.info{
				
				.name{
					font-weight: 400;
					font-size: 30rpx;
					color: #222222;
					image{
						width: 95rpx;
						height: 30rpx;
						display: block;
					}
				}
				.desc{
					font-weight: 400;
					font-size: 24rpx;
					color: #AAAAAA;
					margin-top: 15rpx;
					max-width: 400rpx;
					text-overflow: ellipsis;
					white-space: nowrap;
					overflow: hidden;
				}
			}
			.btn{
				width: 150rpx;
				line-height: 70rpx;
				background: linear-gradient(0deg, #000000, #3D3B38);
				box-shadow: 0px 4rpx 18rpx 0px rgba(42,41,39,0.34);
				border-radius: 70rpx;
				text-align: center;
				font-weight: 500;
				font-size: 24rpx;
				color: #FFFFFF;
				text-align: center;
			}
		}
	}
}
</style>
