<template>
	<view>
		<view class="search" v-if="show">
			<u-divider text="展开搜索"></u-divider>
			<u--input v-model="param.xx" placeholder="输入条件" class="input" clearable></u--input>
			<u--input v-model="param.xx" placeholder="输入条件" class="input" clearable></u--input>
			<u--input v-model="param.xx" placeholder="输入条件" class="input" clearable></u--input>
			<u--input v-model="param.xx" placeholder="输入条件" class="input" clearable></u--input>
			<u--input v-model="param.xx" placeholder="输入条件" class="input" clearable></u--input>
			<view class="flex">
				<view class="f"><button class="btn c" @click="clear()">重置</button></view>
				<view class="f"><button class="btn" @click="search()">搜索</button></view>
			</view>
		</view>
		<view class="list">
			<view class="item" v-for="(item, index) in list" :key="index" @click="detail(item.id)">
				<view class="title">
					<text class="tv">{{item.items.__yZMMXcXNnmKq5pTTfPH.value}}</text>
					<text class="icon">&#xe631;</text>
					<view class="clear"></view>
				</view>
				<view class="con">
					<view class="it">
						<view class="label">委托单编号：</view>
						<view class="name">{{item.items.__BFdnHQXCEaXwAC4nryK.value}}</view>
					</view>
					<view class="it">
						<view class="label">申请单位：</view>
						<view class="name">{{item.items.__VP07fdxAVMa7bSHb8ZU.value}}</view>
					</view>
					<view class="it">
						<view class="label">试验部门：</view>
						<view class="name">{{item.items.__DVAKyCmSOS9bvFpome2.value}}</view>
					</view>
					<view class="tag">{{item.items.__oUywWKvn4BhpnBmxqYT.value}}</view>
				</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 class="footer"><button class="btn" style="width: 30%;border-radius: 25px;">新建</button></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			param: {appId:"__gAPYBW4YxB3UePM3lqO",containTitle:"申请单",opentarget:"detail",viewId:"__km3aURKW95BHxp12XVt" },
			list: [],
			show: false,
			loadMore: true,
			pageNum:1
		};
	},
	onLoad(e) {
		//this.getaccessToken();
		this.getData();
		console.log("0000===");
	},
	methods: {
		getaccessToken() {
			this.http.request({
				url: this.http.urls.accessToken,
				data: this.param,
				loading: 'false',
				success: res => {
				//console.log("gfgh==="+JSON.stringify(res));
				if(res.data.errcode==0){
								
				uni.removeStorageSync('user');
				uni.setStorageSync('user', res.data.data);
				this.getData();
				console.log("res.data.resultCode==="+res.data.errcode);
				}
				}
			});
		},	getData() {
			
			this.http.request({
				url: this.http.urls.wt_list+'&_currpage='+this.pageNum,
				data: this.param,
				method:'POST',
				loading: 'false',
				success: res => {
					console.log("res.data.data.page==="+JSON.stringify(res));
					console.log("this.pageNum==="+this.pageNum);
					this.loadMore = res.data.data.page > this.pageNum? true : false;
					res.data.data.data.forEach(item => {
						this.list.push(item);
					});
					//console.log("this.list==="+JSON.stringify(this.list));
				}
			});
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.pageNum = 1;
			this.list = [];
			this.getData();
			console.log("11111===");
		},
		//跳转到详情
		detail(id) {
			uni.navigateTo({
				url: '/pages/index/detail?id=' + id
			});
		}
	},
	//下拉刷新
	onPullDownRefresh() {
		console.log("222===");
		setTimeout(() => {
			this.refresh();
			uni.stopPullDownRefresh();
		}, 1000);
	},
	//上拉加载
	onReachBottom() {
		console.log("333===");
		if (this.loadMore) {
			
			this.pageNum++;
			console.log("this.pageNum==="+this.pageNum);
			this.getData();
		}
	},
	//展开搜索
	onNavigationBarButtonTap() {
		this.show = !this.show;
	}
};
</script>

<style lang="scss">
page {
	background-color: #f2f3f5;
}
.search {
	background-color: white;
	padding: 5px 15px;
	.input {
		margin-bottom: 10px;
	}
	.f {
		padding: 5px;
		background-color: white;
	}
	.c {
		background-color: #f44336;
	}
}
.list {
	padding: 0px 15px;
	.item {
		margin-top: 10px;
		background-color: white;
		border-radius: 5px;
		overflow: hidden;
		padding-bottom: 5px;
		box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
		.title {
			border-bottom: 1px solid #efefef;
			padding: 12px;
			.tv {
				float: left;
				width: 90%;
			}
		}
		.con {
			position: relative;
			.it {
				font-size: 14px;
				padding: 5px 12px 5px 12px;
				.label {
					float: left;
					color: #969696;
				}
			}
			.tag {
				position: absolute;
				top: 10%;
				right: 0px;
				padding: 3px 10px;
				background-color: red;
				color: white;
				border-radius: 15px 0px 0px 15px;
			}
		}
	}
}

</style>
