<template>
	<view>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<myCarCard @delItem="delItem" :list="list"></myCarCard>
		</mescroll-body>
		<wm-list-add  ref="add" @clickAdd="add"/>
	</view>
</template>

<script>
	import wmListAdd from '@/components/wm-list-add/wm-list-add';
	import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
	import myCarCard from "../comps/my-car-card.vue"
	var that;
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components:{
			myCarCard,wmListAdd
		},
		data() {
			return {
				personId:'',
				list:[]
			}
		},
		onLoad() {
			that=this
			this.personId=this.$cache.get('userId')
		},
		onShow() {
			//刷新mescroll数据
			this.$util.reload(this.mescroll)
		},
		methods: {
			add(){
				uni.navigateTo({
					url:"/pages/index/car/my-car/add"
				})
			},
			delItem(item){
				this.$dialog.showModal('确认要删除此记录吗？').then(res=>{
					this.$api.car.carRemove(item.id).then(res=>{
						if (res.success==true) {
							this.$u.toast('操作成功')
							this.mescroll.resetUpScroll();
						}else{
							this.$dialog.showModal(res.msg,false)
						}
					})
				})
			},
			downCallback(){
				setTimeout(()=>{
					this.mescroll.resetUpScroll();
				},1200)
			},
			upCallback(mescroll){
				let params={
					current:mescroll.num,
					size:mescroll.size,
					selectType:3,//员工，我的车辆
					personId:this.personId
				}
				try{
					this.$api.car.carList(params).then(res=>{
						let data=res.data.records
						let total=res.data.total
						mescroll.endBySize(data.length,total);
						if(mescroll.num == 1) that.list = []; //如果是第一页需手动制空列表
						that.list=that.list.concat(data); //追加新数据
					})
				}catch(e){
					this.mescroll.endErr()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	
</style>
