<template>
	<view class="content">
		<view class="navbar">
			<view v-for="(item,index) in navList" :key="index" class="nav-item"
				:class="{ current: tabCurrentIndex === index}" @click="tabClick(index)">{{ item.text }}</view>
		</view>
		<swiper :current="tabCurrentIndex" :style="{'height':height}" class="swiper-box" duration="300"
			@change="changeTab">
			<swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
				<scroll-view scroll-y="true" class="list-scroll-content" :style="{'height':height}">
					<!-- 申请列表 -->
					<view class="apply-box" v-for="item in 20">
						<view class="box-top">
							<image src="" mode="" class="user-img"></image>
							<view class="user-info">
								<view class="user-name clamp">
									假猪套 假猪套假猪套假
								</view>
								<view class="user-phone">
									13245678911
								</view>
							</view>
						</view>
						<view class="apply-info flex">
							<view class="img-wrap">
								<image src="" mode="" class="upimg" v-for="item in 2"></image>
							</view>
							<view class="btn-wrap flex" v-if="tabCurrentIndex == 0">
								<view class="btn btn-reject">拒绝</view>
								<view class="btn btn-pass">通过</view>
							</view>
							<view class="btn-wrap" v-if="tabCurrentIndex == 1">
								已通过
							</view>
						</view>
					</view>
				</scroll-view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import {
		getApplyList
	} from '../../api/apply.js'
	export default {
		data() {
			return {
				height: '',
				tabCurrentIndex: 0,
				navList: [{
						state: 0,
						text: '未审核',
						loadingType: 'more',
						orderList: [],
						page: 1,
						limit: 10,
					},
					{
						state: 1,
						text: '已审核',
						loadingType: 'more',
						orderList: [],
						page: 1,
						limit: 10,
					}
				]
			}
		},
		onReady(res) {
			var obj = this;
			uni.getSystemInfo({
				success: resu => {
					const query = uni.createSelectorQuery();
					query.select('.swiper-box').boundingClientRect();
					query.exec(function(res) {
						console.log(res, 'ddddddddddddd');
						obj.height = resu.windowHeight - res[0].top + 'px';
						console.log('打印页面的剩余高度', obj.height);
					});
				},
				fail: res => {}
			});
		},
		onLoad() {
			this.loadData()
		},
		methods: {
			//顶部tab点击
			tabClick(index) {
				this.tabCurrentIndex = index;
			},
			changeTab(e) {
				this.tabCurrentIndex = e.target.current;
				this.loadData('tabChange');
			},
			loadData(source) {
				console.log('swiper')
				let index = this.tabCurrentIndex;
				let navItem = this.navList[index];
				let state = navItem.state + 1;
				if (source === 'tabChange' && navItem.loaded === true) {
					//tab切换只有第一次需要加载数据
					return;
				}
				if (navItem.loadingType === 'loading') {
					//防止重复加载
					return;
				}
				//修改当前对象状态为加载中
				navItem.loadingType = 'loading';
				getApplyList({
					page: navItem.page,
					limit: navItem.limit,
					status: state
				}).then( res => {
					console.log(res)
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.navbar {
		display: flex;
		height: 40px;
		padding: 0 5px;
		background: #000;
		box-shadow: 0 1px 5px rgba(0, 0, 0, 0.06);
		position: relative;
		z-index: 10;

		.nav-item {
			flex: 1;
			display: flex;
			justify-content: center;
			align-items: center;
			height: 100%;
			font-size: 15px;
			color: #999999;
			position: relative;

			&.current {
				color: $base-color;

				&:after {
					content: '';
					position: absolute;
					left: 50%;
					bottom: 0;
					transform: translateX(-50%);
					width: 44px;
					height: 0;
					border-bottom: 2px solid $base-color;
				}
			}
		}
	}

	.swiper-box {
		background-color: #15130f;

		.apply-box {
			height: 317rpx;
			width: 702rpx;
			// background-color: red;
			margin: 0 auto;
			border-bottom: 1px solid #6c6a68;
			padding-top: 30rpx;

			.box-top {
				height: 80rpx;
				// background-color: #bfa;
				display: flex;
				justify-content: flex-start;

				.user-img {
					width: 80rpx;
					height: 80rpx;
					background-color: #eee;
					margin-right: 20rpx;
					flex-shrink: 0;
					border-radius: 50%;
				}

				.user-name {
					max-width: 500rpx;
					font-size: 30rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FFFFFF;
				}

				.user-phone {
					padding-top: 10rpx;
					font-size: 22rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #FFFFFF;
				}
			}

			.apply-info {
				padding: 25rpx 0 0 100rpx;
				justify-content: space-between;

				.img-wrap {
					.upimg {
						width: 153rpx;
						height: 152rpx;
						border-radius: 10rpx;
						background-color: #999;
						margin-left: 10rpx;
					}
				}

				.btn-wrap {
					align-self: flex-end;
					color: #FAD6B0;
					font-size: 24rpx;
					font-family: PingFang SC;
					font-weight: 500;
					color: #FAD6B0;

					.btn {
						width: 98rpx;
						line-height: 47rpx;
						text-align: center;
					}

					.btn-reject {
						border: 1px solid #FAD6B0;
						border-radius: 5rpx;
						color: #FAD6B0;
					}

					.btn-pass {
						background: linear-gradient(-74deg, #CE9C6D, #FFECD6);
						border-image: linear-gradient(115deg, #FEEBD5, #FFFFFF, #E1AD7D) 1 1;
						box-shadow: 3rpx 4rpx 5rpx 0rpx rgba(151, 118, 74, 0.5);
						border-radius: 5rpx;
						color: #874B19;
						margin-left: 10rpx;
					}
				}
			}
		}
	}
</style>
