<template>
    <div class="bingo-list">
        <!-- 搜索 -->
        <div class="my-search" :style="{right:rightWidth}" :class="{ fullScreen: fullFlag }">
            <bingo-search
                v-if="isSearch"
                v-bind="$attrs"
                v-on="$listeners"
                @get-data-list="getDataList"
                ref="bingoSearch"
            >
                <template slot="searchType">
                    <slot name="searchType"></slot>
                </template>
            </bingo-search>
            <bingo-search-advance
                v-if="isSearchAdvance"
                v-bind="$attrs"
                v-on="$listeners"
                ref="searchAdvance"
            >
                <template slot="queryForm">
                    <slot name="queryForm"></slot>
                </template>
            </bingo-search-advance>
        </div>
        <!-- toolbarNew组件 -->
        <bingo-toolbar-new
            v-bind="$attrs"
            v-on="$listeners"
            v-if="isToolbarNew"
            ref="toolbarNew"
            @on-refresh="onRefresh"
            @on-full-screen="openFullModal"
            @on-switch="onSwitch"
        >
            <template slot="toolbarNew">
                <slot name="toolbarNew"></slot>
            </template>
            <template slot="toolbarNew-r">
                <slot name="toolbarNew-r"></slot>
            </template>
        </bingo-toolbar-new>
        <bingo-table
            v-bind="$attrs"
            v-on="$listeners"
            v-if="isTable=='normal'"
            :columns="columns"
            :searchObj="searchObj"
            :topHeight="topHeight"
            :fullScreen="fullFlag"
            :isCustomData="isCustomData"
            @onRefresh="onRefresh"
            ref="table"
        >
            <template slot="toolbar">
                <slot name="toolbar"></slot>
            </template>
            <!-- table列自定义 -->
            <template slot-scope="{ row, index }" v-for="col in columns" :slot="col.slot">
                <slot :name="col.slot" :row="row" :index="index"></slot>
            </template>
            <!-- 操作按钮 -->
            <template slot="action" slot-scope="{ row, index }">
                <slot name="action" :row="row" :index="index"></slot>
            </template>
            <!-- 表格上的批量操作 -->
            <template slot="tableFun">
                <slot name="tableFun"></slot>
            </template>
            <!-- 定义右键弹出菜单 -->
            <template slot="contextMenu">
                <slot name="contextMenu"></slot>
            </template>
        </bingo-table>
        <bingo-advance-table
            v-bind="$attrs"
            v-on="$listeners"
            v-if="isTable=='high'"
            :columns="columns"
            :searchObj="searchObj"
            :topHeight="topHeight"
            :fullScreen="fullFlag"
            :isCustomData="isCustomData"
            @onRefresh="onRefresh"
            ref="advanceTable"
        >
            <template slot="toolbar">
                <slot name="toolbar"></slot>
            </template>
            <!-- 表格上的批量操作 -->
            <template slot="tableFun">
                <slot name="tableFun"></slot>
            </template>
        </bingo-advance-table>
    </div>
</template>
<script>
    import bingoSearch from '@/components/bingo-search'
    import bingoSearchAdvance from '@/components/bingo-search-advance'
    import bingoToolbarNew from '@/components/bingo-toolbar-new'
    import bingoTable from '@/components/bingo-table'
    import bingoAdvanceTable from '@/components/bingo-advance-table'
    export default {
        props: {
            // 是否存在搜索
            isSearch: {
                type: Boolean,
                default: true
            },
            // 是否存在弹出层搜索
            isSearchAdvance: {
                type: Boolean,
                default: true
            },
            // 是否存在工具栏
            isToolbarNew: {
                type: Boolean,
                default: true
            },
            // high高级normal正常none不存在
            isTable: {
                type: String,
                default: 'normal'
            },
            // 表格列
            columns: {
                type: Array,
                required: true
            },
            // 是否自定义data
            isCustomData: {
                type: Boolean,
                default: false
            }
        },
        inheritAttrs: false,
        data () {
            return {
                searchObj: {},
                rightWidth: '',
                fullFlag: false,
                topHeight: 0
            }
        },
        components: {
            bingoSearch,
            bingoSearchAdvance,
            bingoToolbarNew,
            bingoTable,
            bingoAdvanceTable
        },
        created () {
            if (this.isToolbarNew) {
                this.topHeight = 42;
            }
        },
        mounted () {
            if (this.isToolbarNew) {
                setTimeout(() => {
                    this.rightWidth = this.$refs.toolbarNew.$refs.icolr.offsetWidth + 10 + 'px';
                }, 400);
            }
            if (this.isSearch) {
                this.searchObj = this.$refs.bingoSearch.getQueryParams();
            }
        },
        methods: {
            getDataList (obj) {
                if (this.isCustomData) {
                    this.$emit('get-data', obj)
                } else {
                    this.getTableData(obj);
                }
            },
            // 获取数据
            getTableData (obj) {
                if (this.isTable === 'high') {
                    this.$refs.advanceTable.getTableData(obj);
                } else {
                    this.$refs.table.getTableData(obj);
                }
            },
            handleMatch () {
                this.$refs.table.handleMatch();
            },
            // 刷新
            onRefresh () {
                if (this.$refs.bingoSearch.isSelectedSpecialFlag == 0) {
                    let obj = this.$refs.bingoSearch.getQueryParams();
                    if (this.isCustomData) {
                        this.$emit('get-data', obj)
                    } else {
                        this.getTableData(obj);
                    }
                } else if (this.$refs.bingoSearch.isSelectedSpecialFlag == 1) {
                    this.$emit('get-special-type');
                } else if (this.$refs.bingoSearch.isSelectedSpecialFlag == 2) {
                    this.$emit('on-query-submit');
                }
                this.$emit('on-refresh');
            },
            // 切换
            onSwitch () {
                this.$emit('on-switch');
            },
            // 全屏
            openFullModal (fullFlag) {
                this.fullFlag = fullFlag;
                if (this.isTable === 'high') {
                    this.$refs.advanceTable.openFullModal(fullFlag);
                } else {
                    this.$refs.table.openFullModal(fullFlag);
                }
                // this.$emit('open-full-modal', this.fullFlag);
            }
        }
    }
</script>
