<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" :xglxlist="xglxList" :wtdt="wtdt" type='patrollist' @getDetail="getDetail" @getAddFn="getAddFn" @getDelFn="getDelFn"></car-list>
		</view>
		<block v-if="checkPermi(['wuYe:checkPointManage:add'])">
			<view style="height: 100rpx;"></view>
			<view class="rfbtn" @click="getAddFn">新增巡更点</view>
		</block>
		<loading></loading>
	</view>
</template>

<script>
	import config from '@/config'
	const baseUrl = config.baseUrl
	import carList from "@/service/components/car/list.vue"
	import { checkPermi, checkRole } from "@/utils/permission"; // 权限判断函数
	import {xgdglList,xgdglDel} from "@/api/work/service.js"
	import {getDictionaryFn} from "@/api/system/user.js"
	export default{
		components:{carList},
		data(){
			return{
				reset:require('@/car/static/car/reset.png'),
				up:require('@/car/static/car/up.png'),
				day:require('@/service/static/service/day.png'),
				cxrq:"",
				text:'',
				list:[{tit:'皖A IC520',type:1},{tit:'晋E KD783',type:2},],
				pageSize: 10,
				pageNum: 1,
				reachflag: true,
				wtdt:'',
				xglxList:[],
			}
		},
		onUnload() {
			uni.$off('refpatrolSet')
		},
		onLoad: function(){
			uni.$on('refpatrolSet',(res)=>{
				this.getrefreshData()
			})
			this.init()
			this.getDataFn()
		},
		// 上拉触底加载更多触发事件
		onReachBottom() {
			if (this.reachflag) {
				this.pageNum++
				this.getDataFn()
			}
		},
		methods:{
			checkPermi, checkRole,
			init(){
				// 巡更类型
				getDictionaryFn('patrol_type').then(res=>{
					if(res.code==200){
						this.xglxList = res.data.map(v => {
							return {
								dictLabel: v.dictLabel,
								dictValue: v.dictValue
							}
						})
					}
				})
			},
			getDetail(id){
				this.$tab.navigateTo("/service/pages/service/patrolset?id="+id)
			},
			getAddFn(){
				this.$tab.navigateTo("/service/pages/service/patrolset?")
			},
			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;
			},
			getDelFn(id){
				var that=this;
				xgdglDel(id).then(res=>{
					if(res.code==200){
						this.$toast("删除成功")
						setTimeout(function(){
							that.getrefreshData()
						},1500)
					}
				})
			},
			getDataFn(){
				var params={
					pageSize:this.pageSize,
					pageNum: this.pageNum,
				}
				xgdglList(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: 24rpx;}
.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>