<template>
	<view>
		<!-- 胶囊 -->
		<mvBar :mysNavConfig="mysNavConfig"></mvBar>
		<view :style="{paddingTop:navH}" style="background-color: #fff;"></view>
		<view class="menu-head">
			<view class="menu" style="padding-bottom: 10rpx;">
				<view class="menu-item" @click="toShowTask()">
					<view class="menu-item-p">
						<p v-bind:class="showTask?'lor':'unlor'">任务大厅</p>
					</view>
					<!-- <span class="point" v-if="showPoint1" key="0"></span> -->
				</view>
				<view class="menu-item" @click="toShowSec()">
					<view class="menu-item-p">
						<p v-bind:class="showSec?'lor':'unlor'">选品广场</p>
					</view>
					<!-- <span class="point" v-if="showPoint2" key="1"></span> -->
				</view>
			</view>

			<view class="menu" v-if="showTask">

				<view class="menu-item" @click="toShow(index)" v-for="(item,index) in taskTabList">
					<view class="menu-item-p">
						<p v-bind:class="showList[index]?'lor':'unlor'">{{item}}</p>
					</view>
					<span class="point" v-if="showPoint[index]" :key="index"></span>
				</view>
			</view>

			<view class="menu" v-if="showSec">
				<view class="menu-item" @click="toShow(4)">
					<view class="menu-item-p">
						<p v-bind:class="showList[4]?'lor':'unlor'">待交作业</p>
					</view>
					<span class="point" v-if="showPoint[4]" key="0"></span>
				</view>
				<view class="menu-item">
					<view class="menu-item-p">
						<p style="color: #fff;">待传初稿</p>
					</view>
				</view>
				<view class="menu-item">
					<view class="menu-item-p">
						<p style="color: #fff;">待传链接</p>
					</view>
				</view>
				<view class="menu-item">
					<view class="menu-item-p">
						<p style="color: #fff;">待传数据</p>
					</view>
				</view>
			</view>
		</view>

		<view class="home" v-if="showList[0] && !loading">
			<view class="task" v-for="item in taskLists[0]" @click="toTaskDetail(item)">
				<view class="task-card">
					<view class="task-head">
						<view class="task-head-account">
							<image class="platform-img" :src="item.platform_icon_url"></image>
							<p>{{item.platform_nick_name}}</p>
						</view>
						<view class="task-head-status">
							<p>{{item.task_stage_txt}}</p>
						</view>
					</view>
					<view class="task-info">
						<view class="task-info-left">
							<image class="project-img" :src="item.product_img_url"></image>
							<view class="task-info-txt">
								<p style="color: #000;font-size: 32rpx;">{{item.project_name}}</p>
								<p style="color: #F0D232;" v-if="!item.time_out">上传截止时间：{{item.upload_ddl}}</p>
								<p style="color: #f70c0c;" v-else>超时：{{item.upload_ddl}}</p>
								<p>预计违约扣款金额：￥{{item.show_cut_payment}}</p>
								<p>预计收益：￥{{item.show_task_reward}}</p>
							</view>
						</view>
						<view class="task-info-right" v-if="item.isShowModify">
							<image src="../../static/img/icon-edit.png" style="height: 60rpx;width: 60rpx;"></image>
							<p style="font-size: 32rpx;color: #ffcb41;font-weight: 600">改</p>
						</view>
					</view>
					<view style="text-align: right;" v-if="item.task_stage > 6">
						<p style="display: inline-block;">实际收益：￥{{item.show_real_reward}}</p>
					</view>
				</view>
			</view>
		</view>

		<view class="home" v-if="showList[1] && !loading">
			<view class="task" v-for="item in taskLists[1]" @click="toTaskDetail(item)">
				<view class="task-card">
					<view class="task-head">
						<view class="task-head-account">
							<image class="platform-img" :src="item.platform_icon_url"></image>
							<p>{{item.platform_nick_name}}</p>
						</view>
						<view class="task-head-status">
							<p>{{item.task_stage_txt}}</p>
						</view>
					</view>
					<view class="task-info">
						<view class="task-info-left">
							<image class="project-img" :src="item.product_img_url"></image>
							<view class="task-info-txt">
								<p style="color: #000;font-size: 32rpx;">{{item.project_name}}</p>
								<p style="color: #F0D232;" v-if="!item.time_out">上传截止时间：{{item.upload_ddl}}</p>
								<p style="color: #f70c0c;" v-else>超时：{{item.upload_ddl}}</p>
								<p>预计违约扣款金额：￥{{item.show_cut_payment}}</p>
								<p>预计收益：￥{{item.show_task_reward}}</p>
							</view>
						</view>
						<view class="task-info-right" v-if="item.isShowModify">
							<image src="../../static/img/icon-edit.png" style="height: 60rpx;width: 60rpx;"></image>
							<p style="font-size: 32rpx;color: #ffcb41;font-weight: 600">改</p>
						</view>
					</view>
					<view style="text-align: right;" v-if="item.task_stage > 6">
						<p style="display: inline-block;">实际收益：￥{{item.show_real_reward}}</p>
					</view>
				</view>
			</view>
		</view>

		<view class="home" v-if="showList[2] && !loading">
			<view class="task" v-for="item in taskLists[2]" @click="toTaskDetail(item)">
				<view class="task-card">
					<view class="task-head">
						<view class="task-head-account">
							<image class="platform-img" :src="item.platform_icon_url"></image>
							<p>{{item.platform_nick_name}}</p>
						</view>
						<view class="task-head-status">
							<p>{{item.task_stage_txt}}</p>
						</view>
					</view>
					<view class="task-info">
						<view class="task-info-left">
							<image class="project-img" :src="item.product_img_url"></image>
							<view class="task-info-txt">
								<p style="color: #000;font-size: 32rpx;">{{item.project_name}}</p>
								<p style="color: #F0D232;" v-if="!item.time_out">上传截止时间：{{item.upload_ddl}}</p>
								<p style="color: #f70c0c;" v-else>超时：{{item.upload_ddl}}</p>
								<p>预计违约扣款金额：￥{{item.show_cut_payment}}</p>
								<p>预计收益：￥{{item.show_task_reward}}</p>
							</view>
						</view>
						<view class="task-info-right" v-if="item.isShowModify">
							<image src="../../static/img/icon-edit.png" style="height: 60rpx;width: 60rpx;"></image>
							<p style="font-size: 32rpx;color: #ffcb41;font-weight: 600">改</p>
						</view>
					</view>
					<view style="text-align: right;" v-if="item.task_stage > 6">
						<p style="display: inline-block;">实际收益：￥{{item.show_real_reward}}</p>
					</view>
				</view>
			</view>
		</view>

		<view class="home" v-if="showList[3] && !loading">
			<view class="task" v-for="item in taskLists[3]" @click="toTaskDetail(item)">
				<view class="task-card">
					<view class="task-head">
						<view class="task-head-account">
							<image class="platform-img" :src="item.platform_icon_url"></image>
							<p>{{item.platform_nick_name}}</p>
						</view>
						<view class="task-head-status">
							<p>{{item.task_stage_txt}}</p>
						</view>
					</view>
					<view class="task-info">
						<view class="task-info-left">
							<image class="project-img" :src="item.product_img_url"></image>
							<view class="task-info-txt">
								<p style="color: #000;font-size: 32rpx;">{{item.project_name}}</p>
								<p style="color: #F0D232;" v-if="!item.time_out">上传截止时间：{{item.upload_ddl}}</p>
								<p style="color: #f70c0c;" v-else>超时：{{item.upload_ddl}}</p>
								<p v-if="item.fee_form != 1">预计违约扣款金额：￥{{item.show_cut_payment}}</p>
								<p>预计收益：￥{{item.show_task_reward}}</p>
							</view>
						</view>
						<view class="task-info-right" v-if="item.isShowModify">
							<image src="../../static/img/icon-edit.png" style="height: 60rpx;width: 60rpx;"></image>
							<p style="font-size: 32rpx;color: #ffcb41;font-weight: 600">改</p>
						</view>
					</view>
					<view style="text-align: right;" v-if="item.task_stage > 6">
						<p style="display: inline-block;">实际收益：￥{{item.show_real_reward}}</p>
					</view>
				</view>
			</view>
		</view>

		<view class="home" v-if="showList[4] && !loading">
			<view class="task" v-for="item in taskLists[4]" @click="toSecTaskDetail(item)">
				<view class="task-card">
					<view class="task-head">
						<view class="task-head-account">
							<image class="platform-img" :src="item.platform_icon_url"></image>
							<p>{{item.platform_nick_name}}</p>
						</view>
						<view class="task-head-status">
							<p>{{item.task_stage_txt}}</p>
						</view>
					</view>
					<view class="task-info">
						<view class="task-info-left">
							<image class="project-img" :src="item.product_img_url"></image>
							<view class="task-info-txt">
								<p style="color: #000;font-size: 32rpx;">{{item.selection_name}}</p>
								<p v-if="item.sample_mode === 2">预计样品返现金额：￥{{item.show_payment}}</p>
								<p>预计收益：￥{{item.show_task_reward}}</p>
							</view>
						</view>
						<view class="task-info-right" v-if="item.isShowModify">
							<image src="../../static/img/icon-edit.png" style="height: 60rpx;width: 60rpx;"></image>
							<p style="font-size: 32rpx;color: #ffcb41;font-weight: 600">改</p>
						</view>
					</view>
					<view style="text-align: right;" v-if="item.task_stage > 5">
						<p style="display: inline-block;">实际收益：￥{{item.show_real_reward}}</p>
					</view>
				</view>
			</view>
		</view>

		<view style="height: 100rpx;"></view>
	</view>
</template>

<script>
	import mvBar from "@/components/mys_navBar/mysNavBar";
	import {
		fansview,
		money
	} from '@/components/utils.js';
	export default {
		components: {
			mvBar,
		},
		data() {
			return {
				navH: getApp().globalData.navHeight,
				loading: true,
				showPoint: [false, false, false, false, false],
				showTask: true,
				showSec: false,
				showList: [
					true, false, false, false, false
				],
				taskLists: [
					[],
					[],
					[],
					[],
					[]
				],
				taskTabList: [
					"待传脚本",
					"待传初稿",
					"待传链接",
					"待传数据"
				],
				secTaskTabList: [
					"待传作业"
				],
				taskStageList: [],
				secTaskStageList: [],
				mysNavConfig: {
					/* 开启单页显示首页图标 */
					isHome: true,
					/* 固定导航  */
					navFixed: true,
					/* 标题 （屏幕中心居中 两边图标中心居中使用slot center1） */
					navTitle: {
						text: "工作台",
						color: "",
						fontSize: "32rpx", // px upx rpx
						fontWeight: "normal", // 100 - 700
					},
				},
				list: [{
					account: {
						platform: "https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/lQLPDhrXwll1_MsjI7CSK_6e62AG2AGOvh1HgAcA_35_35.png",
						nickname: "丸子在成都",
					},
					status: "待确认",
					mainphoto: "https://static1.paizi.com/uploadfile/2018/1013/20181013013207465.png",
					taskname: "醉码头火锅太古里店",
				}, {
					account: {
						platform: "https://horastar.obs.cn-east-3.myhuaweicloud.com/talent/pingtai2.png",
						nickname: "成都的一颗丸子",
					},
					status: "待确认",
					mainphoto: "https://tse1-mm.cn.bing.net/th/id/R-C.978cb3a3b27875a0cc9d78a254b30b8f?rik=yrP2kNCtfQYEgQ&riu=http%3a%2f%2fnews.southcn.com%2fgd%2fcontent%2fimages%2fattachement%2fpng%2fsite4%2f20190917%2feca86b61fd551eeb23c507.png&ehk=xuWbgLrNmyhNJaByMZPJrX81PrzXrLHqHM%2fdYatFhrs%3d&risl=&pid=ImgRaw&r=0&sres=1&sresct=1",
					taskname: "奥运吉祥物冰墩墩盲盒",
				}],
			}
		},
		async onShow() {
			this.token = uni.getStorageSync('token')
			await this.$https.get('/youngee/c/t/g/is-login')
				.then(res => {
					if (res.data.code == 403) {
						this.token = ""
						uni.clearStorage();
					}
				});
			if (this.token === '') {
				uni.showModal({
					content: '请先登录',
					success: function(res) {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/login/login'
							});
						} else if (res.cancel) {
							uni.switchTab({
								url: '/pages/tasksquare/tasksquare'
							});
						}
					}
				});
			}

			let curTab = 0
			this.showList.forEach(async function(item, index) {
				if (item === true) {
					curTab = index
				}
			});
			await this.getInfoList()
			this.getTaskList(parseInt(curTab) + 1);
		},
		methods: {
			getInfoList() {
				return this.$http.get('/youngee/c/g/get-info-tables')
					.then(res => {
						if (res.data.code == 0) {
							this.taskStageList = res.data.data.TaskStage
							this.secTaskStageList = res.data.data.SecTaskStage
						}
					})
			},
			toShowTask() {
				this.showTask = true;
				this.showSec = false;
				this.toShow(0)
			},
			toShowSec() {
				this.showTask = false;
				this.showSec = true;
				this.toShow(4)
			},
			toShow(value) {
				let that = this
				this.showList.forEach(function(item, index) {
					if (index == value) {
						that.showList[index] = true
					} else {
						that.showList[index] = false
					}
				})
				if (value < 4) {
					this.getTaskList(value);
				} else {
					this.getSecTaskList(value);
				}
			},
			toTaskDetail(item) {
				uni.navigateTo({
					url: '/page_workspace/task/taskdetail?taskId=' + item.task_id,
					success(res) {},
					fail(err) {}
				});
			},
			toSecTaskDetail(item) {
				uni.navigateTo({
					url: '/page_workspace/selection/sectaskdetail?taskId=' + item.task_id,
					success(res) {},
					fail(err) {}
				});
			},

			async getTaskList(value) {
				let that = this
				this.loading = true
				uni.showLoading({
					title: '加载中'
				});
				await this.$https.get('/youngee/c/t/g/get-task-exe-num')
					.then(res => {
						if (res.data.data != null) {
							let nums = res.data.data
							this.showPoint.forEach(function(item, index) {
								that.showPoint[index] = false
							})
							for (let i = 0; i < nums.length; ++i) {
								if (nums[i].task_stage == 7 && nums[i]["COUNT(*)"] != 0) {
									this.showPoint[0] = true
								}
								if (nums[i].task_stage == 9 && nums[i]["COUNT(*)"] != 0) {
									this.showPoint[1] = true
								}
								if (nums[i].task_stage == 11 && nums[i]["COUNT(*)"] != 0) {
									this.showPoint[2] = true
								}
								if (nums[i].task_stage == 13 && nums[i]["COUNT(*)"] != 0) {
									this.showPoint[3] = true
								}
							}
						}
					});
				var taskList = [];
				await this.$https.get('/youngee/c/t/g/get-task-exe-list' +
					"?" +
					"taskStage" +
					"=" +
					value).then(res => {
					taskList = res.data.data
					if (taskList != null) {
						for (let i = 0; i < taskList.length; ++i) {
							// 主图
							let productPhoto = JSON.parse(taskList[i].product_photo_snap);
							for (let j = 0; j < productPhoto.length; j++) {
								if (productPhoto[j].Symbol == 1) {
									taskList[i].product_img_url = productPhoto[j].PhotoUrl
								}
							}

							// 待修改标识
							if ((taskList[i].task_stage == 7 && taskList[i].script_status == 3) ||
								(taskList[i].task_stage == 9 && taskList[i].sketch_status == 3) ||
								(taskList[i].task_stage == 11 && taskList[i].link_status == 3) ||
								(taskList[i].task_stage == 13 && taskList[i].data_status == 3)) {
								taskList[i].isShowModify = true
							} else {
								taskList[i].isShowModify = false
							}

							// 任务阶段展示文字
							taskList[i].task_stage_txt = this.taskStageList[taskList[i].task_stage - 1]
								.task_stage

							// 任务收益
							taskList[i].real_reward = taskList[i].task_reward * (100 - taskList[i]
								.break_rate) / 100
							taskList[i].cut_payment = taskList[i].task_reward - taskList[i].real_reward
							taskList[i].show_task_reward = money(taskList[i].task_reward)
							taskList[i].show_real_reward = money(taskList[i].real_reward)
							taskList[i].show_cut_payment = money(taskList[i].cut_payment)

							// 截止时间
							let ddl = this.thistime(taskList[i].cur_break_at)
							console.log("isTimeOut", ddl.isTimeOut)
							console.log("ddl", ddl.deadline_time)
							taskList[i].time_out = ddl.isTimeOut
							taskList[i].upload_ddl = ddl.isTimeOut ? ddl.deadline_time : taskList[i]
								.cur_break_at.replace(/-/g,
									"/").slice(0, -3)
						}
					}
					this.taskLists[value] = taskList
				})
				uni.hideLoading();
				this.loading = false
			},

			async getSecTaskList(value) {
				this.loading = true
				uni.showLoading({
					title: '加载中'
				});
				var taskList = [];
				await this.$https.get('/youngee/c/t/g/get-exe-sec-task-list' +
					"?" +
					"taskStage" +
					"=" +
					value).then(res => {
					taskList = res.data.data
					if (taskList != null) {
						for (let i = 0; i < taskList.length; ++i) {
							// 主图
							let productPhoto = JSON.parse(taskList[i].product_photo_snap);
							for (let j = 0; j < productPhoto.length; j++) {
								if (productPhoto[j].Symbol == 1) {
									taskList[i].product_img_url = productPhoto[j].PhotoUrl
								}
							}

							// 待修改标识
							if (taskList[i].task_stage == 8 && taskList[i].assignment_status == 3) {
								taskList[i].isShowModify = true
							} else {
								taskList[i].isShowModify = false
							}

							// 任务阶段展示文字
							taskList[i].task_stage_txt = this.secTaskStageList[taskList[i].task_stage - 1]
								.task_stage

							// 任务收益
							taskList[i].real_reward = taskList[i].task_reward
							taskList[i].show_task_reward = money(taskList[i].task_reward)
							taskList[i].show_real_reward = money(taskList[i].real_reward)
							taskList[i].show_payment = money(taskList[i].talent_payment)
						}
					}
					this.taskLists[value] = taskList;
				})
				uni.hideLoading();
				this.loading = false
			},

			// 计算结束时间
			thistime(val) {
				// 转换格式
				var beginTime = new Date(val.replace(/-/g, "/"));
				// 当前时间
				var thisTime = new Date();
				// 相减
				var dateMiss = beginTime.getTime() - thisTime.getTime();
				let isTimeOut = dateMiss < 0 ? true : false
				dateMiss = dateMiss < 0 ? -dateMiss : dateMiss
				// 天数
				var day = Math.floor(dateMiss / (24 * 3600 * 1000));
				// 减去天数剩下的毫秒数
				var backOne = dateMiss % (24 * 3600 * 1000);
				// 小时数
				var hours = Math.floor(backOne / (3600 * 1000));
				// 减去小时数剩下的毫秒数
				var backHour = backOne % (3600 * 1000);
				// 分钟数
				var min = Math.floor(backHour / (60 * 1000));
				var deadline_time = day + '天' + hours + '时' + min + '分'
				var result = {
					isTimeOut: isTimeOut,
					deadline_time: deadline_time
				}
				return result
			},
		}
	}
</script>

<style lang="scss" scoped>
	view {
		font-size: 14px;
		line-height: inherit;
	}

	.menu-head {
		// padding-top: 20rpx;
		background-color: #fff;
		position: fixed;
		width: 100%;
	}

	.menu {
		border-bottom: #FCCF41;
		background-color: #FFFFFF;
		justify-content: space-around;
		height: 60rpx;
		width: 100%;
		padding-bottom: 40rpx;
		display: flex;
		z-index: 10;
	}

	.menu-item {
		display: flex;
	}

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

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

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

	.home {
		margin-top: 180rpx;
	}


	.task-card {
		margin: 10rpx 0;
		// border-bottom: 1rpx #d7d7d7 solid;

		.task-head {
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 10rpx 20rpx;

			.task-head-account {
				display: flex;
			}

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

			.task-head-status p {
				color: red;
			}
		}

		.task-info {
			display: flex;
			justify-content: space-between;
			padding: 10rpx 20rpx;

			.task-info-left {
				display: flex;
				// align-items: center;

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

				.task-info-txt {
					margin-left: 10rpx;
				}

				.task-info-txt p {
					font-size: 24rpx;
					color: #85859d;
					margin-bottom: 10rpx;
				}
			}

			.task-info-right {
				width: 100rpx;
				height: 100rpx;
				border-radius: 50%;
				border: #ffcb41 2rpx solid;
				display: flex;
				align-items: center;
				justify-content: center;
			}

			.task-info-right p {
				font-size: 24rpx;
			}
		}
	}

	// .task {
	// 	margin-bottom: 20rpx;
	// 	border-bottom: 1rpx #d7d7d7 solid;

	// 	.task-head {
	// 		display: flex;
	// 		justify-content: space-between;
	// 		align-items: center;
	// 		padding: 10rpx 20rpx;

	// 		.task-head-account {
	// 			display: flex;
	// 		}

	// 		.task-head-status {
	// 			color: red;
	// 		}
	// 	}

	// 	.task-info {
	// 		display: flex;
	// 		align-items: center;
	// 		justify-content: space-between;
	// 		padding: 10rpx 20rpx;

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

	// 		.task-info-right {
	// 			width: 100rpx;
	// 			height: 100rpx;
	// 			border-radius: 50%;
	// 			border: #ffcb41 2rpx solid;
	// 			display: flex;
	// 			align-items: center;
	// 			justify-content: center;
	// 		}
	// 	}
	// }

	.line {
		border-bottom: 1rpx #AAAAAA solid;
	}

	.menu-point {
		position: relative;
		left: 30rpx;
		top: 20rpx;
	}

	.point {
		width: 20rpx;
		height: 20rpx;
		background: red;
		border-radius: 50%;
	}
</style>