<template>
	<view class="page">
		<!-- <view class="navBox">
			<view v-for="(item,index) in navList" :key="index">
				<view class="nav">
					{{item.name}}
				</view>
			</view>	
		</view> -->
		<u-tabs :list="navList" :is-scroll="false" :current="current" @change="change" :active-color="mainColor">
		</u-tabs>
		<view class="visitBox">
			<view class="visit">
				<view class="num">
					{{allVisit}}
				</view>
				<view class="name">
					总浏览量
				</view>
			</view>
			<view class="visit">
				<view class="num">
					{{todayVisit}}
				</view>
				<view class="name">
					今日访客
				</view>
			</view>
			<view class="visit">
				<view class="num">
					{{todayVisit}}
				</view>
				<view class="name">
					今日浏览量
				</view>
			</view>
		</view>
		<u-empty v-if="visitorData.length == 0" text="暂无访问记录" mode="list"></u-empty>
		<view v-if="visitorData.length > 0" style="
		    height: calc(100vh-160rpx-80rpx);
		    width: calc(100vw);
		    overflow: hidden;
		    padding-bottom: 50px;
		   ">
			<scroll-view :scroll-y="true" :enable-back-to-top="true" :enable-flex="true" @scrolltolower="lower"
				:style="{ height: '100%' }">
				<view v-for="(item,index) in visitorData" :key="index">
					<view class="itemBox">
						<view class="date">
							{{item.DateStr}}
						</view>
						<view v-if="item.List" v-for="(subItem,subIndex) in item.List" :key="subIndex">
							<view class="subItemBox">
								<view class="avaBox">
									<image class="avatar" src="subItem.Photo"></image>
									<image class="sex" src="sex[subItem.Sex]"></image>
								</view>
								
								
								<view class="rightBox">
									<view class="infoBox">
										<view class="name">
											{{subItem.UserName}}
										</view>
										<view class="time">
											{{subItem.CreateDateHour}}访问了你的自画像
										</view>
									</view>
									<view class="icon"> </view>
								</view>
							</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" :load-text="loadText" :font-size="24" :margin-top="20" :margin-bottom="20"
					bg-color="#FFF" />
			</scroll-view>
		</view>
		<!-- 加载中 -->
		<view class="loading" v-if="loading">
			<u-loading mode="flower" size="48"></u-loading>
			<Text style="color: #fff; margin-top: 10rpx;">加载中...</Text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				pageTitle: "访客",
				sex:{0:"https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/basic-nv.png",1:"https://viitto-1301420277.cos.ap-chengdu.myqcloud.com/Static/basic-nan.png"},
				msg: {
					pageIndex: 1,
					pageSize: 10,
					VsisitorType: 1,
					Status: -1
				},
				pageCount: 0,
				mainColor: "",
				secondary: '',
				pricecolor: '',
				navList: [{
					name: "谁看过我"
				}, {
					name: "我看过谁"
				}],
				current: 0,
				allVisit: 100, //总浏览量
				todayVisit: 1, //今日访客,今日浏览量
				visitorData: [],
				loading: false,
				status: "loadmore",
				loadText: {
					loadmore: "轻轻上拉，加载更多",
					loading: "努力加载中",
					nomore: "没有更多了",
				},
			}
		},
		methods: {
			change(index) {
				this.current = index;
			},
			getMiaiMessageVisitorStatistics() {
				this.request2({
						url: '/api/AppletMiai/GetMiaiMessageVisitorStatistics',
						data: {}
					},
					res => {
						if (res.resultCode == 1) {
							this.allVisit = res.data.TCount
							this.todayVisit = res.data.PeopleNum
						}
					}
				);
			},
			getMiaiMessageVisitorPageList() {
				this.request2({
						url: '/api/AppletMiai/GetMiaiMessageVisitorPageList',
						data: this.msg
					},
					res => {
						if (res.resultCode == 1) {
							this.loading = false;
							this.handleDate(res.data.pageData,"CreateDateDay")
							// this.visitorData = this.visitorData.concat(data);
							this.pageCount = res.data.pageCount
						}
					}
				);
			},
			handleDate(array,date){
				let newArr=array.reduce((results, item) => {
				  const current = results.find(i => i.date === item.date);
				  if (current) {
				    for (let property in item) {
				      if (property !== date) {
				        current[property] = item[property];
				      }
				    }
				  } else {
				    results.push({...item});
				  }
				  return results;
				}, []);
				console.log(newArr)
			},
			lower(e) {
				console.log(e)
				if (this.msg.pageIndex < this.pageCount) {
					this.msg.pageIndex++;
					this.status = "loading";
					this.getMiaiMessageVisitorPageList();
				} else {
					this.status = "nomore";
				}
			},
		},
		created() {
			this.mainColor = this.$uiConfig.mainColor;
			this.secondary = this.$uiConfig.secondary;
			this.pricecolor = this.$uiConfig.pricecolor;
		},
		mounted() {
			this.getMiaiMessageVisitorStatistics()
			this.getMiaiMessageVisitorPageList()
			uni.setNavigationBarTitle({
				title: this.pageTitle,
			});
		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding: 0 30rpx;
	}

	.navBox {
		width: 100%;
		height: 115rpx;
		// display: flex;
		// justify-content: space-around;
		// align-items: center;

		.nav {
			width: 170rpx;
			height: 56rpx;
			border-radius: 28rpx;
			font-size: 28rpx;
			font-weight: 500;
			color: #888888;
			text-align: center;
		}
	}

	.visitBox {
		height: 160rpx;
		display: flex;
		justify-content: space-around;
		align-items: center;

		.visit {
			width: 115rpx;
			height: 72rpx;

			.num {
				text-align: center;
				font-size: 40rpx;
				font-weight: bold;
				color: #111111;
			}

			.name {
				text-align: center;
				font-size: 22rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #888888;
			}
		}
	}

	.itemBox {
		.date {
			font-size: 26rpx;
			font-weight: 500;
			color: #111111;
			margin-top: 40rpx;
		}

		.subItemBox {
			height: 140rpx;
			display: flex;
			align-items: center;

			.avaBox{
				position: relative;
				.avatar {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					background-color: #00BFFF;
					margin-right: 30rpx;
				}
				.sex{
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					position:absolute;
					right: 0;
					bottom: 0;
				}
			}
			

			.rightBox {
				flex-grow: 5;
				display: flex;
				justify-content: space-between;
				align-items: center;
				height: 100%;
				border-bottom: 1rpx solid #E2E2E2;

				.infoBox {
					.name {
						margin-bottom: 5rpx;
						font-size: 30rpx;
						font-weight: 800;
						color: #000000;
					}

					.time {
						font-size: 24rpx;
						font-weight: 500;
						color: #888888;
					}
				}

				.icon {
					width: 30rpx;
					height: 6rpx;
					background-color: #000000;
				}
			}
		}
	}
</style>
