<template>
	<view class="container club-visit">
		<tui-skeleton
			v-if="skeletonShow"
			backgroundColor="#fafafa"
			borderRadius="10rpx"
			:isLoading="true"
			:loadingType="5"
		></tui-skeleton>
		<template v-else>
			<view class="visit-content clearfix">
				<view class="info-title">{{ listQuery.accessDate }}</view>
				<view class="info-main" v-for="(visit, index) in list" :key="index">
					<view class="info-p">访问时间：<text>{{ visit.accessNewTime }}</text></view>
					<view class="info-p">页面类型：<text>{{ visit.pageType ? visit.pageType : '--' }}</text></view>
					<view class="info-p">页面标签：<text>{{ visit.pageLabel ? visit.pageLabel : '--' }}</text></view>
					<view class="info-p">商品名称：<text>{{ visit.productName ? visit.productName  : '--'  }}</text></view>
					<view class="info-p">商品图片： <text v-if="!visit.productImage">--</text></view>
					<view class="info-img" v-if="visit.productImage"><image :src="visit.productImage" alt=""/></view>
					<view class="info-p">访问来源：<text>{{ visit.accessSource | accessSourceFilters }}</text></view>
					<view class="info-p">访问客户端：<text>{{ visit.accessClient | accessClientFilters }}</text></view>
					<view class="info-p">访问时长：<text>{{ visit.accessDuration }}</text></view>
				</view>
				<!--加载loadding-->
				<tui-loadmore :visible="loadding" :index="3" type="black"></tui-loadmore>
				<tui-nomore :visible="!pullUpOn" :backgroundColor="'#F7F7F7'" :text="nomoreText"></tui-nomore>
				<!--加载loadding-->
			</view>
		</template>
		<!-- 侧边 -->
		<view class="scrollTop" :style="{bottom:'150rpx'}">
			<view class="icon top" @click="onPageScrollTop" :class="isScrollTop ? 'show' : 'none'">
				<text class="iconfont icon-zhiding"></text>
			</view>
		</view>
	</view>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
import authorize from '@/common/config/authorize.js'
import wxLogin from '@/common/config/wxLogin.js'

export default {
	data() {
		return {
			skeletonShow: true,
			isScrollTop:false,
			nomoreText: '上拉显示更多',
			hasNextPage: false,
			loadding: false,
			pullUpOn: true,
			pullFlag: true,
			listQuery:{
				clubId:0,
				accessDate:'',
				ip:'',
				pageNum:1,
				pageSize:10
			},
			list:[] ,
		}
	},
	filters: {
		accessClientFilters(value) {
		  // 访问客户端
		  const map = {
			'0': '网站',
			'1': '小程序'
		  }
		  return map[value]
		},
		accessSourceFilters(value) {
		  // 访问来源
		  if(!value) return '--'
		  const map = {
			'0': '直接访问',
			'1': '百度搜索',
			'2': '360搜索',
			'3': '谷歌搜索',
			'4': '神马搜索',
			'5': '头条搜索',
			'6': '搜狗搜索',
			'7': '直接访问'
		  }
		  return map[value]
		}
	},
	computed: {},
	onLoad(option) {
		this.listQuery.clubId = option.clubId
		this.listQuery.accessDate = option.accessDate
		this.listQuery.ip = option.ip
		this.getClubRecordDetail()
		setTimeout(() => {
			this.skeletonShow = false
		}, 1000)
		this.listQuery
	},
	methods: {
		getClubRecordDetail() {
			//获取记录详情
			this.listQuery.pageNum = 1
			this.UserService.userClubRecordDetail(this.listQuery)
				.then(response => {
					let data = response.data
					if (data.list && data.list.length > 0) {
						this.hasNextPage = response.data.hasNextPage
						this.list = data.list
						this.pullFlag = false
						setTimeout(() => {
							this.pullFlag = true
						}, 500)
						if (this.hasNextPage) {
							this.pullUpOn = false
							this.nomoreText = '上拉显示更多'
						} else {
							this.pullUpOn = true
							this.loadding = false
							this.nomoreText = '已至底部'
						}
					}
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		getOnReachBottomData() {
			this.listQuery.pageNum += 1
			this.UserService.userClubRecordDetail(this.listQuery)
				.then(response => {
					let data = response.data
					if (data.list && data.list.length > 0) {
						this.hasNextPage = response.data.hasNextPage
						this.list = this.list.concat(data.list)
						this.pullFlag = false // 防上拉暴滑
						setTimeout(() => {
							this.pullFlag = true
						}, 500)
						if (this.hasNextPage) {
							this.pullUpOn = false
							this.nomoreText = '上拉显示更多'
						} else {
							this.pullUpOn = false
							this.loadding = false
							this.nomoreText = '已至底部'
						}
					}
				})
				.catch(error => {
					this.$util.msg(error.msg, 2000)
				})
		},
		onPageScrollTop(){
			uni.pageScrollTo({
			    scrollTop: 0,
			    duration: 600
			})
		},
	},
	onPullDownRefresh() {
		setTimeout(() => {
			this.getClubRecordDetail()
			uni.stopPullDownRefresh()
		}, 200)
	},
	onReachBottom() {
		if (this.hasNextPage) {
			this.loadding = true
			this.pullUpOn = true
			this.getOnReachBottomData()
		}
	},
	onPageScroll(e) {
		//实时获取到滚动的值
		if (e.scrollTop > 800) {
			this.isScrollTop = true
		} else {
			this.isScrollTop = false
		}
	},
	onShow() {}
}
</script>

<style lang="scss">
page {
	height: auto;
}
.club-visit {
	width: 100%;
	.visit-content {
		width: 100%;
		height: auto;
		float: left;
		box-sizing: border-box;
		.info-title {
			width: 100%;
			padding: 24rpx 24rpx 0 24rpx;
			position: relative;
			line-height: 48rpx;
			font-size: 40rpx;
			color: #333;
			font-weight: bold;
		}
		.info-main {
			width: 100%;
			height: auto;
			padding: 20rpx 0;
			margin-bottom: 24rpx;
			border-bottom: 30rpx solid #f5f5f5;
			&:last-child {
				border-bottom: none;
			}
			.info-p {
				width: 100%;
				box-sizing: border-box;
				padding: 0 24rpx;
				position: relative;
				line-height: 66rpx;
				font-size: 30rpx;
				color: #999999;
				text-overflow: ellipsis;
				overflow: hidden;
				display: -webkit-box;
				-webkit-line-clamp: 1;
				line-clamp: 1;
				-webkit-box-orient: vertical;
				text {
					color: #333333;
				}
			}
			.info-img {
				width: 200rpx;
				height: 200rpx;
				image {
					width: 200rpx;
					height: 200rpx;
					display: block;
					margin-left: 24rpx;
					border: 1px dashed #e2e2e2;
				}
			}
		}
	}
}
.scrollTop{
	width: 80rpx;
	height: 100rpx;
	position: fixed;
	right: 20rpx;
	z-index: 99;
	.icon{
		width: 80rpx;
		height: 80rpx;
		border-radius: 50%;
		float: left;
		margin: 10rpx 0;
		line-height: 80rpx;
		text-align: center;
		.contact-btn{
			width: 80rpx;
			height: 80rpx;
			background-color: rgba(0,0,0,0);
			line-height: 80rpx;
			.iconfont{
				font-size: $font-size-44;
				color: #FFFFFF;
			}
		}
		&.top{
			background-color: rgba(0,0,0,0.4);
			&.show{
				opacity: 1;
			}
			&.none{
				opacity: 0;
			}
		}
		.iconfont{
			font-size: $font-size-44;
			color: #FFFFFF;
		}
	}
	}
</style>
