<template>
	<!-- 会员详情 -->
	<view class="content">
		<view class="card_info">
			<image class="card_info_bg"
				:src="shopUserInfo.shopExtend?shopUserInfo.shopExtend.value:'https://czg-qr-order.oss-cn-beijing.aliyuncs.com/menber/member_bg.png'"
				mode="aspectFill"></image>
			<view class="card_info_bg_box"></view>
			<view class="card_content">
				<view class="card_head">
					<view class="card_head_left">
						<image class="card_head_left_head"
							src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/menber/member_head.png"
							mode="aspectFill"></image>
						<text class="card_head_left_name">{{shopUserInfo.shopInfo.shopName||''}}会员卡</text>
						<view class="card_head_left_icon_box" v-if="shopUserInfo.shopInfo.isVip != 0">
							<image class="card_head_left_icon1"
								src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/menber/member_icon1.png"
								mode="aspectFill"></image>
							<text class="card_head_left_iconText">VL1</text>
						</view>
					</view>
					<view class="card_head_right" @click="clickEvent" v-if="shopUserInfo.shopInfo.isVip != 0">
						<image class="card_head_left_qrCode"
							src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/menber/member_qrCode.png"
							mode="aspectFill"></image>
					</view>
				</view>
				<view class="card_cen">
					<view class="card_cen_left">{{ shopUserInfo.shopInfo.isVip == 0 ? '尚未开通会员暂无法享受会员权益' : '欢迎加入本店会员~'}}
					</view>
					<view class="card_cen_right" v-if="shopUserInfo.shopInfo.isVip != 0">查看特权</view>
				</view>
				<view class="card_bom" v-if="shopUserInfo.shopInfo.isVip != 0">
					<view class="card_bom_item" @click="itemClick(1)">
						<text>{{shopUserInfo.shopInfo.amount || '0.00'}}</text><text>储值</text>
					</view>
					<view class="card_bom_item" @click="itemClick(2)">
						<text>{{shopUserInfo.shopInfo.accountPoints || '0'}}</text><text>积分</text>
					</view>
					<view class="card_bom_item" @click="itemClick(3)">
						<text>{{shopUserInfo.shopInfo.couponNum || '0'}}</text><text>优惠券</text>
					</view>
					<view class="card_bom_item">
						<text>0</text><text>权益卡</text>
					</view>
				</view>
			</view>
		</view>


		<view class="card_bottom" :class="shopUserInfo.shopInfo.isVip == 0 ? 'n' : ''">
			<view class="card_bottom_Box" v-if="shopUserInfo.shopInfo.isVip != 0">
				<view class="card_bottom_left flex-start">
					<image class="card_bottom_head"
						src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/menber/member_head2.png"
						mode="aspectFill"></image>
					<view class="">
						<view class="card_bottom_title">感谢你 2 天陪伴</view>
						<view class="flex-start">
							<view class="card_bottom_text">您今天的幸运词：<text class="luckyWord">林波微步</text></view>
						</view>
					</view>
				</view>
				<image class="card_bottom_right_img"
					src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/menber/member_img3.png" mode="aspectFill">
				</image>
			</view>
			<view class="card_bottom_Box" v-else>
				<view class="card_bottom_equity">
					<view class="card_bottom_equity_title">专享2项权益</view>
					<view class="card_bottom_equity_list">
						<view class="card_bottom_equity_list_item">
							<image class="list_item_icon"
								src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/menber/member_icon01.png"
								mode="aspectFill"></image>
							<text class="list_item_text">会员专属活动</text>
						</view>
						<view class="card_bottom_equity_list_item">
							<image class="list_item_icon"
								src="https://czg-qr-order.oss-cn-beijing.aliyuncs.com/menber/member_icon02.png"
								mode="aspectFill"></image>
							<text class="list_item_text">福利商品</text>
						</view>

					</view>
				</view>
			</view>
		</view>

		<registermember :memberOpen="form.memberOpen" :shopUserInfo="shopUserInfo.shopInfo">
		</registermember>

	</view>
</template>

<script setup>
	import {
		reactive,
		ref,
		onMounted
	} from 'vue'
	import {
		APIusershopInfodetail,
		APIshopUserInfo
	} from '@/common/api/member.js'

	import registermember from './components/registermember.vue'


	const shopUserInfo = reactive({
		shopInfo: {},
		shopExtend: {},
		shopId: ""
	})

	const form = reactive({
		memberOpen: false,
		shopName: "",
		amount: '',
		lucky: {
			list: ['鸿运当头', "财运亨通", "时来运转", "否极泰来", "花逢时发"],
			index: 0,
			text: ""
		},
	})

	const itemClick = (type) => {
		if (type == 1) {
			uni.pro.navigateTo('user/member/index', {
				shopId: shopUserInfo.shopId,
				type: type
			})
		} else if (type == 2) {
			uni.pro.navigateTo('user/member/billDetails', {
				shopId: shopUserInfo.shopId,
				type: type,
				shopInfo: JSON.stringify(shopUserInfo.shopInfo)
			})
		} else if (type == 3) {
			uni.pro.navigateTo('user/coupon', {
				shopId: shopUserInfo.shopId,
				shopInfo: shopUserInfo.shopInfo
			})
		}
	}

	// * 注册会员卡
	const clickEvent = () => {
		uni.pro.navigateTo('user/member/paycode', {
			shopId: shopUserInfo.shopId,
			shopInfo: JSON.stringify(shopUserInfo.shopInfo)
		})
	}

	// * 注册会员卡
	const getRegisterMember = () => {
		this.memberOpen = e;
		this.init()
	}

	// 会员总信息
	const asyncshopUserInfo = async () => {
		let res = await APIshopUserInfo({
			shopId: shopUserInfo.shopId
		})
		uni.cache.set('orderVIP', res)
		uni.cache.set('ordershopUserInfo', res.shopInfo)
		form.memberOpen = res.isVip == 1 ? false : true

	}


	onMounted(async () => {
		// 获取当前页面栈
		const pages = getCurrentPages();
		// 检查页面栈是否为空
		if (pages.length === 0) {
			console.error('未获取到页面栈');
			return;
		}
		// 获取当前页面实例
		const currentPage = pages[pages.length - 1];
		// 获取页面参数
		const pageParams = currentPage.options;
		if (pageParams.shopId) {
			asyncshopUserInfo()
			uni.cache.set('shopId', pageParams.shopId, 30)
			let res = await APIusershopInfodetail({
				shopId: pageParams.shopId
			})
			// 根据传的shopInfo来返回上面的值
			shopUserInfo.shopExtend = res.shopExtend.member_bg
			shopUserInfo.shopId = pageParams.shopId
		}

	})
</script>

<style lang="scss">
	page {
		background: #F9F9F9;
	}

	.content {
		padding: 0 28rpx;
		font-size: 12rpx;

		.card_info {
			width: 630rpx;
			height: 304rpx;
			margin: auto;
			position: relative;
			z-index: 2;
			padding-top: 20rpx;

			.card_info_bg {
				width: 630rpx;
				height: 304rpx;
				position: absolute;
				z-index: 1;
			}

			.card_info_bg_box {
				width: 630rpx;
				height: 304rpx;
				position: absolute;
				z-index: 1;
				border-radius: 24rpx;
				background-color: rgba(51, 51, 51, 0.5);
			}

			.card_content {
				position: relative;
				left: 0;
				top: 0;
				z-index: 2;
				color: #fff;
				padding: 30rpx;

				.card_head {
					display: flex;
					align-items: center;
					justify-content: space-between;

					.card_head_left {
						display: flex;
						align-items: center;

						.card_head_left_head {
							width: 40rpx;
							height: 40rpx;
							margin-right: 16rpx;
						}

						.card_head_left_name {
							font-weight: 400;
							font-size: 32rpx;
							color: #FFFFFF;
							margin-right: 12rpx;
						}

						.card_head_left_icon_box {
							width: 64.23rpx;
							height: 26.56rpx;
							position: relative;
							display: flex;
							align-items: center;
							justify-content: center;

							.card_head_left_icon1 {
								width: 64.23rpx;
								height: 26.56rpx;
								position: absolute;
								left: 0;
								top: 0;
							}

							.card_head_left_iconText {
								font-weight: bold;
								font-size: 18rpx;
								color: #FFFFFF;
								position: relative;
								z-index: 1;
							}
						}

					}

					.card_head_right {
						width: 56rpx;
						height: 56rpx;
						border-radius: 50%;
						background: #000000;
						box-shadow: 0rpx 6rpx 12rpx 2rpx rgba(0, 0, 0, 0.16);
						display: flex;
						justify-content: center;
						align-items: center;

						.card_head_left_qrCode {
							width: 24rpx;
							height: 24rpx;
						}
					}
				}

				.card_cen {
					display: flex;
					justify-content: space-between;
					font-weight: 400;
					font-size: 20rpx;
					color: #FFFFFF;
					margin-top: 20rpx;
				}

				.card_bom {
					display: flex;
					justify-content: space-between;
					margin-top: 60rpx;

					.card_bom_item {
						width: 25%;
						display: flex;
						flex-direction: column;
						align-items: center;
						font-weight: 400;

						text:nth-child(1) {
							font-size: 30rpx;
							color: #FFFFFF;
						}

						text:nth-child(2) {
							font-size: 24rpx;
							color: #FFFFFF;
						}
					}
				}
			}
		}

		.card_bottom {
			width: 100%;
			height: 280rpx;
			background-color: #fff;
			border-radius: 24rpx;
			position: relative;
			z-index: 1;
			margin-top: -120rpx;
			display: flex;
			align-items: flex-end;
			padding: 16rpx 42rpx;

			.card_bottom_Box {
				width: 100%;
				display: flex;
				justify-content: space-between;
				align-items: flex-end;

				.card_bottom_left {
					margin-bottom: 16rpx;
				}

				.card_bottom_head {
					width: 80rpx;
					height: 80rpx;
					margin-right: 14rpx;
				}

				.card_bottom_title {
					font-weight: 400;
					font-size: 32rpx;
					color: #333333;
				}

				.card_bottom_text {
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					margin-right: 8rpx;
				}

				.card_bottom_icon {
					width: 22.7rpx;
					height: 22.18rpx;
				}

				.card_bottom_right_img {
					width: 132rpx;
					height: 132rpx;
				}


				.card_bottom_equity {
					display: flex;
					flex-direction: column;

					.card_bottom_equity_title {
						font-weight: bold;
						font-size: 32rpx;
						color: #333333;
					}

					.card_bottom_equity_list {
						display: flex;
						flex-wrap: wrap;
						margin-top: 32rpx;

						.card_bottom_equity_list_item {
							display: flex;
							flex-direction: column;
							align-items: center;
							margin-right: 56rpx;

							.list_item_icon {
								width: 52rpx;
								height: 46rpx;
								margin-bottom: 6rpx;
							}

							.list_item_text {
								font-weight: 500;
								font-size: 22rpx;
								color: #333333;
							}
						}
					}
				}
			}
		}

		.card_bottom.n {
			padding: 24rpx 42rpx;
			margin-top: -80rpx;
		}

		.towcontentitem {
			width: 100%;
			position: relative;
			padding: 32rpx;
			border-radius: 12rpx;
			background: linear-gradient(126deg, #FFFBF2 0%, #F2D093 100%);
			border-radius: 12rpx 12rpx 12rpx 12rpx;

			&::after {
				position: absolute;
				bottom: 0;
				right: 68rpx;
				content: '';
				display: inline-block;
				width: 240rpx;
				height: 232rpx;
				background: url(https://czg-qr-order.oss-cn-beijing.aliyuncs.com/member.png) no-repeat;
				background-size: 100% 100%;
			}

			.towcontentitemimage {
				top: 0;
				left: 0;
				position: absolute;
				width: 100%;
				height: 100%;
				border-radius: 12rpx;
				z-index: 5;
			}

			.towcontentitemone {
				width: 100%;
				position: relative;
				z-index: 9;

				.towcontentitemoneimage {
					width: 76rpx;
					height: 76rpx;
					border-radius: 50%;
				}



				.towcontentitemonetext {
					height: 76rpx;
					margin-left: 16rpx;

					.towcontentitemonetextone {
						font-family: Source Han Sans CN, Source Han Sans CN;
						font-weight: 500;
						font-size: 36rpx;
						color: #333333;
					}

					.towcontentitemonetexttow {
						font-size: 24rpx;
						font-family: Source Han Sans CN-Regular, Source Han Sans CN;
						font-weight: 400;
						color: #422A07;
					}

				}
			}

			.towcontentitemprogressa {
				padding: 8rpx 44rpx;
				z-index: 10;
				position: relative;
				margin-top: 54rpx;
			}

			.towcontentitemtow {
				margin-top: 84rpx;
				z-index: 10;
				font-size: 24rpx;
				font-family: Source Han Sans CN-Regular, Source Han Sans CN;
				font-weight: 400;
				color: #422A07;
			}

			.towcontentitevip {
				position: absolute;
				right: 0;
				top: 0;
				width: 92rpx;
				height: 40rpx;
				font-size: 20rpx;
				background: #F4C380;
				border-radius: 0rpx 12rpx 0rpx 12rpx;
				text-align: center;
				line-height: 40rpx;
				color: #fff;
				font-family: Source Han Sans CN-Medium;
				font-weight: Medium;

			}

			.towcontentitemthere {
				margin-left: 92rpx;
				font-family: Source Han Sans CN, Source Han Sans CN;
				font-weight: Medium;
				font-size: 24rpx;
				color: #333333;

				.towcontentitemtheretext {
					font-family: Source Han Sans CN, Source Han Sans CN;
					font-weight: bold;
					font-size: 36rpx;
					color: #333333;
				}
			}
		}

		.therecontent {
			margin-top: 32rpx;
			position: relative;
			padding: 22rpx 32rpx;
			width: 100%;
			background: #FFFFFF;
			border-radius: 8rpx;

			input {
				padding-left: 30rpx;
				text-align: right;
				font-size: 28rpx;
				font-family: Source Han Sans CN-Medium, Source Han Sans CN;
				font-weight: 500;
				color: #666666;
			}
		}

		.therecontent::after {
			position: absolute;
			top: 50%;
			left: 32rpx;
			transform: translateY(-50%);
			content: '￥';
			display: inline-block;
			width: 28rpx;
			height: 40rpx;
			font-size: 28rpx;
			font-family: Source Han Sans CN-Regular, Source Han Sans CN;
			font-weight: 400;
			color: #333333;
		}

		.fourcontent {
			.fourcontentlnage {
				width: 33.33%;

				.fourcontentitem {
					margin: 24rpx 10rpx;
					padding: 16rpx 0;
					text-align: center;
					background: #FFFFFF;
					border-radius: 8rpx;
					border: 1rpx solid #333333;
					font-size: 28rpx;
					font-family: Roboto-Medium, Roboto;
					font-weight: 500;
					color: #333333;
				}

				.fourcontentitems {
					margin: 24rpx 10rpx;
					padding: 16rpx 0;
					text-align: center;
					border-radius: 8rpx;
					background: #F1CB66;
					border-radius: 8rpx 8rpx 8rpx 8rpx;
					border: 2rpx solid #F1CB66;
					font-size: 28rpx;
					font-family: Roboto-Medium, Roboto;
					font-weight: 500;
					color: #FFFFFF;
				}
			}

		}

		.fivecontent {
			position: relative;
			bottom: 44rpx;
			margin-top: 62rpx;
			padding: 20rpx 0;
			text-align: center;
			width: 100%;
			font-size: 36rpx;
			font-family: PingFang SC-Bold, PingFang SC;
			font-weight: bold;
			color: #FFFFFF;
			border-radius: 8rpx;
			background: #F1CB66;
		}

		// 会员详情
		.memberdetailsStyle {
			margin-top: 32rpx;
			border-radius: 24rpx 24rpx 24rpx 24rpx;
			background-color: #fff;
			padding: 32rpx;
			height: 252rpx;
			display: flex;
			justify-content: space-between;
			flex-direction: column;

			>text {
				font-weight: bold;
				font-size: 32rpx;
				color: #333333;
			}

			>view {
				font-weight: 400;
				font-size: 28rpx;
				color: #333333;
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
		}

	}
</style>