<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>
		<!-- <scroll-view class="scroll-list" scroll-x>
			<view class="scoll-box" v-for="ls in cationList" :class="{ active: ls.id === currentId }" @click="tabtap(ls.id)">
				<view class="scoll-name">{{ ls.cate_name }}</view>
			</view>
		</scroll-view> -->
		<swiper :current="tabCurrentIndex" class="swiper-box" duration="300" @change="changeTab">
			<swiper-item class="tab-content" v-for="(tabItem, tabIndex) in navList" :key="tabIndex">
				<scroll-view class="list-scroll-content" scroll-y @scrolltolower="loadData">
					<!-- 空白页 -->
					<empty v-if="tabItem.loaded === true && tabItem.orderList.length === 0"></empty>
		
					<!-- 订单列表 -->
					<view class="list">
						<view class="list-item" v-for="ls in tabItem.orderList"> <!-- @click="ToIndex(ls)" -->
							<view class="item-top">
								<view class="tip-info flex-shrink-false" v-if="ls.cname">{{ls.cname}}</view>
								<view class="name clamp flex-grow-true">{{ls.explain}}</view>
							</view>
							<view class="title">申请人：{{ls.name}}</view>
							<view class="title">状态：{{ls.status == 0 ? '正在审核' : ls.status == 1 ? '审核通过' :'审核驳回' }} {{ ls.status == 2 ? ls.fail_msg : ''}}</view>
						</view>
					</view>
					
					<uni-load-more :status="tabItem.loadingType"></uni-load-more>
				</scroll-view>
			</swiper-item>
		</swiper>
		
		<view class="tip" @click="ToHelp"><text>申请帮扶</text></view>
	</view>
</template>
<script>
import { getList,gethelp } from '@/api/applyHelp.js';
import { getMyHelpApplyList } from '@/api/help.js'
import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue';
import empty from '@/components/empty';
export default {
	components: {
		empty
	},
	data() {
		return {
			tabCurrentIndex: 0,
			navList: [
				{
					state: 1,
					text: '审核中',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页数
					limit: 10 //每次信息条数
				},
				{
					state: 2,
					text: '已通过',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页数
					limit: 10 //每次信息条数
				},
				{
					state: 3,
					text: '已拒绝',
					loadingType: 'more',
					orderList: [],
					page: 1, //当前页数
					limit: 10 //每次信息条数
				},
			],
			cationList:[],
			currentId:0,
			hpleList:''
		};
	},
	onLoad() {
		this.loadData()
	},
	methods: {
		//swiper 切换
		changeTab(e) {
			this.tabCurrentIndex = e.target.current;
			this.loadData('tabChange');
		},
		//顶部tab点击
		tabClick(index) {
			this.tabCurrentIndex = index;
		},
		// 载入数据
		loadData(source){
			let obj = this;
			let index = this.tabCurrentIndex;
			let navItem = this.navList[index];
			let state = navItem.state;
			if (source === 'tabChange' && navItem.loaded === true) {
				//tab切换只有第一次需要加载数据
				return;
			}
			if (navItem.loadingType === 'noMore') {
				//防止重复加载
				return;
			}
			// 修改当前对象状态为加载中
			navItem.loadingType = 'loading';
			getMyHelpApplyList({
				page: navItem.page,
				limit:navItem.limit,
				type: state,
			})
				.then(({ data }) => {
					navItem.orderList = navItem.orderList.concat(data);
					console.log(navItem.orderList);
					navItem.page++;
					if (navItem.limit == data.length) {
						//判断是否还有数据， 有改为 more， 没有改为noMore
						navItem.loadingType = 'more';
						return;
					} else {
						//判断是否还有数据， 有改为 more， 没有改为noMore
						navItem.loadingType = 'noMore';
					}
					this.$set(navItem, 'loaded', true);
				})
				.catch(err => {
					console.log(err);
				});
		},
		ToIndex(ls){
			let id = ls.id;
			if(ls.status == 0 || ls.status == 2){
				uni.navigateTo({
					url:'/pages/applyHelp/index?id='+id
				})
			}
			if(ls.status == 1){
				uni.navigateTo({
					url:'/pages/applyHelp/index?id='+id+'&status=2'
				})
			}
		},
		ToHelp(){
			uni.navigateTo({
				url:'/pages/applyHelp/index'
			})
		},
		//一级分类点击
		tabtap(item) {
			let obj = this;
			obj.currentId = item;
			this.GetHple()
		},
	}
};
</script>

<style lang="scss">
page {
	background: $page-color-base;
	height: 100%;
	padding-bottom: 200rpx;
	.content{
		height: 100%;
	}
}
.navbar {
	display: flex;
	height: 40px;
	padding: 0 5px;
	background: #fff;
	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: $font-color-dark;
		position: relative;
		&.current {
			color: $motif-color;
			&:after {
				content: '';
				position: absolute;
				left: 50%;
				bottom: 0;
				transform: translateX(-50%);
				width: 44px;
				height: 0;
				border-bottom: 2px solid $motif-color;
			}
		}
	}
}
.swiper-box {
	height: calc(100% - 40px);
	padding: 0 20rpx;
}
.list-scroll-content {
	height: 100%;
}

.tip{
	width: 100%;
	color: #FFFFFF;
	padding: 30rpx 25rpx;
	position: fixed;
	background-color: #FF727E;
	bottom: 5%;
	width: 80%;
	left: 10%;
	text-align: center;
	border-radius:100rpx;
	box-shadow:0px 5px 16px 0px rgba(230,33,41,0.22);
}
.scroll-list {
		width: 100%;
		overflow: hidden;
		white-space: nowrap;
		background-color: #FFFFFF;
		font-size: 32rpx;
		.scoll-box {
			text-align: center;
			display: inline-block;
			margin: 0rpx 38rpx;
			padding: 15rpx 0rpx;
			.scoll-img {
				width: 130rpx;
				height: 85rpx;
				border-radius: 100%;
				image {
					width: 85rpx;
					height: 100%;
					border-radius: 100%;
				}
			}
			.scoll-name {
				padding-top: 15rpx;
			}
			&.active {
				color: #FF727E;
				border-bottom:6rpx solid #FF727E;
			}
		}
	}
	.list{
		width: 100%;
		padding: 25rpx 25rpx;
		.list-item{
			width: 100%;
			padding: 30rpx 28rpx;
			background-color: #FFFFFF;
			border-radius: 25rpx;
			margin-bottom: 25rpx;
			.item-top{
				display: flex;
				align-items: center;
				.tip-info{
					background-color: #FF727E;
					color: #FFFFFF;
					border-radius: 10rpx;
					font-size: 28rpx;
					padding: 8rpx 15rpx;
					margin-right: 15rpx;
				}
				.name{
					font-size:36rpx;
					font-weight:500;
					color:rgba(34,34,34,1);
					overflow: hidden;
					text-overflow: ellipsis;
					white-space: nowrap;
				}
			}
			.title{
				font-weight:400;
				padding-top: 25rpx;
				font-size:28rpx;
				color:rgba(34,34,34,1);
			}
		}
	}
</style>
