<template>
	<view>
		<view class="">
			<view class="margin-lr margin-top" style="position: relative;border-radius: 10upx;overflow: hidden;">
				<image src="../static/vip.png" style="width: 100%;height: 250rpx;"></image>
				<view class=" u-flex u-p-l-30 u-p-t-80 u-p-b-30" style="position: absolute;top: 0;width: 100%;">
					<view class="u-m-r-20">
						<u-avatar :src="avatar" size="100"></u-avatar>
					</view>
					<view class="u-flex-1 ">
						<view class="u-font-18 text-white text-bold">{{userName}}</view>
						<view class="u-font-14 u-m-t-10 u-tips-color" style="color: #C59D7C;" v-if="!isVip">您目前还未开通会员</view>
					</view>
				</view>
			</view>
			<view class="flex margin-top-sm flex-wrap padding-lr-sm">
				<view v-for="(item,index) in vipList" :key='index' @click="select(item)" class=""
					style="display: inline-block;width: 216rpx;height: 250rpx;margin: 10rpx 10rpx;">
					<view class="text-center flex flex-direction justify-between padding-tb radius"
						:class="selNum == item.id?'active': ''"
						style="color: #DFC5A7;width: 216rpx;height: 250rpx;background: linear-gradient(-30deg, #2B2A30, #4A4A4A);border: 1px;">
						<view class="text-bold">{{item.vipName}}</view>
						<view class="text-bold">¥<text class="text-xxl">{{item.money}}</text></view>
						<view>立即预约</view>
					</view>
				</view>
			</view>
			<view class="padding-tb radius margin-top margin-lr"
				style="background-color: #343339;border-radius: 10upx;">
				<view class="text-center text-xl text-bold " style="color: #CAB49C;">开通专享特权</view>
				<view class="flex  flex-wrap">
					<view v-for="(item,index) in MemberList" :key="index"
						style="width: 33%;text-align: center;margin-top: 34upx;">
						<image :src="item.memberImg" mode="" style="margin: 0 auto;height: 45rpx;width: 45rpx;"></image>
						<view class="grid-text margin-top-sm" style="color: #DFC5A7;">{{item.memberName}}</view>
					</view>
				</view>
			</view>
		</view>
		<view style="height: 110rpx;"></view>
		<view class="flex justify-between cu-bar foot bg padding-lr" v-if="!isVip">
			<view style="color: #DFC5A7;">
				实付：<text style="font-size: 38upx;margin-top: 8upx;">{{price}}</text>金元
			</view>
			<view class="">
				<u-button :custom-style="customStyle" @click="pay()" shape="circle" :hair-line="false">立即开通</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				customStyle: {
					width: '250rpx',
					color: '#402321',
					background: "#DFC5A7",
					border: 0,
					fontWeight: '700'
				},
				gridData: [{
						title: '专享九折',
						image: '../static/1.png'
					},
					// {
					// 	title: '特权礼物',
					// 	image: '../static/2.png'
					// },
					{
						title: '身份标识',
						image: '../static/3.png'
					},
					// {
					// 	title: '超值专享券',
					// 	image: '../static/4.png'
					// },
					// {
					// 	title: '商家特权',
					// 	image: '../static/5.png'
					// },
					// {
					// 	title: '定制挂件',
					// 	image: '../static/6.png'
					// }
				],
				avatar: '',
				userName: '匿名',
				vipList: [],
				selNum: 2,
				newPrice: 0,
				money: 0,
				price: 0,
				MemberList: [],
				isVip: false
			}
		},
		onLoad() {
			this.avatar = uni.getStorageSync('avatar')
			this.userName = uni.getStorageSync('userName')

			this.getVipList()
			this.getMemberList()
			this.getMoney()
			this.getIsVip()
			this.getUserInfo()
		},
		methods: {
			getUserInfo() {
				this.$Request.get("/app/user/selectUserById").then(res => {
					if (res.code == 0) {
						this.avatar = res.data.avatar?res.data.avatar: '../../static/logo.png'
						
						uni.setStorageSync('avatar', res.data.avatar)
					}
				});
			},
			//获取VIP列表
			getVipList() {
				this.$Request.get('/app/VipDetails/selectVipDetails').then(res => {
					if (res.code == 0) {
						this.vipList = res.data
						this.price = this.vipList[0].money
					}
				})
			},
			// 获取特权列表
			getMemberList() {
				this.$Request.get('/app/member/selectMemberList').then(res => {
					if (res.code == 0) {
						this.MemberList = res.data
					}
				})
			},
			getIsVip() {
				this.$Request.get("/app/UserVip/isUserVip").then(res => {
					if (res.code == 0) {
						this.isVip = res.data
					}
				});
			},
			// 我的金元
			getMoney() {
				this.$Request.get("/app/userMoney/selectMyMoney").then(res => {
					if (res.code == 0 && res.data) {
						this.money = res.data.money
					}
				});
			},
			select(e) {
				this.selNum = e.id
				this.price = e.money
			},
			pay() {
				this.getMoney()
				// console.log(this.money, this.newPrice)
				if (this.money >= this.price) {
					let data = {
						id: this.selNum,
						type: '2'
					}
					this.$Request.get('/app/orders/generateOrder', data).then(res => {
						if (res.code == 0) {
							this.$Request.get('/app/userMoney/payTakingOrder', {
								orderId: res.data.ordersId
							}).then(res => {
								console.log(res.data)
								if (res.code == 0) {
									this.isVip = true
									uni.showToast({
										title: '开通成功！'
									})
									// setTimeout(function() {
									// 	uni.navigateBack()
									// },1000)
								} else {
									uni.showToast({
										title: res.msg
									})
								}
							})
						}
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '当前账户余额不足，请充值',
						success: function(res) {
							if (res.confirm) {
								console.log('用户点击确定');
								uni.navigateTo({
									url: '/my/wallet/index'
								})
							} else if (res.cancel) {
								console.log('用户点击取消');
							}
						}
					})
				}
			}
		},
		computed: {

		}
	}
</script>

<style>
	.bg {
		background: #f7f7f7;
	}

	.btn {
		width: 100%;
		height: 88upx;
		background: linear-gradient(0deg, #af8262 0%, #cab49c 100%);
		border-radius: 44upx;
		text-align: center;
		line-height: 88upx;
		margin-top: 40upx;
		font-size: 34upx;
		font-weight: 600;
		color: #402321;
	}

	.active {
		border: 1px solid #cab49c !important;
		border-radius: ;
		    background: black !important;
	}
</style>
