<template>
	<view class='member-center'>
		<view class='header'>
			<swiper class="swiper" :current="swiperIndex" previous-margin="55rpx" next-margin="55rpx"
				@change="swiperChange" :indicator-dots="true">
				<block v-for="(item, index) in distributionLevel" :key="index">
					<swiper-item>
						<view class="swiper-item" v-if="item.image" :class="{on: swiperIndex == index}"
							:style="{'background-image': 'url('+item.image+')'}">
							<view class="acea-row row-middle user-wrap">
								<image class="image" :src="item.icon"></image>
								<view class="user-msg">
									<view class="text">
										<view class="name">{{item.name}}</view>
										<view class="level">
											{{item.explain }}
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="swiper-item" v-else :class="{on: swiperIndex == index}"
							style="background: #333333;">
							<view class="acea-row row-middle user-wrap">
								<image class="image" :src="item.icon"></image>
								<view class="user-msg">
									<view class="text">
										<view class="name">{{item.name}}</view>
										<view class="level">
											{{item.explain }}
										</view>
									</view>
								</view>
							</view>
						</view>
					</swiper-item>
				</block>
			</swiper>
		</view>
		<view class="info" v-if="task.length != 0">
			<view class="info-title">
				任务说明：
			</view>
			<view class="info-main">
				<view class="info-item flex" v-for="(item,index) in task">
					<view class="info-name">
						{{item.name}}
					</view>
					<view class="info-success" v-if="item.finish == 1">
						已完成
					</view>
					<view class="info-success" v-if="item.finish != 1">
						{{item.task_type_title}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		agentLevelList,
		agentLevelTaskList
	} from '@/api/user.js';
	import {
		toLogin
	} from '@/libs/login.js';
	import {
		mapGetters
	} from "vuex";
	export default {
		data() {
			return {
				distributionLevel: [],
				swiperIndex: 0,
				task: [], //任务列表
				level_id: 0, //任务id,
				grade: 0,
			};
		},
		watch: {
			distributionLevel: function() {
				let that = this;
				if (that.distributionLevel.length > 0) {
					that.distributionLevel.forEach(function(item, index) {
						if (item.is_clear === false) {
							// that.swiper.slideTo(index);
							that.activeIndex = index;
							that.grade = item.grade;
						}
					});
				}
			},
		},
		onLoad() {
			this.agentLevelList();
		},
		methods: {
			agentLevelList: function() {
				agentLevelList().then(({
					data
				}) => {
					this.distributionLevel = data.list;
					this.level_id = this.distributionLevel[this.swiperIndex].id
					this.getTask();
				});
			},
			/**
			 * 会员切换
			 * 
			 */
			swiperChange(e) {
				let index = e.detail.current;
				this.swiperIndex = index;
				this.level_id = this.distributionLevel[index].id || 0;
				this.getTask();
			},
			/**
			 * 获取任务要求
			 */
			getTask: function() {
				let that = this;
				that.taskNum = 0
				agentLevelTaskList({}, this.level_id).then(res => {
					that.task = res.data.task
				});
			}
		},
	}
</script>

<style lang="scss" scoped>
	page {
		background: #f5f5f5;
	}

	.swiper {
		width: 700rpx;
		margin: 0 auto;
		height: 285rpx;

		.swiper-item {
			height: 100%;
			border-radius: 6rpx;
			background-color: #333333;
			background: center/100% 100% no-repeat;
			transform: scale(0.9);
			transition: all 0.2s ease-in 0s;
			line-height: 1.1;

			&.on {
				transform: none;
			}
		}

		.user-wrap {
			padding-top: 20rpx;
			padding-left: 22rpx;
			line-height: 1.1;

			.image {
				width: 90rpx;
				height: 90rpx;
				border-radius: 50%;
			}

			.user-msg {
				margin-left: 14rpx;

				.text {
					flex: 1;
					display: flex;
					align-items: center;
					min-width: 0;
					font-size: 22rpx;
					color: #666666;

					.num {
						margin-right: 10rpx;
						margin-left: 10rpx;
						font-size: 30rpx;
						font-style: italic;
					}
				}
			}

			.name {
				flex: 1;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
				font-weight: bold;
				font-size: 28rpx;
				color: #fff;
				margin-right: 8rpx;
			}

			.state {
				position: absolute;
				top: 0rpx;
				right: 0;
				width: 70rpx;
				height: 70rpx;

				.lock {
					width: 100%;
					height: 100%;
				}
			}
		}

		.grow-wrap {
			padding-left: 34rpx;
			margin-top: 70rpx;
			font-size: 20rpx;
			color: #474747;
			display: flex;

			.num {
				margin-right: 8rpx;
				margin-left: 8rpx;
				font-size: 26rpx;
			}
		}

		.level {
			font-size: 24rpx;
			color: #fff;
			border-radius: 4rpx;
			border: 1px solid #fff;
			padding: 3rpx 8rpx;
		}
	}


	.member-center .header {
		// height: 470rpx;
		padding-top: 37rpx;
	}

	.member-center .header swiper {
		position: relative;
		// height: 330rpx;
	}

	.member-center .growthValue {
		background-color: #fff;
		border-radius: 16rpx;
		position: fixed;
		top: 266rpx;
		left: 50%;
		width: 560rpx;
		min-height: 440rpx;
		margin-left: -280rpx;
		z-index: 99;
		transform: translate3d(0, -200%, 0);
		transition: all .3s cubic-bezier(.25, .5, .5, .9);
	}

	.member-center .growthValue.on {
		transform: translate3d(0, 0, 0);
	}

	.member-center .growthValue .pictrue {
		width: 100%;
		height: 257rpx;
		position: relative;
	}

	.member-center .growthValue .pictrue image {
		width: 100%;
		height: 100%;
		border-radius: 16rpx 16rpx 0 0;
	}

	.member-center .growthValue .conter {
		padding: 0 35rpx;
		font-size: 30rpx;
		color: #333;
		margin-top: 58rpx;
		line-height: 1.5;
		height: 350rpx;
		overflow: auto;
	}

	.member-center .growthValue .iconfont {
		position: absolute;
		font-size: 65rpx;
		color: #fff;
		bottom: -90rpx;
		left: 50%;
		transform: translateX(-50%);
	}


	.swiper .level-sty {
		opacity: 0.7;
	}

	.info {
		margin-top: 40rpx;
		padding: 0 20rpx;

		.info-title {
			font-size: 34rpx;
		}

		.info-main {
			margin-top: 40rpx;

			.info-item {
				width: 100%;
				padding: 10px 25rpx;
				border-radius: 10rpx;
				margin-top: 20rpx;
				background-color: #ffffff;
				box-shadow: 0 5rpx 10rpx 0 #F8F8F8;

				.info-name {
					font-size: 28rpx;
				}

				.info-success {
					font-size: 24rpx;
					color: red;
				}
			}
		}
	}
</style>