<template>
	<view class="">
		<up-overlay :show="overlayshow" @click="overlayshow = false">
			<view class="boxoverlay">
				<view class="rect" @tap.stop>
					<!-- 抖音 -->
					<view class="bottomconstant">
						<view class="itemlist">
							<!-- <view class="ordernumber">
								订单号：111
							</view> -->
							<view class="title">
								请选择商品
							</view>
							<view class="itemlists" v-for="(item,index) in form.goods" :key="index">
								<view class="top">
									<view class="tag">
										{{item.title}}
									</view>
									<view class="date">
										¥{{item.amount}}
									</view>
								</view>
								<!-- <view class="bottom">
									核销
								</view> -->
								<view v-if="item.type" @click="item.type =!item.type">
									<up-icon name="checkmark-circle" color="#2979ff" size="22"></up-icon>
								</view>
								<view class="icon" v-else @click="item.type =!item.type"></view>
							</view>
							<view class="bouttonbox">
								<view class="keep" @click="confirms">
									确定核销
								</view>
								<view class="cancel" @click="overlayshow = false">
									取消
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</up-overlay>
	</view>
</template>

<script setup>
	import {
		onLoad,
		onShow,
		onReachBottom
	} from '@dcloudio/uni-app';
	import {
		computed,
		reactive,
		ref,
		watch,
		defineExpose
	} from 'vue';
	const form = reactive({
		id: "",
		number: '',
		sum_pay_amount: '',
		goods: [],
		verify_token: '',
	});
	import {
		certificateprepares
	} from '@/http/php/api.ts';

	//显示
	const overlayshow = ref(false);
	const open = (val) => {
		Object.assign(form, val)
		form.goods.map((item) => {
			item.type = true
		})
		overlayshow.value = true
	}
	let confirms = async () => {
		// 判断是否选择商品
		if (form.goods.filter(i => i.type).length == 0) {
			uni.showToast({
				title: '请选择商品',
				icon: 'none'
			})
			return false
		}
		let data = null
		if (uni.getStorageSync('clint_type') == 1) {
			data = {
				couponCode: form.couponCode,
				num: form.goods.length
			}
		} else {
			let encrypted_codes = form.goods.filter(i => i.type).map((obj, index) => {
				return obj.encrypted_code;
			})
			data = {
				verify_token: form.verify_token,
				encrypted_codes: encrypted_codes.toString(),
				id: form.id
			}
		}
		await certificateprepares(data)
		uni.showToast({
			title: '验证成功',
			icon: 'none'
		})
		overlayshow.value = false
	}
	defineExpose({
		open
	})
</script>

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

	.boxoverlay {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;

		.rect {
			padding: 32rpx 28rpx;
			width: 80%;
			background-color: #fff;
			border-radius: 18rpx;

			.bottomconstant {
				padding: 0 28rpx;
				width: 100%;
				border-radius: 18rpx 18rpx 18rpx 18rpx;

				.itemlist:nth-child(1) {
					margin-top: 0;
				}

				.itemlist {
					// margin-top: 16rpx;
					width: 100%;
					background: #FFFFFF;
					border-radius: 18rpx 18rpx 18rpx 18rpx;

					.ordernumber {
						font-family: Source Han Sans CN, Source Han Sans CN;
						font-weight: 400;
						font-size: 24rpx;
						color: #999999;
					}

					.title {
						margin-top: 16rpx;
						padding-bottom: 16rpx;
						font-family: Source Han Sans CN, Source Han Sans CN;
						font-weight: bold;
						font-size: 28rpx;
						color: #333333;
						border-bottom: 1rpx solid #E5E5E5;
					}

					.itemlists {
						padding-top: 16rpx;
						display: flex;
						justify-content: space-between;
						align-items: center;

						.top {
							display: flex;
							flex-direction: column;
							justify-content: center;
							align-items: flex-start;

							.date {
								margin-top: 10rpx;
								font-family: Source Han Sans CN, Source Han Sans CN;
								font-weight: 400;
								font-size: 24rpx;
								color: #999999;
							}

							.tag {
								width: 350rpx;
								overflow: hidden; //超出的文本隐藏
								text-overflow: ellipsis; //溢出用省略号显示
								white-space: nowrap; //溢出不换行
								font-family: Source Han Sans CN, Source Han Sans CN;
								font-weight: 500;
								font-size: 28rpx;
								color: #333333;
							}
						}

						.icon {
							width: 40rpx;
							height: 40rpx;
							border: 1px solid #909399;
							border-radius: 50%;
						}

						.bottom {
							background: #EAF4FD;
							border-radius: 4rpx 4rpx 4rpx 4rpx;
							padding: 6rpx 12rpx;
							font-family: Source Han Sans CN, Source Han Sans CN;
							font-weight: 400;
							font-size: 20rpx;
							color: #318AFE;
						}
					}

					.bouttonbox {
						margin-top: 80rpx;
						display: flex;
						flex-direction: column;
						justify-content: center;
						align-items: center;

						.keep {
							width: 490rpx;
							height: 80rpx;
							background: #318AFE;
							border-radius: 40rpx 40rpx 40rpx 40rpx;
							font-family: Source Han Sans CN, Source Han Sans CN;
							font-weight: 500;
							font-size: 32rpx;
							color: #FFFFFF;
							text-align: center;
							line-height: 80rpx;
						}

						.cancel {
							text-align: center;
							width: 490rpx;
							height: 80rpx;
							background: #ffffff;
							border-radius: 40rpx 40rpx 40rpx 40rpx;
							font-family: Source Han Sans CN, Source Han Sans CN;
							font-weight: 400;
							font-size: 24rpx;
							color: #999999;
							line-height: 80rpx;
						}
					}
				}
			}
		}
	}
</style>