/**
 * Created by Tony on 2018/8/21.
 */

let fieldLocationOprObj = {
    columnWorkBook: null,
    columnParentNode: null,
    contentParentNode: null,
    columnFieldCtrls: null,
    iniSpreadJs: function (columnParentNode, contentParentNode) {
        let me = this;
        if (me.columnWorkBook === null) {
            me.columnWorkBook = new GC.Spread.Sheets.Workbook($('#rptTplColumnWorkbook')[0], {sheetCount: 1});
            // me.columnWorkBook.setHei
            me.columnWorkBook.options.tabStripVisible = false;
            // me.columnWorkBook.options.scrollbarMaxAlign = true;
            me.columnWorkBook.options.allowCopyPasteExcelStyle = false;
            // me.columnWorkBook.options.allowExtendPasteRange = isExtendPaste? true : false;
            me.columnWorkBook.options.allowUserDragDrop = false;
            me.columnWorkBook.options.allowContextMenu = false;
            let sheet = me.columnWorkBook.getActiveSheet();
            sheet.options.allowCellOverflow = false;
            sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;
            // sheet.showRowOutline(false);
            // sheet.setRowCount(10, GC.Spread.Sheets.SheetArea.viewport);
            sheet.bind(GC.Spread.Sheets.Events.EnterCell, me.onCellEnter);
        }
        me.columnParentNode = columnParentNode;
        me.contentParentNode = contentParentNode;
    },
    restoreColumn: function () {
        let me = this;
        let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
        me.setupColumn(rptTpl, me.columnParentNode, me.contentParentNode);
    },
    setupColumn: function (rptTpl, columnParentNode, contentParentNode) {
        let me = this, yPos = [], xPos = [];
        me.columnFieldCtrls = [];
        let selectedBand = visualCommonOprObj.getBandEx(columnParentNode[JV.PROP_BAND_NAME], rptTpl);
        if (selectedBand !== null) {
            let sheet = me.columnWorkBook.getActiveSheet();
            sheet.suspendPaint();
            sheet.clearSelection();
            sheet.setRowCount(0);
            let spans =sheet.getSpans();
            for(let i = 0; i < spans.length; i++)
            {
                sheet.removeSpan(spans[i].row, spans[i].col, GC.Spread.Sheets.SheetArea.viewport);
            }
            // sheet.setRowCount(1);
            // sheet.setColumnCount(1);
            let bandH = Math.round(parseFloat(selectedBand[JV.BAND_PROP_HEIGHT]) / 2.54 * 96);
            let bandW = 700;
            let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
            if (pIdx >= 0) {
                bandW = Math.round(JV.PAGES_SIZE[pIdx][0] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
                if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
                    rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
                    bandW = Math.round(JV.PAGES_SIZE[pIdx][1] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
                }
            }
            if (columnParentNode.items && columnParentNode.items.length > 0) {
                for (let itemNode of columnParentNode.items) {
                    visualCommonOprObj.pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos);
                    visualCommonOprObj.pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_RIGHT, bandW, xPos);
                    visualCommonOprObj.pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_TOP, bandH, yPos);
                    visualCommonOprObj.pushPos(itemNode, itemNode[JV.PROP_AREA][JV.PROP_V_CALCULATION], JV.PROP_BOTTOM, bandH, yPos);
                }

                sheet.setRowCount(yPos.length, GC.Spread.Sheets.SheetArea.viewport);
                sheet.setColumnCount(xPos.length - 1, GC.Spread.Sheets.SheetArea.viewport);
                for (let idx = 1; idx < xPos.length; idx++) {
                    me.columnFieldCtrls.push(me.private_create_dft_ctrl());
                }
                // sheet.clear();
                let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
                let selectableFields = visualCommonOprObj.getSelectedFields(rptTpl);
                cellType.items(selectableFields);
                //设置 最后一行为 行数据选择combobox
                let iSelectedRow = sheet.getRowCount() - 1;
                sheet.setRowHeight(iSelectedRow, 20);
                sheet.getRange(iSelectedRow, -1, 1, -1).backColor("LightCyan");
                sheet.getRange(iSelectedRow, -1, 1, -1).locked(true);
                for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
                    sheet.getCell(iSelectedRow, jCol).cellType(cellType);
                }
                xPos.sort(function(x1, x2){
                    return (x1 - x2);
                });
                yPos.sort(function(y1, y2){
                    return (y1 - y2);
                });
                for (let contentItemNode of contentParentNode.items) {
                    let idxCol = xPos.indexOf(visualCommonOprObj.getActPosEx(contentItemNode, contentItemNode[JV.PROP_AREA][JV.PROP_H_CALCULATION], JV.PROP_LEFT, bandW, xPos));
                    let cell = sheet.getCell(iSelectedRow, idxCol);
                    cell.value(contentItemNode[JV.PROP_NAME]);
                    me.private_merge_ctrl(rptTpl, idxCol, contentItemNode, null);
                    visualCommonOprObj.setupCell(cell, contentItemNode);
                }
                for (let idx = 1; idx < xPos.length; idx++) {
                    sheet.setColumnWidth(idx - 1, xPos[idx] - xPos[idx - 1]);
                }
                for (let idx = 1; idx < yPos.length; idx++) {
                    sheet.setRowHeight(idx - 1, yPos[idx] - yPos[idx - 1]);
                    sheet.getRange(idx - 1, -1, 1, -1).backColor(undefined);
                }
                for (let itemNode of columnParentNode.items) {
                    visualCommonOprObj.addSpan(itemNode, sheet, bandW, bandH, xPos, yPos, GC.Spread.Sheets.SheetArea.viewport);
                }
            } else {
                sheet.setRowCount(2);
                sheet.setColumnCount(1);
                me.columnFieldCtrls.push(me.private_create_dft_ctrl());
                let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
                let selectableFields = visualCommonOprObj.getSelectedFields(rptTpl);
                cellType.items(selectableFields);
                //设置 最后一行为 行数据选择combobox
                let iSelectedRow = sheet.getRowCount() - 1;
                sheet.setRowHeight(iSelectedRow, 20);
                sheet.getRange(iSelectedRow, -1, 1, -1).backColor("LightCyan");
                sheet.getRange(iSelectedRow, -1, 1, -1).locked(true);
                for (let jCol = 0; jCol < sheet.getColumnCount(); jCol++) {
                    sheet.getCell(iSelectedRow, jCol).cellType(cellType);
                }
                sheet.setColumnWidth(0, bandW);
                sheet.setRowHeight(0, bandH);
            }
            sheet.resumePaint();
        }
    },
    onCellEnter: function (sender, args) {
        let me = fieldLocationOprObj,
            sheet = me.columnWorkBook.getActiveSheet();
        if (args.row === sheet.getRowCount() - 1) {
            me.private_setup_control_options(true);
            me.private_update_ctrl_cfg(args.col);
        } else {
            me.private_setup_control_options(false);
        }
    },
    addRow: function () {
        let me = fieldLocationOprObj,
            sheet = me.columnWorkBook.getActiveSheet();
        sheet.addRows(sheet.getRowCount() - 1, 1);
        let rc = sheet.getRowCount();
        for (let cc = 0; cc < sheet.getColumnCount(); cc++) {
            visualCommonOprObj.setupCellDft(sheet.getCell(rc - 2, cc));
        }
    },
    deleteRow: function () {
        let me = fieldLocationOprObj,
            sheet = me.columnWorkBook.getActiveSheet(),
            selectedRanges = sheet.getSelections()
        ;
        let rc = sheet.getRowCount();
        if (rc > 2) {
            if (selectedRanges.length > 0) {
                sheet.deleteRows(selectedRanges[0].row, 1);
            }
        } else {
            alert('不能删除行！');
        }
    },
    addCol: function (rptTpl) {
        let me = fieldLocationOprObj,
            sheet = me.columnWorkBook.getActiveSheet();
        sheet.suspendPaint();
        sheet.addColumns(sheet.getColumnCount(), 1);
        let cellType = new GC.Spread.Sheets.CellTypes.ComboBox();
        let selectableFields = visualCommonOprObj.getSelectedFields(rptTpl);
        cellType.items(selectableFields);
        //设置 最后一行为 行数据选择combobox
        // sheet.getRange(sheet.getRowCount() - 1, -1, 1, -1).locked(true);
        let colIdx = sheet.getColumnCount() - 1;
        sheet.getCell(sheet.getRowCount() - 1, colIdx).cellType(cellType);
        for (let iRow = 0; iRow < sheet.getRowCount() - 1; iRow++) {
            visualCommonOprObj.setupCellDft(sheet.getCell(iRow, colIdx));
        }
        //
        me.columnFieldCtrls.push(me.private_create_dft_ctrl());
        sheet.resumePaint();
    },
    deleteCol: function () {
        let me = fieldLocationOprObj,
            sheet = me.columnWorkBook.getActiveSheet(),
            selectedRanges = sheet.getSelections()
        ;
        let cc = sheet.getColumnCount();
        if (cc > 1) {
            if (selectedRanges.length > 0) {
                sheet.deleteColumns(selectedRanges[0].col, 1);
            }
        } else {
            alert('不能删除列！');
        }
    },
    mergeCells: function () {
        let me = fieldLocationOprObj,
            sheet = me.columnWorkBook.getActiveSheet();
        let selectedRanges = sheet.getSelections();
        if (selectedRanges.length > 0) {
            if (selectedRanges[0].row + selectedRanges[0].rowCount < sheet.getRowCount()) {
                sheet.suspendPaint();
                sheet.addSpan(selectedRanges[0].row, selectedRanges[0].col, selectedRanges[0].rowCount, selectedRanges[0].colCount);
                sheet.resumePaint();
            } else {
                alert("指标列不能被合并！")
            }
        }
    },
    disMergeCells: function () {
        let me = fieldLocationOprObj,
            sheet = me.columnWorkBook.getActiveSheet();
        let selectedRanges = sheet.getSelections();
        let spans = sheet.getSpans();
        if (selectedRanges.length > 0 && spans.length > 0) {
            let selectedSpans = [];
            for(let i = 0; i < spans.length; i++)
            {
                for (let j = 0; j < selectedRanges.length; j++) {
                    if (spans[i].row >= selectedRanges[j].row && spans[i].col >= selectedRanges[j].col &&
                        spans[i].row < selectedRanges[j].row + selectedRanges[j].rowCount && spans[i].col < selectedRanges[j].col + selectedRanges[j].colCount) {
                        selectedSpans.push(spans[i]);
                    }
                }
            }
            for (let span of selectedSpans) {
                sheet.removeSpan(span.row, span.col, GC.Spread.Sheets.SheetArea.viewport);
            }
        }
    },
    fitTheWidth: function (factor) {
        let me = this, rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
        let pIdx = JV.PAGES_SIZE_STR.indexOf(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_PAGE_SIZE]);
        let bandW = 700;
        if (pIdx >= 0) {
            bandW = Math.round(JV.PAGES_SIZE[pIdx][0] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
            if (rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE ||
                rptTpl[JV.NODE_MAIN_INFO][JV.NODE_PAGE_INFO][JV.PROP_ORIENTATION] === JV.ORIENTATION_LANDSCAPE_CHN) {
                bandW = Math.round(JV.PAGES_SIZE[pIdx][1] * 96 - (parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_LEFT]) + parseFloat(rptTpl[JV.NODE_MAIN_INFO][JV.NODE_MARGINS][JV.PROP_RIGHT])) /2.54*96 );
            }
        }
        bandW *= factor;
        let currentWidth = 0;
        let sheet = me.columnWorkBook.getActiveSheet();
        for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
            currentWidth += sheet.getColumnWidth(idx);
        }
        let actFactor = bandW / currentWidth;
        for (let idx = 0; idx < sheet.getColumnCount(); idx++) {
            sheet.setColumnWidth(idx, Math.round(sheet.getColumnWidth(idx) * actFactor));
        }
    },
    changeCtrl: function (dom) {
        let me = fieldLocationOprObj,
            sheet = me.columnWorkBook.getActiveSheet(),
            fieldRowIdx = sheet.getRowCount() - 1
        ;
        //sheet.getSelectio
        let selectedRanges = sheet.getSelections();
        for(let i = 0; i < selectedRanges.length; i++){
            if (selectedRanges[i].row === fieldRowIdx) {
                let ctrl = me.columnFieldCtrls[selectedRanges[i].col]
                ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = 'F';
                ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = 'F';
                ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = 'F';
                ctrl.isNarrow = false;
                ctrl.isAutoHeight = false;
                if ($("#eleShrinkEx")[0].checked) {
                    ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = 'T';
                }
                if ($("#eleShowZeroEx")[0].checked) {
                    ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = 'T';
                }
                if ($("#eleAutoWrapEx")[0].checked) {
                    ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = 'T';
                }
                if ($("#eleIsNarrowEx")[0].checked) {
                    ctrl.isNarrow = true;
                }
                if ($("#eleIsAutoHeightEx")[0].checked) {
                    ctrl.isAutoHeight = true;
                }

                if ($("#hOptionLeft")[0].checked) {
                    ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[0];
                } else if ($("#hOptionCenter")[0].checked) {
                    ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[1];
                } else {
                    ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = JV.OUTPUT_ALIGN.H[2];
                }
                if ($("#vOptionUp")[0].checked) {
                    ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[0];
                } else if ($("#vOptionCenter")[0].checked) {
                    ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[1];
                } else {
                    ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = JV.OUTPUT_ALIGN.V[2];
                }
            }
        }
    },
    private_update_ctrl_cfg: function (ctrlIdx) {
        let me = fieldLocationOprObj;
        if (ctrlIdx >= 0) {
            if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]])) {
                $("#eleShrinkEx")[0].checked = true;
            } else {
                $("#eleShrinkEx")[0].checked = false;
            }
            if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]])) {
                $("#eleShowZeroEx")[0].checked = true;
            } else {
                $("#eleShowZeroEx")[0].checked = false;
            }
            if (stringUtil.convertStrToBoolean(me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]])) {
                $("#eleAutoWrapEx")[0].checked = true;
            } else {
                $("#eleAutoWrapEx")[0].checked = false;
            }
            if (me.columnFieldCtrls[ctrlIdx].isNarrow) {
                $("#eleIsNarrowEx")[0].checked = true;
            } else {
                $("#eleIsNarrowEx")[0].checked = false;
            }
            if (me.columnFieldCtrls[ctrlIdx].isAutoHeight) {
                $("#eleIsAutoHeightEx")[0].checked = true;
            } else {
                $("#eleIsAutoHeightEx")[0].checked = false;
            }
            switch (me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]]) {
                case JV.OUTPUT_ALIGN.H[0]:
                    $("#hOptionLeft")[0].checked = `true`;
                    break;
                case JV.OUTPUT_ALIGN.H[1]:
                    $("#hOptionCenter")[0].checked = `true`;
                    break;
                default:
                    $("#hOptionRight")[0].checked = `true`;
                    break;
            }
            switch (me.columnFieldCtrls[ctrlIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]]) {
                case JV.OUTPUT_ALIGN.V[0]:
                    $("#vOptionUp")[0].checked = `true`;
                    break;
                case JV.OUTPUT_ALIGN.V[1]:
                    $("#vOptionCenter")[0].checked = `true`;
                    break;
                default:
                    $("#vOptionDown")[0].checked = `true`;
                    break;
            }
        }
    },
    private_create_dft_ctrl: function () {
        return {"Shrink" : "T", "ShowZero" : "T", "Horizon": "left", "Vertical": "bottom", "Wrap": "F", "isNarrow": false, "isAutoHeight": false };
    },
    private_merge_ctrl: function (rptTpl, srcIdx, fieldNode, directCtrl) {
        let me = this, ctrl = null;
        if (directCtrl) {
            ctrl = directCtrl;
        } else {
            if (typeof fieldNode[JV.PROP_CONTROL] === 'string') {
                let idx = rpt_tpl_cfg_helper.reportCfg.controlArr.indexOf(fieldNode[JV.PROP_CONTROL]);
                if (idx >= 0) {
                    ctrl = rpt_tpl_cfg_helper.reportCfg.ctrls[idx];
                }
            } else {
                ctrl = fieldNode[JV.PROP_CONTROL];
            }
            for (let font of rpt_tpl_cfg_helper.reportCfg.fonts) {
                if (font.ID === fieldNode[JV.PROP_FONT]) {
                    if (font[JV.FONT_PROPS[JV.FONT_PROP_IDX_NAME]].indexOf(`Narrow`) >= 0) {
                        ctrl.isNarrow = true;
                    } else {
                        ctrl.isNarrow = false;
                    }
                    break;
                }
            }
            ctrl[JV.PROP_IS_AUTO_HEIGHT] = fieldNode[JV.PROP_IS_AUTO_HEIGHT];
        }
        if (ctrl) {
            me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHRINK]];
            me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_SHOW_ZERO]];
            me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_HORIZON]];
            me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_VERTICAL]];
            me.columnFieldCtrls[srcIdx][JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]] = ctrl[JV.CONTROL_PROPS[JV.CONTROL_PROP_IDX_WRAP]];
            me.columnFieldCtrls[srcIdx].isNarrow = ctrl.isNarrow;
            me.columnFieldCtrls[srcIdx][JV.PROP_IS_AUTO_HEIGHT] = ctrl[JV.PROP_IS_AUTO_HEIGHT];
        }
    },
    private_setup_control_options: function (enable) {
        if (enable) {
            $("#fieldControlDiv")[0].style.cursor = "";
            $("#hOptionLeft")[0].removeAttribute("disabled");
            $("#hOptionCenter")[0].removeAttribute("disabled");
            $("#hOptionRight")[0].removeAttribute("disabled");
            $("#vOptionUp")[0].removeAttribute("disabled");
            $("#vOptionCenter")[0].removeAttribute("disabled");
            $("#vOptionDown")[0].removeAttribute("disabled");
            $("#eleShrinkEx")[0].removeAttribute("disabled");
            $("#eleShowZeroEx")[0].removeAttribute("disabled");
            $("#eleAutoWrapEx")[0].removeAttribute("disabled");
            $("#eleIsNarrowEx")[0].removeAttribute("disabled");
            $("#eleIsAutoHeightEx")[0].removeAttribute("disabled");
        } else {
            $("#fieldControlDiv")[0].style.cursor = "not-allowed";
            $("#hOptionLeft")[0].disabled = "disabled" ;
            $("#hOptionCenter")[0].disabled = "disabled" ;
            $("#hOptionRight")[0].disabled = "disabled" ;
            $("#vOptionUp")[0].disabled = "disabled" ;
            $("#vOptionCenter")[0].disabled = "disabled" ;
            $("#vOptionDown")[0].disabled = "disabled" ;
            $("#eleShrinkEx")[0].disabled = "disabled" ;
            $("#eleShowZeroEx")[0].disabled = "disabled" ;
            $("#eleAutoWrapEx")[0].disabled = "disabled" ;
            $("#eleIsNarrowEx")[0].disabled = "disabled" ;
            $("#eleIsAutoHeightEx")[0].disabled = "disabled" ;
        }
    },
    private_create_content_node: function (colWidthArr, cellValue, colIdx, rptTpl) {
        let me = this;
        let rst = {"Name": cellValue, "Title": '', "FieldID": -1, "font": "Content", "control": "Column", "style" : "Default_Normal", "isAutoHeight" : false,
            "area" : {"Left" : 0, "Right" : 100, "Top" : 0, "Bottom" : 100, "H_CalculationType" : "percentage", "V_CalculationType" : "percentage"}
        };
        //1. 设置FieldID
        let hasChkField = false;
        if (rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS] !== undefined && rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS].length > 0) {
            for (let field of rptTpl[JV.NODE_FIELD_MAP][JV.NODE_DETAIL_FIELDS]) {
                if (field[JV.PROP_NAME] === cellValue) {
                    rst.FieldID = field[JV.PROP_ID];
                    rst["Title"] = "ID: " + field[JV.PROP_ID];
                    hasChkField = true;
                    break;
                }
            }
        }
        if (!hasChkField && rptTpl[JV.NODE_NO_MAPPING_FIELDS] !== undefined && rptTpl[JV.NODE_NO_MAPPING_FIELDS].length > 0) {
            for (let field of rptTpl[JV.NODE_NO_MAPPING_FIELDS]) {
                if (field[JV.PROP_NAME] === cellValue) {
                    rst.FieldID = field[JV.PROP_ID];
                    rst["Title"] = "ID: " + field[JV.PROP_ID];
                    hasChkField = true;
                    break;
                }
            }
        }
        //2. 字体
        if (me.columnFieldCtrls[colIdx].isNarrow) {
            rst[JV.PROP_FONT] = "Content_Narrow";
        }
        //3. 自动行高
        if (me.columnFieldCtrls[colIdx][JV.PROP_IS_AUTO_HEIGHT]) {
            rst[JV.PROP_IS_AUTO_HEIGHT] = true;
        }
        //4. 左右位置%
        let width = colWidthArr[colWidthArr.length - 1];
        if (colIdx > 0) {
            rst[JV.PROP_AREA][JV.PROP_LEFT] = (colWidthArr[colIdx - 1] / width * 100).toFixed(2);
        }
        rst[JV.PROP_AREA][JV.PROP_RIGHT] = (colWidthArr[colIdx] / width * 100).toFixed(2);
        if (me.columnFieldCtrls[colIdx]["Vertical"] === "center") {
            switch (me.columnFieldCtrls[colIdx]["Horizon"]) {
                case "left":
                    rst["control"] = "Column_Left";
                    break;
                case "center":
                    rst["control"] = "Column";
                    break;
                default:
                    rst["control"] = "Column_Right";
                    break;
            }
        } else if (me.columnFieldCtrls[colIdx]["Vertical"] === "bottom") {
            switch (me.columnFieldCtrls[colIdx]["Horizon"]) {
                case "left":
                    rst["control"] = "Content_Left";
                    break;
                case "center":
                    rst["control"] = "Content_Center";
                    break;
                default:
                    rst["control"] = "Content_Right";
                    break;
            }
        }
        //return {"Shrink" : "T", "ShowZero" : "T", "Horizon": "left", "Vertical": "bottom", "Wrap": "F", "isNarrow": false, "isAutoHeight": false };
        return rst;
    },

    applyColumnBack: function () {
        let me = this;
        let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
        if (rptTpl && me.columnParentNode && me.contentParentNode && confirm(`请确认提交应用！`)) {
            let sheet = me.columnWorkBook.getActiveSheet();
            if (sheet.getRowCount() > 1 && sheet.getColumnCount() > 0) {
                let texts = [], colWidthArr = [], rowHeightArr = [];
                visualCommonOprObj.collectSheetTxt(sheet, texts, 1, colWidthArr, rowHeightArr);
                let nodes = [];
                //表栏重置
                //0. 先清除原先所有的column text
                dataInfoMapTreeOprObj.treeObj.removeChildNodes(me.columnParentNode);
                //1. 需要重新设置columnBand的高度
                //2. 重新生成text节点
                for (let text of texts) {
                    let node = visualCommonOprObj.createTxtNode(text, me.columnParentNode, colWidthArr, rowHeightArr);
                    nodes.push(node);
                }
                dataInfoMapTreeOprObj.treeObj.addNodes(me.columnParentNode, -1, nodes, true);
                //内容重置
                //0. 先清除原先所有的content node
                dataInfoMapTreeOprObj.treeObj.removeChildNodes(me.contentParentNode);
                //1. 重新生成节点
                let contentNodes = [];
                let contenRowIdx = sheet.getRowCount() - 1;
                let rptTpl = (zTreeOprObj.currentNode)?zTreeOprObj.currentNode.rptTpl:null;
                for (let iCol = 0; iCol < sheet.getColumnCount(); iCol++) {
                    let cellValue = sheet.getValue(contenRowIdx, iCol);
                    if (!(stringUtil.isEmptyString(cellValue))) {
                        contentNodes.push(me.private_create_content_node(colWidthArr, cellValue, iCol, rptTpl));
                    }
                }
                dataInfoMapTreeOprObj.treeObj.addNodes(me.contentParentNode, -1, contentNodes, true);
                displayMessage("应用提交成功！", "green", 5000, "id_column_setup_lbl");
            } else {
                displayMessage("模板行列数量不足！", "red", 5000, "id_column_setup_lbl");
            }
        }
    }

};