<template>
    <div class="bingo-search-advance">
        <Tooltip content="弹出层查询">
            <Button class="more-btn" @click="open"><i class="icon iconfont icongengduo"></i></Button>
        </Tooltip>
        <Form :model="queryData" ref="form">
            <bingo-modal-form ref="modal" :col="col" :title="$t('page.common.search')" :width="queryWidth" :button="false"
                :labelWidth="labelWidth" :showDefault="false">
                <slot name="queryForm"></slot>
                <div slot="footer-button">
                    <Button type="primary" html-type="submit" @click="handleSubmit">{{$t('page.common.search')}}</Button>
                    <Button class="ivu-ml-8" @click="handleReset">{{$t('page.common.reset')}}</Button>
                </div>
            </bingo-modal-form>
        </Form>
    </div>
</template>
<script>
export default {
    props: {
        col: {
            type: Number,
            default: 2
        },
        queryWidth: {
            type: Number,
            default: 900
        },
        labelWidth: {
            type: Number,
            default: 90
        },
        queryData: {
            type: Object
        }
    },
    methods:{
        getBrotherSearch(){
            for(let i=0;i<this.$parent.$children.length;i++){
                if(this.$parent.$children[i].$options.name=='bingo-search'){                   
                    return this.$parent.$children[i];
                }
            }
        }, 
        getParams(){
            return this.$refs.form.model;
        },
        open(){
            this.$refs.modal.show = true;
        },
        handleSubmit(){
            this.$emit('on-query-submit', this.getParams());
            this.$refs.modal.show = false;
            if(this.getBrotherSearch()){
                this.getBrotherSearch().isSelectedSpecialFlag=2;
            }
        },
        handleReset(){
            let modelData = this.$refs.form.model;
            for(let i in modelData){
                if(Array.isArray(modelData[i])){
                    modelData[i] = [];
                }else{
                    modelData[i] = '';
                }
            }
            this.$emit('on-query-reset');
        }
    }
}
</script>