/**
 * Created by Zhong on 2017/8/31.
 * 特征及内容
 */
let contentOprObj = {
    workBook: null,
    currentCache: [],//按照serialNo排序
    setting: {
        header: [
            {headerName:"工作内容", headerWidth: 360, rateWidth:0.93, dataCode:"content", dataType: "String", hAlign: "left", vAlign: "center", formatter: '@'},
            {headerName:"输出", headerWidth: 40, rateWidth: null, dataCode:"isChecked", cellType:"checkBox", hAlign: "center", vAlign: "center"}
        ]
    },
    buildSheet: function(container) {
        let me = contentOprObj;
        me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
        //获取工作内容列比例
        let workBookWidth = pageCCOprObj.getWorkBookWidth();
        me.setRateWith(workBookWidth);
        sheetCommonObj.setColumnWidthByRate(workBookWidth, me.workBook, me.setting.header);
        me.workBook.options.allowUserDragDrop = false;
        me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
        me.workBook.options.allowCopyPasteExcelStyle = false;
        if(!projectReadOnly){
            me.onContextmenuOpr();//右键菜单
        }
        me.bindEvents(me.workBook);
    },
    setRateWith: function (workBookWidth) {
        let me = this;
        let otherWidthRate = scMathUtil.roundTo(me.setting.header[1]['headerWidth'] / workBookWidth, -3);
        let contentWidthRate = 1 - otherWidthRate;
        me.setting.header[0]['rateWidth'] = contentWidthRate;
    },
    bindEvents: function (workBook) {
        let sheet = workBook.getActiveSheet(), me = contentOprObj;
        const EVENTS = GC.Spread.Sheets.Events;
        workBook.bind(EVENTS.ButtonClicked, me.onButtonClicked);
        sheet.bind(EVENTS.EditStarting, me.onEditStart);
        sheet.bind(EVENTS.ValueChanged, me.onValueChanged);
        sheet.bind(EVENTS.ClipboardPasting, me.onClipboardPasting);
        sheet.bind(EVENTS.ClipboardPasted, me.onClipboardPasted);
        sheet.bind(EVENTS.SelectionChanged, me.onSelectionChanged);
        workBook.bind(EVENTS.RangeChanged, me.onRangeChanged);
        me.bindTools();
    },

    bindTools: function () {
        let me = contentOprObj;
        let sheet = me.workBook.getActiveSheet();
        $('#jobAdd').click(function () {
            me.insertContent(sheet, me.currentCache.length, '');
            me.workBook.focus();
        });
        $('#jobInsert').click(function(){
            me.insertContent(sheet, sheet.getActiveRowIndex(), '');
            me.workBook.focus();
        });
        $('#jobDel').click(function(){
            me.deleteContent(sheet.getActiveRowIndex());
            me.workBook.focus();
        });
        $('#jobUp').click(function(){
            me.upMove({row: sheet.getActiveRowIndex(), col: sheet.getActiveColumnIndex()});
            me.workBook.focus();
        });
        $('#jobDown').click(function(){
            me.downMove({row: sheet.getActiveRowIndex(), col: sheet.getActiveColumnIndex()});
            me.workBook.focus();
        });
    },
    //将从清单库中添加的清单，把标准清单的工作内容转化成清单的工作内容
    buildJobContent: function (jobs) {
        let jobContent = [];
        for(let i = 0, len = jobs.length; i < len; i++){
            let newJob = {serialNo: i + 1, content: jobs[i].content, isChecked: true};//从清单库添加过来的默认输出
            jobContent.push(newJob);
        }
        return jobContent;
    },
    //显示在jobSpread的数据
    showContentData: function (sheet, setting, datas) {
        sheetCommonObj.showData(sheet, setting, datas);
        sheet.suspendPaint();
        sheet.suspendEvent();
        for(let i = 0, len = datas.length; i < len; i++){
            sheet.getCell(i, 0).locked(true);
        }
        sheet.resumePaint();
        sheet.suspendEvent();
    },
    //显示到清单工作内容列的数据
    getColData: function (jobsArr) {
        let me = contentOprObj;
        let rstStr = "", count = 0;
        for(let i = 0, len = jobsArr.length; i < len; i++){
            if(jobsArr[i].isChecked === true){
                count ++;
              /*  if(count === 1){
                    rstStr += "“";
                }
                else{
                    rstStr += " ";
                }*/
                rstStr += count + ". " + jobsArr[i].content + "\n";
            }
        }
        if(rstStr.trim().length > 0){
            let reg = /\n+$/g;
            let newStr = rstStr.replace(reg, "");
            return newStr;
        }
        return null;
    },
    //新增行
    addRow: function (idx, sheet) {
        let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
        checkBox.isThreeState = false;
        sheet.addRows(idx, 1);
        sheet.getCell(idx - 1, 1).cellType(checkBox);
    },
    upMove: function (cell) {
        let me = contentOprObj;
        let thisObj = me.currentCache[cell.row],
            preObj = me.currentCache[cell.row - 1],
            temp, contentTxt;
        temp = thisObj.serialNo;
        thisObj.serialNo = preObj.serialNo;
        preObj.serialNo = temp;
        me.sortCache(me.currentCache);
        me.save(function () {
            me.workBook.focus();
            me.workBook.getSheet(0).setActiveCell(cell.row - 1, cell.col);
            me.initSelection(cell.row - 1);
        });
    },
    downMove: function (cell) {
        let me = contentOprObj;
        let thisObj = me.currentCache[cell.row],
            nextObj = me.currentCache[cell.row + 1],
            temp, contentTxt;
        temp = thisObj.serialNo;
        thisObj.serialNo = nextObj.serialNo;
        nextObj.serialNo = temp;
        me.sortCache(me.currentCache);
        me.save(function () {
            me.workBook.focus();
            me.workBook.getSheet(0).setActiveCell(cell.row + 1, cell.col);
            me.initSelection(cell.row + 1);
        });
    },
    deleteContent: function (rowIdx) {
        let me = contentOprObj;
        me.currentCache.splice(rowIdx, 1);
        me.save();
        me.workBook.focus();
    },
    //更新
    updateContent: function (job, newContent, save = true) {
        let me = contentOprObj;
        job.content = newContent;
        if(save){
            me.save();
        }
    },
    //新增
    insertContent: function (sheet, idx, content) {
        let me = contentOprObj;
        me.addRow(idx, sheet);
        let newObj = {content: content, isChecked: true};
        me.currentCache.splice(idx, 0, newObj);
        //重新排序赋值
        pageCCOprObj.resortNo(me.currentCache);
        me.save();
        me.workBook.focus();
    },
    save: function (callback) {
        let selectedNode = projectObj.mainController.tree.selected;
        const setting = projectObj.project.property.addRule !== undefined ? projectObj.project.property.addRule : getAddRuleSetting();
        pageCCOprObj.setCharacterBySetting(selectedNode, setting, callback, contentOprObj);
    },
    onEditStart(sender, args){
        if(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
            args.cancel = true;
            return;
        }
    },
    onValueChanged: function (sender, args) {
        let me = contentOprObj;
        if(me.setting.header[args.col].dataCode === 'isChecked'){
            return;
        }
        args.newValue = args.newValue ?  args.newValue : '';
        //更新
        if(args.row < me.currentCache.length){
            let job = me.currentCache[args.row];
            me.updateContent(job, args.newValue);
        }

    },
    //复选框控制输出
    onButtonClicked: function (sender, args) {
        let me = contentOprObj, contentTxt;
        if(args.sheet.isEditing()){
            args.sheet.endEdit(true);
        }
        let isChecked = args.sheet.getValue(args.row, args.col);
        // 锁定清单值不变
        if(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
            args.sheet.setValue(args.row, args.col, !isChecked);
            return;
        }
        if(me.currentCache.length > args.row){
            me.currentCache[args.row].isChecked = isChecked;
            me.save();
        }
        //else的情况就是新增
        else{
            //还没数据清空复选框
            args.sheet.setValue(args.row, args.col, 0);
        }
    },
    onRangeChanged: function (sender, args) {
        let me = contentOprObj;
        let rangeCell = isDef(args.changedCells[0]) ? args.changedCells[0] : null;
        if(!rangeCell){
            return;
        }
        let rangeData = isDef(me.currentCache[rangeCell.row]) ? me.currentCache[rangeCell.row] : null;
        if(!rangeData){
            return;
        }
        if(rangeCell.col === 0){//工作内容
            me.updateContent(rangeData, '');
        }
        else if(rangeCell.col === 1){//输出
            rangeData.isChecked = false;
            me.save();
        }
    },
    //复制粘贴
    onClipboardPasting: function (sender, args) {
        if(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
            args.cancel = true;
            return;
        }
        if(args.cellRange.colCount > 1 || args.cellRange.col !== 0){
            args.cancel = true;
        }
    },
    onClipboardPasted: function (sender, args) {
        let me = contentOprObj;
        let items = sheetCommonObj.analyzePasteData(me.setting, args);
        let toSave = false;
        for(let i = 0, len = items.length; i < len; i++){
            let rowIdx = args.cellRange.row + i;
            //更新
            if(rowIdx < me.currentCache.length){
                toSave = true;
                me.updateContent(me.currentCache[rowIdx], items[i].content, false);
            }
        }
        if(toSave){
            me.save();
        }
    },
    onSelectionChanged: function (sender, args) {
        let me = contentOprObj;
        if(args.newSelections && args.newSelections.length > 0){
            me.initSelection(args.newSelections[0].row);
        }
    },
    initSelection: function (row) {
        let me = contentOprObj;
        let disObj = {jobAdd: false, jobInsert: true, jobDel: true, jobUp: true, jobDown: true};
        disObj.jobAdd = !pageCCOprObj.canAddType();
        if(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
            disObj.jobAdd = true;
            disObj.jobInsert = true;
            disObj.jobDel = true;
            disObj.jobUp = true;
            disObj.jobDown = true;
        }
        else{
            if(row !== -1){
                //在表内
                if(row < me.currentCache.length){
                    disObj.jobDel = false;
                    disObj.jobInsert = false;
                    if(row !== 0){
                        disObj.jobUp = false;
                    }
                    if(row !== me.currentCache.length - 1){
                        disObj.jobDown = false;
                    }
                }
            }
        }
        me.refreshTools(disObj);
    },
    //刷新工具条
    refreshTools: function (disObj) {
        for(let o in disObj){
            let jqSel = $(`#${o}`);
            jqSel.removeClass('disabled');
            if(disObj[o]){
                jqSel.addClass('disabled');
            }
        }
    },
    sortCache: function (cacheArr) {
        cacheArr.sort(function (a, b) {
            let rst = 0;
            if(a.serialNo > b.serialNo){
                rst = 1;
            }
            else if(a.serialNo < b.serialNo){
                rst = -1;
            }
            return rst;
        });
    },
    onContextmenuOpr: function () {//右键菜单
        let me = contentOprObj;
        $.contextMenu({
            selector: '#jobSpread',
            build: function($triggerElement, e){
                //控制允许右键菜单在哪个位置出现
                let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
                let sheet = me.workBook.getSheet(0);
                let addDis = pageCCOprObj.canAddType() ? false : true,  insertDis = false, delDis = false, upDis = false, downDis = false;
                if(target.hitTestType === 3){//在表格内&& typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
                    //清单锁定，不可用
                    if(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
                        addDis = true;
                        insertDis = true;
                        delDis = true;
                        upDis = true;
                        downDis = true;
                    }
                    else{
                        if(typeof target.row !== 'undefined'){
                            //控制按钮是否可用
                            sheet.setActiveCell(target.row, target.col);
                            if(!me.currentCache ||target.row >= me.currentCache.length){//右键定位在有数据的行，删除键才显示可用
                                insertDis = true;
                                delDis = true;
                                downDis = true;
                                upDis = true;
                            }
                            else{//有数据
                                if(typeof target.col === 'undefined'){//定位不在表格内
                                    insertDis = true;
                                    downDis = true;
                                    upDis = true;
                                    delDis = true;
                                }
                                else{//定位在表格内
                                    if(target.row === me.currentCache.length -1){//定位在最后一行，不可下移
                                        downDis = true;
                                    }
                                    if(target.row === 0){//定位在第一行,不可上移
                                        upDis = true;
                                    }
                                }
                            }
                        }
                        else{
                            insertDis = true;
                            delDis = true;
                            downDis = true;
                            upDis = true;
                        }
                    }
                    me.refreshTools({jobAdd: addDis, jobInsert: insertDis, jobDel: delDis, jobUp: upDis, jobDown: downDis});
                    return {
                        callback: function(){},
                        items: {
                            "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
                                me.insertContent(sheet, sheet.getActiveRowIndex(), '');
                            }},
                            "add": {name: "添加", disabled: addDis, icon: "fa-plus", callback: function (key, opt) {
                                me.insertContent(sheet, me.currentCache.length, '');
                            }},
                            "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
                                me.deleteContent(target.row);
                            }},
                            "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
                                me.upMove({row: target.row, col: target.col});

                            }},
                            "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
                                me.downMove({row: target.row, col: target.col});
                            }}
                        }
                    };
                }
                else{
                    me.refreshTools({jobAdd: addDis, jobInsert: insertDis, jobDel: delDis, jobUp: upDis, jobDown: downDis});
                    return false;
                }
            }
        });
    }
};


let characterOprObj = {
    workBook: null,
    currentCache: [],
    setting: {
        header: [
            {headerName:"项目特征",headerWidth:120, rateWidth:0.9, dataCode:"character", dataType: "String", hAlign: "left", vAlign: "center", formatter: '@'},
            {headerName:"特征值",headerWidth:160,dataCode:"eigenvalue", dataType: "String", cellType: "comboBox", hAlign: "left", vAlign: "center", formatter: '@'},
            {headerName:"输出",headerWidth:40,dataCode:"isChecked", cellType:"checkBox", hAlign: "center", vAlign: "center"}
        ]
    },
    buildSheet: function(container) {
        let me = characterOprObj;
        me.workBook = sheetCommonObj.buildSheet(container, me.setting, 30);
        //获取项目特征列比例
        let workBookWidth = pageCCOprObj.getWorkBookWidth();
        me.setRateWith(workBookWidth);
        sheetCommonObj.setColumnWidthByRate(workBookWidth, me.workBook, me.setting.header);
        me.workBook.options.allowUserDragDrop = false;
        me.workBook.getSheet(0).setColumnWidth(0, 20, GC.Spread.Sheets.SheetArea.rowHeader);
        me.workBook.options.allowCopyPasteExcelStyle = false;
        if(!projectReadOnly){
            me.onContextmenuOpr();
        }
        me.bindEvents(me.workBook);
    },
    setRateWith: function (workBookWidth) {
        let me = this;
        let otherWidthRate = (me.setting.header[1]['headerWidth'] + me.setting.header[2]['headerWidth']) / workBookWidth;
        let contentWidthRate = 1 - otherWidthRate;
        me.setting.header[0]['rateWidth'] = contentWidthRate;
    },
    bindEvents: function (workBook) {
        let sheet = workBook.getActiveSheet(), me = characterOprObj;
        const EVENTS = GC.Spread.Sheets.Events;
        workBook.bind(EVENTS.ButtonClicked, me.onButtonClicked);
        sheet.bind(EVENTS.EnterCell, me.onEnterCell);
        sheet.bind(EVENTS.ValueChanged, me.onValueChanged);
        sheet.bind(EVENTS.EditStarting, me.onEditStart);
        sheet.bind(EVENTS.ClipboardPasting, me.onClipboardPasting);
        sheet.bind(EVENTS.ClipboardPasted, me.onClipboardPasted);
        sheet.bind(EVENTS.SelectionChanged, me.onSelectionChanged);
        workBook.bind(EVENTS.RangeChanged, me.onRangeChanged);
        me.bindTools();
    },
    bindTools: function () {
        let me = characterOprObj;
        let sheet = me.workBook.getActiveSheet();
        $('#itemAdd').click(function () {
            me.insertCharacter(sheet, me.currentCache.length, '');
            me.workBook.focus();
        });
        $('#itemInsert').click(function(){
            me.insertCharacter(sheet, sheet.getActiveRowIndex(), '');
            me.workBook.focus();
        });
        $('#itemDel').click(function(){
            me.deleteCharacter(sheet.getActiveRowIndex());
            me.workBook.focus();
        });
        $('#itemUp').click(function(){
            me.upMove({row: sheet.getActiveRowIndex(), col: sheet.getActiveColumnIndex()});
            me.workBook.focus();
        });
        $('#itemDown').click(function(){
            me.downMove({row: sheet.getActiveRowIndex(), col: sheet.getActiveColumnIndex()});
            me.workBook.focus();
        });
    },
    //将从清单库中添加的清单，把标准清单的项目特征转化成清单的项目特征
    buildItemCharactet: function (items) {//从清单库过来的默认不输出
        let itemCharacter = [];
        for(let i = 0, len = items.length; i < len; i++){
            let newItem = {serialNo: i + 1, character: items[i].content, eigenvalue: [], isChecked: false};
            let eigenvalues = items[i].itemValue;
            for(let j = 0, len = eigenvalues.length; j < len; j++){
                let newValue = {value: eigenvalues[j].value, isSelected: false};
                newItem.eigenvalue.push(newValue);
            }
            itemCharacter.push(newItem);
        }
        return itemCharacter;
    },
    //显示在itemSpread的数据
    showCharacterData: function (sheet, setting, datas) {
        let me = characterOprObj;
        sheetCommonObj.showData(sheet, setting, datas);
        sheet.suspendPaint();
        sheet.suspendEvent();
        for(let i = 0, len = datas.length; i < len; i++){
            let comboObj = me.getComboBox(datas[i]);
            comboObj.combo.editable(false);//不可编辑
            sheet.getCell(i, 1).cellType(comboObj.combo).value(typeof comboObj.selectedValue !== 'undefined' ? comboObj.selectedValue : '');
            sheet.getCell(i, 0).locked(true);
        }
        sheet.resumePaint();
        sheet.suspendEvent();
    },
    //获得项目特征特征值comboBox
    getComboBox: function (characterItem) {
        let rst = {};
        let combo = sheetCommonObj.getDynamicCombo();
        let comboItems = [], eigenvalues = characterItem.eigenvalue;
        for(let i = 0, len = eigenvalues.length; i < len; i++){
            comboItems.push(eigenvalues[i].value);
            if(eigenvalues[i].isSelected){
                rst.selectedValue = eigenvalues[i].value;
            }
        }
        combo.items(comboItems);
        rst.combo = combo;
        return rst;
    },
    //获得当前行选中的特征值
    getCurrentSelected: function (item) {
        let rst = null;
        for(let i = 0, len = item.eigenvalue.length; i < len; i++){
            if(item.eigenvalue[i].isSelected){
                rst = item.eigenvalue[i].value;
                break;
            }
        }
        return rst;
    },
    //显示到清单项目特征列的数据
    getColData: function (itemsArr) {
        let me = characterOprObj;
        let rstStr = "", count = 0;
        for(let i = 0, len = itemsArr.length; i < len; i++){
            if(itemsArr[i].isChecked === true){
                //获取选中的特征值
                let eigenvalueStr = "";
                let eigenvalue = itemsArr[i].eigenvalue;
                for(let j = 0, vLen = eigenvalue.length; j < vLen; j++){
                    if(eigenvalue[j].isSelected){
                        eigenvalueStr += eigenvalue[j].value;
                        break;
                    }
                }
                count ++;
                /*if(count === 1){
                    rstStr += "“";
                }
                else{
                    rstStr += " ";
                }*/
                rstStr += count + ". " + itemsArr[i].character + ": " + eigenvalueStr + "\n";
            }
        }
        if(rstStr.trim().length > 0){
            let reg = /\n+$/g;
            let newStr = rstStr.replace(reg, "");
            return newStr;
        }
        return null;
    },
    addRow: function (idx, sheet) {
        let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox(),
            combo = new GC.Spread.Sheets.CellTypes.ComboBox();
        checkBox.isThreeState = false;
        combo.editable(true);
        sheet.addRows(idx, 1);
        sheet.getCell(idx, 1).cellType(combo);
        sheet.getCell(idx, 2).cellType(checkBox);
    },
    upMove: function (cell) {
        let me = characterOprObj;
        let thisObj = me.currentCache[cell.row],
            preObj = me.currentCache[cell.row - 1],
            temp;
        temp = thisObj.serialNo;
        thisObj.serialNo = preObj.serialNo;
        preObj.serialNo = temp;
        contentOprObj.sortCache(me.currentCache);
        me.save(function () {
            me.workBook.getSheet(0).setActiveCell(cell.row - 1, cell.col);
            me.workBook.focus();
            me.initSelection(cell.row - 1);
        });
    },
    downMove: function (cell) {
        let me = characterOprObj;
        let thisObj = me.currentCache[cell.row],
            nextObj = me.currentCache[cell.row + 1],
            temp;
        temp = thisObj.serialNo;
        thisObj.serialNo = nextObj.serialNo;
        nextObj.serialNo = temp;
        contentOprObj.sortCache(me.currentCache);
        me.save(function () {
            me.workBook.getSheet(0).setActiveCell(cell.row + 1, cell.col);
            me.workBook.focus();
            me.initSelection(cell.row + 1);
        });
    },
    deleteCharacter: function (rowIdx) {
        let me = characterOprObj;
        me.currentCache.splice(rowIdx, 1);
        me.save();
        me.workBook.focus();
    },
    //取消选择的特征值
    unsetSelected: function (item) {
        for(let i = 0, len = item.eigenvalue.length; i < len; i++){
            if(item.eigenvalue[i].isSelected){
                item.eigenvalue[i].isSelected = false;
            }
        }
    },
    //设置选中的特征值
    setSelected: function (item, value) {
        for(let i = 0, len = item.eigenvalue.length; i < len; i++){
            if(item.eigenvalue[i].value === value){
                item.eigenvalue[i].isSelected = true;
            }
        }
    },
    //改变选择特征值
    changeSelected: function (item, value) {
        let me = characterOprObj;
        me.unsetSelected(item);
        me.setSelected(item, value);

    },
    insertValue: function (item, value) {
        let me = characterOprObj;
        me.unsetSelected(item);
        let newValue = {value: value, isSelected: true};
        item.eigenvalue.push(newValue);
    },
    updateCharacter: function (item, character, value, save = true) {
        let me = characterOprObj;
        if(character !== undefined && character !== null){
            item.character = character;
        }
        if(value !== undefined && value !== null){
            if(value !== ''){
                let isExist = false;
                for(let i = 0, len = item.eigenvalue.length; i < len; i++){
                    if(item.eigenvalue[i].value === value){
                        isExist = true;
                        break;
                    }
                }
                //不存在，新增进eigenvalue,自动打勾输出
                if(!isExist){
                    //更新selected
                    me.insertValue(item, value);
                    item.isChecked = true;
                }
                //存在,选择特征值,自动打勾输出
                else{
                    me.changeSelected(item, value);
                    item.isChecked = true;
                }
            }
            else {
                me.unsetSelected(item);
            }
        }
        if(save){
            me.save();
        }
    },
    insertCharacter: function (sheet, idx, character) {
        let me = characterOprObj;
        me.addRow(idx, sheet);
        let newObj = {character: character, eigenvalue: [], isChecked: false};
        me.currentCache.splice(idx, 0, newObj);
        pageCCOprObj.resortNo(me.currentCache);
        me.save();
        me.workBook.focus();
    },
    save: function (callback) {
        let selectedNode = projectObj.mainController.tree.selected;
        const setting = projectObj.project.property.addRule !== undefined ? projectObj.project.property.addRule : getAddRuleSetting();
        pageCCOprObj.setCharacterBySetting(selectedNode, setting, callback, characterOprObj);
    },
    onEditStart: function (sender, args) {
        let me = characterOprObj;
        if(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
            args.cancel = true;
            return;
        }
        if(args.col === 1){//改变选择的特征值
            me.currentSelectedValue = me.currentCache.length > args.row ?  me.getCurrentSelected(me.currentCache[args.row]) : null;
        }
    },
    onEnterCell: function (sender, args) {
        args.sheet.repaint();
    },
    onValueChanged: function (sender, args) {
        let me = characterOprObj;
        args.newValue = args.newValue ? args.newValue : '';
        //更新
        if(args.row < me.currentCache.length){
            let thisCha = me.currentCache[args.row];
            if(args.col === 0){//特征
                me.updateCharacter(thisCha, args.newValue, null);
            }
            else if(args.col === 1){//特征值
                me.updateCharacter(thisCha, null, args.newValue);
            }
        }
    },
    onClipboardPasting: function (sender, args) {
        if(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
            args.cancel = true;
        }
        if(args.cellRange.col + args.colCount - 1 > 1){
            args.cancel = true;
        }
    },
    onClipboardPasted: function (sender, args) {
        let me = characterOprObj;
        let items = sheetCommonObj.analyzePasteData(me.setting, args);
        let toSave = false;
        for(let i = 0, len = items.length; i < len; i++){
            //更新
            let rowIdx = args.cellRange.row + i;
            if(me.currentCache.length > rowIdx){
                toSave = true;
               me.updateCharacter(me.currentCache[rowIdx], items[i].character, items[i].eigenvalue, false);
            }
        }
        if(toSave){
            me.save();
        }
    },
    onRangeChanged: function (sender, args) {
        let me = characterOprObj;
        let rangeCell = isDef(args.changedCells[0]) ? args.changedCells[0] : null;
        if(!rangeCell){
            return;
        }
        let rangeData = isDef(me.currentCache[rangeCell.row]) ? me.currentCache[rangeCell.row] : null;
        if(!rangeData){
            return;
        }
        if(rangeCell.col === 0){//特征
            me.updateCharacter(rangeData, '', null);
        }
        else if(rangeCell.col === 1){//特征值
            me.updateCharacter(rangeData, null, '');
        }
        else if(rangeCell.col === 2){
            rangeData.isChecked = false;
            me.save();
        }
        /*if(rangeCell.col === 1){//特征值
            rangeData.isChecked = false;
            for(let value of rangeData.eigenvalue){
                value.isSelected = false;
            }
        }*/
        //me.save();
    },
    //复选框控制输出
    onButtonClicked: function (sender, args) {
        let me = characterOprObj, characterTxt;
        if(args.sheet.isEditing()){
            args.sheet.endEdit(true);
        }
        let isChecked = args.sheet.getValue(args.row, args.col);
        // 锁定清单值不变
        if(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
            args.sheet.setValue(args.row, args.col, !isChecked);
            return;
        }
        if(me.currentCache.length > args.row){
            me.currentCache[args.row].isChecked = isChecked;
            me.save();
        }
        //else的情况就是新增
        else{
            args.sheet.setValue(args.row, args.col, 0);
        }
    },
    onSelectionChanged: function (sender, args) {
        let me = characterOprObj;
        if(args.newSelections && args.newSelections.length > 0){
            me.initSelection(args.newSelections[0].row);
        }
    },
    initSelection: function (row) {
        let me = characterOprObj;
        let disObj = {itemAdd: false, itemInsert: true, itemDel: true, itemUp: true, itemDown: true};
        disObj.itemAdd = !pageCCOprObj.canAddType();
        //清单锁定，不可用
        if(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
            disObj.itemAdd = true;
            disObj.itemInsert = true;
            disObj.itemDel = true;
            disObj.itemUp = true;
            disObj.itemDown = true;
        }
        else{
            if(row !== -1){
                //在表内
                if(row < me.currentCache.length){
                    disObj.itemDel = false;
                    disObj.itemInsert = false;
                    if(row !== 0){
                        disObj.itemUp = false;
                    }
                    if(row !== me.currentCache.length - 1){
                        disObj.itemDown = false;
                    }
                }
            }
        }
        me.refreshTools(disObj);
    },
    //刷新工具条
    refreshTools: function (disObj) {
        for(let o in disObj){
            let jqSel = $(`#${o}`);
            jqSel.removeClass('disabled');
            if(disObj[o]){
                jqSel.addClass('disabled');
            }
        }
    },
    onContextmenuOpr: function () {//右键菜单
        let me = characterOprObj;
        $.contextMenu({
            selector: '#itemSpread',
            build: function($triggerElement, e){
                //控制允许右键菜单在哪个位置出现
                let target = SheetDataHelper.safeRightClickSelection($triggerElement, e, me.workBook);
                let sheet = me.workBook.getSheet(0);
                let addDis = pageCCOprObj.canAddType() ? false : true, insertDis = false, delDis = false, upDis = false, downDis = false;
                if(target.hitTestType === 3){//在表格内 && typeof target.row !== 'undefined' && typeof target.col !== 'undefined'
                    //清单锁定，则不可用
                    if(projectObj.project.projectInfo.property.lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
                        addDis = true;
                        insertDis = true;
                        delDis = true;
                        upDis = true;
                        downDis = true;
                    }
                    else{
                        if(typeof target.row !== 'undefined'){
                            //控制按钮是否可用
                            sheet.setActiveCell(target.row, target.col);
                            if(!me.currentCache ||target.row >= me.currentCache.length){//右键定位在有数据的行，删除键才显示可用
                                insertDis = true;
                                delDis = true;
                                downDis = true;
                                upDis = true;
                            }
                            else{//有数据
                                if(typeof target.col === 'undefined'){//定位在表格外
                                    insertDis = true;
                                    downDis = true;
                                    upDis = true;
                                    delDis = true;
                                }
                                else{
                                    if(target.row === me.currentCache.length -1){//定位在最后一行，不可下移
                                        downDis = true;
                                    }
                                    if(target.row === 0){//定位在第一行,不可上移
                                        upDis = true;
                                    }
                                }
                            }
                        }
                        else{
                            insertDis = true;
                            delDis = true;
                            downDis = true;
                            upDis = true;
                        }
                    }
                    me.refreshTools({itemAdd: addDis, itemInsert: insertDis, itemDel: delDis, itemUp: upDis, itemDown: downDis});
                    return {
                        callback: function(){},
                        items: {
                            "insert": {name: "插入", disabled: insertDis, icon: "fa-sign-in", callback: function (key, opt) {
                                me.insertCharacter(sheet, sheet.getActiveRowIndex(), '');
                            }},
                            "add": {name: "添加", disabled: addDis, icon: "fa-plus", callback: function (key, opt) {
                                me.insertCharacter(sheet, me.currentCache.length, '');
                            }},
                            "delete": {name: "删除", disabled: delDis, icon: "fa-remove", callback: function (key, opt) {
                                me.deleteCharacter(target.row);
                            }},
                            "upMove": {name: "上移", disabled: upDis, icon: "fa-arrow-up", callback: function (key, opt) {
                                me.upMove({row: target.row, col: target.col});
                            }},
                            "downMove": {name: "下移", disabled: downDis, icon: "fa-arrow-down", callback: function (key, opt) {
                                me.downMove({row: target.row, col: target.col});
                            }}
                        }
                    };
                }
                else{
                    me.refreshTools({jobAdd: addDis, jobInsert: insertDis, jobDel: delDis, jobUp: upDis, jobDown: downDis});
                    return false;
                }
            }
        });
    }
};

let pageCCOprObj = {
    currentFindSet: null,
    mainActiveCell: null,//mainSpread焦点单元格
    nameCache: '',
    //重新赋serialNo
    resortNo: function (items) {
        let count = 1;
        for(let item of items){
            item.serialNo = count++;
        }
    },
    //可以添加的类型：分项、补项、清单
    canAddType: function () {
        let rst = false;
        let selectedNode = projectObj.mainController.tree.selected;
        if(selectedNode && selectedNode.sourceType === projectObj.project.Bills.getSourceType() &&
            (selectedNode.data.type === billType.FX || selectedNode.data.type === billType.BX || selectedNode.data.type === billType.BILL)){//为清单
            rst = true
        }
        return rst;

    },
    setItemContentNode: function (node, jobs, items, name = '') {
        let theCont = contentOprObj, theCha = characterOprObj,
            jobContent, itemCharacter, contentTxt, characterTxt;
        jobContent = theCont.buildJobContent(jobs);
        itemCharacter = theCha.buildItemCharactet(items);
        // contentTxt = theCont.getColData(jobContent);
        // characterTxt = theCha.getColData(itemCharacter);
        node.data.jobContent = jobContent;
        node.data.itemCharacter = itemCharacter;
        this.nameCache = name;
        // 根据规则设置对应特征、内容、名称格式
        const setting = projectObj.project.property.addRule !== undefined ? projectObj.project.property.addRule : getAddRuleSetting();
        const updateData = pageCCOprObj.getCharacterUpdateData(setting, node);
        node.data.jobContentText = updateData.jobContentText;
        node.data.itemCharacterText = updateData.itemCharacterText;
        node.data.name = updateData.name;
    },
    safeItemCharater: function (itemCharater) {
        return characterOprObj.buildItemCharactet(itemCharater);
    },
    //设置特征及内容currentCache
    setCacheAndShow: function (node) {
        if(!projectReadOnly){
            this.refreshRuleTools(projectObj.project.isBillsLocked());
        }
        if(node && node.sourceType === projectObj.project.Bills.getSourceType()){
            let theCont = contentOprObj, theCha = characterOprObj;
            node.data.jobContent = node && typeof node.data.jobContent !== 'undefined' ? node.data.jobContent : [];
            node.data.itemCharacter = node && typeof node.data.itemCharacter !== 'undefined' ? node.data.itemCharacter : [];
            theCont.currentCache =  node.data.jobContent;
            theCha.currentCache = node.data.itemCharacter;
            this.currentFindSet = node && typeof node.data.ID !== 'undefined' && typeof node.data.projectID ? {ID: node.data.ID, projectID: node.data.projectID} : null;
            this.showData(theCont.workBook.getSheet(0), theCont.setting, theCont.currentCache);
            this.showData(theCha.workBook.getSheet(0), theCha.setting, theCha.currentCache);
        }
        else{
            this.clearData();

        }
    },
    //contentSpread、itemSpread展示数据用
    showData: function(sheet, setting, data) {
        let me = this, ch = GC.Spread.Sheets.SheetArea.viewport;
        sheet.suspendPaint();
        sheet.suspendEvent();
        sheet.clear(0, 0, sheet.getRowCount(), sheet.getColumnCount(), GC.Spread.Sheets.SheetArea.viewport, GC.Spread.Sheets.StorageType.data);
        sheet.setRowCount(data.length);
        for (let col = 0; col < setting.header.length; col++) {
            var hAlign = "left", vAlign = "center";
            if (setting.header[col].hAlign) {
                hAlign = setting.header[col].hAlign;
            } else if (setting.header[col].dataType !== "String"){
                hAlign = "right";
            }
            vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign;
            sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign);
            if (setting.header[col].formatter) {
                sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport);
            }
            for (let row = 0; row < data.length; row++) {
                sheet.getCell(row, 0).locked(true);//locked
                let val = data[row][setting.header[col].dataCode];
                if(setting.header[col].cellType === "checkBox"){
                    let checkBox = new GC.Spread.Sheets.CellTypes.CheckBox();
                    checkBox.isThreeState(false);
                    sheet.getCell(row, col).cellType(checkBox).value(val);
                }
                else if(setting.header[col].cellType === 'comboBox'){
                    let comboObj = characterOprObj.getComboBox(data[row]);
                    comboObj.combo.editable(true);//可编辑
                    sheet.getCell(row, 1).cellType(comboObj.combo).value(typeof comboObj.selectedValue !== 'undefined' ? comboObj.selectedValue : '');
                }
                else{
                    sheet.setValue(row, col, val, ch);
                }
                sheet.getCell(row, col).wordWrap(true);
                sheet.autoFitRow(row);
            }
        }
        contentOprObj.initSelection(contentOprObj.workBook.getSheet(0).getActiveRowIndex());
        characterOprObj.initSelection(characterOprObj.workBook.getSheet(0).getActiveRowIndex());
        sheet.resumeEvent();
        sheet.resumePaint();
    },
    clearData: function () {
        let theCon = contentOprObj, theCha = characterOprObj;
        theCon.workBook.getSheet(0).setRowCount(0);
        theCon.refreshTools({jobAdd: true, jobInsert: true, jobDel: true, jobUp: true, jobDown: true});
        theCha.workBook.getSheet(0).setRowCount(0);
        theCha.refreshTools({itemAdd: true, itemInsert: true, itemDel: true, itemUp: true, itemDown: true});
        sheetCommonObj.cleanSheet(theCon.workBook.getSheet(0), theCon.setting, -1);
        sheetCommonObj.cleanSheet(theCha.workBook.getSheet(0), theCha.setting, -1);

        projectObj.mainSpread.focus(true);
    },
    //锁定/解锁清单后添加规则的改变
    refreshRuleTools: function (lockBills) {
        $('#use-to-current').removeClass('disabled');
        $('#use-to-all').removeClass('disabled');
        if(lockBills && projectObj.project.withinBillsLocked(projectObj.project.mainTree.selected)){
            $('#use-to-current').addClass('disabled');
            $('#use-to-all').addClass('disabled');
        }

    },
    //更新特征及内容数据
    updateCharacterContent: function (findSet, updateObj, txtObj, oprObj, callback) {
        let me = pageCCOprObj, updateCol;
        if(txtObj){
            updateCol = txtObj.field === 'itemCharacterText' ? 4 : 5;//更新清单行特征列或内容列
        }
        else{
            updateCol = null;
        }
        let url = '/bills/updateCharacterContent';
        let postData = {
            findSet: findSet,
            updateObj: updateObj,
            txtObj: txtObj
        };
        CommonAjax.post(url, postData, function (rstData) {
            //更新节点数据
            if(updateCol){
                // 已当前选中行更新数据
                let selectedNode = projectObj.mainController.tree.selected;
                selectedNode.data[updateObj.field] = updateObj.updateArr;
                selectedNode.data[txtObj.field] = txtObj.text;
                me.showData(oprObj.workBook.getSheet(0), oprObj.setting, oprObj.currentCache);//刷新特征及内容Spread

                let activeCell = projectObj.mainSpread.getActiveSheet().getSelections()[0];
                projectObj.mainSpread.getActiveSheet().setValue(activeCell.row, updateCol, txtObj.text + ''); //刷新输出显示
                projectObj.mainSpread.getActiveSheet().autoFitRow(activeCell.row);
                if(callback){
                    callback();
                }
            }
        });
    },
    /**
     * 更新bill数据
     *
     * @param {Object} findSet - 更新条件
     * @param {Object} updateData - 更新数据
     * @param {Function} callback - 回调函数
     * @return {void}
     */
    updateBill: function(findSet, updateData, callback) {
        if (!updateData instanceof Array || updateData.length <= 0) {
            return;
        }
        let url = '/bills/updateBill';
        let postData = { findSet, updateData };
        CommonAjax.post(url, postData, function (response) {
            callback(response);
        });
    },
    /**
     * 刷新节点数据
     *
     * @param {Object} node - 节点数据
     * @param {Object} refreshData - 刷新的数据
     * @return {void}
     */
    refreshView: function(node, refreshData) {
        // 更新清单行特征列或内容列
        let updateCol = [
            { name: 'itemCharacterText', col: colSettingObj.getColByField('itemCharacterText')},
            { name: 'jobContentText', col: colSettingObj.getColByField('jobContentText')},
            { name: 'name', col: colSettingObj.getColByField('name')}
        ];
        if (updateCol === '') {
            return;
        }
        const row = node.serialNo();
        // 刷新输出显示
        for (const tmp of updateCol) {
            // 没有默认的数据则跳过刷新
            if (refreshData[tmp.name] === undefined) {
                continue;
            }
            projectObj.mainSpread.getActiveSheet().setValue(row, tmp.col, refreshData[tmp.name] + '');
        }
        projectObj.mainSpread.getActiveSheet().autoFitRow(row);
    },
    bulkSetCharacterBySetting: function(nodes, setting) {
        $.bootstrapLoading.start();
        let me = this;
        let updateDatas = [];
        let updateNodes = [];
        let updateMapping = {};
        for(let node of nodes){
            if(!node || node.sourceType !== projectObj.project.Bills.getSourceType()){
                continue;
            }
            let findSet = {ID: node.data.ID, projectID: node.data.projectID};
            let updateData = this.getCharacterUpdateData(setting, node);
            updateData.jobContent = node.data.jobContent;
            updateData.itemCharacter = node.data.itemCharacter;
            let orgName = isDef(node.data.name) ? node.data.name : '';
            let orgItemCharacterText = isDef(node.data.itemCharacterText) ? node.data.itemCharacterText : '';
            let orgJobContentText = isDef(node.data.jobContentText) ? node.data.jobContentText : '';
            if(orgName == updateData.name && orgItemCharacterText == updateData.itemCharacterText && orgJobContentText == updateData.jobContentText){
                continue;
            }
            updateMapping[node.data.ID] = updateData;
            updateNodes.push(node);
            updateDatas.push({findSet: findSet, updateData: updateData});
        }
        if(updateDatas.length > 0){
            CommonAjax.post('/bills/updateBills', {updateDatas: updateDatas}, function (rstData) {
                for(let node of updateNodes){
                    let mainSheet = projectObj.mainSpread.getActiveSheet();
                    mainSheet.suspendPaint();
                    mainSheet.suspendEvent();
                    me.refreshView(node, updateMapping[node.data.ID]);
                    node.data.name = updateMapping[node.data.ID]['name'];
                    node.data.itemCharacterText = updateMapping[node.data.ID]['itemCharacterText'];
                    node.data.jobContentText = updateMapping[node.data.ID]['jobContentText'];
                    mainSheet.resumePaint();
                    mainSheet.resumeEvent();
                }
                $.bootstrapLoading.end();
            }, function () {
                $.bootstrapLoading.end();
            });
        }
        else {
            $.bootstrapLoading.end();
        }
    },
    /**
     * 根据配置设置清单项目特征
     *
     * @param {Object} node - 选中的node节点
     * @param {Object} setting - 设置
     * @return {void}
     */
    setCharacterBySetting: function(node, setting, callback = null, oprObj = null, usedToAll = null) {
        if(!node || node.sourceType !== projectObj.project.Bills.getSourceType()){
            return;
        }
        let self = this;

        // 保存的条件数据
        const findSet = { ID: node.data.ID, projectID: node.data.projectID };
        const updateData = this.getCharacterUpdateData(setting, node);

        let saveObj = [];
        for (const index in updateData) {
            saveObj.push({field: index, value: updateData[index]});
        }
        //saveObj.push({field: 'addRule', value: setting});
        saveObj.push({field: 'jobContent', value: node.data.jobContent});
        saveObj.push({field: 'itemCharacter', value: node.data.itemCharacter});
        if(usedToAll){
            //应用到所有清单、过滤，只更新会发生变化的清单
            let orgName = isDef(node.data.name) ? node.data.name : '';
            let orgItemCharacterText = isDef(node.data.itemCharacterText) ? node.data.itemCharacterText : '';
            let orgJobContentText = isDef(node.data.jobContentText) ? node.data.jobContentText : '';
            if(orgName == updateData.name && orgItemCharacterText == updateData.itemCharacterText && orgJobContentText == updateData.jobContentText){
                return;
            }
        }
        // 更新到数据库
        pageCCOprObj.updateBill(findSet, saveObj, function(response) {
            self.refreshView(node, updateData);
            // 更新项目属性的配置
            //projectObj.project.property.addRule = setting;
            // 更新节点数据
            node.data.name = updateData.name;
            node.data.itemCharacterText = updateData.itemCharacterText;
            node.data.jobContentText = updateData.jobContentText;
            if (oprObj) {
                pageCCOprObj.showData(oprObj.workBook.getSheet(0), oprObj.setting, oprObj.currentCache);//刷新特征及内容Spread
            }
            if(callback){
                callback();
            }
        });

    },
    /**
     * 格式化序号格式
     *
     * @param {Number} type - 格式化的类型
     * @param {String} serialNo - 待格式化的序号
     * @return {String} - 返回格式化后的字符
     */
    formatSerialNumber: function(type, serialNo) {
        const letter = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
            's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
        switch (type) {
            case '1':
                // 数字
                serialNo = serialNo + '. ';
                break;
            case '2':
                // 英文字母(小写)
                serialNo = letter[serialNo - 1] !== undefined ? letter[serialNo - 1] + '. ' : '';
                break;
            case '3':
                // 英文字母(大写)
                serialNo = letter[serialNo - 1] !== undefined ? letter[serialNo - 1].toUpperCase() + '. ' : '';
                break;
            default:
                serialNo = '';
                break;
        }
        return serialNo;
    },
    /**
     * 查找选中的树节点中定额子目数据
     *
     * @param {Object} selectNode - 选中的节点
     * @param {Object} setting - 设置
     * @return {Array} - 返回定额子目数组
     */
    getRationChapter: function(selectNode, setting) {
        let result = [];
        if (selectNode.children === undefined || selectNode.children.length <= 0) {
            return result;
        }
        // 查找对应的定额数据
        let count = 1;
        for (const tmp of selectNode.children) {
            if (tmp.sourceType !== 'ration') {
                continue;
            }
            const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
            if(setting.childDisplayFormat === '1'){
            }
            let code = isDef(tmp.data.code) ? tmp.data.code : '';
            let name = isDef(tmp.data.name) ? tmp.data.name : '';
            setting.childDisplayFormat === "1" ? result.push(code + ':' + name) : result.push(serialNo + name);
            count++;
        }

        return result;
    },
    /**
     * 获取默认数据
     *
     * @param {Object} node - 节点数据
     * @param {Object} setting - 设置
     * @return {Object}
     */
    getDataBySetting: function(node, setting) {
        let result = {};
        try {
            if (node.data === undefined) {
                throw '数据错误';
            }
            const itemCharacter = node.data.itemCharacter;
            const itemJob = node.data.jobContent;
         /*   if (itemCharacter === undefined || itemCharacter.length <= 0 || itemJob === undefined || itemJob.length <= 0) {
                throw '内部数据错误';
            }*/
            if (itemCharacter === undefined || itemJob === undefined) {
                throw '内部数据错误';
            }
            // 默认名称
            result['name'] = this.nameCache;

            // 特征
            let characterArray = [];
            let count = 1;
            for (const tmp of itemCharacter) {
                if (!tmp.isChecked) {
                    continue;
                }
                if(tmp.eigenvalue === undefined || tmp.eigenvalue.length <= 0){
                    tmp.eigenvalue = [];
                }
                // 获取选中的特征值
                let selectedEigen = '';
                for (const eigen of tmp.eigenvalue) {
                    if (eigen.isSelected) {
                        selectedEigen = eigen.value;
                    }
                }
                // 匹配设置的序号格式
                const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
                let characterString = '';
                // 特征生成方式
                switch (setting.characterFormat) {
                    case '1':
                        // 特征值
                        characterString = serialNo + selectedEigen;
                        break;
                    case '2':
                        // 特征:特征值
                        characterString = serialNo + tmp.character + ': ' + selectedEigen;
                        break;
                }
                characterArray.push(characterString);
                count++;
            }
            result['character'] = characterArray;

            // 内容部分
            let jobArray = [];
            count = 1;
            for (const tmp of itemJob) {
                if (!tmp.isChecked) {
                    continue;
                }
                // 匹配设置的序号格式
                const serialNo = this.formatSerialNumber(setting.serialType, count.toString());
                jobArray.push(serialNo + tmp.content);
                count++;
            }
            result['content'] = jobArray;
        } catch (error) {
            console.log(error);
            result = {};
        }
        return result;
    },

    /**
     * 获取特征内容名称更新的数据
     *
     * @param {Object} setting - 设置
     * @param {Object} node - 节点数据
     * @return {Object} - 返回更新的数据
     */
    getCharacterUpdateData: function(setting, node) {
        let updateData = {
            itemCharacterText: '',
            jobContentText: '',
            name: node.data.name ? node.data.name : '',
        };
        /* let updateData = {
            itemCharacterText: '',
            jobContentText: '',
            name: '',
        };*/
        if(!node.data.itemCharacter){
            node.data.itemCharacter = [];
        }
        if(!node.data.jobContent){
            node.data.jobContent = [];
        }
        if(setting.addContent !== '5'){
            if (node.data.name === undefined || (node.data.itemCharacter.length <= 0 && node.data.jobContent.length <= 0)) {
                return updateData;
            }
        }
        // 获取原名称
        const name = isDef(node.data.name) ? node.data.name.split("\n") : '';
        this.nameCache = name[0] !== undefined ? name[0] : "";
        updateData.name = this.nameCache;

        let contentArray = [];

        // 获取当前设置数据
        const currentData = this.getDataBySetting(node, setting);

        // 组合数据
        let content = '';
        switch (setting.addContent) {
            case "1":
                // 项目特征+工作内容
                contentArray.push('[项目特征]');
                contentArray.push.apply(contentArray, currentData.character);
                contentArray.push('[工作内容]');
                contentArray.push.apply(contentArray, currentData.content);
                break;
            case "2":
                // 工作内容+项目特征
                contentArray.push('[工作内容]');
                contentArray.push.apply(contentArray, currentData.content);
                contentArray.push('[项目特征]');
                contentArray.push.apply(contentArray, currentData.character);
                break;
            case "3":
                // 项目特征
                contentArray.push.apply(contentArray, currentData.character);
                break;
            case "4":
                // 工作内容
                contentArray.push.apply(contentArray, currentData.content);
                break;
            case "5":
                // 定额子目
                const rationChapter = this.getRationChapter(node, setting);
                contentArray.push.apply(contentArray, rationChapter);
                break;
            case "":
                // 无
                break;
        }
        // 显示格式
        switch (setting.displayFormat) {
            case "1":
                // 换行分隔
                content = contentArray.join("\n");

                currentData.character = currentData.character.join("\n");
                currentData.content = currentData.content.join("\n");
                break;
            case "2":
                // 逗号分隔
                content = contentArray.join(',');

                currentData.character = currentData.character.join("，");
                currentData.content = currentData.content.join("，");
                break;
            case "3":
                // 括号分隔
                content = '(' + contentArray.join(',') + ')';
                break;
        }
        // 添加到对应位置
        switch (setting.position) {
            case "1":
                // 添加到项目特征列
                updateData.itemCharacterText = content;
                break;
            case "2":
                // 添加到清单名称列
                content = content !== '' ? this.nameCache + "\n" + content : this.nameCache;
                updateData.name = content;
                break;
            case "3":
                // 添加到工作内容列
                updateData.jobContentText = content;
                break;
            case "4":
                updateData = {
                    itemCharacterText: currentData.character,
                    jobContentText: currentData.content,
                    name: currentData.name,
                };
                break;
        }

        return updateData;
    },
    //获取特征及内容工作簿宽度
    getWorkBookWidth: function () {
        return ($(window).width() - $('.main-nav').width() - $('.main-side').width()) / 3 - 50;
    },
    resizeWidth: function () {
        let workBookWidth = pageCCOprObj.getWorkBookWidth();
        contentOprObj.setRateWith($('#jobDiv').width() - 45);
        sheetCommonObj.setColumnWidthByRate($('#jobDiv').width() - 55, contentOprObj.workBook, contentOprObj.setting.header);
        characterOprObj.setRateWith($('#itemDiv').width() - 45);
        sheetCommonObj.setColumnWidthByRate($('#itemDiv').width() - 48, characterOprObj.workBook, characterOprObj.setting.header);
    }
}

/*
$(window).resize(function () {
    pageCCOprObj.resizeWidth();
});*/
