<template>
	<view>
		<!-- 胶囊 -->
		<mvBar :mysNavConfig="mysNavConfig"></mvBar>
		<view :style="{paddingTop:navH}" style="background-color: #fff;z-index: 10;"></view>

		<view class="menu" v-if="!loading">
			<view class="menu-item" @click="toAll()">
				<p v-bind:class="tab == 'all'?'lor':'unlor'">全部</p>
			</view>
			<view class="menu-item" @click="toApply()">
				<p v-bind:class="tab == 'apply'?'lor':'unlor'">已报名</p>
			</view>
			<view class="menu-item" @click="toexecute()">
				<p v-bind:class="tab == 'execute'?'lor':'unlor'">执行中</p>
			</view>
			<view class="menu-item" @click="toEnd()">
				<p v-bind:class="tab == 'end'?'lor':'unlor'">已结束</p>
			</view>
		</view>

		<view class="home" v-if="tab == 'all' && !loading">
			<view class="task" v-for="item in allList">
				<view @click="toDetail(item)">
					<view class="task-head">
						<view class="task-head-account">
							<image :src="item.platform_icon_url" style="height: 50rpx;width: 50rpx;"></image>
							<p style="margin-left: 20rpx;">{{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 :src="item.product_img_url" style="height: 120rpx;width: 120rpx;"></image>
							<p style="margin-left: 50rpx;">{{item.project_name}}</p>
						</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>
			</view>
		</view>

		<view class="home" v-if="tab == 'apply' && !loading">
			<view class="task" v-for="item in applyList">
				<view @click="toDetail(item)">
					<view class="task-head">
						<view class="task-head-account">
							<image :src="item.platform_icon_url" style="height: 50rpx;width: 50rpx;"></image>
							<p style="margin-left: 20rpx;">{{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 :src="item.product_img_url" style="height: 120rpx;width: 120rpx;"></image>
							<p style="margin-left: 50rpx;">{{item.project_name}}</p>
						</view>
					</view>
				</view>
			</view>
		</view>

		<view class="home" v-if="tab == 'execute' && !loading">
			<view class="task" v-for="item in goingList">
				<view @click="toDetail(item)">
					<view class="task-head">
						<view class="task-head-account">
							<image :src="item.platform_icon_url" style="height: 50rpx;width: 50rpx;"></image>
							<p style="margin-left: 20rpx;">{{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 :src="item.product_img_url" style="height: 120rpx;width: 120rpx;"></image>
							<p style="margin-left: 50rpx;">{{item.project_name}}</p>
						</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>
			</view>
		</view>

		<view class="home" v-if="tab == 'end' && !loading">
			<view class="task" v-for="item in endList">
				<view @click="toDetail(item)">
					<view class="task-head">
						<view class="task-head-account">
							<image :src="item.platform_icon_url" style="height: 50rpx;width: 50rpx;"></image>
							<p style="margin-left: 20rpx;">{{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 :src="item.product_img_url" style="height: 120rpx;width: 120rpx;"></image>
							<p style="margin-left: 50rpx;">{{item.project_name}}</p>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import mvBar from "@/components/mys_navBar/mysNavBar";
	export default {
		components: {
			mvBar,
		},
		data() {
			return {
				navH: getApp().globalData.navHeight,
				loading: true,
				tab: '',
				allList: [],
				applyList: [],
				goingList: [],
				endList: [],
				taskStageList: [],
				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: "奥运吉祥物冰墩墩盲盒",
				}, ],
				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",
					},
				},
			}
		},
		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();
						}
					}
				});
			}

			let data = options.textObj.replace(/""/g, "");
			data = JSON.parse(decodeURIComponent(data))
			this.tab = data.tab
		},
		async onShow() {
			this.loading = true;
			uni.showLoading({
				title: '加载中'
			});
			await this.getInfoTable();
			await this.getList();
			uni.hideLoading();
			this.loading = false;
		},
		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')
						}
					})
			},
			getInfoTable() {
				return this.$https.get('/youngee/c/g/get-info-tables')
					.then(res => {
						console.log(res)
						this.taskStageList = res.data.data.TaskStage
					})
			},
			getList() {
				return this.$https.get('/youngee/c/t/g/get-task-brief-list').then(res => {
					console.log(res)
					this.allList = res.data.data.all_Task_info_list
					if (this.allList != null) {
						for (let i = 0; i < this.allList.length; ++i) {
							let productPhoto = JSON.parse(this.allList[i].product_photo_snap);
							for (let j = 0; j < productPhoto.length; j++) {
								if (productPhoto[j].Symbol == 1) {
									this.allList[i].product_img_url = productPhoto[j].PhotoUrl
								}
							}
							if ((this.allList[i].task_stage == 7 && this.allList[i].script_status == 3) ||
								(this.allList[i].task_stage == 9 && this.allList[i].sketch_status == 3) ||
								(this.allList[i].task_stage == 11 && this.allList[i].link_status == 3) ||
								(this.allList[i].task_stage == 13 && this.allList[i].data_status == 3)) {
								this.allList[i].isShowModify = true
							} else {
								this.allList[i].isShowModify = false
							}

							for (let j = 0; j < this.taskStageList.length; ++j) {
								if (this.allList[i].task_stage == this.taskStageList[j].task_stage_id)
									this.allList[i].task_stage_txt = this.taskStageList[j].task_stage
							}
						}
					}
					this.applyList = res.data.data.sgin_up_Task_info_list
					if (this.applyList != null) {
						for (let i = 0; i < this.applyList.length; ++i) {
							let productPhoto = JSON.parse(this.applyList[i].product_photo_snap);
							for (let j = 0; j < productPhoto.length; j++) {
								if (productPhoto[j].Symbol == 1) {
									this.applyList[i].product_img_url = productPhoto[j].PhotoUrl
								}
							}
							for (let j = 0; j < this.taskStageList.length; ++j) {
								if (this.applyList[i].task_stage == this.taskStageList[j].task_stage_id)
									this.applyList[i].task_stage_txt = this.taskStageList[j].task_stage
							}
						}
					}
					this.goingList = res.data.data.going_on_Task_info_list
					if (this.goingList != null) {
						for (let i = 0; i < this.goingList.length; ++i) {
							let productPhoto = JSON.parse(this.goingList[i].product_photo_snap);
							for (let j = 0; j < productPhoto.length; j++) {
								if (productPhoto[j].Symbol == 1) {
									this.goingList[i].product_img_url = productPhoto[j].PhotoUrl
								}
							}
							if ((this.goingList[i].task_stage == 7 && this.goingList[i].script_status == 3) ||
								(this.goingList[i].task_stage == 9 && this.goingList[i].sketch_status == 3) ||
								(this.goingList[i].task_stage == 11 && this.goingList[i].link_status == 3) ||
								(this.goingList[i].task_stage == 13 && this.goingList[i].data_status == 3)) {
								this.goingList[i].isShowModify = true
							} else {
								this.goingList[i].isShowModify = false
							}
							for (let j = 0; j < this.taskStageList.length; ++j) {
								if (this.goingList[i].task_stage == this.taskStageList[j].task_stage_id)
									this.goingList[i].task_stage_txt = this.taskStageList[j].task_stage
							}
						}
					}
					this.endList = res.data.data.completed_Task_info_list
					if (this.endList != null) {
						for (let i = 0; i < this.endList.length; ++i) {
							let productPhoto = JSON.parse(this.endList[i].product_photo_snap);
							for (let j = 0; j < productPhoto.length; j++) {
								if (productPhoto[j].Symbol == 1) {
									this.endList[i].product_img_url = productPhoto[j].PhotoUrl
								}
							}
							for (let j = 0; j < this.taskStageList.length; ++j) {
								if (this.endList[i].task_stage == this.taskStageList[j].task_stage_id)
									this.endList[i].task_stage_txt = this.taskStageList[j].task_stage
							}
						}
					}
				})
			},
			async toAll() {
				this.tab = 'all'
				uni.showLoading({
					title: '加载中'
				});
				await this.getList()
				uni.hideLoading()
			},
			async toApply() {
				this.tab = 'apply'
				uni.showLoading({
					title: '加载中'
				});
				await this.getList()
				uni.hideLoading()
			},
			async toexecute() {
				this.tab = 'execute'
				uni.showLoading({
					title: '加载中'
				});
				await this.getList()
				uni.hideLoading()
			},
			async toEnd() {
				this.tab = 'end'
				uni.showLoading({
					title: '加载中'
				});
				await this.getList()
				uni.hideLoading()
			},
			toDetail(item) {
				console.log("func toDetail running")
				uni.navigateTo({
					url: '/page_workspace/task/taskdetail?taskId=' + item.task_id,
					success(res) {
						console.log(res);
					},
					fail(err) {
						console.log(err);
					}
				});
				console.log("func toDetail end")
			},
		}
	}
</script>

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

	.menu {
		position: fixed;
		border-bottom: #FCCF41;
		background-color: #FFFFFF;
		justify-content: space-around;
		height: 5%;
		width: 100%;
		display: flex;
		z-index: 10;
	}

	.menu-item 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: 100rpx;
	}

	.task {
		z-index: 1;
		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;
	}
</style>
