<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, '1',item.items.__oUywWKvn4BhpnBmxqYT.value)">
				<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="it">
						<view class="label">当前审批人：</view>
						<view class="name">{{ item.items.__hInQ1R0YkMQNrgTq3q0.value }}</view>
					</view>
					
					<view class="tag" v-if="item.items.__oUywWKvn4BhpnBmxqYT.value != ''">{{ 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;" @click="detail('0', 2)">新建</button></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			param: { appId: '__gAPYBW4YxB3UePM3lqO', containTitle: '申请单', opentarget: 'detail', viewId: '__km3aURKW95BHxp12XVt', _currpage: 1 },
			list: [],
			show: false,
			loadMore: true
		};
	},
	onLoad(e) {
		//this.getaccessToken();
		this.getData();
	},
	methods: {
		getaccessToken() {
			this.http.request({
				url: this.http.urls.accessToken,
				data: this.param,
				loading: 'false',
				success: res => {
					console.log('gfgh===1111' + 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,
				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 => {
						this.list.push(item);
					});
				}
			});
		},
		//刷新数据
		refresh() {
			this.loadMore = true;
			this.param._currpage = 1;
			this.list = [];
			this.getData();
		},
		//跳转到详情
		detail(id, ste,sta) {
			uni.navigateTo({
				url: '/pages/index/detail?id=' + id + '&ste=' + ste+ '&sta=' + sta
			});
		},
		//跳转到详情
		add() {
			uni.navigateTo({
				url: '/pages/index/addwt'
			});
		}
	},
	//下拉刷新
	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">
page {
	background-color: #f2f3f5;
}
.list {
	padding: 10px 15px 80px 15px;
	.item {
		margin-bottom: 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%;
			}
			.icon {
				float: right;
			}
		}
		.con {
			position: relative;
			.it {
				font-size: 14px;
				padding: 5px 12px 5px 12px;
				.label {
					float: left;
					color: #969696;
				}
				.name {
					color: $font-c;
				}
			}
			.tag {
				position: absolute;
				top: 10%;
				right: 0px;
				padding: 3px 10px;
				background-color: #e64340;
				color: white;
				border-radius: 15px 0px 0px 15px;
			}
		}
	}
}
</style>
