<template>
	<view class="user-item" :class="{'item-select' : isSelect}">
		<view @click="toDetail('top')" class="top-info">
			<!-- 头像 -->
			<!-- <block v-if="!isShowPlay">
				<image class="poster" :src="memberInfo.cover" mode=""></image>
			</block> -->
			<block v-if="isVideoPlay">
				<video 
					x5-video-player-type='h5' 
					x5-video-player-fullscreen='true' 
					x5-video-orientation='portraint' 
					:class="isVideoPlay?'openvideo':'video'" 
					:id="videoId"
					:src="memberInfo.video" 
					:show-center-play-btn="false"
					object-fit="contain"
					controls>
				</video>
				<view class="iconfont icon-close videoClose" @click="closeVideo">
					
				</view>
			</block>
			<block v-else>
				<image class="poster" :src="memberInfo.cover" mode=""></image>
			</block>
			<view class="istop" v-if="memberInfo.is_top == 2">
				<view class="iconfont icon-favor_fill_light"></view>
				<view class="text">置顶</view>
			</view>
			<block v-if="isShowPlayBtn">
				<image class="play-btn" :src="imgfixUrls + 'dating/bd_play_video.png'" mode="" @click.stop="videoPlay"></image>
			</block>
			<!-- 浏览量 -->
			<block v-if="isShowViews">
				<view class="look-box">
					<view class="iconfont icon-attention"></view>
					<view class="num">{{memberInfo.pv}}</view>
				</view>
			</block>
			<!-- 操作 -->
			<block v-else>
				<image class="operation" :src="imgfixUrls + 'dating/bd_message2.png'" mode="" @click.stop="extension"></image>
			</block>
			<!-- 位置 -->
			<view class="location">
				<view class="iconfont icon-locationfill"></view>
				<view>{{memberInfo.area}}<span v-if="memberInfo.distances_text">{{memberInfo.distances_text}}</span></view>
			</view>
		</view>
		<view @click="toDetail('bottom')" class="user-info">
			<view class="info">
				<view class="name">{{memberInfo.nickname}}</view>
				<view class="sex woman" :class="{'man': memberInfo.gneder == 1}">
					<view v-if="memberInfo.gneder == 2" class="iconfont icon-female"></view>
					<view v-else class="iconfont icon-male"></view>
					<view class="age">{{memberInfo.age}}</view>
				</view>
			</view>
			<view class="property" style="position: relative;" v-if="propertyInfo.is_show_property || memberInfo.work">
				<view v-if="propertyInfo.is_have_house" class="property-item" style="margin-left: 30rpx;">
					<view class="iconfont icon-home"></view>
					<view>有房</view>
				</view>
				<view v-if="propertyInfo.is_have_car" class="property-item">
					<view class="iconfont icon-qiche"></view>
					<view>有车</view>
				</view>
				<view v-if="memberInfo.work" class="property-item" style="position: absolute;right: 0;width: auto;">
					<view class="iconfont icon-wode"></view>
					<view>{{memberInfo.work}}</view>
				</view>
			</view>
			<view v-if="isShowSelect" @click.stop="select">
				<view v-if="!isSelect" class="iconfont icon-round select"></view>
				<view v-else class="iconfont icon-chenggong select"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import App from '@/common/js/app.js';
	let videoContext = null;
	export default {
		data() {
			return {
				isSelect: false,
				isVideoPlay: false,  //显示video组件
				videoId: '',
				isShowPlayBtn: false,  //显示播放按钮
			}
		},
		computed: {
			propertyInfo() {
				return {
					is_have_car: this.memberInfo.travel == 2,
					is_have_house: (this.memberInfo.live == 1 || this.memberInfo.live == 2),
					is_show_property: this.memberInfo.travel == 2 || (this.memberInfo.live == 1 || this.memberInfo.live == 2)
				}
			}
		},
		watch: {
			isVideoPlay() {
				videoContext = uni.createVideoContext(this.videoId, this)
				console.log(videoContext,'创建后')
			}
		},
		onReady() {
			this.videoId = this.memberInfo.id
			videoContext = uni.createVideoContext(this.videoId, this);
		},
		mounted() {
			this.isShowPlayBtn = this.isShowPlay
		},

		props: {
			// 是否显示浏览量
			isShowViews: {
				type: Boolean,
				default: true
			},
			// 是否可以选择
			isShowSelect: {
				type: Boolean,
				default: false
			},
			// 播放按钮
			isShowPlay: {
				type: Boolean,
				default: false,
			},
			// 会员信息
			memberInfo: {
				type: Object,
				default() {
					return {}
				}
			}
		},

		methods: {
			// 推荐点击
			extension() {
				this.$emit('extension',this.memberInfo.id)
			},
			
			// 选择
			select() {
				this.isSelect = !this.isSelect
				this.$emit('select',this.isSelect,this.memberInfo.id)
			},
			// 跳转去详情页面
			toDetail(type) {
				// 有视频时必须点信息区域才跳转，没有视频不要求
				if((this.isShowPlay && type === 'bottom') || !this.isShowPlay) {
					App.navigationTo({
						url: `pages/subPages2/blindDate/member/detail?id=${this.memberInfo.id}`
					})
				}
			},
			
			// 点击播放视频
			videoPlay(e) {
				let that = this;
				that.isVideoPlay = true;
				that.isShowPlayBtn = false
				//延时操作,防止视频组件获取失败
				setTimeout(() => {
					console.log("video play");
					console.log(videoContext,'videoContext2222')
					videoContext.play();
					// videoContext.requestFullScreen()
					
				}, 200);
			},
			
			// 退出或进入全屏
			fullscreenchange(e) {
				console.log(e,'全屏信息')
				if(!e.detail.fullScreen) {
					this.isVideoPlay = false
					this.isShowPlayBtn = true
				}
			},
			closeVideo(){
				this.isVideoPlay = false
				this.isShowPlayBtn = true
			}
		}

	}
</script>

<style lang="scss" scoped>
	.user-item {
		width: 335rpx;
		height: auto;
		border-radius: 20rpx;
		background-color: #F8F8F8;
		overflow: hidden;
		padding-bottom: 20rpx;
		.top-info {
			width: 100%;
			height: 445rpx;
			// height: 335rpx;
			position: relative;
			.poster,.video {
				width: 100%;
				height: 100%;
			}
			/deep/ .openvideo{
				width: 100vw;
				height: 100vh;
				position: fixed;
				top: 0;
				left: 0;
				z-index: 99999;
			}
			.videoClose{
				position: fixed;
				top: 30upx;
				right: 30upx;
				color: #ffffff;
				font-size: 50upx;
				font-weight: 700;
				z-index: 100000;
			}
			.istop {
				width: auto;
				height: 30rpx;
				padding: 0 10rpx;
				border-radius: 15rpx;
				background: linear-gradient(90deg, #FB5A8C 0%, #F65D10 100%);
				display: flex;
				position: absolute;
				left: 20rpx;
				top: 20rpx;
				color: #fff;
				font-size: 20rpx;
				align-items: center;
				justify-content: center;
				.iconfont {
					font-size: 20rpx;
				}
			}
			.play-btn {
				width: 80rpx;
				height: 80rpx;
				position: absolute;
				top: 184rpx;
				left: 128rpx;
			}
			.look-box {
				width: 60rpx;
				height: 68rpx;
				position: absolute;
				top: 20rpx;
				right: 16rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				.iconfont {
					font-size: 34rpx;
					color: #fff;
				}
				.num {
					font-size: 20rpx;
					color: #fff;
					margin-top: 6rpx;
				}
			}
			.operation {
				width: 50rpx;
				height: 50rpx;
				position: absolute;
				top: 20rpx;
				right: 20rpx;
			}
			.location {
				width: auto;
				height: 30rpx;
				padding: 0 10rpx;
				background-color: #fff;
				opacity: 0.8;
				border-radius: 10rpx;
				display: flex;
				color: #333;
				font-size: 20rpx;
				align-items: center;
				justify-content: center;
				position: absolute;
				bottom: 20rpx;
				right: 20rpx;
				.iconfont {
					font-size: 20rpx;
				}
			}
		}
		
		.user-info {
			width: 100%;
			height: auto;
			overflow: hidden;
			position: relative;
			.info {
				width: 100%;
				height: 45rpx;
				margin-top: 20rpx;
				display: flex;
				align-items: center;
				.name {
					height: 45rpx;
					width: 200rpx;
					font-size: 32rpx;
					color: #333;
					font-weight: bold;
					margin-left: 30rpx;
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
				.sex {
					width: 70rpx;
					height: 30rpx;
					border-radius: 15rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					color: #fff;
					margin-left: 20rpx;
					.iconfont {
						font-size: 22rpx;
					}
					.icon-female {
						transform: rotate(45deg);
					}
					.age {
						font-size: 20rpx;
					}
				}
				.woman {
					background-color: #FE83AF;
				}
				.man {
					background-color: #0084FF;
				}
			}
			.property {
				width: 100%;
				height: 40rpx;
				margin-top: 20rpx;
				display: flex;
				.property-item {
					width: 90rpx;
					height: 40rpx;
					border-radius: 20rpx;
					background-color: #fff;
					color: #333;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 20rpx;
					margin-right: 13rpx;
					.iconfont {
						font-size: 24rpx;
					}
				}
			}
			.select {
				font-size: 40rpx;
				position: absolute;
				right: 20rpx;
				bottom: 0;
			}
			.icon-round {
				color: #ccc;
			}
			.icon-chenggong {
				color: #FDAD28;
			}
		}
	}
	
	.item-select {
		box-sizing: border-box;
		border: 1rpx solid #FDAD28;
	}
</style>
