<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="/pages/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="/pages/index/zylx" open-type="redirect" hover-class="none">
						<text>治愈练习</text>
					</navigator>
					<navigator class="indihh" url="/pages/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>

		<scroll-view scroll-x="true" class="card_list">
			<view :class="card_checked == index ? 'card_a card_item':'card_item'" v-for="(item, index) in card_list"
				@click="changeCard(index)">
				<view class="card_dis_title" v-if="item.dis">{{item.dis.title}}</view>
				<view class="card_dis_title" v-else>暂无折扣</view>
				<view class="card_title">{{item.title}}</view>
				<view class="card_price" v-if="item.dis"><text class="card_price_icon">¥</text>{{item.dis.price}}</view>
				<view class="card_price" v-else><text class="card_price_icon">¥</text>{{item.price}}</view>
				<view class="card_origin" v-if="item.dis"><text class="del_line">¥{{item.price}}</text>特惠</view>
				<view class="card_origin" v-else><text class="del_line"></text>特惠</view>
			</view>
		</scroll-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">
			开通会员/¥{{card_list[card_checked].dis ? card_list[card_checked].dis.price : card_list[card_checked].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',
				scrollTop: 0,
				old: {
					scrollTop: 0
				},
				card_list: [],
				card_checked: 0,
				card: {},

			}
		},
		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: {
			changeCard(index) {
				this.card_checked = index;
				this.card = this.card_list[index];
			},
			getvipinfo() {
				let user_id = uni.getStorageSync('id');


				this.$post({
					data: {
						do: 'Vip',
						data: {
							user_id: user_id,
							pw: '375'
						}
					}
				}).then(res => {
					
					if (res.data.is_vip == 1) {
						uni.setStorageSync('is_vip', 1);
						this.is_vip = uni.getStorageSync('is_vip');
					}
					
					this.info = res.data,
					this.card_list = this.info.vip_card;
					this.card = this.info.vip_card[0];
				})
			},
			pay() {


				let that = this;
				console.log(that.card, 'accc');
				let user_id = uni.getStorageSync('id');
				that.$post({
					data: {
						do: 'VipOrder',
						data: {
							card_id: that.card.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;
	}

	.card_list {
		white-space: nowrap;
		width: 100%;
	}

	.card_item {
		width: 200rpx;
		height: 260rpx;
		border-radius: 20rpx;
		margin: 0 10rpx;
		display: inline-block;
		border: 6rpx solid #f1f1f1;
	}

	.card_item:last-child {
		margin-right: 42rpx;
	}

	.card_item:first-child {
		margin-left: 42rpx;
	}

	.card_dis_title {
		line-height: 50rpx;
		height: 50rpx;
		background-color: #ffcb7d;
		text-align: center;
		font-weight: 700;
		border-radius: 15rpx 15rpx 0 0;
		color: #fff;
		width: 100%;
	}

	.card_title {
		line-height: 50rpx;
		height: 50rpx;
		text-align: center;
	}

	.card_price {
		line-height: 88rpx;
		text-align: center;
		height: 88rpx;
		font-weight: 700;
		font-size: 50rpx;
	}

	.card_price_icon {
		font-size: 25rpx;
		margin-right: 5rpx;
	}

	.card_origin {
		text-align: center;
	}

	.del_line {
		text-decoration: line-through;
		margin-right: 5rpx;
	}

	.card_a {
		border: 6rpx solid #ffcb7d;
	}
</style>
