<template>
	<view>
		<view class="tab"><u-tabs :list="tab" :current="current" @click="click"></u-tabs></view>
		<view class="list">
			<view class="spitem" v-for="(item, index) in list" :key="index" @click="detail(item.formId, item.docId)">
				<view class="title">
					<text class="icon">&#xe602;</text>
					<text class="tit">[{{ item.flowName }}]</text>
					<view class="dev">{{ item.subject.summaryText }}</view>
				</view>
				<view class="desc">
					<view class="name">{{ item.initiator }}</view>
					<view class="bm omit">{{ item.initiatorDept }}</view>
					<view class="date">{{ item.actionTime }}</view>
				</view>
				<view class="clear"></view>
			</view>
			<view class="loading" v-if="loadMore"><u-loadmore :status="loadMore ? 'loading' : 'nomore'" /></view>
			<u-empty v-if="!loadMore && list.length == 0"></u-empty>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			param: { appId: '__gAPYBW4YxB3UePM3lqO', containTitle: '申请单', opentarget: 'detail', viewId: '__km3aURKW95BHxp12XVt', _currpage: 1 },
			list: [],
			tab: [{ name: '全部' }, { name: '主流程' }, { name: '数字实验室' }, { name: '数字实验室' }, { name: '实验流程' }, { name: '设备借用' }],
			show: false,
			loadMore: true
		};
	},
	onLoad(e) {
		//this.getaccessToken();
		//this.getData();
	},
	methods: {
		getData() {
			this.http.request({
				url: this.http.urls.myPending,
				data: this.param,
				method: 'POST',
				loading: 'false',
				success: res => {
					let totalPage = res.data.data.row_count < 10 ? 1 : res.data.data.row_count / 10;
					this.loadMore = totalPage > this.param._currpage ? true : false;
					res.data.data.data.forEach(item => {
						item.subject = JSON.parse(item.subject);
						item.subject.summaryText = item.subject.summaryText.replace(/\r|\n/gi, '');
						this.list.push(item);
					});
				}
			});
		},
		//选择tab
		click(e) {
			
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param._currpage = 1;
			this.list = [];
			this.getData();
		},
		//跳转到详情
		detail(id, ste) {
			uni.navigateTo({
				url: '/pages/index/detail?id=' + id + '&ste=' + ste
			});
		},
	},
	//下拉刷新
	onPullDownRefresh() {
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		if (this.loadMore) {
			this.param._currpage++;
			this.getData();
		}
	},
	//展开搜索
	onNavigationBarButtonTap() {
		this.show = !this.show;
	}
};
</script>

<style lang="scss">
.tab {
	background-color: white;
}
.list {
	padding: 5px 0px 0px 0px;
}
</style>
