<template>
	<mobile-frame>
		<view class="main">
			<view class="one">
				<scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
					<view class="list-scroll-view">
						<view class="one_1">
							<view class="list" v-for="(item,index) in list" :key="index">
								<view class="name textOver">
									{{item.name||'暂无'}}
								</view>
								<view class="other_1">
									身份证号：<text>{{item.card||'暂无'}}</text>
								</view>
								<view class="other_1">
									手机号：<text>{{item.phone||'暂无'}}</text>
								</view>
								<view class="other_1">
									状态：<text>{{item.zhStatus||'暂无'}}</text>
								</view>
								<view class="other_1">
									审核结果：<text>{{item.cause||'暂无'}}</text>
								</view>
							</view>
						</view>
					</view>
				</scroll-view>
			</view>
			<view class="is_bottom" v-if="is_bottom">
				<text>{{config.bottom_title}}</text>
			</view>
		</view>
	</mobile-frame>
</template>

<script>
	export default {
		data() {
			return {
				// 系统设置
				config: {},
				user: {},
				searchInfo: {},
				list: [],
				total: 0,
				page: 0,
				skip: 0,
				limit: 10,
				statusList: [],
				// 数据是否触底
				is_bottom: false,
				scrollTop: 0
			};
		},
		onLoad: async function(e) {
			const that = this;
			that.searchConfig();
			await that.watchLogin();
		},
		onPullDownRefresh: async function() {
			const that = this;
			that.clearPage();
			await that.search();
			uni.stopPullDownRefresh();
		},
		methods: {
			watchLogin() {
				const that = this;
				uni.getStorage({
					key: 'token',
					success: async (res) => {
						let user = that.$jwt(res.data);
						if (user) that.$set(that, `user`, user);
						// 查询其他信息
						await that.searchOther();
						await that.search();
					},
					fail: (err) => {}
				})
			},
			// 查询基本设置
			searchConfig() {
				const that = this;
				uni.getStorage({
					key: 'config',
					success: function(res) {
						if (res.data) that.$set(that, `config`, res.data)
					},
					fail: function(err) {
						console.log(err);
					}
				})
			},
			async search() {
				const that = this;
				let info = {
					skip: that.skip,
					limit: that.limit,
					user_id: that.user.id
				}
				const res = await that.$api(`/userleader`, `GET`, {
					...info,
					...that.searchInfo
				})
				if (res.errcode == '0') {
					let list = [...that.list, ...res.data]
					for (let val of list) {
						let status = that.statusList.find(i => i.value == val.status)
						if (status) val.zhStatus = status.label;
					}
					that.$set(that, `list`, list)
					that.$set(that, `total`, res.total)
				} else {
					uni.showToast({
						title: res.errmsg,
					});
				}
			},
			// 查询其他信息
			async searchOther() {
				const that = this;
				let res;
				res = await that.$api(`/dictData`, 'GET', {
					code: "exam_status"
				});
				if (res.errcode == '0') that.$set(that, `statusList`, res.data)
			},
			// 分页
			toPage() {
				const that = this;
				let list = that.list;
				let limit = that.limit;
				if (that.total > list.length) {
					uni.showLoading({
						title: '加载中',
						mask: true
					})
					let page = that.page + 1;
					that.$set(that, `page`, page)
					let skip = page * limit;
					that.$set(that, `skip`, skip)
					that.search();
					uni.hideLoading();

				} else that.$set(that, `is_bottom`, true)
			},
			toScroll(e) {
				const that = this;
				let up = that.scrollTop;
				that.$set(that, `scrollTop`, e.detail.scrollTop);
				let num = Math.sign(up - e.detail.scrollTop);
				if (num == 1) that.$set(that, `is_bottom`, false);
			},
			// 清空列表
			clearPage() {
				const that = this;
				that.$set(that, `list`, [])
				that.$set(that, `skip`, 0)
				that.$set(that, `limit`, 6)
				that.$set(that, `page`, 0)
			}
		}

	}
</script>

<style lang="scss">
	.main {
		display: flex;
		flex-direction: column;
		width: 100vw;
		height: 100vh;

		.one {
			position: relative;
			flex-grow: 1;

			.one_1 {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;

				.list {
					width: 100%;
					background: #fff;
					padding: 2vw;
					border-radius: 5px;
					margin: 2vw 1vw 0 1vw;
					border: 1px solid var(--f1Color);


					.name {
						font-size: var(--font15Size);
						margin: 0 0 2vw 0;
					}

					.other_1 {
						font-size: var(--font14Size);

						text {
							color: var(--f85Color);
						}

					}
				}
			}
		}
	}

	.scroll-view {
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;

		.list-scroll-view {
			display: flex;
			flex-direction: column;
		}
	}

	.is_bottom {
		text-align: center;

		text {
			padding: 2vw 0;
			display: inline-block;
			color: #858585;
			font-size: 14px;
		}
	}
</style>
