<template>
	<view>
		<!-- 顶部 -->
		<view class="uni-head">
			<view class="uni-head-title">
				input输入框
			</view>
		</view>
		<view class="container">
			<view class="uni-form-item uni-column">
				<view class="title">可自动聚焦的input</view>
				<input class="uni-input" focus placeholder="自动获得焦点" />
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">键盘右下角按钮显示为搜索</view>
				<input class="uni-input" confirm-type='search' placeholder="自动获得焦点" />
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">控制最大输入长度的input</view>
				<input class="uni-input" maxlength="10" placeholder="最大输入长度为10" />
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">实时获取输入值：{{inputValue}}</view>
				<input class="uni-input" @input="onKeyInput" placeholder="实时获取" />
			</view>
			<view class="uni-form-item uni-column">
				<view class="title">密码输入的input</view>
				<input class="uni-input" password type="text" placeholder="这是一个密码输入框" />
			</view>
			<view class="uni-form-item uni-column">
				<view class="title"><text class="uni-form-item__title">带清除按钮的输入框</text></view>
				<view class="uni-input-wrapper">
					<input class="uni-input" placeholder="带清除按钮的输入框" :value="inputClearValue" @input="clearInput" />
					<text class="uni-icon" v-if="showClearIcon" @click="clearIcon">&#xe434;</text>
				</view>
			</view>

		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
				inputValue: '',
				showClearIcon: false,
				inputClearValue: '',
			}
		},
		methods: {
			onKeyInput: function(event) {
				this.inputValue = event.detail.value;
			},
			clearInput: function(event) {
				this.inputClearValue = event.detail.value;
				// if (event.detail.value.length > 0) {
				//     this.showClearIcon = true;
				// } else {
				//     this.showClearIcon = false;
				// }
			},
			clearIcon: function() {
				this.inputClearValue = '';
				this.showClearIcon = false;
			},
		}
	}
</script>

<style>
	@import url('../../lib/smart.css');

	.uni-icon {
		position: absolute;
		right: 20rpx;
		top: 50%;
		transform: translateY(-50%);
		font-size: 32rpx;
		color: #999;
		/* 引入 uni-app 内置图标字体（确保图标显示） */
		font-family: uniicons;
		cursor: pointer;
	}

	.uni-icon:active {
		color: #666;
		/* 点击时加深颜色，提升交互感 */
	}
</style>