<!--单据列表查询，以表格形式展示通用模板窗口-->
<!--封装了数据获取请求、分页查询、高级搜索等用户交互方式-->
<!--events-->
<!--单元格点击cell-click，详见lj-grid-->
<!--行点击row-click，详见lj-grid-->
<!--高级筛选条件点击query-field-click，详见lj-query-list-->
<!--高级筛选条件值改变query-field-change，详见lj-query-list-->
<!--methods-->
<!--打开右侧抽屉openRightDrawer()-->
<!--关闭右侧抽屉closeRightDrawer()-->
<!--直接设置条件的值setQueryParam(property, value)同lj-query-list-->
<!--slots-->
<!--header：app bar中间，默认为标题-->
<!--header_right：appbar 右侧，通常为图标按钮-->
<!--header_sub： appbar下方子标题，固定在顶部-->
<!--footer：底部，固定-->
<template>
    <lj-win-common :title="title" right-drawer-title="搜索" :rightDrawerInitOpen="rightDrawerInitOpen" @fix-body="autoFixBody"
                   ref="baseWin">
        <slot slot="header" name="header"></slot>
        <mu-button v-if="columnCustomizable" icon slot="header_right"
                   @click="openSettingWin">
            <i class="iconfont icon-settings"></i>
        </mu-button>
        <!-- <mu-button v-if="showFilter" icon slot="header_right" @click="openRightDrawer">
            <i class="iconfont icon-filter"></i>
        </mu-button> -->
        <slot name="header_right" slot="header_right"></slot>
        <div slot="body">
            <slot name="header_sub" :ifShowSearchbar="ifShowSearchbar" :searchtext="keyword" :search="handleSearchbar">
                <!-- <lj-searchbar v-if="ifShowSearchbar" ref="searchbarDom" hint="请输入关键字" v-model="searchText" @search="handleSearchbar" /> -->
                <lj-searchbar-pro
                    ref="searchbarPro"
                    :keyword="keyword"
                    :apiName="apiName"
                    v-on:update:keyword="emitChangeKeyword"
                    :actions="searchActions"
                    :hint="hint"
                    scanicon
                    @search="handleSearchbar"
                    @cancel="handleSearchbarCancel"
                    @focusSearch="handleSearchFocus"
                    @blurSearch="handleSearchBlur"
                    @scan-click="handleSearchScan"
                >
                </lj-searchbar-pro>
            </slot>
            <slot name="header_filtrate" v-if="showFilter">
                <lj-tabs-filtrate
                    ref="ljTabsFiltrate"
                    :apiName="apiName"
                    :query-fields="queryQuick"
                    @click-right-btn="openFilterPopup"
                    @confirm="handleFilterConfirm"
                >
                    <template  v-if="showFilter" slot="right" slot-scope="data">
                        <div class="right-part" @click="data.clickRightBtn" :class="{'filtering': ifBottomFilter}">
                            筛选
                            <i class="iconfont" :class="ifBottomFilter ? 'icon-filter_dark' : 'icon-filter_light'"></i>
                        </div>
                    </template>
                </lj-tabs-filtrate>
            </slot>
            <slot name="body"
                :table-data="list"
                :loading="loading"
                :height="gridHeight"
                :fntouch="handleGridCellTouch"
                :columns="displayColumns"
                :row-click="hanleGridRowClick"
                :cell-click="hanleGridCellClick"
                :pagination="pagination"
                :total="totalRowCount"
                :current="currentPageIndex"
                :change="handlePaginationChange"
                :page-size="currentPageSize"
            >
                <lj-grid ref="ljGrid" :loading="loading" :table-data="list" :columns="displayColumns" :height="gridHeight"
                        @row-click="hanleGridRowClick"
                        @sort-change="handleGridSortChange"
                        @cell-touchstart="handleGridCellTouch"
                        @cell-click="hanleGridCellClick"/>
                <mu-pagination
                        v-if="pagination"
                        :total="totalRowCount"
                        :current.sync="currentPageIndex"
                        raised
                        @change="handlePaginationChange(currentPageIndex)"
                        :page-count="5"
                        :page-size="currentPageSize"
                        style="padding: 5px 0;justify-content:center"
                        ref="pagination"/>
            </slot>
            <mu-dialog :open.sync="moreDialogOpen" width="100%" scrollable>
                <lj-dictionary :columns="popupColumns" :data="currentRowObject"/>
            </mu-dialog>

            <lj-bottom-filtrate
                v-if="showFilter"
                ref="ljBottomFiltrate"
                :query-fields="queryFields"
                :hard-parms="queryHardParms"
                @confirm="handleFilterConfirm"
                @filter="handleFilterBottomFiltering"
            >
                <template v-for="(item,idx) in queryFields">
                    <template :slot="'bottomFilter'+idx">
                        <slot name="widgetDateBottomFilterExtend"></slot>
                    </template>
                </template>
            </lj-bottom-filtrate>

            <slot name="longpress-nav"
                :query-longpress="queryLongpress"
                :handle-filter-confirm="handleFilterConfirm"
                :handle-filter-bottom-filtering="handleFilterBottomFiltering"
            >
                <lj-longpress-nav
                    ref="longpressQuick"
                    :query-fields="queryLongpress"
                    :longpress-list="longpressList"
                    @gotoTitle="handleGotoTitle"
                    @confirm="handleFilterConfirm"
                    @filter="handleFilterBottomFiltering"
                >
                </lj-longpress-nav>
            </slot>
        </div>
        <slot slot="footer" name="footer"></slot>
        <!-- 右方抽屉内容 -->
        <!-- <lj-query-list v-if="showFilter" slot="drawer_right" :query-fields="queryFields" :habit-key="apiName"
                       :hard-parms="queryHardParms"
                       :binding-parms="bindingParms"
                       :show-scan="ifShowScan"
                       @on-query-submit="handleQuerySubmit"
                       @field-click="handleQueryFieldClick"
                       @field-change="handleQueryFieldChange"
                       @scan-click="handleClickScan"
                       ref="queryList"/> -->
                       
    </lj-win-common>
</template>

<script>
    import LjWinCommon from 'components/lj-win-common'
    // import LjQueryList from "components/lj-query-list";
    import LjGrid from "components/lj-grid";
    import {Pagination} from 'muse-ui'
    import LjDictionary from "components/lj-dictionary";
    import LjSearchbar from 'components/lj-searchbar';
    import LjSearchbarPro from 'components/lj-searchbar-pro';
    import LjTabsFiltrate from 'components/filtrate-widget/lj-tabs-filtrate'
    import LjBottomFiltrate from 'components/filtrate-widget/lj-bottom-filtrate'
    import LjLongpressNav from "components/filtrate-widget/lj-longpress-nav";
    // import {DropdownMenu, DropdownItem, Toast, Search} from 'vant'

    export default {
        name: "lj-win-grid-view-filter",
        components: {
            LjDictionary,
            LjGrid,
            // LjQueryList,
            LjWinCommon,
            'mu-pagination': Pagination,
            LjSearchbar,
            LjSearchbarPro,
            LjTabsFiltrate,
            LjBottomFiltrate,
            LjLongpressNav
            // 'van-dropdown-menu': DropdownMenu,
            // 'van-dropdown-item': DropdownItem,
            // 'van-search': Search 
        },
        props: {
            // 标题名称
            title: {
                type: String,
                required: true
            },
            // 同lj-query-list的queryFields，设置后显示筛选按钮，点击弹出高级筛选框
            queryFields: {
                type: Array
            },
            // 同lj-query-list的queryFields，快捷筛选
            queryQuick: {
                type: Array
            },
            // 同lj-longpress-nav的queryFields，长按菜单
            queryLongpress: {
                type: Array
            },
            // 同lj-query-list的hardParms
            queryHardParms: {
                type: Object
            },
            // 同lj-query-list的bindingParms
            bindingParms: {
                type: Object
            },
            // 获取单据列表的接口的接口
            apiName: {
                type: String,
                required: true
            },
            // 字段设置，详见lj-grid
            columns: {
                type: Array
            },
            // 是否分页
            pagination: {
                type: Boolean,
                default: true
            },
            // 分页高度
            paginationHeight: {
                type: Number,
                default: 0
            },
            rightDrawerInitOpen: {
                type: Boolean,
                default: false
            },
            columnCustomizable: {
                type: Boolean,
                default: true
            },
            ifShowSearchbar: {
                type: Boolean,
                default: false
            },
            ifShowScan: {
                type: Boolean,
                default: false
            },
            searchText:{
                type: String,
                default: "" 
            },
            searchHeight:{
                type: Number,
                default: 0 
            },
            extraHeight:{
                type: Number,
                default: 0 
            },
            useInnerMergeCustomSetting:{
                type: Boolean,
                default: true
            },
            searchActions:{
                type: Array,
                default: function() {
                    return []
                }
            },
            // 继承lj-searchbar-pro: 输入框默认提示信息
            hint: {
                type: String,
                default: "请输入关键字搜索"
            },
            // 继承lj-longpress-nav:长按菜单快速入口列表
            longpressList: {
                type: Array
            },
            // 创建时调用
            initHandler: {
                type: Function,
            },
            // 搜索记录，可选，默认用apiName
            habitKey: {
                type: String,
                default: ''
            }
        },
        data() {
            return {
                loadedAll: true,
                loading: false,
                moreDialogOpen: false,
                gridHeight: 400,
                dwname: "L1APP",
                totalPage: 1,
                currentRowObject: {},
                currentPageIndex: 1,
                currentPageSize: 40,
                currentRequestBody: {},
                list: [],
                displayColumns: [],
                popupColumns: [],
                moreColumn: {
                    property: "more_button",
                    label: "更多",
                    width: 100,
                    slot: this.moreSlotRender
                },
                //searchText: ""
                show: true,
                showPopover: false,
                ifBottomFilter: false, // 筛选标签状态
                userFilterName: '', // 用户筛选记录名称
            }
        },
        created() {
            this.userFilterName = this.habitKey || this.apiName;
        },
        mounted() {
            this.getGridHeight(this.searchHeight, this.paginationHeight);

            if(this.useInnerMergeCustomSetting){
                this.MergeCustomSetting();
            }
            // console.log('是否刷新》》》》》》》》》 !this.showFilter :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(!this.showFilter));
            // console.log(' this.queryFields && this.queryFields.length > 0 :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.queryFields && this.queryFields.length > 0));
            // if (!this.showFilter) {
                // this.refresh();
            // }
            this.initSearched();
        },
        methods: {
            handleGotoTitle(mtrlBase) {
                this.$emit('gotoTitle', mtrlBase);
            },
            /**搜索栏：扫码 */
            handleSearchScan(status) {
                this.$emit('scan-click', status);
            },
            handlePaginationChange(index) {
                console.log('handlePaginationChange index :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(index));
                this.currentPageIndex = index;
                this.load();
            },
            handleGridSortChange(ev) {
                this.$emit('row-sort-change', ev);
            },
            hanleGridCellClick(ev) {
                this.$emit('cell-click', ev);
            },
            hanleGridRowClick(ev) {
                this.$emit('row-click', ev);
            },
            autoQuickEnter(colOrNot, inputArr, list) {
                console.log('返回成功！！！ :>>');
                // for (let i = 0; i < list.length; i++) {
                //     let index = list[i].index;
                //     let property = list[i].id;
                //     this.empList[index][property] = list[i].value;
                // }

                this.$refs.longpressQuick.enterDone();
            },
            /**触碰表格 */
            handleGridCellTouch({column, row, index}) {
                // console.log('handleGridCellTouch start :>>', JSON.stringify(column));    
                // console.log('handleGridCellTouch start :>>', JSON.stringify(row));    
                // console.log('handleGridCellTouch start :>>', JSON.stringify(index));    
                // if (!this.ifedit) {
                //     return;
                // }
                // if (!column.editable) {
                //     return;
                // }
                let self = this;
                api.addEventListener({
                    name:'longpress'
                }, function(ret, err){
                    if (self.longpressList) {
                        self.$refs.longpressQuick.open({column, row, index});
                        self.$nextTick(() => {
                            let navList = self.$refs.longpressQuick.navList;
                            self.$emit('opened-longpress', {column, row, index, navList});
                        })
                    }
                    api.notification({
                        vibrate:[50,50],
                    });
                    setTimeout(() => {
                        api.removeEventListener({
                            name: 'longpress'
                        });
                    }, 200);
                });
            },
            updateLongpressData(val) {
                this.$refs.longpressQuick.updatedMtrl(val);
            },
            // /**重置-底部筛选栏 */  
            // handleFilterReset(item) {
            //     this.ifBottomFilter = false;
            //     let keywordObj = this.$refs.searchbarPro.handleCancel(false);
            //     console.log('handleFilterReset +++++++++++++++++++++ keywordObj :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(keywordObj));
            //     let maxObj = Object.assign({}, this.currentRequestBody, keywordObj, item, this.queryHardParms);
            //     console.log(' maxObj :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(maxObj));
            //     console.log('handleFilterConfirm item :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(item));
            //     $lj.setUserFilterParams(this.apiName, maxObj);
            //     this.refresh(maxObj);
            // },
            /**读取搜索记录 */
            initSearched() {
                let keywordObj = $lj.getUserFilterParams(this.userFilterName);
                let keywordObjTitle = $lj.getUserFilterTitle(this.userFilterName);
                this._fnSetSearchedForTabsFiltrate(keywordObj, keywordObjTitle);
                this._fnSetSearchedForSearchbar(keywordObj);
                if (this.initHandler) {
                    keywordObj = this.initHandler(keywordObj, this.$refs.ljGrid.sortArray);
                }
                this.refresh(keywordObj);

                this.$refs.ljBottomFiltrate.initSearched(keywordObj);
            },
            /**设置ljTabsFiltrate的搜索状态 */
            _fnSetSearchedForTabsFiltrate(keywordObj, keywordObjTitle) {
                if (JSON.stringify(keywordObj) == '{}') {
                    // 如果是第一次进来，或没有历史搜索记录，读取默认属性
                    for (let i = 0; i < this.queryFields.length; i++) {
                        if (this.queryFields[i].hasOwnProperty("initValue")) {
                            keywordObj[this.queryFields[i].property] = this.queryFields[i].initValue
                        }
                    }
                    for (let i = 0; i < this.queryQuick.length; i++) {
                        if (this.queryQuick[i].hasOwnProperty("initValue")) {
                            keywordObj[this.queryQuick[i].property] = this.queryQuick[i].initValue
                        }
                    }
                    console.log('initSearched 读取默认值 keywordObj :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(keywordObj));
                }
                this.$refs.ljTabsFiltrate.initSearched(keywordObj, keywordObjTitle);
            },
            /**设置SearchbarPro的搜索状态 */
            _fnSetSearchedForSearchbar(keywordObj) {
                // let keywordObj_arr = [];
                // for (const key in keywordObj) {
                //     keywordObj_arr.push(key);
                // }

                // let searchList = JSON.parse(JSON.stringify(this.searchActions));
                // let keywordList_target = {};
                // for (let i = 0; i < searchList.length; i++) {
                //     if (keywordObj_arr.indexOf(searchList[i].property) > -1 && keywordObj[searchList[i].property]) {
                //         searchList[i].value = keywordObj[searchList[i].property];
                //         keywordList_target = searchList[i];
                //         // break;
                //     }
                // }
                // console.log(' _fnSetSearchedForSearchbar :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(keywordList_target));
                // this.$refs.searchbarPro.initSearch(keywordList_target);

                let keywordObj_arr = [];
                for (const key in keywordObj) {
                    keywordObj_arr.push(key);
                }

                let searchList = JSON.parse(JSON.stringify(this.searchActions));
                let keywordList = [];
                for (let i = 0; i < searchList.length; i++) {
                    if (keywordObj_arr.indexOf(searchList[i].property) > -1 && keywordObj[searchList[i].property]) {
                        searchList[i].value = keywordObj[searchList[i].property];
                        keywordList.push(searchList[i]);
                        // break;
                    }
                }

                console.log(' _fnSetSearchedForSearchbar :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(keywordList));
                this.$refs.searchbarPro.initSearch(keywordList);
                $lj.setUserFilterParams(this.userFilterName, this.currentRequestBody);
            },
            /**回调绑定值 */
            emitChangeKeyword(val) {
                this.$emit('update:searchText', val)
                // this.searchText = val;
                // console.log(' emitChangeKeyword this.searchText :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.searchText));
            },
            /**聚焦搜索条 */
            handleSearchFocus() {
                this.$refs.ljTabsFiltrate && this.$refs.ljTabsFiltrate.close();
            },
            /**失去聚焦搜索条 */
            handleSearchBlur() {
                console.log('handleSearchBlur :>> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!');
                setTimeout(() => {
                    this.$refs.baseWin.initStyle();
                }, 200);
            },
            close() {
                this.show = false;
            },
            onSelect(action) {
                this.$toast(action.text);
            },
            openFilterPopup() {
                console.log('this.$refs.ljBottomFiltrate :>> ', this.$refs.ljBottomFiltrate);
                this.$refs.ljBottomFiltrate.open();
            },
            openRightDrawer() {
                this.$refs.baseWin.openRightDrawer();
            },
            closeRightDrawer() {
                this.$refs.baseWin.closeRightDrawer();
            },
            closeWin() {
                $lj.closeWin();
            },
            /**搜索 */
            handleSearchbar(item, ifscan) {
                console.log(' handleSearchbar searchText:>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.keyword));
                console.log(' item :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(item));
                console.log(' ifscan :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(ifscan));
                this.refresh(item);

                if (ifscan) {
                    this._fnSetSearchedForSearchbar(item);
                } else {
                    this.$refs.ljTabsFiltrate && this.$refs.ljTabsFiltrate.close();
                }
                this.$refs.ljBottomFiltrate.initSearched(item);
                // this.keyword = '';
                this.$refs.searchbarPro.clearText();
                console.log(' handleSearchbar searchText end:>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.keyword));
            },
            /**tabs栏-筛选 */
            handleFilterConfirm(item, titles) {
                console.log('handleFilterConfirm item :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(item));
                console.log('handleFilterConfirm titles :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(titles));
                $lj.setUserFilterParams(this.userFilterName, item);
                titles != undefined && $lj.setUserFilterTitle(this.userFilterName, titles);
                this.refresh(item);
            },
            /**扫描仓位码设置仓库 */
            fnScanStorage(property, title, value) {
                this.$refs.ljTabsFiltrate && this.$refs.ljTabsFiltrate.fnSetValue(property, title, value);
                let obj = {};
                obj[property] = title;
                $lj.setUserFilterTitle(this.userFilterName, obj);
            },
            /**检测是否需要标记：筛选中 */
            _fnCheckIfFilter() {
                console.log(' this.currentRequestBody :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.currentRequestBody));
                let ifFilter = false;
                for (let i = 0; i < this.queryFields.length; i++) {
                    let property = this.queryFields[i].property;
                    if (this.currentRequestBody[property] != this.queryFields[i].initValue) {
                        console.log(' this.queryFields[i] :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.queryFields[i]));
                        ifFilter = true;
                        break;
                    }
                }
                return ifFilter;
            },
            /**底部筛选栏-筛选中 -状态 */
            handleFilterBottomFiltering() {
                this.ifBottomFilter = this._fnCheckIfFilter();

                // let keywordObj = $lj.getUserFilterParams(this.apiName);
                console.log(' this.currentRequestBody :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.currentRequestBody));
                let keywordObj = this.currentRequestBody;
                // console.log(' handleFilterBottomFiltering initSearched keywordObj :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(keywordObj));
                // let keywordObj_arr = [];
                // for (const key in keywordObj) {
                //     keywordObj_arr.push(key);
                // }

                // let searchList = JSON.parse(JSON.stringify(this.searchActions));
                // let keywordList = [];
                // for (let i = 0; i < searchList.length; i++) {
                //     if (keywordObj_arr.indexOf(searchList[i].property) > -1 && keywordObj[searchList[i].property]) {
                //         searchList[i].value = keywordObj[searchList[i].property];
                //         keywordList.push(searchList[i]);
                //         // break;
                //     }
                // }

                // console.log(' keywordList_target :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(keywordList));
                // this.$refs.searchbarPro.initSearch(keywordList);
                console.log(' handleFilterBottomFiltering keywordObj :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(keywordObj));
                this._fnSetSearchedForSearchbar(keywordObj);
                this.$refs.ljBottomFiltrate.autoSetCurrentQuery(keywordObj);
            },
            /**取消搜索 */
            handleSearchbarCancel(item) {
                console.log('handleSearchbarCancel item :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(item));
                $lj.setUserFilterParams(this.userFilterName, item);

                this.$emit('update:searchText', '')
                this.refresh(item);
                this.$refs.ljBottomFiltrate.initSearched(item);
                this.$refs.ljTabsFiltrate && this.$refs.ljTabsFiltrate.close();
            },
            handleClickScan(){
                this.$emit("scan-click");
            },
            handleQuerySubmit(queryParams) {
                // this.closeRightDrawer();
                this.list = [];
                this.refresh(queryParams);
            },
            refresh(queryParams) {
                this.$emit("bfRefresh");
                this.currentPageIndex = 1;
                this.totalPage = 1;
                // this.currentRequestBody = Object.assign(queryParams || this.currentRequestBody || {}, this.queryHardParms);
                // old -> new
                this.currentRequestBody = Object.assign({}, this.currentRequestBody, queryParams, this.queryHardParms);
                this.load();
                this.$emit("refresh");
            },
            load() {
                this.currentRequestBody.token = $lj.getStorage("token");
                if (this.pagination) {
                    this.currentRequestBody.pageindex = this.currentPageIndex;
                    this.currentRequestBody.pagesize = this.currentPageSize;
                }
                this.loading = true;
                let self = this;
                $lj.postLJRequest(this.apiName, this.currentRequestBody, function (ret) {
                    self.loading = false;
                    if (ret) {
                        self.$emit("loadedAllData",ret);
                        for (let key in ret) {
                            if (self.currentPageIndex >= self.totalPage) {
                                let resultLength = ret[key].length;
                                if (resultLength === 0 && self.currentPageIndex > 1) {
                                    self.currentPageIndex--;
                                    self.totalPage = self.currentPageIndex;
                                    $lj.toast("数据已加载完毕");
                                    return;
                                } else if (resultLength < self.currentPageSize) {
                                    self.totalPage = self.currentPageIndex;
                                    $lj.toast("数据已加载完毕");
                                } else {
                                    self.totalPage = self.currentPageIndex + 1;
                                }
                            }
                            self.list = ret[key];
                            self.$emit("loaded", ret[key], self.currentPageSize);
                            return;
                        }
                    }
                })
            },
            MergeCustomSetting: function () {
                let userInfo = $lj.getStorage('userInfo');
                let empid = userInfo.empid;
                let requestBody = {
                    token: $lj.getStorage("token"),
                    empid: empid,
                    dwname: this.dwname,
                    itemname: this.apiName,
                    ifcompress: 1
                };
                let self = this;
                this.displayColumns = [];
                this.popupColumns = [];
                $lj.postLJRequest(
                    "GetSysUserFileString", requestBody,
                    function (ret) {
                        if (ret && ret.itemvalue) {
                            let customSetting = JSON.parse(ret.itemvalue);
                            // 构建field-style键值对
                            let customSettingDictionary = new Map();
                            for (let item of customSetting) {
                                customSettingDictionary.set(item.property, item);
                            }
                            // 合并过滤字段，以这个字典为准，用户历史设置多删少补
                            for (let item of self.columns) {
                                let curField = item.property;
                                let userStyle = customSettingDictionary.get(curField);
                                if (userStyle) {
                                    // for (let prop in userStyle) {
                                    //     item[prop] = userStyle[prop];
                                    // }
                                    item.order = userStyle.order;
                                    item.invisible = userStyle.invisible;
                                    item.width = userStyle.width;
                                    item.sticky = userStyle.sticky;
                                } else {
                                    // 新增字段，暂不显示
                                    item.invisible = true;
                                }
                            }
                        } else {
                            for (let i in self.columns) {
                                self.columns[i].order = i;
                            }
                        }
                        self.columns.sort(function (object1, object2) {
                            return object1.order - object2.order;
                        });
                        for (let i in self.columns) {
                            let item = self.columns[i];
                            item.order = i;
                            if (item.optionid) {
                                let optionName = $lj.getOptionValue(item.optionid);
                                item.label = optionName ? optionName : item.label;
                            }
                            if (item.fixed) {
                                self.displayColumns.push(item);
                            } else if (!item.invisible) {
                                self.popupColumns.push(item);
                            }
                        }
                        if (self.popupColumns.length > 0) {
                            self.displayColumns.push(self.moreColumn);
                        }
                    }
                );
            },
            openSettingWin() {
                let self = this;
                $lj.removeEventListener("grid_style_updated");
                $lj.addEventListener("grid_style_updated", function (ret) {
                    if (ret.value) {
                        if (ret.value.dwname === self.dwname && ret.value.itemname === self.apiName) {
                            self.MergeCustomSetting();
                        }
                    }
                });
                $lj.openWin('grid-drag-setting', {
                    columns: this.columns,
                    apiName: this.apiName
                });
            },
            moreSlotRender(h, {row, column, rowIndex}) {
                let self = this;
                return h('mu-button', {
                        attrs: {icon: true},
                        on: {
                            click: function () {
                                self.currentRowObject = self.list[rowIndex];
                                self.moreDialogOpen = true;
                            }
                        }
                    },
                    [h('i', {class: ["iconfont", "icon-format-list-bulleted"]})]
                )
            },
            handleQueryFieldClick(event) {
                this.$emit("query-field-click", event);
            },
            handleQueryFieldChange(event){
                this.$emit("query-field-change", event);
            },
            setQueryParam(property, value) {
                this.$refs.queryList.setQueryParam(property, value);
            },
            setDisplayColumns(data){
                this.$nextTick(() => this.displayColumns = data);
            },
            getGridHeight(searchH, paginationH) {
                let paginationHeight = 0;
                if (this.$refs.pagination) {
                    if (this.$refs.pagination.$el) {
                        paginationHeight = this.$refs.pagination.$el.offsetHeight;
                    } else {
                        paginationHeight = this.$refs.pagination.offsetHeight;
                    }
                }
                paginationHeight = paginationH > 0 ? paginationH : paginationHeight;
                console.log('!!!!!!!!!!! paginationHeight :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(paginationHeight));
                if (!this.$slots.header_sub) {
                    if(this.ifShowSearchbar) {
                        let serchBarHeight = this.$refs.searchbarPro ? this.$refs.searchbarPro.$el.offsetHeight : searchH;
                        let tabsFiltrateHeight = this.showFilter && this.$refs.ljTabsFiltrate ? this.$refs.ljTabsFiltrate.$el.offsetHeight : searchH;
                        console.log('this.$refs.ljTabsFiltrate.$el.offsetHeight  :>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(this.$refs.ljTabsFiltrate.$el.offsetHeight));
                        this.gridHeight = this.$refs.baseWin.contentStyle.minHeight.replace("px", "") - paginationHeight - serchBarHeight - tabsFiltrateHeight - this.extraHeight;
                    } else {
                        this.gridHeight = this.$refs.baseWin.contentStyle.minHeight.replace("px", "") - paginationHeight - this.extraHeight;
                    }
                }
            },
            autoFixBody(item) {
                this.getGridHeight(this.searchHeight, this.paginationHeight);
            }
        },
        computed: {
            showFilter() {
                return this.queryFields && this.queryFields.length > 0;
            },
            hasLoadmoreFunction() {
                return this.dataLoadedCallback;
            },
            totalRowCount() {
                return this.totalPage * this.currentPageSize;
            },
            keyword: {
                get() {
                    return this.searchText
                },
                set(val) {
                    this.$emit('update:searchText', val)
                }
            },
        },
        watch: {
            searchHeight(newVal) {
                this.getGridHeight(newVal, this.paginationHeight);
            },
            paginationHeight(newVal) {
                console.log(' paginationHeight _____________________________________________:>>>>>>>>>>>>>>>>>>>>>', JSON.stringify(newVal));
                this.getGridHeight(this.searchHeight, newVal);
            }
        }
    }
</script>
