<template>
	<view>
	   <mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<card :list="dataList"></card>
		</mescroll-body>
	</view>
</template>
<script>
	import card from "./comps/card.vue"
	import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		components:{
			card
		},
		data() {
			return {
				loginType:'',
				downOption: { 
					auto:false
				},
				dataList:[],
			}
		},
		onLoad() {
			this.loginType=this.$cache.get('loginType')
		},
		methods: {
			downCallback(){
				setTimeout(()=>{
					uni.showToast({title:"刷新成功",icon:"none"})
					this.mescroll.resetUpScroll();
				},1500)
			},
			upCallback(mescroll){
				let params={
					current:mescroll.num,
					size:mescroll.size,
				}
				if (this.loginType==this.$loginType.AGENCY) {
					//管理员
					params.tenantId=this.$cache.get('agencyTenantId')
				}else if (this.loginType==this.$loginType.STAFF) {
					//员工
					params.userId=this.$cache.get('userId')
				}else if (this.loginType==this.$loginType.ENTERPRISE) {
					//企业
					params.enterpriseId=this.$cache.get('enterpriseId')
				}
				try{
					this.$api.accessrecord.page(params).then(res=>{
						let data=res.data.records
						this.mescroll.endBySize(data.length, res.total)
						if (mescroll.num==1) this.dataList=[]
						this.dataList=this.dataList.concat(data)
						setTimeout(()=>{
							this.mescroll.endBySize(data.length, res.total)
						},20)
					})
				}catch(e){
					this.mescroll.endErr();
				}
			}
		}
	}
</script>

<style lang="scss">
page{
	background-color: #FFFFFF;
}
</style>