<template>
	<view>
		<view class="status_bar"></view>
		<u-navbar :is-back="false" :border-bottom="false" :background="background">
			<view style="width: 100%;padding: 0 10rpx;">
				<view class="flztoa inlbhhe ">
					<navigator class="indihh" url="../index/index" open-type="redirect" hover-class="none">
						<text>最新</text>
					</navigator>
					<view class="indihh">
						<text style="font-size: 44rpx;color:  #374B6E;">会员</text>
						<view
							style="width: 26rpx;height: 4rpx;background: #374B6E;border-radius: 4rpx;margin-top: 10rpx;">
						</view>
					</view>
					<navigator class="indihh" url="../index/zylx" open-type="redirect" hover-class="none">
						<text>治愈练习</text>
					</navigator>
					<navigator class="indihh" url="../index/hd" open-type="redirect" hover-class="none">
						<text>活动</text>
					</navigator>
				</view>
			</view>
		</u-navbar>

		<view class="hyinnr" style="overflow: hidden;">
            <image src="/static/my/my01.png" style="width: 100%; height: 103%; position: absolute; left: 0; top: 0rpx; z-index: -1;" mode=""></image>
			<view class="hyinnrks">
				<view style="margin: 60rpx 40rpx 36rpx 40rpx;">
					<image src="/static/my/my02.png" style="width: 227.14rpx;height: 56rpx;" mode=""></image>
				</view>
				<view class="hyintxt">
					<text>开通会员尽享三大权益</text>
				</view>
				<view class="hyinrq">
					<text>到期：{{info.vip.over_time}}</text>
				</view>
			</view>
		</view>

		<view class="myxmkstt">
			<view class="myhbtui">
				<view class="myshutt"></view>
				<text>专属权益</text>
			</view>

			<view class="flztoa" style="margin: 0 66rpx; margin-top: 20rpx;">
				<view class="myiodde">
					<image src="/static/my/myb01.png" style="width: 80rpx;height: 80rpx;margin-bottom: 6rpx;" mode="">
					</image>
					<text>会员价</text>
				</view>
				<view class="myiodde">
					<image src="/static/my/myb02.png" style="width: 80rpx;height: 80rpx;margin-bottom: 6rpx;" mode="">
					</image>
					<text>体检理疗</text>
				</view>
				<view class="myiodde">
					<image src="/static/my/myb03.png" style="width: 80rpx;height: 80rpx;margin-bottom: 6rpx;" mode="">
					</image>
					<text>更多优惠</text>
				</view>
			</view>
		</view>

		<view class="myxmkstt">
			<view class="myhbtui">
				<view class="myshutt"></view>
				<text>会员规则</text>
			</view>

			<view class="mytxtjs">
				<rich-text :nodes="info.vip_set.agreement"></rich-text>
			</view>
		</view>
		<view class="btn" @click="pay" v-if="is_vip == 0">开通会员/¥{{info.vip_card[0].price}}</view>
		<view style="height: 130rpx;"></view>
		<view class="dibuboot">
			<navigator class="dibubootlb" url="../index/index" open-type="redirect" hover-class="none">
				<image src="/static/dibu/bob1.png" style="width: 48rpx;height: 48rpx;"></image>
				<text style="color: #374B6E">首页</text>
			</navigator>
<!-- 			<navigator class="dibubootlb" url="../lecturer/wdzx" open-type="redirect" hover-class="none">
				<image src="/static/dibu/boa2.png" style="width: 48rpx;height: 48rpx;"></image>
				<text>咨询</text>
			</navigator>
			<navigator class="dibubootlb" url="../index/jiehuo" open-type="redirect" hover-class="none">
				<image src="/static/dibu/boa3.png" style="width: 48rpx;height: 48rpx;"></image>
				<text>解惑</text>
			</navigator> -->
			<navigator class="dibubootlb" url="../lecturer/my" open-type="redirect" hover-class="none">
				<image src="/static/dibu/boa4.png" style="width: 48rpx;height: 48rpx;"></image>
				<text>我的</text>
			</navigator>
		</view>
	</view>
</template>
<style>
	page {
		background: #FAFAFA;
	}
</style>
<script>
	export default {
		data() {
			return {
				background: {
					backgroundColor: '#ffffff',
				},
				info: {},
				is_vip:0,
				deviceType:'wxapp'
			}
		},
		onLoad() {
			// #ifdef APP-PLUS
				this.deviceType = 'wxh5'
			// #endif
			// #ifdef MP-WEIXIN
				this.deviceType = 'wxapp'
			// #endif
			this.getvipinfo();
			this.is_vip = uni.getStorageSync('is_vip');
			
		},
		methods: {
			getvipinfo() {
				let user_id = uni.getStorageSync('id');
				this.$post({
					data: {
						do: 'Vip',
						data: {
							user_id: user_id,
							pw: '375'
						}
					}
				}).then(res => {
					this.info = res.data
				})
			},
			pay() {
				let that = this;
				let user_id = uni.getStorageSync('id');
				that.$post({
					data:{
					do: 'VipOrder',
					data: {
						card_id: that.info.vip_card[0].id,
						cdkey: '',
						user_id: user_id,
						pw: '375'
					},
					deviceType:this.deviceType
				}
				}).then(res => {
					that.wechatpay(res.data);
				})
			},
			wechatpay(pay){
				var that = this
				// #ifdef APP-PLUS
						uni.requestPayment({
								"provider": "wxpay", 
								orderInfo: pay.orderinfo, //微信、支付宝订单数据 【注意微信的订单信息，键值应该全部是小写，不能采用驼峰命名】
								success: function (res) {
										console.log('success:' + JSON.stringify(res));
										uni.showToast({
											title: '支付成功'
										})
										that.is_vip = 1;
										uni.setStorageSync('is_vip',1)
										that.getvipinfo();
								},
								fail: function (err) {
									console.log(pay.orderinfo,'eeeeeeeeeeeeeeeee')
										console.log('fail:' + JSON.stringify(err));
										uni.showToast({
											title: '支付失败',
											icon: 'error'
										})
								}
						});
				// #endif
						
				
				// #ifdef MP-WEIXIN
				uni.requestPayment({
					provider: 'wxpay',
					timeStamp: pay.timeStamp,
					nonceStr: pay.nonceStr,
					package: pay.package,
					signType: 'MD5',
					paySign: pay.paySign,
					success() {
						uni.showToast({
							title: '支付成功'
						})
						that.is_vip = 1;
						uni.setStorageSync('is_vip',1)
						that.getvipinfo();
					},
					fail(res) {
						console.log(res)
						uni.showToast({
							title: '支付失败',
							icon: 'error'
						})
					}
				})
				// #endif
			
			}
		}
	}
</script>

<style lang="scss" scoped>
	.status_bar {
		height: var(--status-bar-height);
		width: 100%;
	}
	.btn {
		width: 524upx;
		height: 100upx;
		background: #F8DAB9;
		font-size: 36upx;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 100upx;
		margin: 50upx auto;
	}
</style>
