| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 | let selectFBObject = {     spread:null,    datas:[],    setting:{        header: [            {headerName: "编号", headerWidth: 158, dataCode: "code", dataType: "String"},            {headerName: "名称", headerWidth: 210, dataCode: "name", dataType: "String"},            {headerName: "单位", headerWidth: 70, dataCode: "unit", dataType: "String", hAlign: "center"},        ],        view:{ lockColumns: ["name","code","unit"]}    },    initSpread:function(){        if(!this.spread){            this.spread = SheetDataHelper.createNewSpread($("#selectFBSheet")[0]);            sheetCommonObj.spreadDefaultStyle(this.spread);            let sheet = this.spread.getSheet(0);            sheetCommonObj.initSheet(sheet,this.setting,0);              /*   sheet.bind(GC.Spread.Sheets.Events.SelectionChanged,this.onSelectionChange); */            if(projectReadOnly){                sheetCommonObj.disableSpread(this.spread);            }        }else{            this.spread.refresh();        }            },    getSelectedData:function(){        let sel = this.spread.getSheet(0).getSelections()[0];        if(sel && gljUtil.isDef(sel.row)){            return this.datas[sel.row]        }        return null;    },    showTreeData:function(roots){        let me = this;        let parentIDs = [];        let node = me.getSelectedNode();        if(node) parentIDs = me.getAllParentIDs(node);        this.datas = [];        for(let r of roots){            me.setDatas(r,parentIDs);        }        sheetCommonObj.showTreeData(me.spread.getSheet(0), me.setting, me.datas);        let row = me.getSelectedRow(node);        me.spread.getSheet(0).setSelection(row,0,1,1);        me.spread.getSheet(0).showRow(row, GC.Spread.Sheets.VerticalPosition.center);    },    showData:function(){        let budgetType = projectObj.project.property.budgetType||commonConstants.BudgetType.BUILDING;        if(budgetType===commonConstants.BudgetType.BUILDING){//建筑安装工程显示清单树 显示定额章节树            this.showRationTree();        }else{//城市轨道交通工程 显示分部            this.showBillTree();        }    },    showRationTree:async function(){        let rationLibID = rationLibObj.getDefaultStdRationLibID();        if(!this.rationChapterTree){            $.bootstrapLoading.start();            let treeData = await ajaxPost('/complementaryRation/api/getRationTree', {userId: userID, rationRepId: rationLibID, type: 1});            this.rationChapterTree = idTree.createNew({id: 'ID', pid: 'ParentID', nid: 'NextSiblingID', rootId: -1, autoUpdate: false});            this.rationChapterTree.loadDatas(treeData);            $.bootstrapLoading.end();        }        if(this.rationChapterTree.roots.length >0){            this.showTreeData(this.rationChapterTree.roots[0].children);        }    },    showBillTree:function(){        let me = selectFBObject;        billsGuidance.initBillsLibs(()=>{             me.showTreeData(billsGuidance.bills.tree.roots);        });    },    getSelectedRow:function(node){        let row = 0;//要选中的行;           if(node){            return _.findIndex(this.datas,{'ID':node.data.ID})         }        return row;    },    getSelectedNode:function(){        let node = null;        if($("#selectFBFor").val() == "replace") return node;      //如果是添加分部,则应选中对应的节点        /*1.当前定位在“分项”,则弹出“选择分部”窗口,并且默认定位在:根据分项编号的前9位查找清单规则中的父项。如果查找不到父项,则默认定位在第一行。 */        let selected = projectObj.project.mainTree.selected;        if(selected.data.type==billType.FX || selected.data.type==billType.BX){            let code = selected.data.code;            if(code.length === 12){                let matchCode =  code.substring(0,9);                for(let i of billsGuidance.bills.tree.items){                    if (i.data.code == matchCode) return i.parent;                }             }         }        return node;    },    getAllParentIDs:function(node){        let list = [];        getID(node,list);        return list;        function getID(node,l){            if(node.parent){                l.push(node.parent.data.ID);                 getID(node.parent,l)            }        }    },    setDatas:function(node,parentIDs){           let budgetType = projectObj.project.property.budgetType||commonConstants.BudgetType.BUILDING;        let nodeData = node.data;        let d = {            ID:nodeData.ID,            ParentID:nodeData.ParentID,            code:nodeData.code,            name:nodeData.name,            unit:nodeData.unit        }        if(nodeData.name  && budgetType === commonConstants.BudgetType.BUILDING){            let index = nodeData.name.indexOf(' ');            if(index !== -1){                d.code = nodeData.name.substring(0,index);                d.name = nodeData.name.substring(index+1);            }        }        if(parentIDs.includes(d.ID)) d.collapsed = false        this.datas.push(d);        if(node.children.length > 0){            for(let c of node.children){                this.setDatas(c,parentIDs)            }        }    }}$(function () {    $('#selectFBDiv').on('shown.bs.modal', function (e) {        selectFBObject.initSpread();        selectFBObject.showData();        sheetCommonObj.refreshWorkbookDelDefer(selectFBObject.spread, 200);    })    $("#selectFBConfirm").click(async ()=>{        let data = selectFBObject.getSelectedData();        if(!data) return;        let project = projectObj.project;        let controller =  projectObj.mainController;        let selected = project.mainTree.selected;        if($("#selectFBFor").val() == "replace"){            let datas = [{                type:'bills',                data:{                    ID:selected.data.ID,                    name:data.name,                    code:data.code,                    unit:data.unit                }              }]              await project.syncUpdateNodesAndRefresh(datas);        }else{            let ext = {name:data.name,code:data.code};            if(selected.data.type==billType.FX || selected.data.type==billType.BX){                //添加成分项的父亲                ProjectController.addFXParent(selected,ext);              }else{//正常添加分部               ProjectController.addFB(project, controller,null,ext);               projectObj.selectColAndFocus(project.mainTree.selected);           }        }           })})
 |