<template>
	<view>
		<view class="upper-search">
			<uni-easyinput suffixIcon="search" v-model="searchVal" placeholder="请输入" @iconClick="clickSearch"></uni-easyinput>
		</view>
		<h5 style="width: 90%; margin: 20rpx auto; display: flex; justify-content: space-between;">
			<span>历史记录</span>
			<uni-icons type="trash" @click="cleanHistory" size="20"></uni-icons>
		</h5>
		<view class="history-area">
			<view 
				class="single-history"
				v-for="(history, index) in historyList"
				:key="index"
				@click="refillIpt(history.name)"
			>
				{{ history.name }}
			</view>
		</view>
		<button @click="jumpDetail">ss</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				searchVal: '',
				historyList: []
			}
		},
		methods: {
			clickSearch () {
				this.historyList.unshift({
					name: this.searchVal
				})
			},
			refillIpt (val) {
				this.searchVal = val
			},
			cleanHistory () {
				this.historyList = []
			},
			jumpDetail () {
				uni.navigateTo({
					url: '/pages/deviceDetail/deviceDetail'
				})
			}
		},
		watch: {
			searchVal: {
				handler (newVal, oldVal) {
					// console.log(newVal, oldVal);
				}
			}
		}
	}
</script>

<style lang="scss">
	.upper-search{
		width: 90%;
		margin: 20rpx auto;
	}
	.history-area{
		width: 90%;
		margin: 20rpx auto;
		display: flex;
		flex-wrap: nowrap;
		overflow-x: auto;
		.single-history{
			box-sizing: border-box;
			padding: 10rpx;
			white-space: nowrap;
			background-color: #EBEBEB;
			border-radius: 15rpx;
			margin-right: 20rpx;
			font-size: 12px;
			margin-bottom: 10rpx;
		}
	}
</style>
