<!-- 套餐分享页 -->
<template>
	<view class="color-333 u-font-28 min-page bg-f7" v-if="item.id">
		<view class="relative">
			<up-swiper height="428rpx" :list="item.images" @click="prveImg"></up-swiper>
			<view class="share-box">
				分享
				<button class="share" open-type="share" @click="shareCallback">分享</button>
			</view>
		</view>
		<view class="sku">
			<view class="u-flex u-col-center">
				<text class="price">¥{{ item.price }}</text>
				<text class="old-price">¥{{ item.originPrice }}</text>
			</view>
			<view>
				<view class="u-m-t-16 text" v-if="item.limitBuyNum">限购{{ item.limitBuyNum }}份</view>
				<view class="text u-m-t-10">已售：{{ item.saleNum || 0 }}</view>
			</view>
		</view>
		<view class="goods">
			<view class="goods-name">{{ item.packageName }}</view>
			<view class="u-m-t-20 color-666">
				{{ item.description }}
			</view>
		</view>
		<view class="bg-f7" style="height: 32rpx"></view>
		<view class="desc">
			<view class="u-flex">
				<view class="color-666 no-wrap" style="min-width: 180rpx">可核销门店：</view>
				<view class="">{{ item.shopName }}</view>
			</view>
			<view class="u-flex u-m-t-16 u-col-baseline">
				<view class="color-666 no-wrap" style="min-width: 180rpx">门店地址：</view>
				<view class="">{{ item.shopAddress }}</view>
			</view>
		</view>
		<!-- <template v-if="flase">
			<view class="bg-f7" style="height: 32rpx"></view>
			<view class="groups">
				<view class="color-000 u-m-b-28 u-font-32 font-700">立即拼团</view>
				<view class="item u-flex" v-for="(item, index) in item.gbOrderList" :key="index">
					<up-avatar size="76rpx" :src="item.avatar"></up-avatar>
					<view class="u-flex u-flex-1 u-p-l-22 u-col-center u-row-between">
						<view>
							<view class="color-000 u-line-1" style="max-width: 180rpx">{{ item.nickName }}</view>
							<view class="main-color u-m-t-2">差{{ returnNeedPerpole(item) }}人拼成</view>
						</view>
						<view class="u-m-t-22">
							<text class="color-666">剩余：</text>
							<text class="main-color">{{ getRemainingHMS(item) }}</text>
						</view>

						<view class="btn" @click="fastBuy(item)">快速拼成</view>
					</view>
				</view>
			</view>
		</template> -->
		<view class="bg-f7" style="height: 24rpx"></view>
		<view class="goods-group">
			<view class="u-flex u-row-between">
				<view class="name">套餐商品</view>
				<view class="u-flex color-666" @click="showGroup = !showGroup" style="align-items: baseline">
					<text class="u-m-r-18">{{ showGroup ? '收起' : '展开' }}</text>
					<view class="guodu" :class="{ rotate: !showGroup }">
						<up-icon name="arrow-down" bold></up-icon>
					</view>
				</view>
			</view>
			<view class="" v-if="showGroup">
				<view class="u-m-t-48" v-for="(item, index) in item.packageContent" :key="index">
					<view class="font-bold">
						<text class="">{{ item.name }}</text>
						<text class="u-m-l-30">{{ item.packageProducts.length }}选{{ item.num }}</text>
					</view>
					<view class="">
						<view class="u-flex u-m-t-24 u-row-between" v-for="(goods, goodsIndex) in item.packageProducts" :key="goodsIndex">
							<text>{{ goods.name }}</text>
							<view class="u-flex text-right">
								<text class="color-666 u-m-r-42">x{{ goods.num }}</text>
								<view style="min-width: 110rpx">¥{{ goods.price }}</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="desc" v-if="item.tieredDiscount && item.tieredDiscount.length > 0">
			<view class="u-flex u-row-between">
				<view class="name">分享说明</view>
				<view class="u-flex color-666" @click="showDesc = !showDesc" style="align-items: baseline">
					<text class="u-m-r-18">{{ showDesc ? '收起' : '展开' }}</text>
					<view class="guodu" :class="{ rotate: !showDesc }">
						<up-icon name="arrow-down" bold></up-icon>
					</view>
				</view>
			</view>
			<template v-if="showDesc">
				<view class="u-m-t-26 text-center table">
					<view class="u-flex header color-666">
						<view class="u-flex-1 u-p-t-32 u-p-b-32">分享人数</view>
						<view class="u-flex-1 u-p-t-32 u-p-b-32">购买价格（元）</view>
					</view>
					<view class="u-flex row" v-for="(step, index) in item.tieredDiscount" :key="index">
						<view class="u-flex-1 u-p-t-32 u-p-b-32">{{ step.peopleNum }}</view>
						<view class="u-flex-1 u-p-t-32 u-p-b-32">¥{{ step.price }}</view>
					</view>
				</view>

				<view class="u-m-t-26">
					<view>分享期限（小时）：{{ item.expireHours }}</view>
					<view class="u-m-t-10">规定期限内的助力才会被计入</view>
					<view class="u-m-t-40">如何才是分享成功？被分享人只需要点击《助力》，提示助力成功后即可</view>
				</view>
			</template>
		</view>
		<view class="desc">
			<view class="u-flex u-row-between">
				<view class="name">使用说明</view>
				<view class="u-flex color-666" @click="useDescShow = !useDescShow" style="align-items: baseline">
					<text class="u-m-r-18">{{ useDescShow ? '收起' : '展开' }}</text>
					<view class="guodu" :class="{ rotate: !useDescShow }">
						<up-icon name="arrow-down" bold></up-icon>
					</view>
				</view>
			</view>
			<template v-if="useDescShow">
				<view class="u-m-t-16 color-666">
					<view>1、可用时间段：{{ canuseTime }}</view>
					<view v-if="item.otherDesc">2、其他使用说明：{{ item.otherDesc }}</view>
				</view>
			</template>
		</view>
		<view class="goods-detail" v-if="item.goodsCategory != '优惠券'">
			<view class="u-flex u-row-center">
				<view class="title">商品详情</view>
			</view>
			<view class="u-m-t-32">
				<image class="w-full" v-for="(item, index) in item.detailImages" :key="index" mode="widthFix" :src="item"></image>
			</view>
		</view>
		<my-footer-btn confirmColor="#E3AD7F" confirmText="立即参加" @confirm="toMiniApp"></my-footer-btn>
	</view>
</template>
<script setup>
import { ref, computed, reactive } from 'vue';
import { onLoad, onShareAppMessage } from '@dcloudio/uni-app';
import { packageDetail } from '@/http/api/ware.js';

const showGroup = ref(true);
const showDesc = ref(true);
const useDescShow = ref(true);

const canuseTime = computed(() => {
	return item.useWeeks.join('、') + ' ' + item.useTimes;
});

function prveImg(index) {
	uni.previewImage({
		urls: coverImgs.value,
		current: index
	});
}

const query = reactive({
	shopId: '',
	id: ''
});

const coverImgs = ref([]);
const item = reactive({
	goodsDescription: []
});

function getDetail() {
	packageDetail(query).then((res) => {
		Object.assign(item, res);
		coverImgs.value = res.images;
	});
}

onLoad((options) => {
	if (options.id) {
		query.id = options.id;
		query.shopId = options.shopId;
		getDetail();
	}
});

const path = '/pageMarket/packagePopularize/share';
const shareOptions = ref({
	title: '',
	path: '',
	imageUrl: ''
});

function shareCallback() {
	shareOptions.value.title = item.packageName;
	shareOptions.value.path = `${path}?shopId=${item.shopId}&id=${item.id}`;
	shareOptions.value.imageUrl = item.images[0];
}

onShareAppMessage(() => {
	console.log('onShareAppMessage', shareOptions.value);
	return shareOptions.value;
});

// 跳转到用户小程序
function toMiniApp() {
	uni.navigateToMiniProgram({
		appId: 'wxd88fffa983758a30',
		path: `/userPackage/goodsDetail/goodsDetail?id=${query.id}&shopId=${query.shopId}`,
		envVersion: 'trial', // 环境版本：release(正式版)、trial(体验版)、develop(开发版)
		success: () => {},
		fail: () => {}
	});
}
</script>

<style lang="scss" scoped>
$topHeight: 350rpx;

.top-img {
	width: 750rpx;
	height: $topHeight;
}

.top {
	margin: 14rpx 18rpx;
	background-size: cover;
	height: $topHeight;
	box-sizing: border-box;
	padding-left: 70rpx;
	padding-top: 95rpx;

	.name {
		color: #000000;
		font-size: 36rpx;
		font-weight: 700;
	}

	.info {
		color: #333333;
		font-size: 48rpx;
		font-weight: 700;
		margin-top: 62rpx;
	}
}

.sku {
	display: flex;
	justify-content: space-between;
	padding: 20rpx 36rpx;
	align-items: center;
	background: linear-gradient(90deg, #ff4a63 0%, #fd1f48 100%);

	.price {
		color: #fff;
		font-weight: 700;
		font-size: 40rpx;
	}

	.old-price {
		margin-left: 16rpx;
		color: #e7e7e7;
		opacity: 0.85;
		font-weight: 700;
		text-decoration: line-through;
	}

	.text {
		color: #fff;
		font-size: 28rpx;
	}
}

.goods {
	padding: 20rpx 28rpx;
	background: #fff;

	.goods-name {
		font-size: 32rpx;
		font-weight: 700;
		color: #333;
	}
}

.desc {
	padding: 32rpx 28rpx;
	background-color: #fff;
}

.goods-detail {
	padding: 32rpx;

	.title {
		position: relative;
		padding: 0 22rpx;

		&::before {
			content: '';
			display: block;
			position: absolute;
			right: 100%;
			width: 70rpx;
			height: 2rpx;
			top: 50%;
			transform: translateY(-50%);
			background: linear-gradient(90deg, #f7f8f9 0%, #c9cbcc 100%);
		}

		&::after {
			left: 100%;
			content: '';
			position: absolute;
			top: 50%;
			transform: translateY(-50%);
			display: block;
			width: 70rpx;
			height: 2rpx;
			background: linear-gradient(90deg, #c9cbcc 0%, #f7f8f9 100%);
		}
	}
}

.fixed-bottom {
	position: fixed;
	left: 98rpx;
	right: 98rpx;
	padding-bottom: 30px;
	padding-top: 32rpx;
	bottom: 0;
	z-index: 10;

	.btn {
		padding: 22rpx;
		border-radius: 200rpx;
		font-size: 32rpx;
		color: #fff;
		width: 556rpx;
		text-align: center;
		background-color: #e8ad7b;
		border: 1px solid transparent;

		&.gray {
			background: #fff;
			color: #e8ad7b;
			border-color: #e8ad7b;
		}
	}
}

.waring {
	background-color: rgba(255, 204, 0, 0.09);
	padding: 32rpx 24rpx;
	color: #ff8d28;
}

.popup-content {
	font-size: 28rpx;
	min-height: 300px;

	.popup-content-top {
		padding: 32rpx 28rpx;
		border-bottom: 1px solid #ededed;
	}

	.goods-info {
		padding: 32rpx 28rpx;
		border-bottom: 1px solid #ededed;

		.cover {
			width: 184rpx;
			height: 184rpx;
			border-radius: 16rpx;
			background: #d9d9d9;

			&.bg-fff {
				background-color: #fff;
			}
		}

		.price {
			font-size: 32rpx;
			font-weight: 700;
			color: #ed5a2e;
			line-height: 46rpx;
		}

		.old-price {
			font-size: 32rpx;
			color: #999;
			text-decoration-line: line-through;
			line-height: 48rpx;
		}

		.limitBuyNum {
			color: #666;
			line-height: 42rpx;
		}
	}

	.bottom {
		padding: 20rpx;
		border-bottom: 1px solid #ededed;

		.price {
			color: #ed5a2e;
			font-size: 32rpx;
			font-weight: 700;
		}
	}

	.btn {
		display: flex;
		padding: 22rpx 214rpx;
		align-items: flex-start;
		gap: 20rpx;
		border-radius: 66rpx;
		background: #e8ad7b;
		font-size: 32rpx;
		color: #fff;
		font-size: 700;
	}
}

.w-full {
	width: 100%;
}

.groups {
	padding: 28rpx 22rpx;
	background-color: #fff;

	.item {
		padding: 28rpx 0;
		border-bottom: 2rpx solid #ededed;

		&:last-child {
			border-bottom: none;
		}

		.main-color {
			color: #ed5a2e;
		}

		.btn {
			padding: 8rpx 26rpx;
			border-radius: 36rpx;
			background: #e8ad7b;
			font-weight: 700;
			color: #fff;
		}
	}
}

.share-box {
	top: 0;
	position: absolute;
	right: 0;
	padding: 4rpx 30rpx;
	border-radius: 0 0 0 24rpx;
	color: #ed5a2e;
	font-weight: 700;
	background: #fff;
	overflow: hidden;

	.share {
		position: absolute;
		left: 0;
		right: 0;
		top: 0;
		bottom: 0;
		opacity: 0;
	}
}

.goods-group {
	padding: 32rpx 46rpx;
	background-color: #fff;

	.name {
		font-weight: 700;
		font-size: 32rpx;
	}

	.rotate {
		transform: rotate(-90deg);
	}
}

.desc {
	padding: 32rpx 46rpx;
	background-color: #fff;
	margin-top: 32rpx;

	.name {
		font-weight: 700;
		font-size: 32rpx;
	}

	.table {
		border: 2rpx solid #ededed;
		border-radius: 8rpx;
		margin: 0 52rpx;

		.header {
			background: #f8f8f88f;
		}

		.row {
			border-top: 2rpx solid #ededed;

			&:first-child {
				border-top: none;
			}
		}
	}

	.rotate {
		transform: rotate(-90deg);
	}
}

.guodu {
	transition: all 0.3s;
}
</style>
