<!-- 进出记录 -->
<template>
	<view class="accessRecord">
		<view class="title">
			<view v-for="(item,index) in statisticsData" :key="index">
				<view>{{item.num}}</view>
				<view>{{item.name}}</view>
			</view>
		</view>
		<scroll-view scroll-y @scrolltolower="scrollGet" 
		style="padding-bottom:20rpx;flex:1;overflow-y: scroll;">
			<view class="list" v-for="(item,index) in dataList" :key="index">
				<view class="list-t">{{item.showInTime}}</view>
				<view class="list-b" v-for="(item2,index2) in item.list" :key="index2">
					<view class="list-b-t">
						<img v-if="item2.avatar" :src="baseUrl+item2.avatar">
						<img v-else :src="imagesUrl('commonality/icon_01.png')">
						<view>{{item2.userName}}</view>
						<view>{{item2.phone}}</view>
						<view
							:class="item2.accessStatus==1?'color-A':(item2.accessStatus==2?'color-B':(item2.accessStatus==3?'color-C':''))">
							{{item2.accessStatusStr}}
						</view>
					</view>
					<img class="list-b-img" :src="imagesUrl('commonality/for_min_bg.png')">
					<view class="list-b-b">
						<view>签到时间：{{item2.inTime?item2.inTime:'-'}}</view>
						<view>离开时间：{{item2.outTime?item2.outTime:'-'}}</view>
						<view>停留时间：{{item2.hoursMinutes?item2.hoursMinutes:'-'}}</view>
					</view>

				</view>
			</view>
		</scroll-view>
		<view v-if="!dataList[0]" style="text-align: center;line-height:300rpx;color:#999;">暂无数据</view>
	</view>
</template>

<script>
	import {
		config
	} from '@/api/request/config.js'
	import {
		laboratoryAppletPassOutList,
		laboratoryAppletPassOutCount
	} from '@/pages_basics/api/index.js'
	export default {
		name: "accessRecord",
		props: {
			subjectData: {},
		},
		data() {
			return {
				baseUrl: config.base_url,
				statisticsData: [{
						name: '当前实验人数',
						num: '0'
					},
					{
						name: '今日累计人次',
						num: '0'
					},
					{
						name: '当月累计人次',
						num: '0'
					},
				],
				newData: {

				},
				dataList: [],
				// 查询参数
				queryParams: {
					page: 1,
					pageSize: 10,
					subId: '',
				},
				total: 0,
				getDataType: false,
			}
		},
		created() {

		},
		beforeMount() {
			uni.$on('onReachBottom', () => { // 监听上拉加载
				console.log("到达底部，onReachBottom")
				this.scrollGet();
			})
			uni.$on('onPullDownRefresh', () => { // 监听下拉刷新
				console.log("进行了上拉刷新，onPullDownRefresh")
			})
		},
		mounted() {
			this.$set(this.queryParams, 'subId', this.subjectData.subId);
			this.laboratoryAppletPassOutCount();
			this.getList();
		},
		methods: {
			//滚动加载事件
			scrollGet() {
				if (this.total / this.queryParams.pageSize <= this.queryParams.page) {
					this.$set(this, 'getDataType', true);
				} else {
					this.queryParams.page += 1;
					this.$nextTick(() => {
						this.getList();
					})
				}
			},
			async laboratoryAppletPassOutCount() {
				let self = this;
				const {
					data
				} = await laboratoryAppletPassOutCount({subId:this.queryParams.subId});
				if (data.code == 200) {
					this.statisticsData[0].num = data.data.experimenters
					this.statisticsData[1].num = data.data.numberPeople
					this.statisticsData[2].num = data.data.monthNumberPeople
				}

			},
			async getList() {
				let self = this;
				let obj = JSON.parse(JSON.stringify(this.queryParams));
				const {
					data
				} = await laboratoryAppletPassOutList(obj);
				if (data.code == 200) {
					let list = [];
					if (this.queryParams.page != 1) {
						list = JSON.parse(JSON.stringify(this.dataList));
					}
					data.data.records.forEach((item) => {
						let num = 0;
						list.forEach((minItem) => {
							if (item.showInTime == minItem.showInTime) {
								num++
								minItem.list.push(item)
							}
						})
						if (num == 0) {
							list.push({
								showInTime: item.showInTime,
								list: [item]
							})
						}
					})
					this.$set(this, 'dataList', list);
					this.$set(this, 'total', data.data.total);
					if (data.data.total / this.queryParams.pageSize <= this.queryParams.page) {
						this.$set(this, 'getDataType', true);
					}
				}
			},
		},
	}
</script>

<style lang="stylus" scoped>
	.accessRecord {
		flex:1;
		display: flex;
		flex-direction: column;
		overflow: hidden;
		width: 750rpx;

		.title {
			width: 750rpx;
			height: 160rpx;
			background: #fff;
			display: flex;
			justify-content: space-between;
			padding: 0 20rpx;
			box-sizing: border-box;

			>view {
				flex: 1;

				>view:nth-of-type(1) {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 36rpx;
					color: #0183FA;
					line-height: 30rpx;
					text-align: center;
					margin: 30rpx 0 34rpx 0;
				}

				>view:nth-of-type(2) {
					font-family: PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #222222;
					line-height: 30rpx;
					text-align: center;
					border-right: 1rpx solid #E0E0E0;
				}
			}

			>view:last-child {
				>view:nth-of-type(2) {
					border-right: none;
				}
			}
		}

		.list {
			padding: 0 20rpx;
			box-sizing: border-box;

			.list-t {
				height: 80rpx;
				font-family: PingFang SC;
				font-weight: 500;
				font-size: 32rpx;
				color: #222222;
				line-height: 80rpx;
			}

			.list-b {
				margin-bottom: 20rpx;

				.list-b-t {
					background: #FFFFFF;
					border-radius: 20rpx 20rpx 0 0;
					display: flex;
					justify-content: flex-start;
					align-items: center;
					padding: 30rpx 26rpx 16rpx 30rpx;
					box-sizing: border-box;

					>img {
						width: 70rpx;
						height: 70rpx;
						border-radius: 35rpx;
					}

					>view:nth-of-type(1) {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						color: #333333;
						line-height: 30rpx;
						margin-left: 22rpx;
					}

					>view:nth-of-type(2) {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						color: #333333;
						line-height: 30rpx;
						margin-left: 44rpx;
					}

					>view:nth-of-type(3) {
						font-family: PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						line-height: 30rpx;
						flex: 1;
						text-align: right;
					}

					.color-A {
						color: #0183FA;
					}

					.color-B {
						color: #999999;
					}

					.color-C {
						color: #FFAE00;
					}
				}

				.list-b-img {
					width: 710rpx;
					height: 32rpx;
				}

				.list-b-b {
					background: #FFFFFF;
					border-radius: 0 0 20rpx 20rpx;
					padding-top: 32rpx;
					box-sizing: border-box;
					overflow: hidden;

					>view {
						margin: 0 0 26rpx 20rpx;
					}
				}
			}
		}
	}
</style>
