<!-- 任务中心 -->
<template>
	<view class="container">
		<u-navbar :background="background" :is-back="false" :title="title" :border-bottom="false"></u-navbar>
		<view class="task_bg u-absolute">
			<u-image class="task_bg" src="../../static/images/me/task_bg.png" ></u-image>
		</view>
		<view class="icon u-relative padding">
			<u-image class="task_icon1 u-relative" src="../../static/images/me/task_icon1.png"></u-image>
			<view class="icon_title u-font-32 text-bold u-relative">新人好礼送不停</view>
			<u-image class="task_icon2 u-relative" src="../../static/images/me/task_icon2.png"></u-image>
		</view>
		<view class="content margin-lr padding bg-white u-relative" v-if="list.length" style="margin-bottom: 32rpx;">
			<u-steps :list="numList" :current="1" active-color="#EA9EA8" un-active-color="#D8D5D5"></u-steps>
			<view class="cell flex justify-between" v-for="(item,index) in list" :key="index">
				<view class="cell_left flex">
					<view class="cell_title flex">
						<view class="u-font-28 text-bold title" :style="{alignSelf: item.rewardImg?'center':'flex-start'}">{{ item.title}}</view>
						<u-image v-if="item.rewardImg" class="cell_icon" :src="item.rewardImg "></u-image>
						<view class="u-font-24 tip">{{ item.rewardDetail  }}</view>
					</view>
					<view class="subhead u-font-24">{{ item.detail }}</view>
				</view>
				<view class="cell_right flex">
					<view v-if=" item.disabled " class="btn u-font-24 text-bold" :style="{backgroundColor: item.buttonBgColor,color: item.buttonFontColor }" @click="goNav(item)">{{ item.type == 1 ? item.buttonTitle : item.number ? `${item.discNumber}/${item.number}` : ( item.discNumber <= 0 ? item.buttonTitle : `剩余${item.discNumber}次`) }}</view>
					<view v-else class="btn u-font-24 text-bold disabled">{{ item.type == 1 ? item.buttonTitle : item.number ? `${item.discNumber}/${item.number}` : ( item.discNumber <= 0 ? item.buttonTitle : `剩余${item.discNumber}次`) }}</view>
					<!-- <view v-else class="btn u-font-24 text-bold" @click="goNav(item)">{{ item.buttonTitle }}</view> -->
					<!-- <view v-if=" item.type ==4 " class="u-font-20 tip" @click="goNav('/me/gift/gift', item.type)">查看奖品列表</view> -->
				</view>
			</view>
		
		</view>
		<view class="content margin-lr padding bg-white u-relative" v-if="list.length">

			<view class="cell flex justify-between" v-for="(item,index) in list" :key="index">
				<view class="cell_left flex">
					<view class="cell_title flex">
						<view class="u-font-28 text-bold title" :style="{alignSelf: item.rewardImg?'center':'flex-start'}">{{ item.title}}</view>
						<u-image v-if="item.rewardImg" class="cell_icon" :src="item.rewardImg "></u-image>
						<view class="u-font-24 tip">{{ item.rewardDetail  }}</view>
					</view>
					<view class="subhead u-font-24">{{ item.detail }}</view>
				</view>
				<view class="cell_right flex">
					<view v-if=" item.disabled " class="btn u-font-24 text-bold" :style="{backgroundColor: item.buttonBgColor,color: item.buttonFontColor }" @click="goNav(item)">{{ item.type == 1 ? item.buttonTitle : item.number ? `${item.discNumber}/${item.number}` : ( item.discNumber <= 0 ? item.buttonTitle : `剩余${item.discNumber}次`) }}</view>
					<view v-else class="btn u-font-24 text-bold disabled">{{ item.type == 1 ? item.buttonTitle : item.number ? `${item.discNumber}/${item.number}` : ( item.discNumber <= 0 ? item.buttonTitle : `剩余${item.discNumber}次`) }}</view>
					<!-- <view v-else class="btn u-font-24 text-bold" @click="goNav(item)">{{ item.buttonTitle }}</view> -->
					<!-- <view v-if=" item.type ==4 " class="u-font-20 tip" @click="goNav('/me/gift/gift', item.type)">查看奖品列表</view> -->
				</view>
			</view>

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

<script>
	export default {
		
		data() {
			return {
				title: '',
				background: {
					backgroundImage: 'linear-gradient(to right, #FFE5EA 0%, #E4F5FB 49%, #FFF0EE 100%)'
				},
				list: [],
				numList: [
					{ 	name: '第一天' }, 
					{   name: '第二天' }, 
					{   name: '第三天' }, 
					{   name: '第四天' }, 
					{   name: '第五天' }, 
					{   name: '第六天' }, 
					{   name: '第七天' }, 
				],
			}
		},
		onShow() {
			this.getTaskdata()
		},
		methods: {
			/**
			 * 跳转
			 * @param {Object} item
			 */
			goNav( item ) {
				// jumpType (integer, optional): 跳转类型 1 内部路径 2 外部路径 ,
				// type (integer, optional): 任务类型 1 普通任务 2 打卡任务 9 其它 ,
				// buttonUrl
				if ( item.jumpType == 0) {
					this.taskReceive(item.id)
				} else if ( item.jumpType == 1) {
					uni.navigateTo({
						url: item.buttonUrl
					})
				} else if( item.jumpType == 3) {
					uni.switchTab({
						url: item.buttonUrl
					})
				} else if( item.jumpType == 2) {
					plus.runtime.openURL(item.buttonUrl)
				}
				
				
				
			},
			
			/**
			 * 领取
			 */
			taskReceive(id) {
				let data = {
					id: id
				}
				this.$Request.getT('app/taskCenter/taskReceive', data).then(res => {
					if (res.code == 0 ) {
						uni.showToast({
							title: '领取成功',
							icon: 'none'
						})
						setTimeout(()=>{
							this.getTaskdata()
						},1000)
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			},
			
			/**
			 * 获取任务列表
			 */
			getTaskdata() {
			
				this.$Request.getT('app/taskCenter/selectTaskCenter', {}).then(res => {
					if (res.code == 0 ) {
						this.list = res.data
					}
					uni.stopPullDownRefresh();
				})
			},
			
			/**
			 * 下拉加载
			 */
			onPullDownRefresh: function() {
				console.log(2)
				this.getTaskdata();
			},
			
		}
	}
</script>

<style lang="scss">
	.container{
		width: 100%;
		.task_bg{
			width: 100%!important;
			height: 494rpx!important;
		}
		.icon{
			.icon_title{
				color: #000000;
				margin-left: 28rpx;
				top: -20rpx;

			}
			.task_icon1{
				width: 74rpx!important;
				height: 78rpx!important;
				margin-left: 235rpx;
			}
			.task_icon2{
				width: 126rpx!important;
				height: 120rpx!important;
				top: -40rpx;
			}
		}
		.content{
			border-radius: 16rpx;
			top: -115rpx;
			padding: 28rpx;
			.cell{
				align-items: center;
				padding: 32rpx 0;
				border-bottom: 2rpx solid #EBEBEB;
				.cell_left{
					flex-direction: column;
					.cell_title{
						align-items: center;
						margin-bottom: 12rpx;
						color: #333;
						.title{
							flex-shrink: 0;
						}
						.cell_icon{
							width: 34rpx!important;
							height: 34rpx!important;
							margin-left: 16rpx;
						}
						.tip{
							margin-left: 22rpx;
							color: #FC5B67;
						}
					}
					.subhead{
						color: #999;
					}
				}
				.cell_right{
					flex-direction: column;
					align-items: center;
					flex-shrink: 0;
					margin-left: 20rpx;
					.btn{
						width: 148rpx;
						height: 56rpx;
						line-height: 56rpx;
						text-align: center;
						background-color: #EC6F48;
						color: #FFFFFF;
						border-radius: 12rpx 12rpx 12rpx 12rpx;
					}
					.tip{
						color: #666;
						height: 44rpx;
						line-height: 44rpx;
					}
					.opt{
						color: #D39B7E;
						background-color: #FBF3EB;
					}
					.disabled{
						color: #999999;
						background-color: #E2E2E2;
					}
				}
				
			}
			.cell:last-child{
				border-bottom: none;
			}
		}
	}
	

</style>