<template>
	<view class="content">
		<view style="height: 20rpx;"></view>
		<u-search placeholder="景区/关键词搜索" v-model="search" :clearabled="true" @search="query" :show-action="true"
			action-text="搜索" :animation="true"></u-search>
		<!-- <view class="swiper">
			<u-swiper :list="list" height="380"></u-swiper>
		</view> -->
		<view class="title">
			<view class="shuxian"></view>
			<view>我的VLOG视频</view>
		</view>
		<navigator url="../myVlog/myVlog">
			<view class="photoGallery">
				<image class="img" src="../../../static/img/vlog/icon/bg1.png"></image>
				<view class="access"></view>
				<view class="btnn">
					<image src="../../../static/img/vlog/icon/icon_clicktoenter.png"></image>
					<view>
						点击进入
					</view>
				</view>
			</view>
		</navigator>
		<view class="title">
			<view class="shuxian"></view>
			<view>我的DIY影集</view>
		</view>
		<navigator url="../product/product">
			<view class="photoGallery">
				<image class="img" src="../../../static/img/vlog/icon/bg2.png"></image>
				<view class="access"></view>
				<view class="btnn">
					<image src="../../../static/img/vlog/icon/icon_clicktoenter.png"></image>
					<view>
						点击进入
					</view>
				</view>
			</view>
		</navigator>
		<view class="title" v-if="scenicList.length>0">
			<view class="shuxian"></view>
			<view>景区VLOG样片</view>
		</view>
		<view class="row">
			<block v-for="(item,index) in scenicList" :key="index">
				<navigator :url="'../scenicList/scenicList?productUrl='+item.productUrl+'&thumbImageUrl='+item.thumbImageUrl+'&merchantName='+item.merchantName" class="item">
					<image class="fengmian" :src="item.thumbImageUrl"></image>
					<text>{{item.merchantName}}</text>
				</navigator>
			</block>
		</view>
		<view class="bottom">
			<image src="../../../static/img/vlog/icon/bottom.png"></image>
			<navigator url="../vlogface/vlogface">
				<view class="paizhao">
					<image src="../../../static/img/vlog/icon/icon_scan.png"></image>
					<view style="width: 100%;text-align: center;margin-top:10rpx;color: #FFFFFF;">获取Vlog</view>
				</view>
			</navigator>
		</view>

	</view>
</template>
<script>
	export default {
		data() {
			return {
				userInfo: "", //用户信息
				scenicList: [], //景区列表
				search: "", //景区
				list: [{
						image: '../../../static/img/vlog/swipe/swipe1.jpg'
					},
					{
						image: '../../../static/img/vlog/swipe/swipe2.jpg'
					},
					{
						image: '../../../static/img/vlog/swipe/swipe3.jpg'
					}
				],
			}
		},
		onLoad() { //代替 vue 里面的 created
			this.getUserInfo() //获取用户信息
			this.getScenicList() //获取景区列表
			this.openCamera() //打开权限
		},
		onReady() { //代替 vue 里面的 mounted
		},
		methods: {
			getUserInfo() { //获取用户信息
				this.$request('wechatUser/wxUser/findWxUser', {
						openid: uni.getStorageSync("openid")
					})
					.then((res) => {
						if (res.code === "00") { //请求成功
							this.userInfo = res.data
							if (this.userInfo.isVlog === 0) { //未注册
								this.vlogRegister()
							} else {
								console.log("用户已注册");
							}
						} else {
							uni.showModal({
								content: res.message,
								showCancel: false
							})
						}
					})
			},
			getScenicList() { //景区列表查询
				let data = {
					merchantId:"a124Jj6IYiSzCjVV"
				}
				this.$request("scenic/user/merchant/merchantVlogList", data).then(res => {
					if (res.code === "00") { //请求成功
						this.scenicList=res.data.filter((item)=>{
							return item.isPublic===1
						})
					} else {
						uni.showModal({
							content: res.message,
							showCancel: false
						})
					}
				})
			},
			vlogRegister() { //用户注册
				let data = {
					"nickName": this.userInfo.nickname.substr(0,10), //昵称
					"userId": this.userInfo.openid, //用户id(用微信openid)
					"phone": 17347895200, //手机
					"outUserId": this.userInfo.openid, //用户Id,	//外部应用id(用微信openid)
					"userType": "WECHAT", //ALIPAY-支付宝小程序，WECHAT-微信小程序，OTHER-其他
					"gender": this.userInfo.gender //0-男，1-女
				}
				this.$request("distribution/vlog/vlogRegister", data).then(res => { //注册
					if (res.code === "00") {
						let data = {
							userId: uni.getStorageSync("openid"),
							action: "VLOG_DOWNLOAD"
						}
						this.$request("distribution/vlog/backflow", data).then(res => { //埋点
							if (res.code === "00") {
							}
						})
					}
				})
			},
			openCamera() { //用户首次进入打开权限
				uni.authorize({ //摄像头
					scope: 'scope.camera',
					success: (res) => {
					},
					fail: (res) => {
						uni.showModal({
							content: '检测到您没打开摄像头权限，是否去设置打开？',
							confirmText: "确认",
							cancelText: '取消',
							success: (res) => {
								if (res.confirm) {
									uni.openSetting({
										success: (res) => {
											console.log(res);
										},
										fail: (err) => {
											console.log(err);
										}
									})
								} else {
									uni.navigateBack({
										delta: 1
									})
								}
							}
						})
					}
				})
				uni.authorize({
					scope: 'scope.writePhotosAlbum',
					success: (res) => {
					},
					fail: (res) => {
						uni.showModal({
							content: '检测到您没打开相册权限，是否去设置打开？',
							confirmText: "确认",
							cancelText: '取消',
							success: (res) => {
								if (res.confirm) {
									uni.openSetting({
										success: (res) => {
											console.log(res);
										},
										fail: (err) => {
											console.log(err);
										}
									})
								} else {
									uni.navigateBack({
										delta: 1
									})
								}
							}
						})
					}
				})
			},
			query() { //查询
			}

		}
	}
</script>
<style lang="scss" scoped>
	.content {
		padding: 0 20rpx;
		box-sizing: border-box;
		margin: 0 auto;

		.swiper {
			margin-top: 20rpx;
		}

		.title {
			margin-top: 40rpx;
			display: flex;
			align-items: center;

			.shuxian {
				height: 30rpx;
				width: 5rpx;
				background-color: #3688FF;
				margin-right: 20rpx;
			}

			view {
				font-weight: bold;
			}
		}

		.photoGallery {
			height: 180rpx;
			border-radius: 10rpx;
			background-color: #212B44;
			margin-top: 20rpx;
			position: relative;

			.img {
				width: 100%;
				height: 100%;
				border-radius: 10rpx;
			}

			.access {
				width: 100%;
				height: 100%;
				position: absolute;
				background-color: #000000;
				top: 0;
				opacity: 0.3;
				border-radius: 10rpx;
			}

			.btnn {
				display: flex;
				justify-content: center;
				align-items: center;
				color: #fff;
				position: absolute;
				left: 50%;
				top: 50%;
				transform: translate(-50%, -50%);
				font-weight: bold;
				font-size: 32rpx;

				image {
					width: 40rpx;
					height: 40rpx;
					margin-right: 10rpx;
				}
			}
		}

		.row {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;
			margin-top: 20rpx;
			padding-bottom: 250rpx;

			.item {
				width: 49%;
				height: 200rpx;
				margin-top: 15rpx;
				position: relative;

				.fengmian {
					width: 100%;
					height: 100%;
					border-radius: 10rpx;
				}
			}
		}

		.bottom {
			width: 100%;
			position: fixed;
			bottom: 0;
			right: 0rpx;

			image {
				width: 100%;
				height: 100rpx;
				position: fixed;
				bottom: 0;
			}

			.paizhao {
				width:100%;
				z-index: 1;
				position: absolute;
				bottom: 15rpx;
				display: flex;
				flex-wrap: wrap;
				justify-content: center;
				image {
					height:160rpx;
					width:160rpx;
					position: relative;
					top: 30rpx;
				}
			}
		}
	}
</style>
