<template>
	<view class="car">
		<view class="cartop">
			<view class="topa flexc">
				<image :src="day" class="resetimg" @click="getReset"></image>
				<picker mode="date"   @change='bindDateChangea'>
					<view class="chekt flexc">
						<view>{{cxrq|| "选择日期"}}</view>
						<image :src="up"></image>
					</view>
				</picker>
			</view>

		</view>
		<!-- 列表 -->
		<view class="carlists">
			<car-list :datainfo="list" :topval="ttopval" :wtdt="wtdt" type='patrol' @getDetail="getDetail" @getAddFn="getAddFn"></car-list>
		</view>
		<loading></loading>
	</view>
</template>

<script>
	import config from '@/config'
	const baseUrl = config.baseUrl
	import carList from "@/work/components/car/list.vue"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	export default{
		components:{carList},
		data(){
			return{
				reset:require('@/work/static/car/reset.png'),
				up:require('@/work/static/car/up.png'),
				day:require('@/work/static/service/day.png'),
				cxrq:"",
				text:'',
				list:[{tit:'皖A IC520',type:1},{tit:'晋E KD783',type:2},],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
			}
		},
		onLoad: function() {
		
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			getDetail(){
				this.$tab.navigateTo("/work/pages/service/patroldetail")
			},
			getAddFn(){
				this.$tab.navigateTo("/work/pages/service/patroladd")
			},
			getTabtop(val){
				this.ttopval=val
			},
			getConfirm(){
				this.getrefreshData()
			},
			getReset(){
				this.cxrq='';
				this.text='';
				this.getrefreshData()
			},
			getrefreshData(){
				this.pageNum=1;
				this.list=[];
				this.reachflag=true;
				this.getDataFn()
			},
			getTabFn(val){
				this.tabval=val
			},
			bindDateChangea(e){
				var val=e.detail.value;
				this.cxrq=val;
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
				}
				params.noticeType=this.tabidx
				getNoticeList(params).then(res=>{
					if(res.code==200){
						if (res.rows.length < this.pageSize) {
							this.reachflag = false
							this.wtdt = '到底了~';
						} else {
							var num = parseInt(res.rows.length) + parseInt(this.pageSize) * parseInt(this.pageNum -	1)
							if (num < res.total) {
								this.reachflag = true
								this.wtdt = ''
							} else {
								this.reachflag = false
								this.wtdt = '到底了~';
							}
						}
						if (this.pageNum == 1) {
							this.list = res.rows;
						} else {
							this.list = this.list.concat(res.rows)
						}
					}else{
						this.$toast(res.msg)
					}
				})
				
			},
		}
	}
</script>
<style>
	page{background: #F3F3F0;}
</style>
<style lang="scss" scoped>
.car{padding-top: 106rpx;}
.cartop{position: fixed;left: 0;right: 0;top: 0;background-color: #F3F3F0;z-index: 2;
	.topa{padding: 30rpx 74rpx;
		.resetimg{width: 28rpx;height: 30rpx;margin-right: 30rpx;flex: 0 0 auto;}
		.chekt{min-width: 180rpx;
			view{font-weight: 500;font-size: 26rpx;color: #272727;flex: 1;}
			image{width: 24rpx;height: 16rpx;margin-left: 18rpx;flex: 0 0 auto;}
		}
	}
}
.carlists{padding: 0 18rpx;}
</style>