<template>
	<view class="app-container">
		<u-navbar leftText="返回" title="违停记录" :autoBack="true" :placeholder="true" />
		<view class="list-search">
			<view class="timers">
				<uni-datetime-picker v-model="timers" type="daterange" rangeSeparator='至' @change="maskClick" />
			</view>
			<button class="search-btn u-reset-button" @click="search">查询</button>
		</view>
		<view class="list">
			<view class="list-item" v-for="(item, index) in newList" :key="index" @click="handleInfo(item.id)">
				<view class="item-cell">
					<view class="cell-lable">违停人员姓名：</view>
					<view class="cell-value u-line-1">{{item.userName}}</view>
				</view>
				<view class="item-cell">
					<view class="cell-lable">所属网格：</view>	
					<view class="cell-value">{{item.gridName}}</view>
				</view>
				<view class="item-cell">
					<view class="cell-lable">违停时间：</view>
					<view class="cell-value">{{item.leaveTime}}</view>
				</view>
				<!-- <view class="item-cell">
					<view class="cell-lable">违停路段：</view>
					<view class="cell-value u-line-1">xxxxx街道xxx路</view>
				</view> -->
				<view class="item-cell">
					<view class="cell-lable">违停时长：</view>
					<view class="cell-value">{{item.leaveDuty}}分</view>
				</view>
			</view>
			<u-loadmore :status="status" :load-text="loadText" />
		</view>
	</view>
</template>
<script>
	import {
		tgwtList,
	} from "@/api/jn/offDuty.js"
	export default {
		data() {
			return {
				status: 'loadmore', 
				show: false,
				timers: null,
				query: {
				},
				queryParams: {
					type: 1,
					current: 1,
					size: 10,
				},
				newList: [],
				flag: 1,
				loadText: {
					loading: "努力加载中...",
					nomore: "已经到底了~",
				},
				total: 0,
				isClick:false,
			};
		},
		onLoad() {
			this.getList();
		},
		//触底加载
		onReachBottom() {
			if (this.newList.length < this.total) {
				if (this.status == 'loading') return
				this.queryParams.current = this.queryParams.current + 1;
				this.getList()
			}
		},
		methods: {
			getList() {
				uni.showToast({
					icon: 'loading',
					title: '加载中'
				});
				this.status = 'loading';
				if(this.timers?.length > 1 && this.isClick) {
					this.queryParams.params["beginCreateTime"] = this.timers[0];
					this.queryParams.params["endCreateTime"] = this.timers[1];
				}
				tgwtList(this.queryParams).then(res => {
					this.newList = [...this.newList, ...res.data.records]
					uni.hideToast();
					this.total = res.data.total
					this.status = 'nomore'
				})
			},
			search() {
				this.isClick = true;
				this.getList()
			},
			maskClick(e) {
			},
			handleInfo(id) {
				uni.navigateTo({
					url: `/subViolation/ViolationList/info?id=${id}`
				});
			},
		},
	};
</script>

<style lang="scss" scoped>
	.app-container {
		box-sizing: border-box;
		padding: 25rpx 20rpx;
	}

	.list-search {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin-bottom: 25rpx;

		// .start-time,
		// .end-time {
		// 	width: 260rpx;
		// 	height: 88rpx;
		// 	background: #ffffff;
		// 	box-shadow: 0rpx 0rpx 20rpx rgba(57, 118, 241, 0.06);
		// 	border-radius: 16rpx;
		// 	display: flex;
		// 	align-items: center;
		// 	justify-content: center;
		// }

		// .search-unit {
		// 	font-size: 32rpx;
		// 	font-weight: 500;
		// 	color: #2e2f31;
		// }

		.timers {
			width: 80%;
		}

		.search-btn {
			width: 100rpx;
			height: 70rpx;
			line-height: 70rpx;
			font-size: 30rpx;
			font-weight: 500;
			color: #ffffff;
			text-align: center;
			background: linear-gradient(90deg, #3976f1 0%, #3ca0f6 100%);
			border-radius: 16rpx;
			margin: 0;
			margin-left: 10rpx;
		}
	}

	.list-item {
		box-sizing: border-box;
		padding: 25rpx;
		background: #fff;
		margin-bottom: 30rpx;
		box-shadow: 0rpx 0rpx 20rpx rgba(57, 118, 241, 0.06);
		border-radius: 16rpx;

		.item-cell {
			display: flex;
			align-items: center;
			margin-bottom: 20rpx;

			.cell-lable {
				width: 200rpx;
				font-size: 28rpx;
				color: #9da2ab;
			}

			.cell-value {
				flex: 1;
				font-size: 28rpx;
				font-weight: 400;
				color: #2e2f31;
			}
		}

		&>.item-cell:last-child {
			margin-bottom: 0;
		}
	}

	.list-item:active {
		background: #f3f4f6;
	}

	.list>.list-item:last-child {
		margin-bottom: 0;
	}
</style>