<template>
	<!-- 搜索 -->
	<view class="serachBox">
		<view class="serach-box">
			<view class="searchInput">
				<input placeholder="请输入..." class="city-serach-input" v-model="name" />
				<icon v-if="name" class="iconfont icon-error" @click="handlecolse"></icon>
				<view class="voice" v-if="voice && !name">
					<uni-icons class="mic" type="mic-filled" size="26" @click="onMic"></uni-icons>
					<uni-icons class="camera" type="camera-filled" size="26" @click="onCamera"></uni-icons>
				</view>
			</view>
			<view class="searchBtn">
				<view @click="handleSerach">搜索</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "search",
		props: {
			voice: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				name: ""
			};
		},
		methods: {
			// 搜索
			handleSerach() {
				this.$emit("handleSearch", this.name)
			},
			//取消搜索
			handlecolse() {
				this.name = ""
				this.$emit("handleSearch", "")
			},
			onMic() {
				this.$emit("mic")
			},
			onCamera() {
				this.$emit("camera")
			}
		}
	}
</script>

<style scoped lang="scss">
	.serachBox {
		height: 80rpx;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		padding: 0 30rpx 20rpx;
		z-index: 99;
		background-color: #f7f7f7;

		.serach-box {
			height: 80rpx;
			border-radius: 20rpx;
			position: relative;
			background-color: #fff;
		}

		.searchInput {
			position: absolute;
			left: 0;
			right: 120rpx;
			height: 80rpx;

			icon {
				position: absolute;
				right: 20rpx;
				top: 20rpx;
				display: flex;
				z-index: 99999;
			}

			.voice {
				display: flex;
				justify-content: flex-end;
				align-items: center;
				position: absolute;
				right: 20rpx;
				top: 0;
				bottom: 0;
				width: 150rpx;
				display: flex;
				z-index: 99999;

				.mic {
					margin-right: 10rpx;
				}
			}
		}

		.searchBtn {
			position: absolute;
			width: 120rpx;
			right: 0px;
			height: 80rpx;
			line-height: 80rpx;
			background: $maincolor;
			border-radius: 0 20rpx 20rpx 0;
			text-align: center;
			color: #fff;
		}

		input {
			height: 80rpx;
			padding: 0 5px;
			text-align: center;
			position: absolute;
			left: 0px;
			right: 0px;
			border-radius: 20rpx;

		}

		.icon {
			width: 100rpx;
			height: 80rpx;
			position: absolute;
			right: 30rpx;
			display: flex;
			align-items: center;
			justify-content: center;
		}

	}
</style>