<template>
	<view>
		<view class="flex-direction justify-between align-center text-center lf-p-t-30 lf-p-b-30" style="height: 340rpx;position: relative;">
			<view>
				<image :src="userInfo.avatar" mode="aspectFill" style="width: 200rpx;height: 200rpx;border-radius: 50%;border: 2rpx solid #FFFFFF;" @click="lookImg('')"></image>
			</view>
			<view class="lf-font-36 align-center text-center text-white lf-m-t-30 flex justify-center">
				<text>{{userInfo.nickname}}</text>
				<text class="user-label"v-if="userInfo.verifier == 1">核销员</text>
			</view>
			<image class="bg-img" :src="userInfo.avatar" mode="aspectFill" style="filter: blur(3px);"></image>
		</view>
		<view class="list">
			<view class="lf-row-between list-item" hover-class="lf-opacity" @click="$url('/pages/order/order')">
				<view class="lf-row-center">
					<image class="icon-img" src="../../static/center/order.png"></image>
					<text class="lf-text-vertical lf-m-l-20 lf-font-28 lf-color-black">我的订单</text>
				</view>
				<view>
					<text class="lf-iconfont lf-icon-xiangyou lf-text-vertical"></text>
				</view>
			</view>
			<view class="lf-row-between list-item" hover-class="lf-opacity" @click="$url('/pages/message/index')">
				<view class="lf-row-center">
					<image class="icon-img" src="../../static/center/message.png"></image>
					<text class="lf-text-vertical lf-m-l-16 lf-font-28 lf-color-black">消息中心</text>
				</view>
				<view>
					<text class="lf-iconfont lf-icon-xiangyou lf-text-vertical"></text>
				</view>
			</view>
			<view class="lf-row-between list-item" hover-class="lf-opacity">
				<view class="lf-row-center">
					<image class="icon-img" src="../../static/center/feedback.png"></image>
					<text class="lf-text-vertical lf-m-l-16 lf-font-28 lf-color-black">意见反馈</text>
				</view>
				<view>
					<text class="lf-iconfont lf-icon-xiangyou lf-text-vertical"></text>
				</view>
				<button class="feedback-btn" open-type="feedback"></button>
			</view>
			<view class="lf-row-between list-item" hover-class="lf-opacity" @click="$url('/pages/collect/index')">
				<view class="lf-row-center">
					<image class="icon-img" src="../../static/center/collect.png"></image>
					<text class="lf-text-vertical lf-m-l-16 lf-font-28 lf-color-black">我的收藏</text>
				</view>
				<view>
					<text class="lf-iconfont lf-icon-xiangyou lf-text-vertical"></text>
				</view>
			</view>
			<view class="lf-row-between list-item" hover-class="lf-opacity" @click="$url('/pages/about/index')">
				<view class="lf-row-center">
					<image class="icon-img" src="../../static/center/about.png"></image>
					<text class="lf-text-vertical lf-m-l-16 lf-font-28 lf-color-black">关于我们</text>
				</view>
				<view>
					<text class="lf-iconfont lf-icon-xiangyou lf-text-vertical"></text>
				</view>
			</view>
			<view class="lf-row-between list-item" hover-class="lf-opacity">
				<view class="lf-row-center">
					<image class="icon-img" src="../../static/center/service.png"></image>
					<text class="lf-text-vertical lf-m-l-16 lf-font-28 lf-color-black">联系客服</text>
				</view>
				<view>
					<text class="lf-iconfont lf-icon-xiangyou lf-text-vertical"></text>
				</view>
				<button class="feedback-btn" open-type="contact"></button>
			</view>
		</view>
		<!-- 商家工具 -->
		<view class="shop-list" v-if="userInfo.is_verify == 1">
			<view class="lf-row-between">
				<view class="lf-font-36 lf-font-bold">商家工具</view>
			</view>
			<view class="lf-row-between list-item" hover-class="lf-opacity" @click="chargeOff">
				<view class="lf-row-center">
					<image class="icon-img" src="../../static/center/scan.png"></image>
					<text class="lf-text-vertical lf-m-l-16 lf-font-28 lf-color-black">卡券核销</text>
				</view>
				<view>
					<text class="lf-iconfont lf-icon-xiangyou lf-text-vertical"></text>
				</view>
			</view>
		</view>
		
		<view class="lf-p-t-35" style="background-color: #F6F6F6;">
			<!-- <view class="lf-p-t-40 lf-p-b-20 text-center details-title">
				
				<view class="lf-font-32 details-text flex justify-between align-center text-center" style="color: #222;position: relative;left: 270rpx;">
					<view class="rhombus lf-m-l-30"></view>
					<view>为你推荐</view>
					<view class="rhombus lf-m-r-30"></view>
				</view>
			</view> -->
			<lf-title-line title="为你推荐"></lf-title-line>
			<lf-waterfall :list="list" ref="uWaterfall"></lf-waterfall>
			<view class="loading-more">
				<text :class="{'loading-more-text': loading_class}" v-if="list.length">{{ loading_text }}</text>
				<lf-nocontent v-else></lf-nocontent>
			</view>
		</view>
		<!-- 回到顶部 -->
		<u-back-top :scroll-top="pageScrollTop" :custom-style="{background: 'rgba(51, 51 51, 0.3)'}"></u-back-top>
	</view>
</template>

<script>
	import lfWaterfall from '@/components/lf-waterfall-my/lf-waterfall.vue';
	import lfTitleLine from '@/components/lf-title-line/lf-title-line.vue';
	let time = null;
	export default {
		components: {
			lfTitleLine,
			lfWaterfall
		},
		data() {
			return {
				loading_class: false,
				loading_text: '已加载全部数据~',
				list: [],
				page: 1,
				isPage: false,
				showLogin: true,
				userInfo: {
					avatar: '',
					nickname:'',
					id: ''
				}
			}
		},
		computed: {
			hidePhone(){
				return function(tel){
					if(tel.length == 11){
						var reg = /^(\d{3})\d{4}(\d{4})$/;
						var new_phone = tel.replace(reg, "$1****$2");
						return new_phone;
					}else{
						return tel;
					}
				}
			},
			isRight(){
				return function(val){
					return this.$shared.isRight(val);
				}
			}
		},
		methods: {
			// 卡券核销
			chargeOff(){
				uni.scanCode({
					complete: result => {
						console.log("resuly", result)
						if(result.errMsg == 'scanCode:ok'){
							let content = result.result; // 核销码
							this.$http(this.API.API_CONFIRM_CODE, {verify_code: content}).then(res => {
								this.$msg('核销成功!');
							});
						}
					}
				})
			},
			// 检查当前用户登录状态
			verifyUserInfo(){
				let userInfo = uni.getStorageSync('userinfo') || {};
				if(!userInfo.id || !userInfo.nickname || !userInfo.avatar){
					if(this.showLogin){
						this.showLogin = false;
						this.$url('/pages/login/index?type=userinfo');
					}else{
						this.showLogin = true;
						this.$url('/pages/index/index', {type: 'switch'});
					}
				}
			},
			getUserInfo() {
				this.$http(this.API.API_SETUSDRINFO).then(res => {
					this.userInfo = res.data
				}).catch(err => {})
			},
			getRecommond() {
				this.$http(this.API.API_RECOMMOND,{page: this.page}).then(res => {
					let isPage = res.data.next_page_url == null?false:true;
					this.isPage = isPage;
					if(!isPage){
						this.loadingClass = false;
						this.loadingText = '没有更多数据啦~';
					}
					if(this.page == 1){
						this.list = res.data.data;
					}else{
						this.list.push(...res.data.data);
					}
					uni.stopPullDownRefresh();
					console.log(this.list)
				}).catch(err => {
					
				})
			},
			// 预览图片
			lookImg(img){
				this.$u.throttle(() => {
					uni.previewImage({
						urls: [img]
					})
				}, 200);
			},
		},
		onReachBottom(){
			if(this.isPage){
				this.page = this.page + 1;
				this.getRecommond();
			}
		},
		onShow() {
			this.verifyUserInfo()
			this.getRecommond()
			this.getUserInfo()
		}
	}
</script>

<style lang="scss">
	.user-label{
		display: inline-block;
		font-size: 24rpx;
		color: #FFFFFF;
		background-color: #1E89FF;
		padding: 4rpx 16rpx;
		border-radius: 30rpx;
		margin-left: 8rpx;
	}
	.rhombus{
		width: 16rpx;
		height: 16rpx;
		transform: rotateZ(45deg);
		background: #222;
	}
	.details-title {
		position: relative;
	
		&::after {
			position: absolute;
			left: 144rpx;
			top: 60rpx;
			content: '';
			width: 69%;
			height: 1rpx;
			border-bottom: 1rpx solid rgba(0, 0, 0, 0.08)
		}
	
		.details-text {
			position: relative;
			// display: inline-block;
			width: 264rpx;
			background-color: #f5f5f9;
			z-index: 9;
		}
	}
	.list{
		margin-top: 20rpx;
		padding: 0 32rpx;
		background-color: #FFFFFF;
		width: 100%;
		height: auto;
	}
	.list-item{
		border-bottom: 1rpx solid #EEEEEE;
		height: 110rpx;
		box-sizing: border-box;
		position: relative;
		.icon-img{
			width: 50rpx;
			height: 50rpx;
		}
		.feedback-btn{
			position: absolute;
			width: 100%;
			height: 100%;
			z-index: 1;
			background: transparent;
		}
		&:last-child{
			border-bottom: none;
		}
	}
	.bg-img{
		width: 230%;
		height: 230%;
		position: absolute;
		top: 0;
		left: 0;
		z-index: -1;
		filter: blur(14rpx);
	}
	.shop-list{
		margin-top: 20rpx;
		width: 750rpx;
		height: auto;
		background-color: #FFFFFF;
		padding: 0 32rpx;
		padding-bottom: 0;
		box-sizing: border-box;
	}
</style>
