<template>
	<view class="padding padding-lr-sm" v-if="fetch && fetch.user && fetch.user.logo" @click="Dever.close()">
		<use-tabbar :tabbar="false"></use-tabbar>

		<!-- 会员区域 -->
		<view class="vip-area border-radius padding-lg padding-bottom padding-lr-xl w-full dflex-b dflex-flow-c">
			<view class="dflex-b w-full">
				<view class="dflex-c">
					<image :src="fetch.user.logo" class="border-radius-c margin-right-sm"
						style="width: 40px; height: 40px;"></image>
					<view class="ft-white">
						<view class="fwb fs-30">{{fetch.user.name}}</view>
						<view class="fs-xxs">{{fetch.role.info}}</view>
					</view>
				</view>
				<view class="bg-base border-radius-lg fs-xs padding-lr-sm padding-tb-xxs">{{fetch.user.title}}</view>
			</view>

			<view class="dflex-b w-full">
				<view class="dflex">
					<text class="iconfont iconhuiyuan ft-base fs-xl margin-right-xs" style="line-height: 30px;"></text>
					<text class="fs-xs" style="color: rgb(92, 92, 92);">{{fetch.user.card}}</text>
				</view>
				<view class="fs-xs">
					<text style="color: rgb(92, 92, 92);">{{fetch.user.info}}</text>
				</view>
			</view>
		</view>

		<u-empty v-if="fetch.level && fetch.level.length <= 0" marginTop="150" mode="permission"
			:text="`暂无${fetch.role.name}`"></u-empty>

		<view v-else>
			<u-tabs :list="fetch.level" @click="click" :current="current"></u-tabs>

			<view>
				<!-- 会员权益标题 -->
				<view class="role-area border-radius-big fwb tac padding-tb-16 ft-base pos-r pos-l-c fs">
					{{level.name}}/{{level.day_desc}}
				</view>

				<!-- 权益列表 -->
				<view class="bg-main border-radius padding padding-top-lg padding-bottom-big dflex-wrap-w">
					<view class="tac margin-top-sm" style="color: #888;">
						{{level.info}}
					</view>
					<u-empty v-if="level.profit && level.profit.length <= 0" marginTop="50" mode="permission"
						text="暂无权益，敬请期待"></u-empty>

					<u-subsection class="tabs" v-else :list="level.profit" activeColor="#f56c6c" :current="level.active"
						@change="sectionChange"></u-subsection>

					<view class="tab-content">
						<!-- 永久权益 -->
						<view v-if="level.active === 0">
							<view class="" v-for="(item, index) in level.upgrade" :key="index">
								<view class="coupon_box border-radius margin-top-sm bg-main"
									@click="showModal(item.title, item.tip)">
									<view class="dflex-b">
										<view class="left pos-a h-full dflex-c dflex-flow-c">
											<view class="fs-sm">{{item.type_name}}</view>

										</view>
										<view class="right padding left_t flex1">
											<view class="dflex-b padding-bottom-xs">
												<view class="fwb fs">{{ item.name }}</view>
												<text class="arrow" v-if="item.tip">›</text>
											</view>
											<view class="dflex-b ft-dark fs-xs padding-bottom border-line">
												<view class="">{{ item.desc }}</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>

						<!-- 周期权益 -->
						<view v-if="level.active === 1">
							<view class="" v-for="(item, index) in level.period" :key="index">
								<view class="coupon_box border-radius margin-top-sm bg-main"
									@click="showModal(item.title, item.tip)">
									<view class="dflex-b">
										<view class="left pos-a h-full dflex-c dflex-flow-c">
											<view class="fs-sm">{{item.type_name}}</view>
										</view>
										<view class="right padding left_t flex1">
											<view class="dflex-b padding-bottom-xs">
												<view class="fwb fs">{{ item.name }}</view>
												<text class="arrow" v-if="item.tip">›</text>
											</view>
											<view class="dflex-b ft-dark fs-xs padding-bottom border-line">
												<view class="">{{ item.desc }}</view>
											</view>
										</view>
									</view>
								</view>
							</view>
						</view>
					</view>
				</view>

				<!-- 底部按钮 -->
				<view class="margin-top-big border-radius-lg"
					style="position: fixed;bottom: 28px; left: 14px; right: 14px;">
					<view class="tac fwb flex1 bg-base dflex overflow-hidden">
						<view class="flex1 padding-tb-sm tal" style="text-align: center;">
							<u-popover position="top" width="200px">
								<text class="fs-34 line-height-1">{{level.price_text}}</text>
								<view 	v-if="level.promotion_text" style="margin-left:5px;display: inline-block;">
								<u-icon name="question-circle" 
								 color="#00000042"></u-icon>
								 </view>
								<template v-slot:content>
									<view style="color: white;">
										<u-parse :content="level.promotion_text"></u-parse>
									</view>

								</template>
							</u-popover>
						</view>
						<view class="bg-warn ft-white padding-tb-sm" style="width: 40%;" @click="buy">{{level.button}}
						</view>
					</view>
				</view>
			</view>

			<u-modal @confirm="closeModal" :show="show.state" :title="show.title" :closeOnClickOverlay="true">
				<view class="slot-content">
					<u-parse :content="show.content"></u-parse>
				</view>
			</u-modal>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fetch: {},
				level: {},
				id: 0,
				current: 0,
				show: {
					state: false,
					title: '',
					content: '',
				},
			};
		},
		//下拉刷新
		onPullDownRefresh() {
			this.loadData();
		},
		onLoad(options) {
			if (options && options.id) {
				this.id = options.id;
			} else {
				return this.Dever.goHome();
			}
			this.loadData();
		},
		onShow() {
			this.current = 0;
			this.loadData();
		},
		methods: {
			showModal(title, content) {
				if (content) {
					this.show.title = title;
					this.show.content = content;
					this.show.state = true;
				}
			},
			closeModal() {
				this.show.state = false;
			},
			loadData() {
				this.DeverApi.get(this, 'role.info', {
					id: this.id
				}, res => {
					this.level = res.level[this.current];
				});
			},
			sectionChange(index) {
				this.level.active = index;
			},
			click(e) {
				this.current = e.index
				this.level = e;
			},
			buy() {
				var detail = [{
					id: this.level.id,
					num: 1,
				}]
				this.Dever.data('detail', {
					type: 'role',
					type_id: this.fetch.role.id,
					detail: detail,
					jump: 'user/index',
				});
				this.Dever.location('order/create');
			},
		}
	};
</script>

<style lang="scss">
	.vip-area {
		background-image: url('/static/images/role.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		height: 134px;
	}

	.margin-top-sm {
		margin-top: 12rpx;
	}

	.role-area {
		width: 202px;
		top: 19px;
		z-index: 1;
		border: 1px solid rgb(255, 106, 108);
		background: rgb(254, 240, 239);
	}

	.tabs {
		display: flex;
		border-bottom: 2rpx solid #eee;
		margin-bottom: 20rpx;
		margin-top: 30rpx;
	}

	.tab-item {
		flex: 1;
		text-align: center;
		padding: 20rpx;
		font-weight: 500;
		color: #666;
	}

	.tab-item.active {
		color: #007aff;
		border-bottom: 4rpx solid #007aff;
	}

	.fs-xxs {
		font-size: 24rpx;
	}

	.coupon_box {
		background-color: #eee8eb45;
		position: relative;

		&:last-child {
			margin-bottom: 20rpx;
		}

		.left {
			background-color: #6a92ffa1;
			color: #fff;
			width: 30%;

			.price {
				color: #fff !important;
			}
		}

		.right {
			margin-left: 30%;
		}

		.border-line {
			border-bottom: 1px dotted #ededed;
		}
	}

	/* 按钮样式 */
	.btn-receive {
		background: $base-color;
		color: #fff;
		font-weight: bold;
	}

	.btn-receive-disabled {
		color: #fff;
		font-weight: bold;
	}

	.btn-container {
		left: 9px;
		right: 9px;
		bottom: 0;
	}

	.btn-exchange {
		background: #ff6ade;
		color: #fff;
		font-weight: bold;
	}
	
	.u-popover {
		display: block !important;
	}
</style>