<template>
	<MeScroll  :up="up" :down="down" @up="upFn" :fixed="false" @down="downFn" @init="initMeScroll">
		<card :list="dataList" :current="i"></card>
	</MeScroll>
</template>
<script>
	import MeScroll from '@/components/mescroll-body/mescroll-uni.vue'
	import card from './card.vue'
	var app=getApp()
	export default {
		components:{
			MeScroll,card
		},
		props: {
			type: Number,
			i: Number,
			item:Object,
			params:Object
		},
		data() {
			return {
				tenantId:'',
				
				isInit: false, // 是否初始化
				dataList: [], // 列表数据
				mescroll: null, // mescroll 对象
				// 上拉配置参数
				up: {
					noMoreSize: 2, 
					auto: false,
					page: {
						page: 0,
						size: 10
					}
				},
				// 下拉配置参数
				down: {
					use: true, 
					auto: false
				}
			}
		},
		created() {
			this.tenantId=this.$cache.get('agencyTenantId')
		},
		watch:{
			type(val) {
				if(!this.isInit && val === this.i) {
					this.mescroll.resetUpScroll()
				}
			}
		},
		mounted() {
			if(!this.isInit && this.i === 0) {
				this.mescroll.resetUpScroll()
			}
		},
		methods: {
			/**
			 * @param {Object} mescroll 初始化组件
			 */
			initMeScroll(mescroll) {
				this.mescroll = mescroll
			},
			/**
			 * @param {Object} mescroll 上拉回调
			 */
			async upFn(mescroll) {
				let that=this
				let params={
					current:mescroll.num,
					size:mescroll.size,
					// tenantId:this.tenantId,
					carNo:this.params.carNo
				}
				let res=null
				try{
					if (this.i==0) {
						//入场记录
						res=await this.$api.car.enterPage(params)
					}else if (this.i==1) {
						//出场记录
						res=await this.$api.car.outPage(params)
					}
					let data=res.data.records
					this.mescroll.endBySize(data.length, res.total)
					if (mescroll.num==1) this.dataList=[]
					this.dataList=this.dataList.concat(data)
				}catch(e){
					this.mescroll.endErr();
				}
			},
			/**
			 * 下拉回调
			 * */
			downFn(mescroll) {
				setTimeout(()=>{
					this.$u.toast('刷新成功')
					this.mescroll.resetUpScroll()
				},1500)
			},
		}
	}
</script>

<style lang="scss" scoped>
	view{
		box-sizing: border-box;
	}
</style>
