<template>
	<view class="zs-search" :class="[fixed?'fixed':'']">
		<input :readOnly="readOnly" :class="[showPrefix?'input':'fullwidInput']" :style="{lineHeight:height+'rpx',height:height+'rpx',borderRadius:height / 2+'px',color:color,background:bgColor}" :type="type" v-model="value" :placeholder="placeholder" />
		<image v-if="showPrefix" class="icon" src="../../static/search.png" mode=""></image>
		<button v-if="showBtn" class="btn" type="default" @click="search">搜索</button>
	</view>
</template>

<script>
	export default {
		props: {
			type: {
				type: String,
				default: 'text'
			},
			readOnly:{
				type: Boolean,
				default: false
			},
			height: {
				type: String,
				default: '72'
			},
			color: {
				type: String,
				default: '#606266'
			},
			bgColor:{
				type: String,
				default: '#efefef'
			},
			fixed:{
				type: Boolean,
				default: false
			},
			value:{
			},
			placeholder:{
				type: String,
				default: '搜索'
			},
			showBtn:{
				type: Boolean,
				default: true
			},
			showPrefix:{
				type: Boolean,
				default: true
			}
		},
		data() {
			return {
				value1:this.value
			}
		},
		onReady(res) {
		},
		onLoad(){
		},
		
		methods: {
			input(val){
				this.$emit('input',this.value1 )
			},
			search(){
				this.$emit('search',this.value1)
			}
		}
	}
</script>

<style lang="scss">
	.zs-search{
		box-sizing: border-box;
		top: 0%;
		left: 0;
		position: relative;
		margin: 0 30rpx;
		.input{
			box-sizing: border-box;
			padding-left: 100rpx;
			padding-right: 130rpx;
		}
		.fullwidInput{
			// width: 100vw;
			box-sizing: border-box;
			font-size: 22rpx;
			padding-left: 20rpx;
			padding-right: 130rpx;
		}
		.icon {
			width: 37rpx;
			height: 37rpx;
			position: absolute;
			top: 50%;
			left: 36rpx;
			transform: translateY(-50%);
		}
		
		.btn {
			position: absolute;
			top: 50%;
			transform: translateY(-50%);
			right: 10rpx;
			width: 128rpx;
			height: 56rpx;
			line-height: 56rpx;
			background: #FF4C3A;
			color: #fff;
			font-size: 28rpx;
			border-radius: 32rpx;
			padding: 0;
		}

	}
	.fixed{
		position: fixed !important;
	}
</style>