<template>
	<view style="position: relative;">
		<!-- 胶囊 -->
		<mvBar :mysNavConfig="mysNavConfig"></mvBar>
		<view :style="{marginTop:navH}"></view>
		<view class="head">
			<view class="show-income1">
				<view class="show-income1-left">
					<view class="show-income1-left-up">
						<view style="display: flex;align-items: center;">
							<p>我获得的收益总数</p>
							<image id="helpicon" :src="picture.icon_help" mode=""
								style="width: 35rpx;height: 35rpx;padding-left: 10rpx;"
								@click="showIncomeHelp = true" />
						</view>
						<view class="tip_box" v-if="showIncomeHelp">
							<view class="container" :style="{
						  'margin-right': cotainerMargin + 'px',
						  backgroundColor: '#404040', borderRadius: '5px' }">
								<!-- 提示文字 -->
								<view class="tips">
									<p>{{incomeHelpText}}</p>
								</view>
								<view class="close" @click="showIncomeHelp = false">
									<image class="closeImg" src="../../static/delete.png" />
								</view>
							</view>
						</view>
					</view>
					<view class="show-income1-left-down">
						<p @click="toIncome('can')">
							{{information.showIncome?information.showIncome:'0.0'}}
						</p>
					</view>
				</view>
				<view class="show-income1-right">
					<view>
						<button class="show-income1-btn" type="default" @click="toIncome('can')">提现</button>
					</view>
				</view>
			</view>

			<view class="show-income2">
				<view class="show-income2-text" @click="toIncome('can')">
					<p style="padding-bottom: 20rpx;">可提现</p>
					<p>{{information.showCanwithdraw?information.showCanwithdraw:'0.0'}}</p>
				</view>
				<view class="show-income2-text" @click="toIncome('ed')">
					<p style="padding-bottom: 20rpx;">已提现</p>
					<p>{{information.showWithdrawed?information.showWithdrawed:'0.0'}}</p>
				</view>
				<view class="show-income2-text" @click="toIncome('ing')">
					<p style="padding-bottom: 20rpx;">提现中</p>
					<p>{{information.showWithdrawing?information.showWithdrawing:'0.0'}}</p>
				</view>
			</view>
			<view class="show-income3">
				<p style="font-weight: bold;">收益明细</p>
				<view class="menu">
					<view class="menu-item" @click="toShow1()">
						<p v-bind:class="showList1?'lor':'unlor'">可提现</p>
					</view>
					<view class="menu-item" @click="toShow2()">
						<p v-bind:class="showList2?'lor':'unlor'">已提现</p>
					</view>
					<view class="menu-item" @click="toShow3()">
						<p v-bind:class="showList3?'lor':'unlor'">提现中</p>
					</view>
				</view>
			</view>
		</view>
		<view class="home">

			<view class="income-list" v-if="showList1">
				<checkbox-group @change="changeCheck">
					<view class="income-list-cell" v-for="item in unWithdrawList" :key="item.value">
						<view class="income-list-cell-left">
							<label>
								<view>
									<checkbox class="income-list-checkbox" :value="item.task_id"
										:checked="item.checked" />
								</view>
							</label>
							<view class="income-info">
								<view class="income-info-product">
									<image :src="item.photo_url"></image>
								</view>
								<view class="income-info-tp">
									<p>任务ID：{{item.task_id}}</p>
									<view class="income-info-project">
										<image :src="item.platform_icon_url"></image>
										<p>{{item.task_name}}</p>
									</view>
								</view>
							</view>
						</view>

						<view class="income-list-cell-right">
							<p style="color: #f2d22d;font-size: 36rpx;font-weight: 600;">+{{item.showIncome}}
							</p>
							<p>{{item.showLabel}}</p>
						</view>
					</view>
				</checkbox-group>
			</view>

			<view class="income-list" v-if="showList2">
				<view class="income-list-cell" style="margin-left: 50rpx;" v-for="item in withdrawedList"
					:key="item.value">
					<view class="income-list-cell-left">
						<view class="income-info">
							<view class="income-info-product">
								<image :src="item.photo_url"></image>
							</view>
							<view class="income-info-tp">
								<p>任务ID：{{item.task_id}}</p>
								<view class="income-info-project">
									<image :src="item.platform_icon_url"></image>
									<p>{{item.task_name}}</p>
								</view>
							</view>
						</view>
					</view>

					<view class="income-list-cell-right">
						<p style="color: #f2d22d;font-size: 36rpx;font-weight: 600;">+{{item.showIncome}}
						</p>
						<p>{{item.showLabel}}</p>
					</view>
				</view>
			</view>

			<view class="income-list" v-if="showList3">
				<view class="income-list-cell" style="margin-left: 50rpx;" v-for="item in withdrawingList"
					:key="item.value">
					<view class="income-list-cell-left">
						<view class="income-info">
							<view class="income-info-product">
								<image :src="item.photo_url"></image>
							</view>
							<view class="income-info-tp">
								<p>任务ID：{{item.task_id}}</p>
								<view class="income-info-project">
									<image :src="item.platform_icon_url"></image>
									<p>{{item.task_name}}</p>
								</view>
							</view>
						</view>
					</view>

					<view class="income-list-cell-right">
						<p style="color: #f2d22d;font-size: 36rpx;font-weight: 600;">+{{item.showIncome}}
						</p>
						<p>{{item.showLabel}}</p>
					</view>
				</view>
			</view>

			<view class="interval2"></view>
			<view class="income-workList-buttons" v-if="showList1">
				<view>
					<label class="all-check-box left-btn">
						<view>
							<checkbox-group @change="changeAll">
								<checkbox class="income-list-checkbox" :value="allCheck.value"
									:checked="allCheck.checked" />
							</checkbox-group>
						</view>
						<view style="display: flex;justify-content: center;align-items: center;">
							<p>{{allCheck.name}}</p>
						</view>
					</label>
				</view>

				<view>
					<button class="right-btn" type="primary" @click="submitWithdraw()">提现</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import mvBar from "@/components/mys_navBar/mysNavBar";
	import {
		money,
		fansview
	} from '@/components/utils.js';
	export default {
		components: {
			mvBar,
		},
		data() {
			return {
				navH: getApp().globalData.navHeight,
				picture: getApp().globalData.picture,

				unWithdrawList: [],
				withdrawingList: [],
				withdrawedList: [],
				allCheck: {
					name: '全选',
					value: 'all',
					checked: false
				},
				showTab: "",
				showList1: true,
				showList2: false,
				showList3: false,
				mysNavConfig: {
					/* 开启单页显示首页图标 */
					isHome: true,
					/* 固定导航  */
					navFixed: true,
					/* 标题 （屏幕中心居中 两边图标中心居中使用slot center1） */
					navTitle: {
						text: "我的收益",
						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",
					},
				},
				codeImg: '',
				information: {},
				incomeHelpText: "在平台产生的总收益【可提现+已提现+提现中】",
				showIncomeHelp: false,
				labelList: [
					"",
					"任务收益",
					"开团收益",
					"样品返现",
					"悬赏收益"
				],
			};
		},
		async onShow() {
			// 判断登录
			uni.showLoading({
				title: '加载中'
			});
			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();
						}
					}
				});
			} else {
				await this.getTalentInfo();
				// this.toShow1()
				// await this.getTaskInfo();
			}
			uni.hideLoading();
		},
		onLoad(options) {
			console.log(options)
			this.showTab = options.showTab
			// 传过来的id
			console.log(this.showTab)
			if (this.showTab == '1') {
				this.toShow1();
			} else if (this.showTab == '2') {
				this.toShow2();
			} else if (this.showTab == '3') {
				this.toShow3();
			} else {
				this.toShow1();
			}
		},
		methods: {	
			toShow1() {
				this.showList2 = false;
				this.showList3 = false;
				this.showList1 = true;
				this.getTalentIncome(1);
			},
			toShow2() {
				this.showList1 = false;
				this.showList3 = false;
				this.showList2 = true;
				this.getTalentIncome(3);
			},
			toShow3() {
				this.showList2 = false;
				this.showList1 = false;
				this.showList3 = true;
				this.getTalentIncome(2);
			},
			// 全选
			changeAll: function(e) {
				if (e.detail.value.length == 0) {
					this.unWithdrawList.map(item => this.$set(item, 'checked', false));
					this.$set(this.allCheck, 'checked', false);
				} else {
					this.unWithdrawList.map(item => this.$set(item, 'checked', true));
					this.$set(this.allCheck, 'checked', true);
				}
			},
			// 多选
			changeCheck: function(e) {
				var items = this.unWithdrawList;
				var len = this.unWithdrawList.length;
				var values = e.detail.value;
				console.log(values)
				for (var i = 0; i < len; i++) {
					var item = items[i];
					if (values.includes(String(item.task_id))) {
						this.$set(item, 'checked', true);
					} else {
						this.$set(item, 'checked', false);
					}
				}
				// 判断选中状态
				var isAll = this.list1.every(item => item.checked == true)
				isAll ? this.$set(this.allCheck, 'checked', true) : this.$set(this.allCheck, 'checked', false)
			},
			// 判断登陆是否过期
			isLogin() {
				return this.$https.get('/youngee/c/t/g/is-login')
					.then(res => {
						if (res.data.code === 403) {
							// 登陆已失效
							this.token = ""
						} else {
							this.token = uni.getStorageSync('token')
						}
					})
			},
			getTalentInfo() {
				return this.$https.get('/youngee/c/t/g/get-talent-info')
					.then(res => {
						if (res.data.code === 0) {
							this.information = res.data.data
							this.information.showWithdrawing = money(this.information.withdrawing)
							this.information.showWithdrawed = money(this.information.withdrawed)
							this.information.showCanwithdraw = money(this.information.canwithdraw)
							this.information.showIncome = money(this.information.income)
						}
					});
			},
			getTalentIncome(val) {
				return this.$https.post('/youngee/c/t/p/get-talent-income-info', {
					type: val
				}).then(res => {
					if (res.data.code === 0) {
						let data = res.data.data
						for (let i = 0; i < data.length; ++i) {
							data[i].showIncome = money(data[i].income)
							data[i].showLabel = this.labelList[data[i].income_type]
						}
						if (val === 1) {
							this.unWithdrawList = data
						} else if (val === 2) {
							this.withdrawingList = data
						} else {
							this.withdrawedList = data
						}
					}
				})
			},		
			submitWithdraw() {
				let incomeIdList = []
				let totalAmount = 0
				for (let i = 0; i < this.unWithdrawList.length; ++i) {
					if (this.unWithdrawList[i].checked) {
						incomeIdList.push(this.unWithdrawList[i].id)
						totalAmount += this.unWithdrawList[i].income
					}
				}
				if (incomeIdList.length == 0) {
					uni.showToast({
						content: '请先选择提现订单',
						icon: 'none'
					});
					return
				}
				var data = {
					incomeIdList: incomeIdList,
					totalAmount: totalAmount
				};
				data = JSON.stringify(data)
				uni.navigateTo({
					url: '/page_mycenter/myincome/applywithdraw?textObj=' + encodeURIComponent(data)
				});
			}
		// // 获取提现任务
		// getTaskInfo() {
		// 	return this.$https.get('/youngee/c/t/g/get-withdraw-task-info')
		// 		.then(res => {
		// 			this.list1 = []
		// 			this.list2 = []
		// 			this.list3 = []
		// 			// console.log(res)
		// 			if (res.data.data.can_withdraw_task_info_list != null) {
		// 				this.list1 = res.data.data.can_withdraw_task_info_list
		// 				for (let i = 0; i < this.list1.length; i++) {
		// 					this.list1[i].show_task_reward = money(this.list1[i].task_reward)
		// 					this.list1[i].show_settle_amount = money(this.list1[i].settle_amount)
		
		// 					let ProductPhoto = JSON.parse(this.list1[i].product_photo);
		// 					for (let j = 0; j < ProductPhoto.length; ++j) {
		// 						if (ProductPhoto[j].Symbol == 1) {
		// 							this.list1[i].product_photo = ProductPhoto[j]
		// 						}
		// 					}
		// 				}
		// 			}
		// 			if (res.data.data.withdrawed_task_info_list != null) {
		// 				this.list2 = res.data.data.withdrawed_task_info_list
		// 				for (let i = 0; i < this.list2.length; i++) {
		// 					this.list2[i].show_task_reward = money(this.list2[i].task_reward)
		// 					this.list2[i].show_settle_amount = money(this.list2[i].settle_amount)
		// 					let ProductPhoto = JSON.parse(this.list2[i].product_photo);
		// 					for (let j = 0; j < ProductPhoto.length; ++j) {
		// 						if (ProductPhoto[j].Symbol == 1) {
		// 							this.list2[i].product_photo = ProductPhoto[j]
		// 						}
		// 					}
		// 				}
		// 			}
		// 			if (res.data.data.withdrawing_task_info_list != null) {
		// 				this.list3 = res.data.data.withdrawing_task_info_list
		// 				for (let i = 0; i < this.list3.length; i++) {
		// 					this.list3[i].show_task_reward = money(this.list3[i].task_reward)
		// 					this.list3[i].show_settle_amount = money(this.list3[i].settle_amount)
		// 					let ProductPhoto = JSON.parse(this.list3[i].product_photo);
		// 					for (let j = 0; j < ProductPhoto.length; ++j) {
		// 						if (ProductPhoto[j].Symbol == 1) {
		// 							this.list3[i].product_photo = ProductPhoto[j]
		// 						}
		// 					}
		// 				}
		// 			}
		// 		})
		// },
		},
	};
</script>
<style>
	/deep/ .share .uni-popup .uni-popup__wrapper {
		width: 70% !important;
		border-radius: 15rpx !important;
	}
</style>
<style lang="scss" scoped>
	p {
		font-size: 32rpx;
	}

	.head {
		padding: 20rpx 0;
		background-color: #fff;
		position: fixed;
		width: 100%;
		z-index: 999;
	}

	.home {
		padding-top: 550rpx;
	}

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

	.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;
		}
	}

	.show-income1 {
		display: flex;
		align-items: center;
		height: 120rpx;
		margin: 0 3%;
	}

	.show-income1-text {
		margin-left: 20rpx;
		margin-right: 200rpx;
	}

	.show-income1-text2 {
		flex: 1;
		display: flex;
	}

	.show-income1-btn {
		width: 200rpx;
		text-align: center;
		background-color: #F0D232;
		border-radius: 15rpx;
		font-size: 35rpx;
		line-height: 180%;
	}

	.show-income2 {
		display: flex;
		align-items: center;
		justify-content: space-around;
		height: 150rpx;
		margin: 0 3% 3%;
		background-color: #F0D232;
		border-radius: 10rpx;
	}

	.show-income2-text {
		// padding: 0 50rpx;
		text-align: center;
	}

	.show-income3 {
		margin: 0 50rpx;
	}

	.show-income3 p {
		margin-top: 50rpx;
	}

	.income-list {
		margin-bottom: 100rpx;
	}

	.income-list-cell {
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.income-list-cell-left {
		display: flex;
		align-items: center;
		margin: 20rpx 0;
	}

	.income-list-cell-right {
		display: flex;
		flex-direction: column;
		align-items: flex-end;
		width: 50%;
	}

	.income-list-cell-right p {
		// color: #F0D232;
		font-size: 32rpx;
		margin-right: 50rpx;
	}

	// .income-list-cell2 {
	// 	margin-left: 70rpx;
	// }

	.income-info {
		display: flex;
		// align-items: center;
	}

	.income-list-checkbox {
		width: 50rpx;
		transform: scale(0.7)
	}

	.income-info-product image {
		height: 120rpx;
		width: 120rpx;
		padding: 10rpx;
	}

	.income-info-tp {
		display: flex;
		flex-direction: column;
	}

	.income-info-project {
		display: flex;
		align-items: center;
		margin: 10rpx 0;
	}

	.income-info-project image {
		height: 40rpx;
		width: 70rpx;
		padding-right: 20rpx;
	}

	.interval2 {
		width: 100%;
		height: 120rpx;
		margin-top: 5%;
	}

	.income-workList-buttons {
		display: flex;
		justify-content: space-between;
		align-items: center;

		padding: 2% 50rpx;
		position: fixed;
		width: 90%;
		bottom: 20rpx;
		height: 90rpx;
		// padding-top: 2%;
		background-color: #FFFFFF;
		margin-top: 100rpx;
	}

	.all-check-box {
		display: flex;
		margin-left: -20rpx;
	}

	.right-btn {
		width: 150rpx;
		text-align: center;
		color: #000;
		background-color: #F0D232;
		border-radius: 15rpx;
		font-size: 32rpx;
		line-height: 180%;
	}


	.show-income1 {
		height: 150rpx;
		margin: 0 3% 0 8%;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.show-income1-btn {
		width: 150rpx;
		// padding: 0 40rpx;
		text-align: center;
		background-color: #F0D232;
		border-radius: 15rpx;
		font-size: 32rpx;
		line-height: 250%;
	}

	.show-income1-left {
		display: flex;
		flex-direction: column;
		justify-content: start;
	}

	.show-income1-left-up {
		margin-bottom: 10rpx;
	}

	.show-income1-left-down p {
		font-size: 40rpx;
		font-weight: bold;
		color: #F0D232;
	}

	.show-income1-right {
		padding-right: 20rpx;
	}

	.show-income2 {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 150rpx;
		margin: 0 3% 3%;
		background-color: #F0D232;
		border-radius: 10rpx;
		padding: 0 5%;
	}

	.show-income2-text {
		width: 24%;
		text-align: center;
	}

	.tip_box {
		position: absolute;
		right: 0;
		z-index: 9999;
		display: flex;
		justify-content: flex-end;
		align-items: flex-end;
		flex-direction: column;

		.arrow {
			width: 0;
			height: 0;
			border: 10rpx solid;
			border-color: transparent;
		}

		.container {
			display: flex;
			align-items: center;
			justify-content: center;
			padding: 16rpx 24rpx;

			.tips {
				flex: 1;
				padding-right: 12rpx;
			}

			.tips p {
				font-size: 24rpx;
				color: #fff
			}

			.close {
				display: flex;
				align-items: center;
				height: 30rpx;
				width: 30rpx;

				.closeImg {
					height: 100%;
					width: 100%;
				}
			}
		}
	}
</style>