<!-- 订单确认的使用积分弹窗 -->
<template>
	<su-popup :show="show" type="bottom" round="10" @close="emits('close')" showClose backgroundColor="#ffffff">
		<view class="title ss-m-t-16 ss-m-l-20 ss-flex">使用积分</view>
		<view class="model-box ss-p-x-30">

			<input v-model="state.points" class="uni-input input-points ss-m-b-10" type="number"
				placeholder="请输入抵扣积分" />
			<view class="subtitle">当前可用积分 {{state.pointsInfo}}</view>
		</view>
		<view class="modal-footer ss-flex">
			<button class="confirm-btn ss-reset-button" @tap="emits('close')">取消</button>
			<button class="confirm-btn ss-reset-button" @tap="onConfirm">确认</button>
		</view>
	</su-popup>
</template>
<script setup>
	import {
		computed,
		reactive,
		ref,
		watch,
		nextTick
	} from 'vue';

	const props = defineProps({
		modelValue: { // 优惠劵列表
			type: Object,
			default () {},
		},
		show: {
			type: Boolean,
			default: false,
		},
	});
	const emits = defineEmits(['confirm', 'close']);
	const state = reactive({
		pointsInfo: 1000, //computed(() => props.modelValue), 
		points: undefined,
	});


	watch(() => state.points, (newValue) => {
		if (newValue > state.pointsInfo) {
			state.points = state.pointsInfo; // 强制更新为最大值
			// 使用 nextTick 确保 DOM 更新
			nextTick(() => {
				state.points = state.pointsInfo;
			});
		}
	});
	// 确认
	const onConfirm = () => {
		if (!state.points) {
			return false
		}
		emits('confirm', state.points);
	}
</script>
<style lang="scss" scoped>
	:deep() {
		.uni-checkbox-input {
			background-color: var(--ui-BG-Main);
		}

		.uni-input-wrapper {
			width: 100% !important
		}
	}

	.model-box {
		height: 10vh;
		text-align: center;
		font-size: 30rpx;

		.input-points {
			text-align: left;
			text-indent: 20rpx;
			height: 80rpx;
			border: 1px solid #bbbbbb;
			border-radius: 10rpx;
		}
	}

	.title {
		font-size: 36rpx;
		height: 80rpx;
		font-weight: bold;
		color: #333333;
	}

	.subtitle {
		// font-size: 26rpx;
		font-weight: 500;
		color: #333333;
	}

	.model-content {
		height: 15vh;
	}

	.modal-footer {
		width: 100%;
		height: 120rpx;
		//   background: #fff;
	}

	.confirm-btn {
		width: 710rpx;
		margin-left: 20rpx;
		height: 80rpx;
		background: linear-gradient(90deg, var(--ui-BG-Main), var(--ui-BG-Main-gradient));
		border-radius: 40rpx;
		color: #fff;
	}

	.reason-title {
		font-weight: 600;
		font-size: 20rpx;
		line-height: 26rpx;
		color: #ff0003;
	}

	.reason-desc {
		font-weight: 600;
		font-size: 20rpx;
		line-height: 26rpx;
		color: #434343;
	}
</style>