<template>
	<view class="img-list">
		<view class="img-navs">
			<view v-for="(item,index) in navList" :key="index" class="nav-btn" :class="{'check-nav':index===curNavIndex,'last-nav':index===navList.length-1}" @click="changeNav(index)">
				{{item.TagName||'其他'}}
			</view>
		</view>
		  <view class="img-list-box">
			<view v-for="(item,index) in dataList.TagPicList" :key="item.ID" class="img-list-item" :style="{'margin-right':index%2 ==0?'20rpx':0}">
				<view class="img-box" @click="previewImage(index,item.Path)" v-if="item.type==='image'">
					<image :src="item.Path" mode="aspectFill" ></image>
				</view>	
				<view class="img-box" style="position: relative" v-if="item.type==='video'">
					<video id="myVideo" :src="item.Path"
					:controls='controls' 
					:show-center-play-btn='false'
					:show-fullscreen-btn='false' 
					@fullscreenchange='videoControl'
					object-fit ='fill'
					></video>
					<!-- 播放按钮 --> 
					<view @click="enlarge"
						style="position: absolute;left: 50%;top: 50%;transform: translate(-50%,-50%);width: 98rpx;height: 98rpx;border-radius: 20rpx;background-color: rgba(255,255,255,.4);display: flex;align-items: center;justify-content: center;">
						<image
							src="https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Test/Upload/Goods/1616471847000_345.png"
							style="width: 37rpx;height: 44rpx;"></image>
					</view>
				</view>
			</view>
		  </view>
	</view>
</template>

<script>
	
	export default {
		data() {
			return {
				ID:0,
				navList:[],
				curNavIndex:0,
			    dataList:[],
				imgBaseUrl:"",
				controls:false,//显示默认控件
				videoContext:""
			}
		},
		watch:{
			curNavIndex(val){
				
			}
		},
		created() {
			uni.setNavigationBarTitle({
				title: "餐厅图片",
			});
		
		},
		onLoad(options) {
			if (options && options.id) {
				this.ID = options.id
				this.getDetail()
			}
		},
		methods: {
			//获取详情
			getDetail(index=0) {
				this.request2({
						url: '/api/AppletDining/GetDiningDetails',
						data: {
							ID: this.ID
						}
					},
					res => {
						if (res.resultCode == 1) {
							this.navList = res.data.AllPicList;
							this.dataList=res.data.AllPicList[index]
							this.dataList.TagPicList.forEach(item=>{
								if(item.Path.indexOf('jpg')!==-1||item.Path.indexOf('png')!==-1||item.Path.indexOf('jpeg')!==-1){
									item.type='image'
								}else if(item.Path.indexOf('mp4')!==-1){
									item.type='video'
								}
								
							})
							console.log(this.dataList)
						}
					}
				);
		    },
			changeNav(index){
				this.curNavIndex=index
				this.dataList=this.navList[index]
				this.dataList.TagPicList.forEach(item=>{
					if(item.Path.indexOf('jpg')!==-1||item.Path.indexOf('png')!==-1||item.Path.indexOf('jpeg')!==-1){
						item.type='image'
					}else if(item.Path.indexOf('mp4')!==-1){
						item.type='video'
					}
					
				})
			},
			//预览图片
			previewImage(i,url) {
				uni.previewImage({
					urls: [url],
					current: i,
					longPressActions: {
						itemList: ["发送给朋友", "保存图片", "收藏"],
						success: function(data) {
							console.log(data.errMsg);
						},
						fail: function(err) {
							console.log(err.errMsg);
						},
					},
				});
			},
			enlarge(file) {
				// 全屏
				this.videoContext = uni.createVideoContext('myVideo');
				this.videoContext.requestFullScreen({
					direction:0
				})
				
			},
			videoControl(e){
				// if(e.detail.fullScreen===false){
				// 	this.videoContext.stop()
				// 	this.controls=false
				// }else{
				// 	this.videoContext.play()
				// 	this.controls=true
				// }
				console.log(e.detail)
			},
	    }
	}
</script>

<style lang="scss" scoped>
	.img-list{
		.img-navs{
			display: flex;
			margin: 0 45rpx;
			padding: 20rpx 0;
			overflow-x: scroll;
			overflow-y: hidden;
			.nav-btn{
				// width: 230rpx;
				height: 60rpx;
				background-color: #FFFFFF;
				border: 1rpx solid #111111;
				border-radius: 20rpx;
				font-family: PingFang SC;
				font-weight: 500;
				text-align: center;
				line-height: 58rpx;
				padding: 0 20rpx;
				margin-right: 30rpx;
				white-space: nowrap;
			}
			.check-nav{
				background-color: #111111;
				color: #FFFFFF;
			}
			.last-nav{
				margin-right: 0 !important;
			}
		}
		.img-list-box{
			padding: 0 45rpx;
			display: flex;
			flex-wrap: wrap;
			.img-list-item{
				width: 315rpx;
				margin-bottom: 20rpx;
				.img-box{
					width: 315rpx;
					height: 315rpx;
					background-color: #E7E7E7;
					border-radius: 20rpx;
					overflow: hidden;
					image{
						width: 100%;
						height: 100%;
					}
					#myVideo{
						width: 100%;
						height: 100%;
					}
				}
			}
		}
	}
</style>
