<template>
	<!-- 公交投入数据 -->
	<view class="page_box">
		<view class="top_box">
			<view class="list_box">
				<view class="list_item" v-for="(item,index) in listData" :key="index" @click="editItem(item)">
					<view class="list_top">
						<view class="unit_tags">报送时间</view>
						<view class="unit_name">{{item.reportDate || ''}}<text style="margin-left:16rpx;">{{item.statPeriodValue || ''}}</text></view>
					</view>
				</view>
			</view>
			<uni-load-more iconType="circle" :status="status" @clickLoadMore="loadMore"
				:content-text="contentText"></uni-load-more>
		</view>
		<view class="bottom_box">
			<!-- <view class="act_btn" @click="handleAdd">
				<uni-icons type="plusempty" size="18"
						color="#fff" style="margin-right: 9rpx;"></uni-icons>
				新建
			</view> -->
			<view class="act_btn btn1"  @click="handleSearch">
				<uni-icons type="search" size="18" color="#2D8CF0"
						style="margin-right: 9rpx;"></uni-icons>
				查询
			</view>
		</view>
		<view class="pop_conbox">
			<uni-popup ref="popup" style="width: 100%;">
				<view class="pop_box">
					<view class="pop_title">
						查询条件
						<uni-icons @click="this.$refs.popup.close()" type="closeempty" size="18" color="#666" class="pop_close"></uni-icons>
					</view>
					<view class="popup-content">
						<view class="cont_tit">
							统计起止时间
						</view>
						<view class="time_box">
							<uni-datetime-picker v-model="timeRange" type="daterange" />
						</view>
						<view class="cont_tit picker">
							<view>统计时段</view>
							<view class="picker_select">
								<picker @change="bindPickerChange" :value="index" :range="timeArray" range-key="dictLabel">
									<text class="unselect_txt"
										:style="timeName?'color:#333;':''">{{timeName ? timeName:'请选择时段'}}</text>
									<uni-icons type="right" size="16" color="#D4D4D4"></uni-icons>
								</picker>
							</view>
						</view>
					</view>
					<view class="btn_box">
						<p class="btn" @click="searchReset">重置</p>
						<p class="btn" @click="searchList">确认</p>
					</view>
				</view>
			</uni-popup>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				listData:[],
				hasMore:true,
				page:0,
				pageSize:10,
				timeRange:[],
				contentText: {
					contentdown: "点击查看更多",
					contentrefresh: "正在加载...",
					contentnomore: "没有更多数据了",
				},
				status: '',
				timeArray:[],
				timeName:'',
				reportPhase:'',
				query:{
					reportDateStart:"",
					reportDateEnd:"",
					statPeriod:"",
				}
			}
		},
		onShow() {
			this.page = 0;
			this.hasMore = true;
			this.listData = [];
			this.queryTime();
			this.loadMore()
		},
		onPullDownRefresh() {
			this.page = 0;
			this.hasMore = true;
			this.listData = [];
			this.queryTime();
			this.loadMore()
		},
		methods: {
			loadMore(){
				if (this.hasMore) {
					this.page = this.page + 1;
					this.status = 'loading';
					let params = {
						page:this.page,
						pageSize:this.pageSize,
						_t:Date.parse(new Date()),
						...this.query
					}
					this.$request(getApp().globalData.baseUrl + '/api/biz/busdata/list',params,"GET").then(res =>{
						console.log(res)
						if(res.code == 200){
							res.data.list.map(item =>{
								item.show = false;
							})
							this.listData = this.listData.concat(res.data.list);
							if(res.data.list.length == 0 || res.data.list.length < this.size){
								this.hasMore = false;
								this.status = 'nomore';
							}else{
								this.status = 'more';
							}
							uni.stopPullDownRefresh();
						} else {
							this.status = 'more';
							uni.stopPullDownRefresh();
						}
					}).catch(() => {
						this.status = 'more';
						uni.stopPullDownRefresh();
					})
				}
			},
			// 点击查询按钮
			handleSearch(){
				this.$refs.popup.open('bottom')
			},
			//时段
			queryTime() {
				this.$request(getApp().globalData.baseUrl + '/api/dict/dictList?dictType=airport_time' + '&_t=' + Date.parse(
					new Date()), {}, 'GET').then(res => {
					this.timeArray = res.data;
				})
			},
			// 点击筛选弹窗中的筛选按钮
			searchList(){
				this.hasMore = true;
				this.page = 0;
				this.listData = [];
				uni.pageScrollTo({
					scrollTop: 0
				})
				this.query = {
					reportDateStart:this.timeRange.length !== 0 ? this.timeRange[0] : '',
					reportDateEnd:this.timeRange.length !== 0 ? this.timeRange[1] : '',
					statPeriod:this.reportPhase
				}
				this.$refs.popup.close()
				this.loadMore()
			},
			// 点击筛选弹窗中的重置按钮
			searchReset(){
				this.timeRange = [];
				this.timeName = '';
				this.reportPhase = ''
				// this.listData = [];
				// this.hasMore = true;
				// this.page = 0;
				// this.$refs.popup.close()
				// this.loadMore();
			},
			// 选中时段数据
			bindPickerChange(e){
				let index = e.target.value   //取其下标
				var selected = this.timeArray[index]           //获取选中的数组
				console.log(selected)
				this.timeName = selected.dictLabel
				this.reportPhase = selected.dictValue;
				// this.timeName =  this.timeArray[index].dictLabel)
			},
			// 跳转编辑页面
			editItem(row){
				uni.navigateTo({
					url:"/pages/bus/busDataInfo/form?type=edit&item=" + JSON.stringify(row)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
.page_box{
	min-height: 100vh;
	padding: 30rpx 30rpx 195rpx;
	
	.top_box{
		.list_box{
			width: 690rpx;
			display: flex;
			flex-direction: column;
			margin: 0 auto;
			
			.list_item{
				width: 630rpx;
				padding: 30rpx;
				border-radius: 30rpx;
				background: #FFFFFF;
				margin-bottom: 30rpx;
				
				.list_top {
					display: flex;
				
					.unit_tags {
						height: 37rpx;
						line-height: 37rpx;
						color: #E37616;
						font-size: 20rpx;
						font-family: PingFang SC-Regular, PingFang SC;
						font-weight: 400;
						background: #FFF7E4;
						border-radius: 10rpx;
						border: 1rpx solid #EF9A4F;
						padding: 0 11rpx;
					}
				
					.unit_name {
						color: #333333;
						font-size: 30rpx;
						font-family: PingFang SC-Bold, PingFang SC;
						font-weight: 400;
						line-height: 48rpx;
						margin-left: 20rpx;
						word-break: break-all;
					}
				}
				.report_time {
					color: #999999;
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					line-height: 48rpx;
					text-align: center;
					margin-bottom: 30rpx;
				}
				
				.item{
					width: 570rpx;
					// display: flex;
					background: #F8F8F8;
					border-radius: 30rpx 30rpx 30rpx 30rpx;
					padding: 30rpx;
					// justify-content: space-between;
					margin-bottom: 40rpx;
					
					.item_line{
						width: 100%;
						display: flex;
						justify-content: space-between;
						
						.left_txt{
							font-size: 26rpx;
							color: #666;
						}
						.right_txt{
							color: #333;
							font-size: 28rpx;
						}	
					}
					
					.item_bottom{
						width: 100%;
						.bott_item{
							width: 100%;
							display: flex;
							justify-content: space-between;
							margin-top: 32rpx;
							
							
							.left_txt{
								font-size: 26rpx;
								color: #666;
							}
							.right_txt{
								color: #333;
								font-size: 28rpx;
							}
						}
						.omit{
							font-size: 26rpx;
							font-weight: 400;
							color: #666666;
							line-height: 48rpx;
							margin: 20rpx 0;
						}
						.list_item_shouqi {
							color: #2D8CF0;
							font-size: 24rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							text-align: center;
							line-height: 33rpx;
							padding-bottom: 30rpx;
						
							.txt {
								margin-left: 12rpx;
							}
						}
					}
				}
				
				.button_box{
					width: 630rpx;
					display: flex;
					justify-content: flex-end;
					
					.button{
						width: 180rpx;
						height: 70rpx;
						background: #FFFFFF;
						border-radius: 100rpx;
						border: 1rpx solid #C1C1C1;
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 28rpx;
						color: #666;
						margin-left: 30rpx;
						
						&.edit{
							background: #2D8CF0;
							border-radius: 100rpx 100rpx 100rpx 100rpx;
							border: none;
							color: #fff;
						}
					}
				}
			}
		}
	}
	
	.bottom_box{
		position: fixed;
		left: 0;
		right: 0;
		bottom: 0;
		background-color: #F8F8F8;
		padding: 40rpx 30rpx;
		
		.act_btn {
			width: 690rpx;
			height: 90rpx;
			line-height: 88rpx;
			display: flex;
			justify-content: center;
			color: #FFFFFF;
			font-size: 28rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			background: #2D8CF0;
			border-radius: 100rpx;
			border: 1rpx solid #2D8CF0;
		
			.txt {
				margin-left: 9rpx;
			}
		
			&.btn1 {
				color: #2D8CF0;
				background: #F6F6F6;
			}
		}
	}
	
	.pop_conbox{
		.pop_box {
			border-radius: 30rpx 30rpx 0 0;
			background-color: #fff;
			padding: 30rpx;
		
			.pop_title {
				color: #333333;
				font-size: 32rpx;
				font-family: PingFang SC-Bold, PingFang SC;
				font-weight: bold;
				line-height: 45rpx;
				text-align: center;
				margin: 20rpx 0;
		
				.pop_close {
					float: right;
				}
			}
		
			.popup-content {
				// display: flex;
				// flex-direction: column;
		
				.cont_tit {
					width: 100%;
					color: #333333;
					font-size: 26rpx;
					font-family: PingFang SC-Bold, PingFang SC;
					font-weight: bold;
					line-height: 37rpx;
					display: flex;
					margin-bottom: 40rpx;
		
					&.picker {
						display: flex;
						justify-content: space-between;
						margin: 60rpx 0;
		
						.picker_select {
							color: #D4D4D4;
							font-size: 28rpx;
							font-family: PingFang SC-Regular, PingFang SC;
							font-weight: 400;
							text-align: right;
						}
					}
				}
		
				.time_box {
					width: 690rpx;
					margin: 0 auto;
		
					/deep/ .uni-date-x--border {
						border-radius: 30rpx;
		
						.uni-date-x {
							background: transparent;
		
							.icon-calendar {
								padding-left: 20rpx;
							}
						}
					}
		
					/deep/ .uni-date-editor--x .uni-date__icon-clear {
						padding-right: 20rpx;
					}
				}
		
				.picker_box {
					width: 690rpx;
					margin: 0 auto;
		
					/deep/.input-value-border {
						border-radius: 30rpx;
					}
				}
			}
		
			.btn_box {
				width: 100%;
				height: 120rpx;
				display: flex;
				margin-top: 20px;
				align-items: center;
				justify-content: space-between;
		
				.btn {
					width: 290rpx;
					height: 90rpx;
					background: #FFFFFF;
					border-radius: 100rpx;
					border: 1rpx solid #C1C1C1;
					color: #666;
					font-size: 28rpx;
					line-height: 88rpx;
					text-align: center;
		
					&:last-child {
						background: #2D8CF0;
						color: #FFFFFF;
						border-color: #2D8CF0;
					}
				}
			}
		}
	}
}
</style>
