<script>
import { deepCopy } from '../../utils/assist';
import size from '@/components/base/size';
import { resolveComponent } from 'vue';
export default {
    mixins: [size],
    data () {
        return {
            globalConfig:{
                cellbeginedit:'',
                showHeader: true,
                showIndex: true,
                showStripe:false, 
                showBorder: true,
                showCheckBox: false,
                showCondition:false,
                checkByHighlight:true,
                readOnly: false,
                showPage: true,
                tableSize:'default',
                pageSize:null,
                pageShowElevator:true,
                pageShowTotal:true,
                pageShowSizer:true,
                height: null,
                manualLoad: true,
                multiSelect: false,
                operFixedFlag:true,
                gridType:'viewGrid',
                dynamicHeight:false,
                generalOrientation:false,
                showSummary:false,
                showSumGroup:false,
                sumText:'合计',
                pageSizeNum:'',
                adjustHeight:0,
                items:[],
                pageConfig: {
                    page_no: 1,
                    page_size: 100,
                    total_results: 0,
                    pageSizeList: [20, 50, 100, 200, 500, 1000]
                },
                moduleMethod:[],
                headClassName:''
            },
            tempData:[],
            data:[],
            addData:[],
            delData:[],
            columns:[],
            checkInfo:[],
            checkAddInfo:[],
            expand:{},
            dictkey:'',
            currentDictData:{},
            editRowIndex:'',
            editRowFlag:true,
            loading:false,
            conditionSearchParam:{},
            showRowAction:false,
            modulecode:'',
            myToolConfig:{},
            showMoreBtn:false ,
            initData:[],
            showDelRow:false,
            showCondition:true,
            delRowAction:[{
                iconcls: 'row',
                name: 'delRow',
                text: '删除',
                type:'text'
            }],
            operFixedFlag:true,
            editIndex: -1,
            editKey:'',
            newRow:{},
            summaryColumn:[],
            total_summary:{},
            extraHeight:0,
            outsideHeight:0,
            tableColumns:[],
            soltTableColumns:[],
            sumGroupNum:0,
            culPage:1
        };
    },
    props: {
        config: {
            type: Object,
            default: () => {
                return {};          
            }
        },
        dictData: {
            type: Object,
            default:null
        },
        toolConfig: {
            type: Object,
            default: () => {
                return {};          
            }
        },
        isPop:{
            type: Boolean,
            default: false
        }
    },
    created () {
        this.init();
        this.modulecode = this.$Method.getUrlParam('modulecode');
        if (!this.modulecode) {
            this.modulecode = this.$Method.getUrlParam('billmoduleid');
        }
    },
    computed:{
        makeTableColumns() {
            return this.initColumn();
        },
        tableHeight() {
            if (!this.myConfig.dynamicHeight) {
                let currentHeight = this.currentHeight;
                if (this.extraHeight) {
                    currentHeight =  currentHeight - Number(this.extraHeight);
                }
                if (this.outsideHeight) {
                    currentHeight =  currentHeight - Number(this.outsideHeight);
                }
                if (this.myConfig.showSummary) {
                    currentHeight = currentHeight  - 50; 
                }
                return currentHeight;
            } else {
                return null;
            }
        },
        tableMaxHeight() {
            if (this.myConfig.dynamicHeight) {
                let currentHeight = this.currentHeight - this.extraHeight - this.outsideHeight;
                if (this.myConfig.showSummary) {
                    currentHeight = currentHeight  - 50; 
                }
                return currentHeight;
            } else {
                return null;
            }
        }
        
    },
    methods: {
        init() {
            this.myConfig = Object.assign({},this.globalConfig,this.myConfig);

            if (this.config) {
                let config = this.$Method.copy(this.config);
                for (let temp in config) {
                    if (temp === 'pageConfig') {
                        for (let temp2 in config[temp]) {
                            this.myConfig.pageConfig[temp2] = config[temp][temp2];
                        }
                    } else {
                        this.myConfig[temp] = config[temp];
                    }
                }
            }
            if (this.dictData) {
                this.currentDictData = this.dictData;
            } else {
                this.currentDictData = [];
            }
            if (this.myConfig.showDelRow !== undefined) {
                this.showDelRow = this.myConfig.showDelRow;
            }

            if (this.myConfig.showCondition !== undefined) {
                this.showCondition = this.myConfig.showCondition;
            }
            this.myToolConfig = this.$Method.copy(this.toolConfig);

           // 非弹框模式
            if (!this.isPop) {
                // 判断是否显示更多 按钮
                let num = 0;
                if (this.myToolConfig.items) {
                    this.myToolConfig.items.forEach(el => {
                        if (el.iconcls === 'row') {
                            num++;
                        }
                    });
                }
                if (num > 2) {
                    this.showMoreBtn = true;
                } else {
                    this.showMoreBtn = false;
                }
                // 是否开启行编辑栏
                if (num > 0) {
                    this.showRowAction = true;
                } else {
                    this.showRowAction = false;
                }
                // 开启行编辑栏时checkbox显示
                if (this.showRowAction) {
                    if (!this.myConfig.showCheckBox) {
                        if (this.myConfig.multiSelect) {
                            this.myConfig.showCheckBox = true;
                        }
                    }
                }
            }
            
            this.operFixedFlag = this.myConfig.operFixedFlag;
            if (this.myConfig.items && this.myConfig.items.length > 0) {
                this.myConfig.items.some(el => {
                    if (el.resizable === true) {
                        this.myConfig.showBorder = true;
                        return true;
                    }
                });
            }
            this.setSizeConfig(this.myConfig);
            if (this.customInit) {
                this.customInit();
            }
        },
        initCheckColumn(columns) {
            if (this.myConfig.showCheckBox) {
                let check = {};
                check.type = 'selection';
                check.align = 'center';
                check.key ='selection';
                check.width = 40;
                check.multiSelect = this.myConfig.multiSelect;
                columns.push(check);
            }
        },
        isToolBar(obj) {
            let flag = false;
            if (this.myToolConfig && this.myToolConfig.items) {
                this.myToolConfig.items.some(el => {
                    if (el.iconcls === obj) {
                        flag = true;
                        return true;
                    }
                });
            }
            return flag;
        } ,
        initIndexColumn(columns) {
            if (this.myConfig.showIndex) {
                 if (this.myConfig.showSumGroup) {
                    let indexConfig = {
                            label: '行号',
                            name: 'sumindex',
                            type: 'TextBox',
                            align: 'center',
                            width: 45
                    };
                    if (this.myConfig.items[0].name !== 'sumindex') {
                        this.myConfig.items.splice(0, 0, indexConfig);
                    }
                } else {
                    let index = {};
                    index.type = 'index';
                    index.key = 'index';
                    index.width = 45;
                    index.title = '行号';
                    index.align = 'center';
                    if (this.myConfig.headClassName !== undefined) {
                        index.className  = this.myConfig.headClassName;
                    }
                    index.indexMethod = this.indexRender;
                    if (this.myConfig.indexConfig !== undefined) {
                        Object.assign(index, this.myConfig.indexConfig);
                    }
                    columns.push(index);
                }
            }
        },
        initOperColumn(columns) {
            if (this.showRowAction || this.showDelRow) {
                let action ={};
                action.title = '操作';
                if (this.myConfig.headClassName !== undefined) {
                    action.className  = this.myConfig.headClassName;
                }
                action.key = 'action';
                action.render = this.actionRender;
                if (this.operFixedFlag) {
                    action.fixed ='right';
                }
                action.width = 120;
                if (this.myToolConfig.items.length  === 1) {
                    action.width = 80;
                } 
                action.align = 'center';
                if (this.customInitOperColumn) {
                    this.customInitOperColumn(action, columns);
                } else {
                    columns.push(action);
                }
            }
        },
        onColumnWidthResize(newWidth, oldWidth, column) {
            let temp = {};
            temp.newWidth = newWidth;
            temp.oldWidth = oldWidth;
            temp.column = column;
            this.$emit('onColumnWidthResize',temp);
        },
        initExpandColumn(items) {
            this.expand.items=[];
            let columns =[];
            for (let i = 0; i < items.length; i++) {
                if (items[i].isExpand === true) {
                    this.expand.items.push(items[i]);
                } else {
                    columns.push(items[i]);
                }
            }
            if (this.expand.items.length > 0) {
                let expand =  {
                    type: 'expand',
                    width: 50,
                    render:this.expandRendel
                };
                const index =  columns.findIndex(item => item.type === 'index');
                if (index > -1 ) {
                    columns.splice(index+1, 0, expand);
                }  else {
                    const checkindex =  columns.findIndex(item => item.type === 'selection');
                    if (checkindex > -1) {
                        columns.splice(checkindex+1, 0, expand);
                    } else {
                        columns.splice(0, 0, expand);
                    }
                }
                items = columns;
            }

        },
        initColumn() {
            let newRow = {};
            let summaryColumn = [];
            let columns = [];
            if (!this.myConfig.items || this.myConfig.items.length === 0) {
                return columns;
            }
            this.initCheckColumn(columns);
            this.initOperColumn(columns);
            this.initIndexColumn(columns);
            const length = this.myConfig.items.length;
            for (let i = 0; i < length; i++) {
                if (this.myConfig.items[i].visible !== false) {
                    //this.setColumn(i); 
                    // 添加复杂列项的支持
                    this.initCommonColumn(this.myConfig.items[i],columns,summaryColumn,newRow);
                } else {
                    if (this.myConfig.items[i].defaultValue !== undefined) {
                        if (this.myConfig.items[i].name) {
                            newRow[this.myConfig.items[i].name] = this.myConfig.items[i].defaultValue;
                        }
                        if (this.myConfig.items[i].sname) {
                            newRow[this.myConfig.items[i].sname] = this.myConfig.items[i].defaultValue;
                        }
                        if (this.myConfig.items[i].ename) {
                            newRow[this.myConfig.items[i].ename] = this.myConfig.items[i].defaultValue;
                        }
                    }
                }
            }
            this.initExpandColumn(columns);
            let obj = {};
            obj.columns = columns;
            obj.newRow = newRow;
            obj.summaryColumn = summaryColumn;
            return obj;
        },
        initCommonColumn (obj,list,summaryColumn,newRow) {
            let  column = this.$Method.copy(obj);
            if (!column.contentAlign) {
                column.contentAlign = column.align;
            }
            column.title = column.label;
            if (!column.headClassName) {
                if (this.myConfig.headClassName !== undefined) {
                    column.className  = this.myConfig.headClassName;
                }
            } else {
                column.className = column.headClassName;
            }
            
            if (obj.children && obj.children.length > 0) {
                column.children = [];
                for (let i=0;i<obj.children.length; i++) {
                    this.initCommonColumn(obj.children[i],column.children,summaryColumn,newRow);
                }
                list.push(column);
            } else {
                column = this.initColumnConfig(column,summaryColumn,newRow);
                list.push(column);
            }
        },
        initColumnConfig(column,summaryColumn,newRow) {
            let type = '';
            if (column.type) {
                type = column.type.toLowerCase();
            }
            column.key = column.name;
            if (Number(column.width)) {
                column.width = Number(column.width);
            } else {
                delete column.width;
            }

            this.setColumnPro(column,type,summaryColumn,newRow);
          
            if (type !== 'render') {
                if (column.render === undefined)  {
                    if (this.setCustomColumn) {
                        this.setCustomColumn(column);
                    }
                }
            }

            // 处理check
            if (type === 'checkbox' || type === 'picturebox' || type === 'videobox') {
                column.render = this.commonRendel;
                if (type === 'picturebox') {
                    if (column.height === undefined) {
                        column.height = 40;
                    } 
                    column.isGrid = true;
                }
                if (type === 'videobox') {
                    if (column.height === undefined) {
                        column.height = 60;
                    } 
                }
                if (this.myConfig.readOnly) {
                    column.readOnly = true;
                } else {
                    if (column.readOnly !== true) {
                        column.readOnly = false;
                    }
                }
               
            }
            if (column.required) {
                if (!column.className) {
                    column.className = 'efuture-grid-head-required';
                }
            }
           
            // 事件绑定
            if (column.valueChanged) {
                column.valueChanged = this.valueChanged;
            }
            if (column.searchBefore) {
                column.searchBefore = this.searchBefore;
            }
            if (column.setDataBefore) {
                column.setDataBefore = this.setDataBefore;
            }
            if (column.onLinkTo) {
                column.onLinkTo = this.onLinkTo;
            }
            if (type === 'timepicbox' || type === 'datebox' || type === 'daterangebox' || type === 'colorbox' || type === 'combobox') {
                column.transfer = true;
            }
            return column;
        },
        setColumn(i) {
            let  column = this.$Method.copy(this.myConfig.items[i]);
            
            column.title = column.label;
            let type = '';
            if (column.type) {
                type = column.type.toLowerCase();
            }
            if (!type) {
                return;
            }
          
            column.key = column.name;
            if (Number(column.width)) {
                column.width = Number(column.width);
            } else {
                delete column.width;
            }

            this.setColumnPro(column,type);
          
            if (type !== 'render') {
                if (column.render === undefined)  {
                    if (this.setCustomColumn) {
                        this.setCustomColumn(column);
                    }
                }
            }

            // 处理check
            if (type === 'checkbox' || type === 'picturebox' || type === 'videobox') {
                column.render = this.commonRendel;
                if (type === 'picturebox') {
                    if (column.height === undefined) {
                        column.height = 40;
                    } 
                }
                if (type === 'videobox') {
                    if (column.height === undefined) {
                        column.height = 60;
                    } 
                }
                if (this.myConfig.readOnly) {
                    column.readOnly = true;
                } else {
                    column.readOnly = false;
                }
               
            }
            if (column.required) {
                if (!column.className) {
                    column.className = 'efuture-grid-head-required';
                }
            }
            
            if (!column.contentAlign) {
                if (!column.align) {
                    column.contentAlign = column.align;
                }
               
            }
            // 事件绑定
            if (this.myConfig.items[i].valueChanged) {
                column.valueChanged = this.valueChanged;
            }
            if (this.myConfig.items[i].searchBefore) {
                column.searchBefore = this.searchBefore;
            }

            if (this.myConfig.items[i].setDataBefore) {
                column.setDataBefore = this.setDataBefore;
            }
             if (this.myConfig.items[i].onLinkTo) {
                column.onLinkTo = this.onLinkTo;
            }
            if (column.formatValue === undefined) {
                if (this.myConfig.formatValue !== undefined) {
                    column.formatValue = this.myConfig.formatValue;
                }
            }
            this.columns.push(column);
        },
        setColumnPro(column, type, summaryColumn, newRow) {
            column.place = 'grid';
            if (column.sortable === true) {
                column.sortable = 'custom';
            } else if (column.sortable === 'default') {
                column.sortable = true;
            }
            if (type === 'numberbox') {
                if (!column.contentAlign) {
                    column.contentAlign = 'right';
                }
                if (!column.align) {
                    column.align = 'right';
                }
                if (column.summary && summaryColumn !== undefined) {
                    summaryColumn.push(column.name);
                }
            } else if (type === 'datebox' || type === 'checkbox' || type === 'picturebox' || type === 'videobox') {
                 if (this.myConfig.generalOrientation && type === 'datebox') {
                    if (!column.contentAlign) {
                        column.contentAlign = 'left';
                    }
                    if (!column.align) {
                        column.align = 'left';
                    }
                 } else {
                    if (!column.contentAlign) {
                        column.contentAlign = 'center'; 
                    }
                    if (!column.align) {
                        column.align = 'center';
                    }
                 }
                
            } else {
                if (!column.contentAlign) {
                    column.contentAlign = 'left';
                }
                if (!column.align) {
                    column.align = 'left';
                }
            }
            if (type === 'combobox') {
                if (column.data === undefined) {
                    let dictkey = column.dictkey;
                    if (column.customDictkey) {
                        dictkey = column.customDictkey;
                    }
                    column.data = this.currentDictData[dictkey];
                } 
            }
           
            //  处理默认值
            if (column.defaultValue !== undefined) {
                newRow[column.name] = column.defaultValue;
            } else {
                if (type === 'numberbox' || type === 'numberrangebox') {
                    let min = '';
                    if (column.min !== undefined) {
                        min = column.min;
                    } 
                    if (column.smin !== undefined) {
                        min = column.smin;
                    }
                    if (column.smin === undefined && column.emin !== undefined) {
                        min = column.emin;
                    }
                    column.defaultValue = min;
                    if (newRow !== undefined) {
                        newRow[column.name] = min;
                        if(column.boundaryValue === false) {
                            newRow[column.name] = '';
                            column.defaultValue = '';
                        }
                    }
                  
                } else {
                    if (newRow !== undefined) {
                        if (column.type === 'poptagbox') {
                            newRow[column.name] = [];
                        } else {
                            newRow[column.name] = '';
                        }
                    }
                }
            }  
        },
        expandRendel(h, params) {
            return h('div', [
                h(resolveComponent('ExpandRow'), {
                   config: this.expand,
                    valueData:params.row,
                    vstyle:'margin-right: 120px',
                    showRowAction:false,
                    onInputValue:(val) => {
                        this.editIndex = params.index;
                        this.input(val);
                        //this.editValueChanged(params,val);
                    } 
                })
            ]);
        },
        indexRender (row,_index) {
            let index  = _index + 1;
            if (this.myConfig.showPage) {
                index  = index + (this.myConfig.pageConfig.page_no - 1) * this.myConfig.pageConfig.page_size;
            }
            if (this.myConfig.indexMethod) {
                return this.myConfig.indexMethod(row, index);
            } else {
                return index;
            }           
        },
        actionRender (h, params) {
            return h('div', [
                h(resolveComponent('Toolbar'), {
                     config:this.myToolConfig,
                        tooltype:'row',
                        moduleMethod:this.globalConfig.moduleMethod,
                        row:params.row,
                        onDoAction:(val) => {                       
                            val.rowinfo = params;
                            if (val.name === 'editRowForm') {
                                if (this.initRowForm) {
                                    this.initRowForm(val);
                                }
                            } else if (val.name === 'delRow') {
                                if (this.delRow) {
                                    this.delRow(params.index);
                                }
                            } else {
                                this.$emit('doAction',val);
                            }
                        }
                })
            ]);
        },
        remove (index) {
            let _index =  this.data.findIndex(item => item._customIndex === index);
            if (_index ===  -1) {
                _index = index;
            }
            if (_index > -1) {
                if (this.data[_index].flag === undefined || this.data[_index].flag === 'U') {
                    this.data[_index].flag = 'D';
                    const row = this.$Method.copy(this.data[_index]);
                    this.delData.push(row); 
                }
                this.data.splice(_index, 1);
            }
            if (this.customRemove) {
                this.customRemove(_index);
            }
        },
        setEdit(index) {
            if (this.editRowIndex === index) {
                this.editRowIndex = null;
            } else {
                this.editRowIndex = index;
            }
        },
        dbclick (e) {
            this.$emit('dbclick', e);
        },
        click (e) {
            this.$emit('rowclick', e);
            this.$emit('click', e);
        },
        setData(data) {
            this.data = [];
            this.data = data;
            this.initData = this.$Method.copy(this.data);
            this.delData = [];
            this.checkInfo = [];
            if (this.cancelCellEditing) {
                this.cancelCellEditing();
            }
        },
        getData() {
            return this.$Method.copy(this.data);
        },
        clearData() {
            this.editIndex = -1;
            this.editKey = '';
            this.data = [];
            this.delData = [];
            this.initData = [];
            this.checkInfo = [];
            this.addData = [];
            this.checkAddInfo = [];
            this.conditionSearchParam = {};
            this.myConfig.pageConfig.page_no = 1;
            this.myConfig.pageConfig.total_results = 0;
            this.columnWidth = {};
            if (this.customClearData) {
                this.customClearData();
            }
        },
        updataRow(index, para) {
            let row = Object.assign({}, this.data[index], para);
            this.data.splice(index,1,row);
            this.tempData.splice(index,1,row);
        },
        getModuleMethod() {
            this.modulecode = this.$Method.getUrlParam('modulecode');
            if (!this.modulecode) {
                this.modulecode = this.$Method.getUrlParam('billmoduleid');
            }
            this.token = this.$Method.getUrlParam('token');
            if (this.modulecode && this.token) {
                let btnList =  this.getUserModuleMethod();
                if (btnList) {
                    this.globalConfig.moduleMethod = btnList.modulemethod;
                }
            } 
        },
        getSelection() {
            return  this.$refs.table.getSelection();
        },
        input(obj) {
            let index = this.editIndex;
            if (index === -1) {
                if (obj.editIndex !== undefined) {
                    index = obj.editIndex;
                } else {
                    return;
                }
            }
            let tempRow = {};
            if (obj.value !== undefined) {
                tempRow[obj.name] = obj.value;
            }
            if (obj.text !== undefined) {
                tempRow[obj.textName] = obj.text;
            }
            if (obj.svalue !== undefined) {
                tempRow[obj.sname] = obj.svalue;
            }
            if (obj.evalue !== undefined) {
                tempRow[obj.ename] = obj.evalue;
            }
           
            if (this.data[index].flag === undefined) {
                tempRow.flag = 'U';
            }
           
            if (obj.customRows && obj.customRows.length > 0){
                let self = this;
                // 处理更新行
                obj.customRows.forEach(el => {
                    if (el.changeIndex !== undefined) {
                        let newRow = Object.assign({},self.data[el.changeIndex],el);
                        if (self.data[el.changeIndex].flag === undefined) {
                            newRow.flag = 'U';
                        }
                        self.data.splice(el.changeIndex,1,newRow);
                    }
                });
                // 处理新增行
                obj.customRows.forEach(el => {
                    if (el.changeIndex === undefined) {
                        let newRow = Object.assign({},{},el);
                        newRow.flag = 'I';
                        self.data.push(newRow);
                    }
                });
            } else {
                let newRow = Object.assign({},this.data[index],tempRow);
                this.$nextTick(() => {
                    this.data.splice(index,1,newRow); 
                });
                
            }

        },
        updateColPro(name, pro) {
            const index = this.myConfig.items.findIndex(item => name === item.name);
            if (index > -1) {
                let item = Object.assign({},this.myConfig.items[index],pro);
                this.myConfig.items.splice(index,1,item);
            }
        },
        setRowCheck(index , flag) {
            // 单选
            if (!this.myConfig.multiSelect) {
                let data = this.$Method.copy(this.data);
                data.forEach((el,_index) =>{
                    if (_index === index) {
                        if (this.myConfig.onSetRowCheckBefore) {
                            if (this.myConfig.onSetRowCheckBefore(index,flag)) {
                                el._checked = flag;
                                if (this.myConfig.checkByHighlight) {
                                    el._highlight = flag;
                                }
                            }
                        } else {
                            el._checked = flag;
                            if (this.myConfig.checkByHighlight) {
                                el._highlight = flag;
                            }
                        } 
                    } else {
                        el._checked = false;
                        el._highlight = false;
                    } 
                });
                this.$nextTick(() => {
                    this.data = data; 
                });
            // 多选
            } else {
                if (index > -1) {
                    let newRow = Object.assign({},this.data[index],{});
                    newRow._checked = flag;
                    if (this.myConfig.checkByHighlight) {
                        newRow._highlight = flag;
                    }
                    if (this.myConfig.onSetRowCheckBefore) {
                        if (this.myConfig.onSetRowCheckBefore(index,flag)) {
                            this.$nextTick(() => {
                                this.data.splice(index,1,newRow); 
                                this.tempData.splice(index,1,newRow);
                            });
                        }
                    } else {
                        this.$nextTick(() => {
                            this.data.splice(index,1,newRow); 
                            this.tempData.splice(index,1,newRow);
                        });
                    } 
                }
            }
        },
        setAllRowCheck(flag) {
            let data = this.$Method.copy(this.data);
            data.forEach(el =>{
                el._checked = flag;
                if (this.myConfig.checkByHighlight) {
                    el._highlight = flag;
                }
            });
            this.$nextTick(() => {
                this.data = data; 
            });
        },
        setRowDisabled(index , flag) {
            if (index > -1) {
                let newRow = Object.assign({},this.data[index],{});
                newRow._disabled = flag;
                this.$nextTick(() => {
                    this.data.splice(index,1,newRow); 
                    this.tempData.splice(index,1,newRow); 
                });
            }
        },
        setAllRowDisabled(flag) {
            let data = this.$Method.copy(this.data);
            data.forEach(el =>{
                el._disabled = flag;
            });
            this.$nextTick(() => {
                this.data = data; 
            });
        },
        setRowHighlight(index , flag) {
            if (index > -1) {
                let newRow = Object.assign({},this.data[index],{});
                newRow._highlight = flag;
                this.$nextTick(() => {
                    this.data.splice(index,1,newRow); 
                    this.tempData.splice(index,1,newRow);
                });
            }
        },
        setAllRowHighlight(flag) {
            let data = this.$Method.copy(this.data);
            data.forEach(el =>{
                el._highlight = flag;
            });
            this.$nextTick(() => {
                this.data = data; 
            });
        },
        commonRendel(h, params) {
            return h('div', [
                h(resolveComponent('ControlBox'), {
                    config: params.column,
                    valueData:params.row,
                    readOnly:params.row.flag === 'D'? true:false,
                    autofocus:this.editIndex === params.index && this.editKey === params.column.key?true:false,
                    onInputValue:(val) => {
                        this.editIndex = params.index;
                        this.editKey = params.column.key;
                        this.input(val);
                    },
                    onDoAction:(val) =>{
                        this.doAction(val);
                    }     
                })
            ]);
        },
       
        setExtraHeight () {
            let height = 0;
            if (this.$refs.head) {
                height = this.$refs.head.offsetHeight;
            }
            if (this.$refs.page) {
                height = height + this.$refs.page.offsetHeight;
            }
            this.extraHeight = height;
        },
        setOutsideHeight(value) {
            this.outsideHeight = value;
        },
        getSoltTableColumns(config,list) {
            if (config) {
               if (config instanceof Array) {
                    config.forEach(el => {
                        this.getSoltTableColumns(el, list);
                    })
                } else {
                    if (config.children && config.children.length > 0) {
                        config.children.forEach(el => {
                            this.getSoltTableColumns(el, list);
                        })
                    } else {
                        let temp  = Object.assign({},config);
                        if (temp.key !=='action' && temp.key !== 'actionbtn') {
                            list.push(temp);
                        }
                    }
                }
            }  
        },
        findColumnConfig(name,config) {
            if (name) {
               if (config instanceof Array) {
                    let flag = false;
                    let tmpConfig = {};
                    config.some(el => {
                       let tmp = this.findColumnConfig(name,el);
                       if (!!tmp) {
                        flag = true;
                        tmpConfig = tmp;
                        return true;
                       }
                    });
                    if (flag) {
                        return tmpConfig;
                    } else {
                        return false;
                    }
                } else {
                    if (config.children && config.children.length > 0) {
                        let flag = false;
                        let tmpConfig = {};
                        config.children.some(el => {
                            let tmp = this.findColumnConfig(name, el);
                            if (!!tmp) {
                                flag = true;
                                tmpConfig = tmp;
                                return true;
                            }
                        });
                        if (flag) {
                            return tmpConfig;
                        } else {
                            return false;
                        }
                    } else {
                        if(name === config.name) {
                            return config;
                        } else {
                            return false;
                        }
                    }
                }
            }  
        },
        openHelp () {
            window.open(this.curHelpUrl);
        },
        initScrollLeft() {
            if (this.$refs.table && this.$refs.table.$refs.body ) {
                this.$refs.table.$refs.body.scrollLeft = 0;
            }
        },
    },
    watch:{
        data(val){
            this.tempData = deepCopy(val);
        },
        makeTableColumns(val) {
            this.total_summary = {};
            this.newRow = deepCopy(val.newRow); 
            this.summaryColumn = deepCopy(val.summaryColumn); 
            this.tableColumns = deepCopy(val.columns);
            let soltTableColumns = [];
            this.getSoltTableColumns(val.columns, soltTableColumns);
            this.soltTableColumns = soltTableColumns;
        }
    },
    mounted () { 
        
    }
};
</script>