<template>
	<view style="position: relative;">
		<!-- 胶囊 -->
		<mvBar :mysNavConfig="mysNavConfig"></mvBar>
		<view :style="{marginTop:navH}"></view>
		<view class="head">
			<view class="show-income">
				<p>累计开团现金收益</p>
				<p style="margin-top: 20rpx;font-weight: 600;">￥{{moneyIncome}}</p>
			</view>
			<view class="show-income">
				<p>累计开团积分收益</p>
				<p style="margin-top: 20rpx;font-weight: 600;">{{pointIncome}}</p>
			</view>
		</view>

		<view class="content">
			<p>开团明细</p>
			<view>
				<uni-search-bar @confirm="search" :focus="true" cancelButton="none" v-model="searchValue">
				</uni-search-bar>
			</view>

			<view class="menu">
				<view class="menu-item" @click="toShow1()">
					<p v-bind:class="tab == 'exe'?'lor':'unlor'">开团中</p>
				</view>
				<view class="menu-item" @click="toShow2()">
					<p v-bind:class="tab == 'end'?'lor':'unlor'">已结束</p>
				</view>
			</view>

			<view class="team-list" v-if="tab == 'exe' && !loading">
				<view class="team-card" v-for="(item,index) in youngTeamList">
					<view class="project" @click="toTeamDetail(item)">
						<!-- 项目名称 -->
						<image class="platform-img" :src="item.platform_icon"></image>
						<p>{{item.project_name}}</p>
						<view @click="toProject()">
							<image class="togo-icon" :src="picture.icon_right"></image>
						</view>
					</view>
					<view class="team-info">
						<!-- young之团信息 -->
						<image class="project-img" :src="item.project_photo"></image>
						<view class="team-txt">
							<!-- 成团编码 -->
							<view style="display: flex;">
								<p>成团编码ID：{{item.team_id}}</p>
								<image :src="picture.icon_copy" mode=""
									style="padding-left:5rpx;width: 30rpx;height: 30rpx;"
									@click="handleCopy('item.team_id')" />
							</view>
							<!-- 人数信息 -->
							<p style="padding: 10rpx 0;">已报名：{{item.num_apply}}人 &nbsp; 申请成功：{{item.num_apply_success}}人
								&nbsp; 已结案：{{item.num_end}}人</p>
							<!-- 收益信息 -->
							<p style="font-weight: 600;">预计积分收益：{{item.point_income}} &nbsp;
								预计现金收益：￥{{item.show_money_income}}</p>
						</view>
					</view>
					<view class="team-foot">
						<!-- 查看进度按钮 -->
						<button class="team-btn" @click="toTeamDetail(item)" type="default">查看进度</button>
					</view>
				</view>

			</view>



			<view class="team-list" v-if="tab == 'end' && !loading">
				<view class="team-card" v-for="(item,index) in youngTeamList">
					<view class="project" @click="toTeamDetail(item)">
						<!-- 项目名称 -->
						<image class="platform-img" :src="item.platform_icon"></image>
						<p>{{item.project_name}}</p>
						<view @click="toProject()">
							<image class="togo-icon" :src="picture.icon_right"></image>
						</view>
					</view>
					<view class="team-info">
						<!-- young之团信息 -->
						<image class="project-img" :src="item.project_photo"></image>
						<view class="team-txt">
							<!-- 成团编码 -->
							<view style="display: flex;">
								<p>成团编码ID：{{item.team_id}}</p>
								<image :src="picture.icon_copy" mode=""
									style="padding-left:5rpx;width: 30rpx;height: 30rpx;"
									@click="handleCopy('item.team_id')" />
							</view>
							<!-- 人数信息 -->
							<p style="padding: 10rpx 0;">已报名：{{item.num_apply}}人 &nbsp; 申请成功：{{item.num_apply_success}}人
								&nbsp; 已结案：{{item.num_end}}人</p>
							<!-- 收益信息 -->
							<p style="font-weight: 600;">积分收益：{{item.point_income}} &nbsp;
								现金收益：￥{{item.show_money_income}}</p>
						</view>
					</view>
					<view class="team-foot">
						<!-- 查看进度按钮 -->
						<button class="team-btn" @click="toTeamDetail(item)" type="default">查看历史纪录</button>
					</view>
				</view>

			</view>

		</view>
	</view>
</template>

<script>
	import mvBar from "@/components/mys_navBar/mysNavBar";
	import {
		fansview,
		money
	} from '@/components/utils.js';
	import {
		showLoading
	} from "../../uni_modules/sakura-canvas/js_sdk/util";
	export default {
		components: {
			mvBar,
		},
		data() {
			return {
				navH: getApp().globalData.navHeight,
				picture: getApp().globalData.picture,
				mysNavConfig: {
					/* 开启单页显示首页图标 */
					isHome: true,
					/* 固定导航  */
					navFixed: true,
					/* 标题 （屏幕中心居中 两边图标中心居中使用slot center1） */
					navTitle: {
						text: "YOUNG之团",
						color: "",
						fontSize: "32rpx", // px upx rpx
						fontWeight: "normal", // 100 - 700
					},
					btnType: "type2",
					onLeftClick: "/pages/mycenter/mycenter",
					/* type2 按钮 */
					type2Config: {
						// 左图标
						leftPath: "/static/img/png2.png",
						// 右图标
						rightPath: "/static/img/png4.png",
						// 圆角
						radius: "40rpx",
					},
				},
				loading: false,
				platformList: [],

				searchValue: "",
				showList1: false,
				showList2: false,
				tab: 'exe',
				status: 2,

				moneyIncome: 0.0,
				pointIncome: 0,
				youngTeamList: [],

			}
		},
		async onLoad(options) {
			// 判断登录
			await this.isLogin();
			if (this.token === '') {
				uni.showModal({
					content: '请先登录',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/login/login'
							});
						} else if (res.cancel) {
							uni.navigateBack();
						}
					}
				});
			}
			await this.getInfoList()
			let data = options.textObj.replace(/""/g, "");
			data = JSON.parse(decodeURIComponent(data))
			this.tab = data.tab
			this.status = this.tab === 'exe' ? 2 : 3
			this.getYoungTeam()
		},
		methods: {
			// 判断登陆是否过期
			isLogin() {
				return this.$https.get('/youngee/c/t/g/is-login')
					.then(res => {
						if (res.data.code === 403) {
							// 登陆已失效
							this.token = ""
							uni.clearStorage();
						} else {
							this.token = uni.getStorageSync('token')
						}
					})
			},
			async search(res) {
				uni.showToast({
					title: '搜索：' + res.value,
					icon: 'none'
				})
			},
			handleCopy(text) {
				wx.setClipboardData({
					data: text,
					success: function(res) {
						console.log("复制成功");
					}
				});
			},
			toShow1() {
				this.tab = 'exe';
				this.status = 2
				this.getYoungTeam()
			},
			toShow2() {
				this.tab = 'end';
				this.status = 3
				this.getYoungTeam()
			},
			async getYoungTeam() {
				this.loading = true;
				uni.showLoading({
					title: '加载中'
				});
				await this.$https.get('/youngee/c/t/g/get-younggee-team-list?' +
						'status=' +
						this.status)
					.then(res => {
						if (res.data.code === 0) {
							this.youngTeamList = res.data.data.young_team_list
							let num = res.data.data.num
							this.moneyIncome = money(res.data.data.money_income)
							this.pointIncome = res.data.data.point_income
							for (let i = 0; i < num; ++i) {
								this.youngTeamList[i].platform_icon = this.platformList[this.youngTeamList[
										i]
									.platform - 1].platform_icon
								this.youngTeamList[i].show_money_income = money(this.youngTeamList[i]
									.money_income)
							}
						}
					})
				uni.hideLoading();
				this.loading = false;
			},
			getInfoList() {
				return this.$http.get('/youngee/c/g/get-info-tables')
					.then(res => {
						if (res.data.code === 0) {
							this.platformList = res.data.data.ThirdPlatform
						}
					})
			},
		}
	}
</script>

<style>
	/deep/ .uni-searchbar__box-search-input {
		font-size: 32rpx !important;
	}
</style>

<style lang="scss" scoped>
	p {
		font-size: 32rpx;
	}

	.head {
		margin: 10rpx 3%;
		border-radius: 15rpx;
		background-color: #f0d232;
		height: 200rpx;
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.show-income {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.content {
		margin: 30rpx 3%;
	}

	.menu {
		display: flex;
		align-items: center;
		justify-content: space-around;
	}

	.menu-item p {
		font-weight: 600;

		&.lor {
			border-bottom: 5rpx solid #F0D232;
			color: #F0D232;
			padding-bottom: 15rpx;
		}

		&.unlor {
			color: #81838f;
			padding-bottom: 15rpx;
			border-bottom: 5rpx solid #ffffff;
		}
	}

	.point-card {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.point-card-left {
		display: flex;
		flex-direction: column;
		justify-content: start;
	}

	.point-card-right p {
		color: #f0d232;
		font-weight: 600;
	}

	.team-list {
		padding: 20rpx 0;
	}

	.team-card {
		margin: 20rpx 0;
		display: flex;
		flex-direction: column;
		// justify-content: start;
	}

	.project {
		display: flex;
		align-items: center;
	}

	.project p {
		font-weight: 600;
	}

	.platform-img {
		width: 40rpx;
		height: 40rpx;
		// background-color: #F0D232;
		margin-right: 10rpx;
	}

	.togo-icon {
		width: 30rpx;
		height: 30rpx;
	}

	.team-info {
		margin: 20rpx 0;
		display: flex;
		justify-content: start;
		align-items: center;
	}

	.project-img {
		width: 120rpx;
		height: 120rpx;
		background-color: #b3c96b;
	}

	.team-txt {
		margin-left: 10rpx;
		display: flex;
		flex-direction: column;
	}

	.team-txt p {
		font-size: 28rpx;
	}


	.team-foot {
		padding: 0 20rpx;
		text-align: right;
	}

	.team-btn::after {
		border: none;
	}

	.team-btn {
		display: inline-block;
		width: 250rpx;
		border: 1rpx solid #F0D232;
		background-color: #ffffff;
		border-radius: 15rpx;
		font-size: 28rpx;
		line-height: 200%;
	}
</style>