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

<script>
	import ListUnit from './components/businessUnit.vue' 
	export default {
		data() {
			return {
				pageData: {
					pageIndex: 1,
					pageSize: 20,
					isEnd: false,
					loading: true,
					list: []
				}
			}
		},
		components:{
			ListUnit
		},
		methods: {
			goDetail(item){
				this.$util.toNextRoute('navigateTo', "/pages/authorityApproval/detail?id=" + item.id +'&type='+item.type)
				
			},
			getData() {
				let _this = this
				this.$request.$webGet('/CommercialApi/BusinessProcess/GetBusinessProcessList', {
						OperationType: 4, // 只查询门店审批
						pageIndex: _this.pageData.pageIndex,
						pageSize: _this.pageData.pageSize,
						SortStr: 'BusinessProcess_StartDate desc'
				}).then(res => {
					
					uni.hideLoading()
					if (res.Result_Code !== 100) {
						_this.pageData.loading=false
						return
					}
					const list = res.Result_Data.List.map(n => {
						return {
							id: n.BusinessProcess_ID,
							name: n.BusinessProcess_Name,
							serverpart: n.Serverpart_Name,
							username: n.Staff_Name,
							date: n.BusinessProcess_StartDate,
							state: n.BusinessProcess_State,
							title: n.BusinessProcess_Desc,
							type: n.Operation_Type
							
						}
					})
					this.pageData.list = this.pageData.list.concat(list)
					
					if(list.length<_this.pageData.pageSize){
						_this.pageData.isEnd = true
					}
					_this.pageData.loading=false
				})
			},
			loadMore() {
				if (!this.pageData.isEnd) {
					this.pageData.pageIndex += 1
					this.getData()
				}
			},
		},
		onPullDownRefresh() {
			this.pageData.pageIndex = 1
			this.pageData.isEnd = false
			uni.showLoading({
				title: '正在加载'
			})
			this.pageData.list=[]
			this.getData()
			setTimeout(function() {
				uni.stopPullDownRefresh()
			}, 1000)
		},
		onReachBottom() {
			this.loadMore()
		},
		onLoad() {
			uni.showLoading()
			this.pageData.isLoading = true
			
		},
		onShow() {
			this.getData()
		}
	}
</script>

<style>

</style>
