<template>
    <van-popup v-model="showPicker" position="bottom"
               :safe-area-inset-bottom="true"
               :close-on-popstate="true">
        <div style="height: 70vh;overflow: hidden;background: #f7f8fa">
            <search-bar ref="searchBar" label="生产者名称" :fixed="false"
                        @search="_search"></search-bar>
            <div style="height:calc(100% - 55px);overflow:auto">
                <div class="result-item" v-for="item in resultList" :key="item.id"
                     @click="_tapResult(item)">
                    <div> {{item.proName}}</div>
                </div>
            </div>
        </div>
    </van-popup>
</template>

<script>
    import {samplingSummary} from '../../../api'

    export default {
        data() {
            return {
                key: '',
                resultList: [],
                showPicker: false
            }
        },
        methods: {
            _open() {
                this.showPicker = true
                this.key = ''
                this.$nextTick(function () {
                    this.$refs.searchBar.searchValue = ''
                })
                this._getData()
            },
            //简单查询 清空高级查询条件 赋值简单查询数据
            _search(value) {
                this.key = value
                this._getData()
            },
            _searchParams() {
                let obj = {}
                if (this.key) {
                    obj.name = this.key
                }
                return obj
            },
            _getData: async function () {
                let result = await samplingSummary.getProducter(this._searchParams())
                this.resultList = result
            },
            _tapResult(item) {
                this.$emit('on-result-change', item)
                this.showPicker = false
            },
        }
    }
</script>

<style scoped>

</style>
