<template>
	<view class="content">
		<view class="user-top flex">
			<view class="user-avart">
				<image :src="userInfo.avatar" mode="" v-if="userInfo.avatar" class="user-avatar"></image>
				<image src="../../static/error/missing-face.png" mode="" class="user-avatar" v-else></image>
			</view>
			<view class="user-info">
				<view class="user-name clamp">
					{{ userInfo.nickname}}
				</view>
				<view class="user-level">
					{{ userInfo.level ==0 ? '尚未开通VIP':'会员' }}
				</view>
			</view>
			<view class="bottom-bg"></view>
		</view>
		<view class="title">
			会员权益
		</view>
		<view class="tit">
			开通会员可享受无限次使用次数，非会员仅可享受0次。
		</view>
		<view class="title">
			VIP充值套餐
		</view>
		<view class="menber-item flex" v-for="(item,index) in list" :class="{'action': index == currentIndex}" @click="navClick(index,item)">
			<view class="item-right-top">
				{{((item.price*1)/(item.time*1)).toFixed(2)}}元/天
			</view>
			<view class="item-price">
				{{item.title}}
			</view>
			<view class="item-info">
				<text class="old-price">原价{{item.ot_price*1}}元</text>{{item.price*1}}<text class="dw">元</text>
			</view>
		</view>
		<view class="zf-btn" @click="zf" :class="{'press': loading}">
			{{loading?'支付中':'立即支付'}}
		</view>
		<view class="check_box flex_item">
			<view>
				<radio style="transform: scale(0.75)" @click="Getcheckbox" color="#FFCE8A" :checked="checked" />
			</view>
			<view class="">我已阅读并同意会员<text @click="TOprivacy">用户协议</text></view>
		</view>
	</view>
</template>

<script>
	import { getMenberCard,buyMenber } from '@/api/index.js'
	import {
		mapState,
		mapMutations
	} from 'vuex';
	export default {
		data() {
			return {
				currentIndex: 0,
				checked: true,
				list: [],
				loading: false,
				chooosId: '',
			}
		},
		computed: {
			...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
		},
		onLoad() {

		},
		onShow() {
			this.getMenberCard()
		},
		onReachBottom() {

		},
		onReady() {

		},
		methods: {
			navClick(index,item) {
				this.currentIndex = index
				this.chooosId = item.id
			},
			//阅读并同意
			Getcheckbox() {
				let obj = this;
				obj.checked = !obj.checked;
			},
			TOprivacy() {
				// uni.navigateTo({
				// 	url: ''
				// })
			},
			zf() {
				let obj = this
				if(obj.loading) {
					return
				}
				if(!obj.checked) {
					return obj.$api.msg('请阅读并同意会员用户协议')
				}
				obj.loading = true
				buyMenber({
					char_id: obj.chooosId,
					type: 0
				}).then(res => {
					console.log(res)
				}).catch(err => {
					obj.loading = false
				})
			},
			getMenberCard() {
				let obj = this
				getMenberCard().then(res => {
					console.log(res)
					obj.list = res.data
					obj.chooosId = res.data[0].id
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #fff;
	}

	.user-top {
		width: 100%;
		height: 350rpx;
		background-color: #1c1c20;
		font-size: 38rpx;
		font-weight: bold;
		color: #FFFFFF;
		align-items: center;
		justify-content: flex-start;
		padding: 0 52rpx;
		position: relative;

		.user-avart {
			flex-shrink: 0;
			width: 100rpx;
			height: 100rpx;

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

		.user-info {
			flex-grow: 1;
			padding-left: 24rpx;
			.user-name {
				font-size: 38rpx;
				font-weight: bold;
				color: #FFFFFF;
			}
			.user-level {
				font-size: 24rpx;
				font-weight: bold;
				color: #FFFFFF;
			}
		}

		.bottom-bg {
			width: 750rpx;
			height: 55rpx;
			position: absolute;
			border-radius: 25rpx 25rpx 0 0;
			background-color: #fff;
			bottom: 0;
			left: 0;
		}
	}

	.title {
		font-size: 36rpx;
		font-weight: bold;
		color: #000000;
		padding-left: 30rpx;
	}

	.tit {
		font-size: 26rpx;
		font-weight: 500;
		color: #5C5C5C;
		padding: 30rpx 0 30rpx 30rpx;
	}
	.action {
		border: 6rpx solid #ffe5c2;
		font-weight: 900;
		background: #FFFAF3;
	}
	.menber-item {
		width: 690rpx;
		height: 170rpx;
		margin: auto;
		
		// border: 3rpx solid #ffe5c2;
		box-shadow: 2rpx 1rpx 30rpx 0px rgba(0, 0, 0, 0.1);
		border-radius: 18rpx;
		position: relative;
		align-items: center;
		padding: 0 30rpx 0 40rpx;
		margin-top: 30rpx;

		.item-right-top {
			min-width: 128rpx;
			display: inline-block;
			text-align: center;
			line-height: 38rpx;
			font-size: 24rpx;
			font-weight: bold;
			color: #9F570E;
			height: 38rpx;
			background: linear-gradient(270deg, #FFE7C4, #FFCE8A);
			border-radius: 0px 18rpx 0px 18rpx;
			position: absolute;
			right: 0;
			top: 0;
		}

		.item-info {
			font-size: 48rpx;
			font-weight: bold;
			color: #9F570E;

			.item-price {
				font-size: 32rpx;
				font-weight: bold;
				color: #131313;
			}

			.old-price {
				font-size: 24rpx;
				font-weight: bold;
				text-decoration: line-through;
				color: #AEAEAE;
				padding-right: 12rpx;
			}

			.dw {
				font-size: 26rpx;
			}
		}

	}

	.zf-btn {
		width: 620rpx;
		background: linear-gradient(270deg, #FFE7C4, #FFCE8A);
		border-radius: 49rpx;
		margin: 80rpx auto 40rpx;
		font-size: 32rpx;
		font-weight: bold;
		color: #9F570E;
		line-height: 100rpx;
		text-align: center;
	}
	.press {
		background: #999;
		color: #eee;
	}

	.check_box {
		// padding: 25rpx 25rpx;
		padding-bottom: 70rpx;
		font-size: 28rpx;

		text {
			color: #6786FB;
		}
	}

	.flex_item {
		display: flex;
		justify-content: center;
	}
</style>
