<template>
	<!-- 弹窗组件 -->
	<view class="popUpMask" @touchmove.stop.prevent @click="details.close" v-if="showPopUp">
		<view class="container" @click.stop :style="{height:details.height}">
			<scroll-view class="scoolv" scroll-y="true">
				<view class="title">
					{{details.title}}
				</view>
				<!-- 插槽 -->
				<slot></slot>
			</scroll-view>

			<view class="buttonContainer" v-if="details.isShowButton !== false">
				<view class="closeButton" v-if="details.isShowClose !== false" @click="details.close">
					取消
				</view>
				<view class="confirmButton" @click="details.success">
					{{confirmText||'确认'}}
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		reactive,
		toRefs,
		defineExpose
	} from 'vue';
	const details = reactive({
		/**
		 * 确认键内容
		 */
		confirmText: '',
		/**
		 * 是否显示弹框
		 */
		showPopUp: false,
		isShowClose: true,
		isShowButton: true,
		/**
		 * 内容高度
		 */
		height: 'auto',
		/**
		 * 标题
		 */
		title: '',
		/**
		 * 取消按钮事件
		 */
		close() {
			details.showPopUp = false
		},
		/**
		 * 确认按钮事件
		 */
		success() {
			details.showPopUp = false
		}
	})

	const setDetails = (detail) => {
		for (let key in detail) {
			details[key] = detail[key]
		}
	}

	defineExpose({
		setDetails,
		details
	})

	const {
		confirmText,
		showPopUp
	} = toRefs(details)
</script>

<style lang="scss" scoped>
	// $subjectColor: #D3832A;

	// 弹出层
	.popUpMask {
		position: fixed;
		top: 0;
		left: 0;
		width: 100vw;
		height: 100vh;
		// background-color: #00000050;
		background-color: rgba(0, 0, 0, 0.5);
		z-index: 9999;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.container {
		width: 90%;
		// height: 60%;
		border-radius: 10upx;
		background: #fff;

		.title {
			text-align: center;
			margin-bottom: 10upx;
		}

		.scoolv {
			max-height: 70vh;
			padding: 20upx;
			// padding-bottom: 0upx;
			box-sizing: border-box;
		}

		.buttonContainer {
			width: 100%;
			padding: 20upx 0 60upx;
			flex: 1;
			display: flex;
			justify-content: space-around;
			align-items: center;
			zoom: 0.9;

			>view {
				padding: 25upx 100upx;
				border-radius: 10upx;
				background: var(--subjectColor);
				color: #fff;
			}

			.closeButton {
				color: #000;
				background: #F5F5F6;
			}
		}

	}
</style>