| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590 | /** * Created by Zhong on 2017/12/18. */let pageOprObj = {    rationLibName : null,    rationLibId : null,    gljLibId: gljLibId,    rationTreeData: null,    mixedTreeData: null,    mixedGLJData: null,    initPage : function() {        sectionTreeObj.getSectionTree(this.rationTreeData);        //job        jobContentOprObj.radiosChange(jobContentOprObj.radios, jobContentOprObj.tableAll, jobContentOprObj.tablePartial);        $('#addConBtn').click(jobContentOprObj.bindAddConBtn());        $('#updateConBtn').click(jobContentOprObj.bindUpdateConBtn());        jobContentOprObj.bindAllEvents($('#txtareaAll'));        //fz        annotationOprObj.radiosChange(annotationOprObj.radios, annotationOprObj.fzTableAll, annotationOprObj.fzTablePartial);        $('#fzAddConBtn').click(annotationOprObj.bindAddConBtn());        $('#fzUpdateConBtn').click(annotationOprObj.bindUpdateConBtn());        annotationOprObj.bindAllEvents($('#fzTxtareaAll'));    },    getRationLibInfo: function (rationLibId, callback) {        CommonAjax.post('/complementaryRation/api/getRationLib', {rationRepId: rationLibId}, callback);    },};let sectionTreeObj = {    cache: null,//ref to tree.items    tree: null,    controller: null,    workBook: null,    sheet: null,    updateType: {new: 'new', update: 'update'},    insertBtn: $('#tree_Insert'),    removeBtn: $('#tree_remove'),    upLevelBtn: $('#tree_upLevel'),    downLevelBtn: $('#tree_downLevel'),    downMoveBtn: $('#tree_downMove'),    upMoveBtn: $('#tree_upMove'),    type: {std: 'std', complementary: 'complementary'},    setting: {        sheet: {            cols:[                {                    head: {                        titleNames: ['名称'],                        spanCols: [1],                        spanRows: [2],                        vAlign: [1, 1],                        hAlign: [1, 1],                        font: 'Arial'                    },                    data: {                        field: 'name',                        vAlign: 1,                        hAlign: 0,                        font: 'Arial'                    },                    width: 400                }            ],            headRows: 1,            headRowHeight: [47],            emptyRows: 0,            treeCol: 0        },        tree: {            id: 'ID',            pid: 'ParentID',            nid: 'NextSiblingID',            rootId: -1        },        options: {            allowContextMenu: false,            tabStripVisible:  false,            allowCopyPasteExcelStyle : false,            allowExtendPasteRange: false,            allowUserDragDrop : false,            allowUserDragFill: false,            scrollbarMaxAlign : true        }    },    isDef: function (v) {        return v !== undefined && v !== null;    },    isFunc: function (v) {        return this.isDef(v) && typeof v === 'function';    },    //sheet things    setOptions: function (workbook, opts) {        for(let opt in opts){            workbook.options[opt] = opts[opt];        }    },    renderFunc: function (sheet, func) {        sheet.suspendPaint();        sheet.suspendEvent();        if(this.isFunc(func)){            func();        }        sheet.resumePaint();        sheet.resumeEvent();    },    buildSheet: function () {        if(!this.isDef(this.workBook)){            this.workBook = new GC.Spread.Sheets.Workbook($('#sectionSpread')[0], {sheetCount: 1});            sheetCommonObj.spreadDefaultStyle(this.workBook);            sheetCommonObj.bindEscKey(this.workBook, [{sheet: this.workBook.getSheet(0), editStarting: this.onEditStarting, editEnded: this.onEditEnded}]);            this.sheet = this.workBook.getSheet(0);            this.bindEvents(this.sheet);            this.setOptions(this.workBook, this.setting.options);            this.sheet.options.clipBoardOptions = GC.Spread.Sheets.ClipboardPasteOptions.values;        }    },    bindEvents: function (sheet) {        let me = sectionTreeObj;        const Events = GC.Spread.Sheets.Events;        sheet.bind(Events.SelectionChanging, me.onSelectionChanging);        sheet.bind(Events.EditEnded, me.onEditEnded);        sheet.bind(Events.EditStarting, me.onEditStarting);        sheet.bind(Events.ClipboardPasting, me.onClipboardPasting);        sheet.bind(Events.ClipboardPasted, me.onClipboardPasted);    },    onSelectionChanging: function (sender, info) {        let me = sectionTreeObj;        if(info.oldSelections.length === 0 && info.newSelections.length > 0 || info.oldSelections[0].row !== info.newSelections[0].row){            let row = info.newSelections[0].row;            let section = me.cache[row];            me.initSelection(section);        }        else {            me.refreshBtn(null);        }    },    onEditStarting: function (sender, args) {    },    onEditEnded: function (sender, args) {        let me = sectionTreeObj;        let postData = [];        let v = me.isDef(args.editingText) ? args.editingText.toString().trim() : '';        let node = me.cache[args.row];        if(me.isDef(node) && node.data.name !== v){            let updateObj = me.getUpdateObj(me.updateType.update, {ID: node.getID(), name: v});            postData.push(updateObj);            //ajax            //update            me.sectionTreeAjax(postData, function (rstData) {                node.data.name = v;            }, function () {                args.sheet.setValue(args.row, args.col, node.data.name ? node.data.name : '');            });        }    },    onClipboardPasting: function (sender, info) {    },    onClipboardPasted: function (sender, info) {        let me = sectionTreeObj;        let items = sheetCommonObj.analyzePasteData({header: [{dataCode: 'name'}]}, info);        let postData = [];        let frontData = [];        for(let i = 0, len = items.length; i < len; i++){            let row = info.cellRange.row + i;            let node = me.cache[row];            if(me.isDef(node) && me.isDef(items[i].name) && node.data.name !== items[i].name){                let updateObj = me.getUpdateObj(me.updateType.update, {ID: node.getID(), name: items[i].name});                postData.push(updateObj);                frontData.push({row: row, name: items[i].name});                node.data.name = items[i].name;            }        }        if(postData.length > 0){            //ajax            me.sectionTreeAjax(postData, function (rstData) {                for(let i = 0, len = frontData.length; i < len; i++){                    let node = me.cache[frontData[i]['row']];                    if(me.isDef(node)){                        node.data.name = frontData[i]['name'];                    }                }            }, function () {                for(let i = 0, len = frontData.length; i < len; i++){                    let node = me.cache[frontData[i]['row']];                    me.sheet.setValue(frontData[i]['row'], 0, me.isDef(node) ? node.data.name : '');                }            });        }    },    loadRateWidth: function () {        if (this.workBook) {            sheetCommonObj.setColumnWidthByRate($('#sectionSpread').width() - 65, this.workBook, [{rateWidth: 1}]);//65: 列头宽度和垂直滚动条宽度和        }    },    getSectionTree: function (treeData) {        //init        this.buildSheet();        this.initTree(treeData);        this.cache = this.tree.items;        this.bindBtn();        this.initController(this.tree, this.sheet, this.setting.sheet);        this.controller.showTreeData();        this.setColor(this.cache);        this.sheet.setFormatter(-1, 0, '@');        this.initSelection(this.tree.selected);        this.loadRateWidth();    },    setColor: function (nodes) {        let me = this;        me.renderFunc(me.sheet, function () {            for(let i = 0, len = nodes.length; i < len; i++){                if(nodes[i].data.type === me.type.complementary){                    me.sheet.getCell(i, 0).foreColor('gray');                }            }        });    },    initTree: function (datas) {        this.tree = idTree.createNew(this.setting.tree);        this.tree.loadDatas(datas);        this.tree.selected = this.tree.items.length > 0 ? this.tree.items[0] : null;    },    initController: function (tree, sheet, setting) {        this.controller = TREE_SHEET_CONTROLLER.createNew(tree, sheet, setting);    },        refreshBtn: function (selected) {        if (isReadOnly) {            return;        }        let me = this;        me.insertBtn.removeClass('disabled');        me.removeBtn.removeClass('disabled');        me.upLevelBtn.removeClass('disabled');        me.downLevelBtn.removeClass('disabled');        me.downMoveBtn.removeClass('disabled');        me.upMoveBtn.removeClass('disabled');        if(!me.isDef(selected)){            me.removeBtn.addClass('disabled');            me.upLevelBtn.addClass('disabled');            me.downLevelBtn.addClass('disabled');            me.downMoveBtn.addClass('disabled');            me.upMoveBtn.addClass('disabled');        }        else {            if(!me.isDef(selected.preSibling)){                me.downLevelBtn.addClass('disabled');                me.upMoveBtn.addClass('disabled');            }            if(!me.isDef(selected.nextSibling)){                me.downMoveBtn.addClass('disabled');            }            if(!me.isDef(selected.parent)){                me.upLevelBtn.addClass('disabled');            }        }    },        bindBtn: function () {        let me = this;        me.insertBtn.click(function () {            me.insert();        });        $('#delConfirm').click(function () {            if(me.canRemoveSection){                me.remove(me.tree.selected);            }            else {                $('#delAlert').modal('hide');            }        });        me.removeBtn.click(function () {            //不可删除有子节点或有定额数据的节点            let section = me.cache[me.workBook.getActiveSheet().getActiveRowIndex()];            if(!section){                return;            }            let sectionName = me.isDef(section.data.name) ? section.data.name : '';            let sectionRations = rationOprObj.currentRations[`_SEC_ID_${section.data.ID}`];            if(section.children.length > 0 || (sectionRations && sectionRations.length > 0)){                me.canRemoveSection = false;                $('#delAlert').find('.modal-body h5').text('当前节点下有数据,不可删除。');            }            else {                me.canRemoveSection = true;                $('#delAlert').find('.modal-body h5').text(`确认要删除章节 “${sectionName}”吗?`);            }            $('#delAlert').modal('show');        });        me.upLevelBtn.click(function () {            me.upLevel(me.tree.selected);        });        me.downLevelBtn.click(function () {            me.downLevel(me.tree.selected);        });        me.downMoveBtn.click(function () {            me.downMove(me.tree.selected);        });        me.upMoveBtn.click(function () {            me.upMove(me.tree.selected);        });    },    insert: function () {        let me = sectionTreeObj;        me.insertBtn.addClass('disabled');        let postData = [],            newID = uuid.v1();        let selected = me.tree.selected;        let insertObj = me.getUpdateObj(me.updateType.new, {ID: newID, NextSiblingID: -1, ParentID: -1, name: ''});        if(me.isDef(selected)) {            let updateObj = me.getUpdateObj(me.updateType.update, {ID: selected.getID(), NextSiblingID: newID});            postData.push(updateObj);            insertObj.updateData.ParentID = selected.getParentID();            if(me.isDef(selected.nextSibling)){                insertObj.updateData.NextSiblingID = selected.getNextSiblingID();            }        }        postData.push(insertObj);        if(postData.length > 0){            //ajax            me.sectionTreeAjax(postData, function (rstData) {                me.controller.insertByID(newID);                me.refreshBtn(me.tree.selected);                //fresh tools                me.initTools(me.tree.selected);                me.workBook.focus();                me.initSelection(me.tree.selected);            });        }    },    remove: function (selected) {        let me = this;        me.removeBtn.addClass('disabled');        let postData = [],            IDs = [],            deleteObj = {                deleted: true,                deleteDateTime: new Date(),                deleteBy: userID            };        if(!selected){            return;        }        getDelIds(selected);        function getDelIds(node){            if(me.isDef(node)){                IDs.push(node.getID());                if(node.children.length > 0){                    for(let i = 0, len = node.children.length; i < len; i++){                        getDelIds(node.children[i]);                    }                }            }        }        if(me.isDef(selected.preSibling)){            let updateObj = me.getUpdateObj(me.updateType.update, {ID: selected.preSibling.getID(), NextSiblingID: selected.getNextSiblingID()});            postData.push(updateObj);        }        if(IDs.length > 0){            for(let i = 0, len = IDs.length; i < len; i++){                let delObj = me.getUpdateObj(me.updateType.update, {ID: IDs[i], deleteInfo: deleteObj});                postData.push(delObj);            }        }        if(postData.length > 0){            //ajax            me.sectionTreeAjax(postData, function (rstData) {                $('#delAlert').modal('hide');                me.removeRationsCodes(rationOprObj.currentRations["_SEC_ID_" + selected.data.ID]);                me.controller.delete();                me.refreshBtn(me.tree.selected);                me.initTools(me.tree.selected);                me.initSelection(me.tree.selected);                me.workBook.focus();            });        }    },    removeRationsCodes: function (rations) {        for(let ration of rations){            rationOprObj.rationsCodes.splice(rationOprObj.rationsCodes.indexOf(ration.code), 1);        }    },    upLevel: function (selected) {        let me = this;        me.upLevelBtn.addClass('disabled');        let postData = [],            parent = selected.parent;        if(!me.isDef(parent)){            return;        }        //更新父节点        postData.push(me.getUpdateObj(me.updateType.update, {ID: parent.getID(), NextSiblingID: selected.getID()}));        //更新前节点        if(me.isDef(selected.preSibling)){            postData.push(me.getUpdateObj(me.updateType.update, {ID: selected.preSibling.getID(), NextSiblingID: -1}));        }        //更新选中节点的后兄弟节点        let nextIDs = [];        getNext(selected);        function getNext(node){            if(me.isDef(node.nextSibling)){                nextIDs.push(node.getNextSiblingID());                getNext(node.nextSibling);            }        }        for(let nextID of nextIDs){            postData.push(me.getUpdateObj(me.updateType.update, {ID: nextID, ParentID: selected.getID()}));        }        //更新选中节点        postData.push(me.getUpdateObj(me.updateType.update,            {ID: selected.getID(), NextSiblingID: parent.getNextSiblingID(), ParentID: parent.getParentID()}));        if(postData.length > 0){            //ajax            me.sectionTreeAjax(postData, function (rstData) {                me.controller.upLevel();                me.refreshBtn(me.tree.selected);                me.workBook.focus();            });        }    },    downLevel: function (selected) {        let me = this;        me.downLevelBtn.addClass('disabled');        let postData = [],            preSibling = selected.preSibling;        if(!me.isDef(preSibling)){            return;        }        //更新前节点        postData.push(me.getUpdateObj(me.updateType.update, {ID: preSibling.getID(), NextSiblingID: selected.getNextSiblingID()}));        //更新前节点最末子节点        if(preSibling.children.length > 0){            postData.push(me.getUpdateObj(me.updateType.update,                {ID: preSibling.children[preSibling.children.length - 1].getID(), NextSiblingID: selected.getID()}));        }        //更新选中节点        postData.push(me.getUpdateObj(me.updateType.update, {ID: selected.getID(), NextSiblingID: -1, ParentID: preSibling.getID()}));        if(postData.length > 0){            //ajax            me.sectionTreeAjax(postData, function (rstData) {                me.controller.downLevel();                me.refreshBtn(me.tree.selected);                me.workBook.focus();            });        }    },    upMove: function (selected) {        let me = this;        me.upMoveBtn.addClass('disabled');        let postData = [];        if(!me.isDef(selected)){            return;        }        if(!me.isDef(selected.preSibling)){            return;        }        let updateObj = me.getUpdateObj(me.updateType.update, {ID: selected.getID(), NextSiblingID: selected.preSibling.getID()});        postData.push(updateObj);        let updatePre = me.getUpdateObj(me.updateType.update, {ID: selected.preSibling.getID(), NextSiblingID: selected.getNextSiblingID()});        postData.push(updatePre);        if(me.isDef(selected.preSibling.preSibling)){            let updatePrepre = me.getUpdateObj(me.updateType.update, {ID: selected.preSibling.preSibling.getID(), NextSiblingID: selected.getID()});            postData.push(updatePrepre);        }        if(postData.length > 0){            //ajax            me.sectionTreeAjax(postData, function (rstData) {                me.controller.upMove();                me.refreshBtn(me.tree.selected);                me.workBook.focus();            });        }    },    downMove: function (selected) {        let me = this;        me.downMoveBtn.addClass('disabled');        let postData = [];        if(!me.isDef(selected)){            return;        }        if(!me.isDef(selected.nextSibling)){            return;        }        if(me.isDef(selected.preSibling)){            let updatePre = me.getUpdateObj(me.updateType.update, {ID: selected.preSibling.getID(), NextSiblingID: selected.getNextSiblingID()});            postData.push(updatePre);        }        let updateObj = me.getUpdateObj(me.updateType.update, {ID: selected.getID(), NextSiblingID: selected.nextSibling.getNextSiblingID()});        postData.push(updateObj);        let updateNext = me.getUpdateObj(me.updateType.update, {ID: selected.getNextSiblingID(), NextSiblingID: selected.getID()});        postData.push(updateNext);        if(postData.length > 0){            //ajax            me.sectionTreeAjax(postData, function (rstData) {                me.controller.downMove();                me.refreshBtn(me.tree.selected);                me.workBook.focus();            });        }    },    getUpdateObj: function (updateType, updateData) {        let updateObj = Object.create(null);        updateObj.updateType = '';        updateObj.updateData = Object.create(null);        updateObj.updateData.rationRepId = pageOprObj.rationLibId;        if(this.isDef(updateType)){            updateObj.updateType = updateType;        }        if(this.isDef(updateData)){            for(let attr in updateData){                updateObj.updateData[attr] = updateData[attr];            }        }        return updateObj;    },    sectionTreeAjax: function (postData, scFunc, errFunc) {        CommonAjax.post('/complementaryRation/api/updateRationSection', {updateData: postData}, scFunc, errFunc);    },    initTools: function (node) {        if(this.isDef(node)){            explanatoryOprObj.setAttribute(explanatoryOprObj.currentTreeNode ? explanatoryOprObj.currentTreeNode : node, node, node.data.explanation, node.data.ruleText);            explanatoryOprObj.clickUpdate($('#explanationShow'), $('#ruleTextShow'));            explanatoryOprObj.showText($('#explanationShow'), $('#ruleTextShow'), node.data.explanation, node.data.ruleText);            //job            jobContentOprObj.currentSituation = typeof node.data.jobContentSituation !== 'undefined'? node.data.jobContentSituation : jobContentOprObj.situations.NONE;            jobContentOprObj.setAttribute(jobContentOprObj.currentTreeNode ? jobContentOprObj.currentTreeNode : node, node);            jobContentOprObj.clickUpdate($('#txtareaAll'));            //fz            annotationOprObj.currentSituation = typeof node.data.annotationSituation !== 'undefined'? node.data.annotationSituation : annotationOprObj.situations.NONE;            annotationOprObj.clickUpdate($('#fzTxtareaAll'));        }    },    //模仿默认点击    initSelection: function (node) {        node.tree.selected = node ? node : null;        let me = this;        if(!me.isDef(node)){            sheetCommonObj.cleanSheet(rationOprObj.workBook.getActiveSheet(), rationOprObj.setting, -1);            sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);            sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);            sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);            sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);            return;        }        me.workBook.getActiveSheet().setActiveCell(node.serialNo(), 0);        me.initTools(node);        me.refreshBtn(node);        if(!me.isDef(node.children) || node.children.length === 0){            rationOprObj.canRations = true;            rationOprObj.workBook.getSheet(0).clearSelection();            rationOprObj.getRationItems(node.data.ID, function () {                rationOprObj.workBook.getActiveSheet().setActiveCell(0, 0);                rationOprObj.rationSelInit(0, true);            });            rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), 'dynamic');        }        else {            rationOprObj.canRations = false;            rationOprObj.currentSectionId = node.data.ID;            rationOprObj.workBook.getSheet(0).setRowCount(30);            rationOprObj.setCombo(rationOprObj.workBook.getSheet(0), null);           // jobContentOprObj.setRadiosDisabled(true, jobContentOprObj.radios);            jobContentOprObj.hideTable($('#tableAll'), $('#tablePartial'));          //  annotationOprObj.setRadiosDisabled(true, annotationOprObj.radios);            annotationOprObj.hideTable($('#fzTableAll'), $('#fzTablePartial'));            sheetCommonObj.cleanSheet(rationOprObj.workBook.getSheet(0), rationOprObj.setting, -1);            sheetCommonObj.cleanSheet(rationGLJOprObj.sheet, rationGLJOprObj.setting, -1);            sheetCommonObj.cleanSheet(rationCoeOprObj.sheet, rationCoeOprObj.setting, -1);            sheetCommonObj.cleanSheet(rationAssistOprObj.sheet, rationAssistOprObj.setting, -1);            sheetCommonObj.cleanSheet(rationInstObj.sheet, rationInstObj.setting, -1);        }        //rationGLJOprObj.sheet.getParent().focus(false);        me.workBook.focus(true);    }};
 |