<template>
	<view style="position: relative;">
		<!-- 胶囊 -->
		<mvBar :mysNavConfig="mysNavConfig"></mvBar>
		<view :style="{marginTop:navH}"></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 class="income-list" v-if="showList1">
				<checkbox-group @change="changeCheck">
					<view class="income-list-cell" v-for="item in list1" :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>
								<p>任务ID：{{item.task_id}}</p>
								<p>{{item.project_name}}</p>
								<p>商品价值：{{item.product_price}}元</p>
								<p>粉丝量：{{item.RecruitStrategy.show_followers_low}}-{{item.RecruitStrategy.show_followers_up}}
								</p>
								<p>稿费：{{item.RecruitStrategy.show_fee_form}} {{item.show_task_reward}}</p>
								<p>提交时间：{{item.complete_date}}</p>
							</view>
						</view>

						<view class="income-list-cell-right">
							<p>+{{item.show_settle_amount}}</p>
						</view>
					</view>
				</checkbox-group>
			</view>

			<view class="income-list" v-if="showList2">
				<view class="income-list-cell" style="margin-left: 70rpx;" v-for="item in list2" :key="item.value">
					<view class="income-list-cell-left">
						<view>
							<p>任务ID：{{item.task_id}}</p>
							<p>{{item.project_name}}</p>
							<p>商品价值：{{item.product_price}}元</p>
							<p>粉丝量：{{item.RecruitStrategy.show_followers_low}}-{{item.RecruitStrategy.show_followers_up}}
							</p>
							<p>稿费：{{item.RecruitStrategy.show_fee_form}} {{item.show_task_reward}}</p>
							<p>提交时间：{{item.withdraw_date}}</p>
						</view>
					</view>

					<view class="income-list-cell-right">
						<p>+{{item.show_settle_amount}}</p>
					</view>
				</view>
			</view>

			<view class="income-list" v-if="showList3">
				<view class="income-list-cell" style="margin-left: 70rpx;" v-for="item in list3" :key="item.value">
					<view class="income-list-cell-left">
						<view>
							<p>任务ID：{{item.task_id}}</p>
							<p>{{item.project_name}}</p>
							<p>商品价值：{{item.product_price}}元</p>
							<p>粉丝量：{{item.RecruitStrategy.show_followers_low}}-{{item.RecruitStrategy.show_followers_up}}
							</p>
							<p>稿费：{{item.RecruitStrategy.show_fee_form}} {{item.show_task_reward}}</p>
							<p>提交时间：{{item.withdraw_date}}</p>
						</view>
					</view>

					<view class="income-list-cell-right">
						<p>+{{item.show_settle_amount}}</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="withdraw()">提现</button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import mvBar from "@/components/mys_navBar/mysNavBar";
	import {
		getRouter,
		money,
		fansview
	} from '@/components/utils.js';
	export default {
		components: {
			mvBar,
		},
		data() {
			return {
				navH: getApp().globalData.navHeight,
				// 测试数据
				// list1: [{
				// 	task_id: "001abandon",
				// 	project_name: "PUYU朴郁小树茶冻干茶粉",
				// 	product_price: 78,
				// 	RecruitStrategy: {
				// 		followers_low: "1万",
				// 		followers_up: "3万",
				// 		show_fee_form: "创作者自报价",
				// 		offer: 350,
				// 	},
				// 	settle_amount: 350,
				// 	complete_date: "2022-3-2 14:00",
				// 	checked: false
				// }, {
				// 	task_id: "002abash",
				// 	project_name: "Pisco生姜气泡饮料",
				// 	product_price: 68,
				// 	RecruitStrategy: {
				// 		followers_low: "1万",
				// 		followers_up: "3万",
				// 		show_fee_form: "固定稿费",
				// 		offer: 300,
				// 	},
				// 	settle_amount: 150,
				// 	complete_date: "2022-3-2 14:00",
				// 	checked: false
				// }],
				// list2: [{
				// 	task_id: "003abash",
				// 	project_name: "小鹏海南试驾",
				// 	product_price: 68,
				// 	RecruitStrategy: {
				// 		followers_low: "1万",
				// 		followers_up: "3万",
				// 		show_fee_form: "固定稿费",
				// 		offer: 4000,
				// 	},
				// 	settle_amount: 4000,
				// 	complete_date: "2022-3-2 14:00",
				// }, {
				// 	task_id: "004abbreviate",
				// 	project_name: "优衣库三里屯店新店开业",
				// 	product_price: 100,
				// 	RecruitStrategy: {
				// 		followers_low: "5万",
				// 		followers_up: "10万",
				// 		show_fee_form: "固定稿费",
				// 		offer: 1200,
				// 	},
				// 	settle_amount: 1200,
				// 	complete_date: "2022-3-2 14:00",
				// }],
				// list3: [{
				// 	task_id: "001abandon",
				// 	project_name: "PUYU朴郁小树茶冻干茶粉",
				// 	product_price: 78,
				// 	RecruitStrategy: {
				// 		followers_low: "1万",
				// 		followers_up: "3万",
				// 		show_fee_form: "创作者自报价",
				// 		offer: 350,
				// 	},
				// 	settle_amount: 350,
				// 	complete_date: "2022-3-2 14:00",
				// }],

				list1: [],
				list2: [],
				list3: [],
				allCheck: {
					name: '全选',
					value: 'all',
					checked: false
				},
				showTab: "",
				showList1: true,
				showList2: false,
				showList3: false,
				picture: {
					icon_person: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/youngee/talent_upload/icon-person.png',
					icon_location: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/youngee/talent_upload/icon-location.png',
					icon_account: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/youngee/talent_upload/icon-account.png',
					icon_rmb: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/youngee/talent_upload/icon-rmb.png',
					icon_message: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/youngee/talent_upload/icon-message.png',
					icon_right: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/talent_upload/icon-arrow-right.png',
					defaultavatarUrl: 'https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/logoxin01.png',
				},
				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: {},
			};
		},
		async onShow() {
			// 判断登录
			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 {
				this.getTaskInfo()
			}
		},
		onLoad(options) {
			getRouter();
			console.log(options)
			this.showTab = options.showTab
			// 传过来的id
			if (this.showTab == '1') {
				this.toShow1();
			} else if (this.showTab == '2') {
				this.toShow2();
			} else if (this.showTab == '3') {
				this.toShow3();
			}
		},
		methods: {
			// 判断登陆是否过期
			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')
						}
					})
			},
			// 全选
			changeAll: function(e) {
				if (e.detail.value.length == 0) {
					this.list1.map(item => this.$set(item, 'checked', false));
					this.$set(this.allCheck, 'checked', false);
				} else {
					this.list1.map(item => this.$set(item, 'checked', true));
					this.$set(this.allCheck, 'checked', true);
				}
			},
			// 多选
			changeCheck: function(e) {
				var items = this.list1;
				var len = this.list1.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)
			},

			// 获取提现任务
			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)
								this.list1[i].RecruitStrategy.show_followers_low = fansview(this.list1[i]
									.RecruitStrategy.followers_low)
								this.list1[i].RecruitStrategy.show_followers_up = fansview(this.list1[i]
									.RecruitStrategy.followers_up)
								switch (this.list1[i].RecruitStrategy.fee_form) {
									case 1:
										this.list1[i].RecruitStrategy.show_fee_form = "产品置换"
										break
									case 2:
										this.list1[i].RecruitStrategy.show_fee_form = "固定稿费"
										break
									case 3:
										this.list1[i].RecruitStrategy.show_fee_form = "自报价"
										break
								}
							}
						}
						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)
								this.list2[i].RecruitStrategy.show_followers_low = fansview(this.list2[i]
									.RecruitStrategy.followers_low)
								this.list2[i].RecruitStrategy.show_followers_up = fansview(this.list2[i]
									.RecruitStrategy.followers_up)
								switch (this.list2[i].RecruitStrategy.fee_form) {
									case 1:
										this.list2[i].RecruitStrategy.show_fee_form = "产品置换"
										break
									case 2:
										this.list2[i].RecruitStrategy.show_fee_form = "固定稿费"
										break
									case 3:
										this.list2[i].RecruitStrategy.show_fee_form = "自报价"
										break
								}
							}
						}
						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)
								this.list3[i].RecruitStrategy.show_followers_low = fansview(this.list3[i]
									.RecruitStrategy.followers_low)
								this.list3[i].RecruitStrategy.show_followers_up = fansview(this.list3[i]
									.RecruitStrategy.followers_up)
								switch (this.list3[i].RecruitStrategy.fee_form) {
									case 1:
										this.list3[i].RecruitStrategy.show_fee_form = "产品置换"
										break
									case 2:
										this.list3[i].RecruitStrategy.show_fee_form = "固定稿费"
										break
									case 3:
										this.list3[i].RecruitStrategy.show_fee_form = "自报价"
										break
								}
							}
						}
					})
			},
			// 进入收益页面
			toincome(tab) {
				console.log(tab)
			},
			toShow1() {
				this.showList2 = false;
				this.showList3 = false;
				this.showList1 = true;
			},
			toShow2() {
				this.showList1 = false;
				this.showList3 = false;
				this.showList2 = true;
			},
			toShow3() {
				this.showList2 = false;
				this.showList1 = false;
				this.showList3 = true;
			},
			withdraw() {
				if (this.list1.length == 0) {
					uni.showModal({
						content: '请先选择提现任务',
					});
					return
				}
				let taskIdList = []
				let totalAmount = 0
				for (let i = 0; i < this.list1.length; ++i) {
					if (this.list1[i].checked) {
						taskIdList.push(this.list1[i].task_id)
						totalAmount += this.list1[i].settle_amount
					}
				}
				var data = {
					taskIdList: taskIdList,
					totalAmount: totalAmount
				};
				data = JSON.stringify(data)
				uni.navigateTo({
					url: './myincome/applywithdraw?textObj=' + encodeURIComponent(data)
				});
			}
		},
	};
</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;
	}

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

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

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

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

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

		margin-right: 20rpx;
	}

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

	.income-list-cell-right p {
		color: #F0D232;
		font-size: 35rpx;
	}

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

	.income-list-checkbox {
		transform: scale(0.7)
	}

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

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

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

	.all-check-box {
		display: flex;
	}

	.right-btn {
		width: 200rpx;
		text-align: center;
		color: #000;
		background-color: #F0D232;
		border-radius: 15rpx;
		font-size: 32rpx;
		line-height: 200%;
	}
</style>
