<template>
	<view class="content">
		
		<view v-if="contractList.length>0">
			<list-unit v-for="(item,index) in contractList" :key="index" :item="item" :i="index" @goDetail="goDetail"></list-unit>
			
		</view>
		<view v-else-if="pageData.isLoading===false" >
			<noFound :nodata="contractList.length>0 ? false : true"/>
		</view>
		<view class="load-more" v-if="contractList.length>0">
			<text>{{!pageData.isEnd ? '正在加载,请稍后...':'——— 我是有底线的 ———'}}</text>
		</view>
		
	</view>
</template>

<script>
	import {mapGetters, mapMutations} from 'vuex'
	import ListUnit from './components/contractUnit.vue'
	export default {
		data() {
			return {
				pageData: {
					pageIndex: 1,
					pageSize: 10,
					isEnd: false,
					isLoading: true
				},
				contractList:[]
			}
		},
		components:{
			ListUnit
		},
		
		computed:{
			...mapGetters({reloading:'shouldReLoadingList'})
		},
		methods: {
			...mapMutations(['shouldReLoadingList']),
			getList() {
				let _this = this
				_this.$request.$get('GetCompactFlowList',{
				// _this.$request.$webGet('BusinessProcess/GetCompactFlowList',{
					pageIndex: this.pageData.pageIndex,
					pageSize: this.pageData.pageSize
				}).then(res => {
					
					if(!res.ResultCode ||res.ResultCode!='100'){
						_this.pageData.isLoading =false
						_this.contractList = []
					}else{
						let list = res.Data.List
						if (list.length > 0) {
							if( this.pageData.pageIndex==1 ) {
								_this.contractList = list
								
							}else{
								_this.contractList = [..._this.contractList,...list]
							}
						}
						if (list.length < _this.pageData.pageSize) { // 返回条数小于每页条数
							_this.pageData.isEnd = true
						}
						_this.$forceUpdate()
					}
					uni.hideLoading()
					setTimeout(function(){
						_this.pageData.isLoading = false
					},500)
				})
			},
			loadMore(){
				if(!this.pageData.isEnd) {
					this.pageData.pageIndex += 1
					this.getList()
				}
			},
			goDetail(item){
				this.$util.toNextRoute('navigateTo', '/pages/contract/detail?id='+item.HIGHWAYPROINST_ID)
				// uni.navigateTo({
				// 	url: '/pages/contract/detail?id='+item.HIGHWAYPROINST_ID
				// })
			}
		},
		onPullDownRefresh() {
			uni.showLoading({
				title:'正在加载'
			})
			this.pageData.pageIndex = 1
			this.pageData.isEnd = false
			this.getList()
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		onReachBottom(){
			this.loadMore()
		},
		onShow() {
			let _this = this
			
			if(this.reloading) {
				uni.showLoading({
					title:'正在加载'
				})
				this.pageData.pageIndex = 1
				this.pageData.isEnd = false
				this.getList()
				this.shouldReLoadingList(false)
			}
		},
		onLoad() {
			uni.showLoading({
				title:'正在加载'
			})
			this.pageData.isLoading = true
			this.getList()
		},
		onUnload() {
			this.$util.addUserBehavior()
		},
		onHide() {
			
		}
	}
</script>

<style scoped>
	.content {
		padding-top: 6upx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		/* height: 100%; */
		/* box-sizing: border-box; */
	}

</style>
