<template>
	<view class="my-application">
		<!-- 标题栏 -->
		<view class="bg"></view>
		<u-navbar
			back-icon-color="#fff" 
			:back-text="$t('common.Back')" 
			:is-back="true" 
			:background="{background:'#1777FE'}"
			:back-text-style="{color:'#fff'}" 
			:border-bottom="true"
			title-color="#fff"
			:title="title"
			:custom-back="back"
			>
		</u-navbar>
		<view class="line-h"></view>
		<!-- 头部菜单 -->
		<view class="menus" v-if="token">
			<u-tabs :list="menuList"  
			:is-scroll="true" 
			:current="menuIndex" 
			:bar-height="2" 
			:height="40" 
			:bold="false"
			:bar-width="120"
			@change="showDifferentContent" ></u-tabs>
		</view>
		
		<view class="line-h"></view>
		<!-- 选项卡的内容区 -->
		<view class="applicationContent">
			<view class="item" v-for="(item,index) in dataList" :key="index" @click="showDetial(item,index)">
				<view class="label" v-if="item.affiliatedUnitName">{{item.affiliatedUnitName}}</view>
				<view class="label" v-if="item.unitZhName">{{item.unitZhName}}</view>
				<view class="label" v-if="item.reserveOne">{{item.reserveOne}}</view>
				<view class="date">{{formatDate(item.createDate)}}</view>
			</view>
		</view>
		<view class="loading" v-if="showLoading && token">
			<u-loadmore :status="status" iconType="flower" :load-text="{loading: $t('Loading')}" margin-top="200"/>
		</view>
		<view class="nodata" v-if="!showLoading && dataList.length==0" style="text-align: center;margin-top: 120upx;">
			<view class="imgBox" style="height:600upx;margin-bottom:60upx">
				<image src="../../../static/img/public/7.png" style="width: 80%;margin:0 10%" mode="widthFix"></image>
			</view>
			<text style="font-size: 30upx;color:#ccc">{{$t('common.Nodata')}}</text>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import UNavbar from '@/components/uni-nav-bar/uni-nav-bar.vue'
	export default {
		name:'MyApplication',
		components:{
			UNavbar
		},
		data(){
			return {
				menuIndex:0,
				scrollTop: 0,
				userId:'',
				token:'',
				title:'',
				old: {
					scrollTop: 0
				},
				status:'loading',
				showLoading:true,
				menuList:[
					{
						id:0,
						name:this.$t('common.MemberApply'),
						path : "/pages/service/others/applicationDetial",
					},{
						id:1,
						name:this.$t('common.Alliance'),
						path : "/pages/service/others/applicationDetial",
					},{
						id:2,
						// name:'定制服务',
						name:this.$t('common.CustomServiceApply'),
						path : "/pages/service/others/applicationDetial",
					},{
						id:3,
						// name:'资助洽商',
						name:this.$t('common.Donation'),
						path : "/pages/service/others/applicationDetial",
					},{
						id:4,
						// name:'资源共享申请',
						name:this.$t('common.ResourceSharingApplication'),
						path : "/pages/service/others/applicationDetial",
						
					}
				],
				dataList:[],
			}
		},
		onLoad(e){
			this.title= this.$i18n.locale == 'zh'? '我的申请': 'My Application'
		},
		onShow(){
			this.menuIndex = uni.getStorageSync('myApplicationMenuIndex')?parseInt(uni.getStorageSync('myApplicationMenuIndex')):0
			this.token=uni.getStorageSync('Auth-Token')?'Bearer '+uni.getStorageSync('Auth-Token'):'';
			this.userId  = uni.getStorageSync('user')? JSON.parse(uni.getStorageSync('user')).id:'';
			this.showDifferentContent(this.menuIndex)
			
		},
		
		methods:{
			// 获取入会申请数据
			async getBaseMemberApplys(){
				if(this.token.length<=7){
					uni.navigateTo({url:"/pages/public/login?back=1"})
				}else{
					let res =await this.$myRequest({
						url:'/project/baseMemberApplys/getSelfMemberApply'
					})
					if(res.status==200){
						this.dataList = [];
						if(res.data.baseMemberApplies){
							var baseMemberApply = res.data.baseMemberApplies[0];
							this.dataList.push(baseMemberApply);
						}else this.dataList =[]
					}else{
					}
					this.showLoading=false;
				}
			},
			// 获取入盟申请数据
			async getBaseLeagueApplys(){
				let res =await this.$myRequest({
					url:'/project/baseLeagueApplys/getSelfAllianceApply',
				})
				if(res.status==200){
					if(res.data.baseLeagueApplyList){
						this.dataList=res.data.baseLeagueApplyList;
					}else this.dataList =[]
				}
				this.showLoading=false;
			},
			// 获取定制服务+资助洽商数据
			async getCoopCustomServices(type){
				let res =await this.$myRequest({
					url:'/project/coopCustomServices',
					data:{
						createBy:this.userId,
						serviceTypeDict:type
					}
				})
				if(res.status==200){
					if(res.data.coopCustomServices){
						this.dataList = res.data.coopCustomServices;
					}else this.dataList =[]
				}
				this.showLoading=false;
			},
			// 获取资源共享申请
			async getResourceShare(){
				let res =await this.$myRequest({
					url:'/resourceshare/baseResearchApplications/',
					data:{createBy:this.userId,pageNo:"1"}
				})
				if(res.status==200){
					if(res.data.baseResearchApplications){
						this.dataList = res.data.baseResearchApplications;
					}else this.dataList =[]
				}
				this.showLoading=false;
			},
			
			//切换选项卡
			showDifferentContent(index){
				if(this.menuIndex!=index){
					uni.setStorageSync('myApplicationMenuIndex',index);
					this.menuIndex=index;
					this.dataList= [];
					this.showLoading=true;
				}
				switch(index){
					case 0:
						this.getBaseMemberApplys(); 
						break;
					case 1:
						this.getBaseLeagueApplys();
						break;
					case 2:
						this.getCoopCustomServices(1);
						break;
					case 3:
						this.getCoopCustomServices(2);
						break;
					case 4:
						this.getResourceShare();
						break;
				}
				
			},
			//查看详情
			showDetial(item,index){
				if(this.menuList[this.menuIndex]['path']){
					console.log(this.menuList[this.menuIndex]['path']+'?id='+item.id+'&type='
					+this.menuList[this.menuIndex]['id']+'&title='+encodeURIComponent(this.menuList[this.menuIndex]['name']));
					uni.navigateTo({
						url:this.menuList[this.menuIndex]['path']+'?id='+item.id+'&type='+
						this.menuList[this.menuIndex]['id']+'&title='+encodeURIComponent(this.menuList[this.menuIndex]['name'])
					})
				}else {}
				
			},
			scroll(e){
				this.old.scrollTop = e.detail.scrollTop
			},
			
			//路由后退一步
			back(){
				// #ifdef H5
				history.back()
				// #endif
				// #ifndef H5
				uni.navigateBack()
				// #endif
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	.my-application{
		color:#666;
		.bg{
			height:100%;
			background:#fdfdfd;
			position:fixed;
			bottom:0;
			left:0;
			right:0;
			z-index:-1;
		}
		
		.line-h{
			width:100%;
			height:2upx;
			background:#eee;
		}
		// 菜单
		.menus{
			width:750rpx;
			height:50upx;
			border-bottom:1px solid #f0f0f0;
			margin:30upx auto 0;
		}
		//内容
		.applicationContent{
			padding:2%;
			.item{
				display:flex;
				justify-content:space-between;
				border-bottom:2upx solid #e2e2e2;
				.label,.date{
					font-size:28upx;
					padding:0 26upx;
					height:100upx;
					line-height:100upx;
					color:#333;
				}
				.date{
					font-size:24upx;
					color:#aaa;
				}
			}
			
		}
	}
</style>
