<template>
	<view class="wrap">
		<view class='title'>库点监控管理</view>
		<view class="dropdown">
			<view class="left">仓库名称</view>
			<view class="right" @click='show1=true'>
				<view>{{warehouseName}}</view>
				<u-icon name="arrow-right" color=""></u-icon>
				<u-picker @confirm="warehousechange" range-key='warehouseName' mode="selector" v-model="show1"
					:range="warehouseList"></u-picker>
			</view>
		</view>
		<view class="content no-content" v-if="warehouseName!='山东诸城迈饶库'">暂无视频</view>
		<view class="content" v-if="warehouseName=='山东诸城迈饶库'">
			<view class='title'>监控视频</view>
			<view class="video-list">
				<view class=" cu-list grid col-4 no-border">
					<view class="cu-item" style='text-align:center;' v-for="(item,index) in videoList"
						@click="gridClick(item)">
						<view v-if="item.Status == 'ON'">
							<image v-if="item.SnapURL" :src="'https://live.eliangeyun.com'+item.SnapURL" class="sign1">
							</image>
							<view v-else style="background-color: #008000;" class="sign1">
								<image src="../../static/img/play-btn.png"
									style="width: 80rpx;height: 80rpx;margin-top: 40rpx;"></image>
							</view>
						</view>
					</view>
				</view>
				<!-- <iframe class='video-iframe' v-show="item.isPlay"  :src="item.src" width="" height="" allowfullscreen="true"
						webkitallowfullscreen="true" mozallowfullscreen="true"
						allow="autoplay; fullscreen; microphone;"></iframe> -->
			</view>
		</view>
	</view>
	</view>
</template>
<script>
	import {
		mapState
	} from 'vuex';

	export default {
		components: {

		},
		data() {
			return {
				show1: false,
				warehouseName: '',
				warehouseList: [],
				monitorUrl2: '',
				videoList: []
			}
		},

		onLoad() {

		},
		// #ifndef MP
		onNavigationBarButtonTap(e) {
			const index = e.index;
			if (index === 0) {
				this.navTo('/pages/set/set');
			} else if (index === 1) {
				// #ifdef APP-PLUS
				const pages = getCurrentPages();
				const page = pages[pages.length - 1];
				const currentWebview = page.$getAppWebview();
				currentWebview.hideTitleNViewButtonRedDot({
					index
				});
				// #endif
				uni.navigateTo({
					url: '/pages/notice/notice'
				})
			}
		},
		// #endif
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		onShow() {
			this.$api.doRequest('get', '/commonUser/api/checkSession').then(res => {
				console.log("checkSession", res)
				if (res.data.data == "INVALID") {
					uni.showModal({
						title: '登录提示',
						content: '当前登入信息验证失败，是否重新登录？',
						showCancel: true,
						confirmText: '登录',
						success: (e) => {
							if (e.confirm) {
								uni.navigateTo({
									url: '/pages/public/login'
								})
							}
						},
						fail: () => {},
						complete: () => {}
					})
				}
			})
			var that = this
			uni.request({
				url: 'https://live.eliangeyun.com/api/v1/device/channellist',
				method: 'GET',
				success: (res) => {
					if (res.statusCode === 200) {
						that.videoList = res.data.ChannelList
					}
				},
				fail: (res) => {
					console.log("fail::", res)
				}
			})
			this.$api.doRequest('get', '/openServiceInfo/selectCommonCompany', {
				phone: this.userInfo.phone
			}).then(res => {
				if (res.data.code == 200) {
					this.init(res.data.data[0].compId)
				}
			})
			console.log("hasLogin", this.hasLogin)
		},
		methods: {
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url) {
				if (!this.hasLogin) {
					url = '/pages/public/login';
				}
				uni.navigateTo({
					url
				})
			},
			init(compId) {
				console.log(this.userInfo)
				this.$api.doRequest('get', '/warehouseBaseInfo/selectWarehouseSelf', {
					compId: compId,
				}).then(res => {
					if (res.data.data.length != 0) {
						console.log('res', res.data.data)
						this.warehouseName = res.data.data[0].warehouseName
						let _showData = uni.getStorageSync("depotMonitoring")
						this.warehouseList = res.data.data;
						if (_showData) {
							this.warehouseName = _showData.warehouseName
						} else {
							this.warehouseName = res.data.data[0].warehouseName
						}

					} else {
						this.warehouseList = []
						this.warehouseName = '暂无仓库'
					}
				})

			},
			warehousechange(e) {
				this.warehouseName = this.warehouseList[e[0]].warehouseName
				console.log(this.warehouseName)
				uni.setStorageSync("depotMonitoring", this.warehouseList[e[0]])
			},
			gridClick(item) {
				var param = "https://live.eliangeyun.com/play.html?serial=" + item.DeviceID + "&code=" + item.ID +
					"&aspect=fullscreen"
				uni.setStorageSync("mintor", param)
				uni.navigateTo({
					url: '/pages/user/mintor'
				})
				console.log("param", param)
			}
		}
	}
</script>
<style lang='scss' scoped>
	page {
		background: #F5F6FA;
	}

	.cu-list>.cu-item:after {
		border: none;
	}

	.sign {
		width: 35px;
		height: 35px;
		top: 4px;
	}

	.sign1 {
		width: 76px;
		height: 76px;
		top: 4px;
	}

	.wrap {
		background: #fff;
		margin: 10px;
		border-radius: 10px;
		padding: 10px;

		.title {
			font-size: 16px;
			font-weight: 700;
		}

		.dropdown {
			display: flex;
			margin: 20rpx 0;
			justify-content: space-between;
			/* border-bottom: 1px solid #EEEEEE; */
			padding-bottom: 20rpx;

			.left,
			.right {
				display: flex;
				align-items: center;
			}
		}
	}

	.video-list {
		position: relative;

		.video-list-item {
			position: relative;
			height: 400rpx;
			margin: 20rpx 0;

			.img-content {
				position: relative;
				width: 100%;
				height: 400rpx;
				background: green;

				.play {
					position: absolute;
					width: 100rpx;
					height: 100rpx;
					top: 0;
					bottom: 0;
					left: 0;
					right: 0;
					margin: auto;
					z-index: 3;
				}
			}

			.img {}

			.video-iframe {
				position: absolute;
				width: 100%;
				height: 100%;
				z-index: 1;
				border: 0;
			}
		}
	}

	.no-content {
		text-align: center;
	}
</style>
