<template>
    <div class="header-nav-bar-search-panel">
        <header-nav-bar
            :title="title"
            :is-left-arrow="isLeftArrow"
            :is-back="isBack"
            :is-custom-back="isCustomBack"
            @back="onBack" />
        <div class="search-panel" slot="content">
            <slot name="content">
                <van-search
                    v-model="currentValue"
                    background="#fff"
                    :placeholder="searchPlaceholder"
                    show-action
                    :autofocus="autofocus"
                    @search="onSearch"
                    @input="onInput"
                    @click="onClick">
                    <van-button
                        slot="action"
                        type="default"
                        plain size="small"
                        @click="onSearch">搜索</van-button>
                </van-search>
            </slot>
        </div>
    </div>
</template>

<script>
    import HeaderNavBar from '../../HeaderNavBar/src/index'
    export default {
        name: "BgoHeaderNavBarSearch",
        props: {
            value: String,
            title: String,
            searchPlaceholder: {
                type: String,
                default: '请输入'
            },
            isLeftArrow: {
                type: Boolean,
                default: true
            },
            isBack: {
                type: Boolean,
                default: true
            },
            isCustomBack: {
                type: Boolean,
                default: false
            },
            autofocus: {
                type: Boolean,
                default: false
            }
        },
        components: { HeaderNavBar },
        data: function() {
            return {
                currentValue: this.value
            }
        },
        watch: {
            currentValue(val) {
                this.$emit('input', val);
            },
            value(val) {
                this.currentValue = val;
            }
        },
        methods: {
            onSearch: function () {
                this.$emit('search', this.currentValue);
            },
            onBack: function () {
                this.$emit('back');
            },
            onClick: function () {
                this.$emit('click');
            },
            onInput: function (value) {
                this.$emit('input', value);
            }
        }
    }
</script>

<style>
    .search-panel .van-button--small {
        height: 34px;
        font-size: 0.8rem;
    }
</style>
