123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- /**
- * Created by Mai on 2017/6/1.
- */
- ProjectController = {
- /* sc: tree_sheet_controller */
- syncDisplayNewNode: function (sc, newNode,callback) {
- TREE_SHEET_HELPER.massOperationSheet(sc.sheet, function () {
- var sels = sc.sheet.getSelections();
- sc.sheet.addRows(newNode.serialNo(), 1);
- TREE_SHEET_HELPER.refreshTreeNodeData(sc.setting, sc.sheet, [newNode], false);
- sc.setTreeSelected(newNode);
- sc.sheet.setSelection(newNode.serialNo(), sels[0].col, 1, 1);
- //不显示到中间
- //sc.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
- cbTools.refreshFormulaNodes();
- if(callback) callback();
- });
- },
- syncDisplayNewNodes: function (sc, newNodes,withOutSelect=false) {//withOutSelect 不需要自动选中,外面自已处理
- TREE_SHEET_HELPER.massOperationSheet(sc.sheet, function () {
- var sels = sc.sheet.getSelections();
- newNodes.sort(function (a, b) {
- let rst = 0;
- if(a.serialNo() > b.serialNo()){
- rst = 1;
- }
- else {
- rst = -1;
- }
- return rst;
- });
- let lastNode = null;
- for(let newNode of newNodes){
- sc.sheet.addRows(newNode.serialNo(), 1);
- TREE_SHEET_HELPER.refreshTreeNodeData(sc.setting, sc.sheet, [newNode], false);
- lastNode = newNode
- // sc.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
- }
- if(withOutSelect==false&& lastNode){
- sc.setTreeSelected(lastNode);
- sc.sheet.setSelection(lastNode.serialNo(), sels[0].col, 1, 1);
- }
- cbTools.refreshFormulaNodes();
- });
- },
- syncDisplayNewRationGljNode:function (sc,newNode) {
- TREE_SHEET_HELPER.massOperationSheet(sc.sheet, function () {
- sc.sheet.addRows(newNode.serialNo(), 1);
- TREE_SHEET_HELPER.refreshTreeNodeData(sc.setting, sc.sheet, [newNode], false);
- // sc.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
- cbTools.refreshFormulaNodes();
- });
- },
- addBills: function (project, sheetController, std) {
- if (!project || !sheetController) { return null; }
- let target = project.getParentTarget(project.mainTree.selected, 'sourceType', project.Bills.getSourceType());
- let newSource = null, newNode = null, parentID, nextSiblingID, nodeParentID, nodeNextSiblingID;
- if (target) {
- if(target.depth() === 0){
- parentID = target.source.getID();
- nextSiblingID = project.Bills.tree.setting.rootId;
- nodeParentID = target.getID();
- nodeNextSiblingID = project.mainTree.rootID();
- }
- else{
- parentID = target.source.getParentID();
- nextSiblingID = target.source.getNextSiblingID();
- nodeParentID = target.getParentID();
- nodeNextSiblingID = target.getNextSiblingID();
- }
- parentID = target.depth() === 0 ? target.source.getID() : target.source.getParentID();
- nextSiblingID = target.depth() === 0 ? project.Bills.tree.setting.rootId : target.source.getNextSiblingID();
- if (std) {
- let fixedNode = getRootFixedNode(target);
- if(!isFlag(fixedNode.data) || (fixedNode.data.flagsIndex.fixed.flag !== fixedFlag.SUB_ENGINERRING && fixedNode.data.flagsIndex.fixed.flag !== fixedFlag.MEASURE)){
- return false;
- }
- //焦点行属于分部分项
- if(fixedNode.data.flagsIndex.fixed.flag === fixedFlag.SUB_ENGINERRING){
- std.type = billType.FX;
- //焦点行是分部分项
- let subType = getSubType(target);
- if(target.sourceType === project.Bills.getSourceType() && target.data.type === billType.DXFY && subType === billType.FB){
- return false;
- }
- //焦点行是分部
- else if(target.sourceType === project.Bills.getSourceType() && target.data.type === billType.FB){
- if(!subType || subType === billType.FX){
- parentID = target.source.getID();
- nextSiblingID = project.Bills.tree.setting.rootId;
- nodeParentID = target.getID();
- nodeNextSiblingID = project.mainTree.rootID();
- }
- else{
- return false;
- }
- }
- }
- else {
- std.type = billType.BILL;
- }
- let newCode = project.Bills.newFormatCode(std.code);
- newSource = project.Bills.insertStdBills(parentID, nextSiblingID, std, newCode);
- } else {
- newSource = project.Bills.insertBills(parentID, nextSiblingID);
- }
- newNode = project.mainTree.insert(nodeParentID, nodeNextSiblingID, newSource.data.ID);
- } else {
- alert('不可添加清单');
- }
- if (newNode) {
- newNode.source = newSource;
- newNode.sourceType = project.Bills.getSourceType();
- newNode.data = newSource.data;
- this.syncDisplayNewNode(sheetController, newNode);
- return newNode;
- }
- function getSubType(node){
- for(let sub of node.children){
- if(sub.sourceType === project.Bills.getSourceType() && sub.data.type === billType.FB){
- return billType.FB;
- }
- else if(sub.sourceType === project.Bills.getSourceType() && sub.data.type === billType.FX){
- return billType.FX;
- }
- }
- return null;
- }
- },
- addRootBill:function (project, sheetController) {//添加大项费用
- if (!project || !sheetController) { return null; }
- this.addSpecialBill(project, sheetController,null, project.mainTree.selected.nextSibling,true,billType.DXFY);
- },
- addFB:function(project, sheetController) {//添加分部
- if (!project || !sheetController) { return null; }
- let selected = project.mainTree.selected;
- if(selected.parent==null&&isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING){//选中的是分部分项,则插入做为最后一个子项
- return this.addSpecialBill(project, sheetController,selected, null,true,billType.FB);
- }
- if(selected.parent){
- return this.addSpecialBill(project, sheetController,selected.parent, selected.nextSibling,true,billType.FB);
- }
- },
- addFX:function(project, sheetController) {//添加分项
- if (!project || !sheetController) { return null; }
- let selected = project.mainTree.selected;
- console.log(selected);
- if(selected.data.type==billType.FB||(selected.parent==null&&isFlag(selected.data)&&selected.data.flagsIndex.fixed.flag==fixedFlag.SUB_ENGINERRING)){//选中的是分部或者是分部分项工程,则插入做为最后一个子项
- return this.addSpecialBill(project, sheetController,selected, null,true,billType.FX);
- }
- if(selected.parent){
- if(selected.data.type==billType.FX||selected.data.type==billType.BX){
- return this.addSpecialBill(project, sheetController,selected.parent, selected.nextSibling,true,billType.FX);
- }
- }
- },
- addSpecialBill(project,sheetController,parent,nextSibling,isUserAdd,type){
- let newSource = null, newNode = null;
- let b_nexID = nextSibling==null?-1:nextSibling.source.getID();//主树和清单树,对应的树节点ID不一样
- let m_nexID = nextSibling==null?-1:nextSibling.getID();
- let b_parent = parent==null?-1:parent.source.getID();
- let m_parent = parent==null?-1:parent.getID();
- newSource = project.Bills.insertSpecialBill(b_parent, b_nexID,isUserAdd,type);
- newNode = project.mainTree.insert(m_parent,m_nexID, newSource.data.ID);
- if (newNode) {
- newNode.source = newSource;
- newNode.sourceType = project.Bills.getSourceType();
- newNode.data = newSource.data;
- this.syncDisplayNewNode(sheetController, newNode);
- return newNode;
- }
- },
- addRation: function (project, sheetController, rationType, std) {
- if (!project || !sheetController) { return; }
- let selected = project.mainTree.selected, newSource = null, newNode = null;
- if (selected === null) { return; }
- if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
- if (selected.source.children.length > 0) {
- alert('当前清单已有清单子项,不能套用定额。');
- } else if (selected.data.calcBase&&selected.data.calcBase!="") {
- alert('当前有基数计算,不能插入定额/量价/人材机。');
- } else {
- if(selected.data.type === billType.FB){
- return;
- }
- if (std) {
- newSource = project.Ration.insertStdRation(selected.source.getID(), null, std);
- project.ration_glj.addRationGLJ(newSource,std);
- } else {
- newSource = project.Ration.insertRation(selected.source.getID(),null, rationType);
- }
- newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID(), newSource.ID);
- }
- } else if (selected.sourceType === project.Ration.getSourceType()) {
- if (std) {
- newSource = project.Ration.insertStdRation(selected.source[project.masterField.ration], selected.source, std);
- project.ration_glj.addRationGLJ(newSource,std);
- } else {
- newSource = project.Ration.insertRation(selected.source[project.masterField.ration], selected.source, rationType);
- }
- newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID(), newSource.ID);
- };
- if (newNode) {
- newNode.source = newSource;
- newNode.sourceType = project.Ration.getSourceType();
- newNode.data = newSource;
- this.syncDisplayNewNode(sheetController, newNode);
- }
- },
- replaceRation: function (project, sheetController, std) {
- if (!project || !sheetController) { return; }
- let selected = project.mainTree.selected, newSource = null, newNode = null;
- if (selected === null) { return; }
- if ( selected.sourceType === project.Ration.getSourceType()) {
- project.Ration.replaceRation(selected.source, std);
- project.ration_glj.addRationGLJ(selected.source, std);
- sheetController.refreshTreeNode([selected], false);
- } else {
- alert('当前焦点行不是定额,无法替换。');
- }
- },
- addNewNodes:function (updateData){
- let controller = projectObj.mainController;
- let Bill = projectObj.project.Bills;
- let newAddNode = [];
- let newRationNodes = [];
- for(let nb of updateData.bills.add){
- let newSource = Bill.tree.insertByData(nb, nb.ParentID, -1, true);//按顺序插入的情况下,nextID为-1,树节点
- let newNode = projectObj.project.mainTree.insert(nb.ParentID, -1, newSource.data.ID);
- newNode.source = newSource;
- newNode.sourceType = Bill.getSourceType();
- newNode.data = newSource.data;
- controller.sheet.addRows(newNode.serialNo(), 1);
- // controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
- newAddNode.push(newNode);
- Bill.datas.push(nb);
- }
- for(let nr of updateData.ration.add){
- let newNode = projectObj.project.mainTree.insert(nr.billsItemID, -1, nr.ID);
- newNode.source = nr;
- newNode.sourceType = projectObj.project.Ration.getSourceType();
- newNode.data = nr;
- controller.sheet.addRows(newNode.serialNo(), 1);
- // controller.sheet.showRow(newNode.serialNo(), GC.Spread.Sheets.VerticalPosition.center);
- newAddNode.push(newNode);
- newRationNodes.push(newNode);
- projectObj.project.Ration.datas.push(nr);
- }
- TREE_SHEET_HELPER.refreshTreeNodeData(controller.setting, controller.sheet, newAddNode, false);
- return newRationNodes;
- }
- /* addVolumePrice: function (project, sheetController) {
- if (!project || !sheetController) { return null; }
- var selected = project.mainTree.selected;
- var newSource = null, newNode = null;
- if(selected === null) {
- return;
- }
- if (selected.sourceType === project.Bills.getSourceType() && selected.source.children.length === 0) {
- newSource = project.VolumePrice.insertVolumePrice(selected.source.getID());
- newNode = project.mainTree.insert(selected.getID(), selected.tree.rootID());
- } else if (selected.sourceType === project.Ration.getSourceType() || selected.sourceType === project.VolumePrice.getSourceType()) {
- newSource = project.VolumePrice.insertVolumePrice(selected.source[project.masterField.volumePrice], selected.source);
- newNode = project.mainTree.insert(selected.getParentID(), selected.getNextSiblingID());
- }
- if (newNode) {
- newNode.source = newSource;
- newNode.sourceType = project.VolumePrice.getSourceType();
- newNode.data = newSource;
- this.syncDisplayNewNode(sheetController, newNode);
- }
- },*/
- /* calculateAll: function (project, sheetController, CalcType) {
- this.project.setCalcFlag(CalcType);
- let calc = new BillsCalcHelper(project);
- calc.calcAll();
- sheetController.showTreeData();
- project.Bills.updateAll();
- calc = null;
- }*/
- }
|