1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426 |
- /**
- * Created by CSL on 2017-05-12.
- */
- var gljOprObj = {
- sheet: null,
- libID: null,
- ration: null,
- sheetData: [],
- checkb: null,
- detailSheet: null,
- detailData: [],
- GLJSelection: [],
- selectedGLJClass: null,
- parentNodeIds: {},
- activeTab: '#linkGLJ',
- setting: {},
- detailSetting: {
- header: [
- {headerName: "名称", headerWidth: 100, dataCode: "name", dataType: "String"},
- {headerName: "计算式", headerWidth: 120, dataCode: "regex", dataType: "String"},
- {headerName: "结果(C)", headerWidth: 120, dataCode: "result", dataType: "Number", decimalField: "quantity_detail"},
- {headerName: "累加", headerWidth: 120, dataCode: "isSummation", dataType: "String", cellType: "checkBox"}
- ],
- view: {
- lockColumns: [2, 3]
- }
- },
- gljTreeSetting: {
- view: {
- expandSpeed: "",
- selectedMulti: false
- },
- edit: {
- enable: false,
- editNameSelectAll: true,
- showRemoveBtn: true,
- showRenameBtn: true,
- removeTitle: "删除节点",
- renameTitle: "更改名称"
- },
- data: {
- keep: {
- parent: true,
- leaf: true
- },
- key: {
- children: "items",
- name: "Name"
- },
- simpleData: {
- enable: false,
- idKey: "ID",
- pIdKey: "ParentID",
- rootPId: -1
- }
- },
- callback: {
- onClick: function (event, treeId, treeNode) {
- if (treeId == 'gljTree') {
- let me = gljOprObj, gljTypeId = treeNode.ID;
- if (treeNode.ID) {
- me.gljCurTypeId = treeNode.ID;
- me.filterLibGLJSheetData();
- me.showLibGLJSheetData();
- }
- } else {
- if (treeNode.isParent) {
- $('#class_selected_conf').attr("disabled", "disabled");
- $('#selected_class').val("");
- } else {
- $('#class_selected_conf').removeAttr("disabled");
- $('#selected_class').val(treeNode.ID);
- }
- }
- }
- }
- },
- gljLibSheetSetting: {
- owner: 'gljTree',
- header: [
- {headerName: "选择", headerWidth: 40, dataCode: "select", hAlign: "center", vAlign: "center", cellType: "checkBox"},
- {headerName: "编码", headerWidth: 80, dataCode: "code", dataType: "String", formatter: "@", hAlign: "left", vAlign: "center"},
- {headerName: "名称", headerWidth: 120, dataCode: "name", dataType: "String", hAlign: "left", vAlign: "center"},
- {headerName: "规格型号", headerWidth: 80, dataCode: "specs", dataType: "String", hAlign: "center", vAlign: "center"},
- {headerName: "单位", headerWidth: 40, dataCode: "unit", dataType: "String", hAlign: "center", vAlign: "center"},
- {headerName: "单价", headerWidth: 80, dataCode: "basePrice", dataType: "Number", formatter: "0.00", hAlign: "right", vAlign: "center"},
- {headerName: "类型", headerWidth: 80, dataCode: "gljType", dataType: "String", hAlign: "center", vAlign: "center"},
- {headerName: "是否新增", headerWidth: 80, dataCode: "isComplementary", dataType: "String", hAlign: "center", vAlign: "center", cellType: "checkBox"}
- ],
- view: {
- lockColumns: [0, 1, 2, 3, 4, 5, 6]
- }
- },
- gljLibSheet: null,
- initSheet: function (sheet) {
- var me = this;
- me.sheet = sheet;
- sheetCommonObj.initSheet(me.sheet, me.setting, 30);
- sheet.name('ration_glj');
- me.bindSheetEvent(sheet);
- sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
- sheet.bind(GC.Spread.Sheets.Events.CellDoubleClick, me.onCellDoubleClick);
- sheet.bind(GC.Spread.Sheets.Events.ClipboardChanged, me.onClipboardChanged);
- subSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, me.onButtonClick);
- sheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args) {
- if (args.row>=me.sheetData.length){
- args.cancel = true;
- }else if (me.sheetData[args.row].isMixRatio) {
- args.cancel = true;
- }
- });
- gljContextMenu.loadGLJSpreadContextMenu();
- },
- initDetailSheet: function (sheet) {
- var me = this;
- me.detailSheet = sheet;
- sheetCommonObj.initSheet(me.detailSheet, me.detailSetting, 30);
- // me.detailSheet.selectionUnit(0);//0 cell,1 row,2 col;
- sheet.name('quantity_detail');
- me.bindSheetEvent(sheet);
- sheet.bind(GC.Spread.Sheets.Events.EditStarting, function (sender, args) {
- if(me.detailSheetReadonly()){
- args.cancel = true;
- }else {
- if(args.sheet.getValue(args.row,args.col)==null){//这里是为了解决当单元格里的值是null的时候,在单元格里输入数据,按键盘箭头移动光标的时候,会直接结束编辑,跳到另外的单元格。
- args.sheet.setValue(args.row,args.col,"");
- }
- }
- });
- },
- detailSheetReadonly:function () {
- let selected = projectObj.project.mainTree.selected;
- if(selected) {
- //清单锁定时只读
- if(selected.sourceType == ModuleNames.bills && projectObj.project.isBillsLocked() && projectObj.project.withinBillsLocked(selected)){
- return true;
- }
- //是主材或者是设备时只读
- if(selected.sourceType == ModuleNames.ration_glj){
- return true;
- }else if(gljOprObj.isInstallationNode(selected)){//是补项或者是安装类型的定额时只读
- return true;
- }
- return false;
- }
- return true;
- },
- bindSheetEvent: function (sheet) {
- var me = this;
- sheet.bind(GC.Spread.Sheets.Events.ClipboardPasting, me.onClipboardPasting);
- sheet.bind(GC.Spread.Sheets.Events.ClipboardPasted, me.onClipboardPasted);
- sheet.bind(GC.Spread.Sheets.Events.EditEnded, me.onEditEnded);
- sheet.bind(GC.Spread.Sheets.Events.RangeChanged, me.onRangeChanged);
- sheet.bind(GC.Spread.Sheets.Events.EditStarting, me.startEditChecking);
- // sheet.bind(GC.Spread.Sheets.Events.CellClick, me.onCellClick);
- },
- onClipboardPasting: function (sender, args) {
- var me = gljOprObj;
- if(args.sheetName!="quantity_detail"&&(args.cellRange.rowCount!=1||args.cellRange.colCount!=1)){//工程量明细做特殊处理
- args.cancel = true;
- }
- },
- onClipboardPasted: function (e, info) {
- var me = gljOprObj;
- console.log('past');
- // if (!me.ration) {return;};
- // your code...
- },
- startEditChecking:function (sender,args) {
- let me = gljOprObj;
- let selected = projectObj.project.mainTree.selected;
- if(selected){
- if(me.isInstallationNode(selected)==true){
- args.cancel = true;
- }
- }else {
- args.cancel = true;
- }
- },
- isInstallationNode:function(node){
- if(node.sourceType == ModuleNames.ration&&node.data.type == rationType.install){//是定额安装费类型时只读,原先是补项的时候也是控制只读的||(node.sourceType == ModuleNames.bills&&node.data.type==billType.BX)){//是定额安装费类型或者补项
- return true;
- }
- return false
- },
- onEditEnded: function (sender, args) {
- var me = gljOprObj;
- if (args.sheetName == 'ration_glj') {
- me.onEditGLJSheet(args)
- }
- if (args.sheetName == 'quantity_detail') {
- me.onEditDetailSheet(args);
- }
- },
- onEditDetailSheet: function (args,callback) {
- var me = gljOprObj;
- if (args.row > me.detailData.length) {
- return;
- }
- if (args.row == me.detailData.length && args.editingText == null) {
- return;
- }
- var selected = projectObj.project.mainTree.selected;//因为使用了延时方法,所以要先取得选中行;
- var detailList = me.detailData;
- if(args.editingText){
- args.editingText = args.editingText.replace(/(/g, "(");//替换中文左右括号;
- args.editingText = args.editingText.replace(/)/g, ")");
- }
- if (args.row == detailList.length) {
- projectObj.project.quantity_detail.saveQuantityDetail(args, me.detailSetting.header[args.col].dataCode, selected,callback);
- }
- if (args.row < detailList.length) {
- projectObj.project.quantity_detail.updateQuantityDetail(args, me.detailSetting.header[args.col].dataCode, detailList[args.row], selected,callback);
- }
- },
- onEditGLJSheet: function (args) {
- var me = gljOprObj;
- if (args.row >= me.sheetData.length) {
- me.sheet.getCell(args.row, args.col).value(null);
- return;
- }
- me.updateRationGLJ(args);
- },
- onButtonClick: function (sender, args) {
- if(args.sheet.isEditing()){
- args.sheet.endEdit();
- }
- var me = gljOprObj;
- var sheet = args.sheet, row = args.row, col = args.col;
- var cellType = sheet.getCellType(row, col);
- if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) {
- if(args.sheetName == 'rationInstallSheet'){
- installationFeeObj.onPositionButtonClick(sender,args);
- }
- } else {
- me.onCheckBoxClick(sender, args)
- }
- },
- onCheckBoxClick: function (sender, args) {
- let selected = projectObj.project.mainTree.selected;
- if(selected.sourceType == ModuleNames.ration_glj){//选中的是工料机时不可编辑
- return ;
- }
- let checkboxValue = args.sheet.getCell(args.row, args.col).value();
- if(args.sheetName == 'rationInstallSheet' && checkboxValue){
- return;
- }
- if(gljOprObj.isInstallationNode(selected)==true){
- return;
- }
- let newval = 0;
- if (checkboxValue) {
- newval = 0;
- args.sheet.getCell(args.row, args.col).value(newval);
- } else {
- newval = 1;
- args.sheet.getCell(args.row, args.col).value(newval);
- }
- if (args.sheetName == 'ration_glj') {
- gljOprObj.updateIsEstimate(args,newval);
- } else if (args.sheetName == 'quantity_detail') {
- projectObj.project.quantity_detail.isSummationUpdate(args, gljOprObj.detailData, newval);
- } else if (args.sheetName == 'glj_lib') {
- if(gljOprObj.gljLibSheetSetting.header[args.col].dataCode === 'select'){
- gljOprObj.setGLJSelection(args, newval);
- }
- }else if(args.sheetName == 'rationInstallSheet'){
- args.newValue = newval;
- installationFeeObj.onRationInstallValueChange(sender,args);
- }
- },
- onCellClick: function (sender, args) {
- var me = gljOprObj;
- if (args.row >= me.sheetData.length) {
- return;
- }
- me.editChecking(args);
- },
- onCellDoubleClick:function (sender, args) {
- var me = gljOprObj;
- var header = me.setting.header;
- if (args.row >= me.sheetData.length) {
- return;
- }
- if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
- if(me.hasComposition(me.sheetData[args.row])){
- alert("当前工料机的市场价由组成物计算得出,不可直接修改。");
- }
- }
- if (header[args.col] && header[args.col].dataCode == 'basePrice') {
- var isAdd = me.sheetData[args.row].isAdd;
- if(isAdd==1){//是新增但没有组成物时允许修改定额价
- if(me.hasComposition(me.sheetData[args.row])){//如果有组成物,不可修改
- alert("当前工料机的定额价由组成物计算得出,不可直接修改。");
- }
- }
- }
- },
- onClipboardChanged: function (sender, info) {
- let cDatas = sheetCommonObj.getTableData(info.sheet, null);
- sheetCommonObj.copyTextToClipboard(cDatas);
- return;
- },
- editChecking: function (args) {
- var me = gljOprObj;
- var header = me.setting.header;
- var disable = null;
- if (me.sheetData[args.row] != undefined) {
- if (me.sheetData[args.row].isMixRatio) {
- disable = true;
- }else {
- if (header[args.col] && header[args.col].dataCode == 'marketPrice') {
- if(me.marketPriceReadOnly({data:me.sheetData[args.row]})){
- disable = true;
- }else {
- disable = false;
- }
- }
- if (header[args.col] && header[args.col].dataCode == 'basePrice') {
- var isAdd = me.sheetData[args.row].isAdd;
- if(isAdd==1){//是新增但没有组成物时允许修改定额价
- if(me.marketPriceReadOnly({data:me.sheetData[args.row]})){//如果有组成物,不可修改
- disable = true;
- }else {
- disable = false;
- }
- } else {
- disable = true;
- }
- }
- }
- }
- if (disable != null) {
- me.sheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(disable);
- }
- },
- hasComposition:function (ration_glj,isRationType) {//判断是否有组成物,有则返回true 现在主材类型的工料机也有可能有组成物。
- let type = isRationType==true? ration_glj.subType:ration_glj.type;
- if(notEditType.indexOf(type)!=-1||type==gljType.MAIN_MATERIAL){
- let keyArray = isRationType==true? rationKeyArray:gljKeyArray;
- let con_key = this.getIndex(ration_glj,keyArray);
- var mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
- if(mixRatioMap[con_key]&&mixRatioMap[con_key].length>0){
- return true;
- }
- }
- return false;
- },
- onRangeChanged: function (sender, args) {
- var me = gljOprObj;
- if(args.sheetName == 'quantity_detail'){
- me.batchUpdateQuantityDetail(args);
- }else {
- if (args.action == GC.Spread.Sheets.RangeChangedAction.clear) {
- args.editingText = null;
- }else if(args.action == GC.Spread.Sheets.RangeChangedAction.paste){
- args.editingText = args.sheet.getCell(args.row,args.col).value();
- }else {
- return;
- }
- if (args.sheetName == 'ration_glj') {
- me.onEditGLJSheet(args);
- }
- }
- },
- batchUpdateQuantityDetail:function (args) {
- let me = gljOprObj;
- let updateArray = [];
- for(let i =0;i<args.changedCells.length;i++){
- let c = args.changedCells[i];
- let tem = {
- row:c.row,
- col:c.col,
- editingText:args.sheet.getCell(c.row,c.col).text(),
- sheet:args.sheet,
- sheetName:args.sheetName,
- index:i
- };
- updateArray.push(tem);
- }
- if(updateArray.length>0){
- updateArray.length == 1?me.onEditDetailSheet(updateArray[0]):me.onEditDetailSheet(updateArray[0],updateCallback);
- }
- function updateCallback(i_args) {
- let index = i_args.index;
- if(index < updateArray.length-1){
- let nextIndex = index+1;
- updateArray[nextIndex].replace = i_args.replace;
- if(nextIndex == updateArray.length-1){//是最后一个,则不用调callback了
- me.onEditDetailSheet(updateArray[nextIndex]);
- }else {
- me.onEditDetailSheet(updateArray[nextIndex],updateCallback);
- }
- }
- }
- },
- showDataIfRationSelect: function (node,selectedNodeId) {
- var isShow = false;
- if(selectedNodeId){
- this.selectedNodeId = selectedNodeId;
- }
- if (node) {
- if (this.selectedNodeId && this.selectedNodeId == node.getID()) {
- return;
- } else {
- this.selectedNodeId = node.getID();
- }
- if (node.sourceType == "ration") {
- if(node.data.type==rationType.gljRation){
- if($('#linkGLJ').hasClass('active')){
- this.showMixRatio(node);
- }
- }else {
- if($('#linkGLJ').hasClass('active')){
- this.showRationGLJData(node);
- }
- if($('#linkAZZJF').hasClass('active')){
- installationFeeObj.showRationInstallationData(node);
- }
- }
- isShow = true;
- }
- if(node.sourceType == ModuleNames.ration_glj){
- if($('#linkGLJ').hasClass('active')) {
- this.showMixRatio(node);
- }
- isShow = true;
- }
- if($('#linkGCLMX').hasClass('active')){
- this.showQuantityDetailData(node);
- }
- } else {
- this.selectedNodeId = null;
- }
- if (!isShow) {
- this.clearSheetData();
- }
- //子目换算
- zmhs_obj.showZMHSData(node);
- // $('#dropdown').hide();
- },
- showMixRatio:function (node) {//显示组成物到定额工料机
- let mixRatioMap = projectObj.project.projectGLJ.datas.mixRatioMap;
- let projectGljs = projectObj.project.projectGLJ.datas.gljList;
- let indexArray =node.sourceType==ModuleNames.ration?rationKeyArray:gljKeyArray;
- let connect_index = this.getIndex(node.data,indexArray);
- let gljList=[];
- if(mixRatioMap[connect_index]){ //说明是有组成物的类型
- gljList = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
- }
- if(gljList.length>0){//计算总消耗量
- if(node.sourceType==ModuleNames.ration){
- this.calcMixRationTotalQuantity(gljList,node.data.quantity);
- }else {
- let totalQuantity = this.getTotalQuantity(node.data);
- this.calcMixRationTotalQuantity(gljList,totalQuantity)
- }
- }
- this.sheetData = gljList;
- this.sheet.setRowCount(0);
- this.sheetData = sortRationGLJ(this.sheetData);
- this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType([]));
- sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
- this.sheet.getRange(-1, 0, -1, this.setting.header.length).locked(true);//锁住定额工料机的所有列
- this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);//锁住工程量明细的所有列
- },
- showRationGLJData: function (node) {
- var gljList = [];
- var ration_glj = projectObj.project.ration_glj;
- node = node ? node : projectObj.project.mainTree.selected;
- if (node.sourceType == ModuleNames.ration) {
- if(node.data.type==rationType.gljRation){
- this.showMixRatio(node);
- }else {
- let ration = node.data;
- gljList = this.filterGljByRation(ration, ration_glj.datas);
- this.showInSheet(gljList);
- }
- }else if(node.sourceType == ModuleNames.ration_glj){
- this.showMixRatio(node);
- }
- },
- showRationGLJSheetData: function (init) {
- let selected = this.sheet.getSelections();
- this.combineWithProjectGlj(this.sheetData);
- this.sheet.setRowCount(0);
- //console.log(+new Date())
- //this.sheet.getRange(0,-1,this.sheet.getRowCount(),-1).visible(true); //这个方法导致加载缓慢
- this.sheetData = sortRationGLJ(this.sheetData);
- this.sumQuantity();//计算总消耗量
- this.addMixRatioToShow();//显示组成物信息
- this.initRationTree(init);
- sheetCommonObj.showData(this.sheet, this.setting, this.sheetData);
- if(selected){//定位光标到之前的位置
- this.sheet.setSelection(selected[0].row,selected[0].col,selected[0].rowCount,selected[0].colCount);
- }
- },
- initRationTree: function (init) {
- this.sheet.getRange(-1, 0, -1, 1).cellType(this.getTreeNodeCellType(this.sheetData));
- for (var i = 0; i < this.sheetData.length; i++) {
- if (this.sheetData[i].hasOwnProperty('subList')) {
- /* var collapsed = false;
- if (init) {
- this.sheetData[i].collapsed = true;
- collapsed = true;
- } else {
- collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
- }*/
- var collapsed = this.sheetData[i].collapsed == undefined ? true : this.sheetData[i].collapsed;
- if (collapsed == true) {
- this.sheet.getRange(i + 1, -1, this.sheetData[i].subList.length, -1).visible(false);
- }
- //this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).visible(!collapsed);// this.sheet.getRange(i+1, -1, this.sheetData[i].subList.length, -1).locked(true);
- //这个方法导致加载缓慢
- }
- }
- },
- filterGljByRation: function (ration, datas) {
- var gljList = [];
- if (datas && datas.length > 0) {
- gljList = _.filter(datas, {'rationID': ration.ID})
- }
- return gljList;
- },
- showInSheet: function (gljList) {
- this.sheetData = gljList;
- this.showRationGLJSheetData(true);
- },
- sumQuantity: function (node) {
- if (this.sheetData.length > 0) {
- node = node ? node : projectObj.project.mainTree.selected;
- let ration = node.data;
- let quantity = ration.quantity;
- quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
- for (let glj of this.sheetData) {
- glj.totalQuantity= this.getTotalQuantity(glj,ration);
- }
- }
- },
- getTotalQuantity:function(glj,ration){
- ration=ration?ration: _.find(projectObj.project.Ration.datas,{"ID":glj.rationID});
- if(ration){
- let quantity = ration.quantity;
- quantity = (quantity == 0 || quantity == undefined || quantity == null || quantity == "") ? 0 : quantity;
- if (glj.isMixRatio == true) {//如果是用于显示的组成物,则不用计算,跳过
- return;
- }
- quantity = scMathUtil.roundForObj(quantity, getDecimal("ration.quantity"));//计算前进行4舍5入
- glj.quantity = scMathUtil.roundForObj(glj.quantity, getDecimal("glj.quantity"));
- glj.totalQuantity = scMathUtil.roundToString(quantity * glj.quantity, getDecimal("glj.quantity"));
- if (glj.hasOwnProperty('subList')) {//需要计算glj下挂的组成物的总消耗量
- this.calcMixRationTotalQuantity(glj.subList,glj.totalQuantity);
- }
- return glj.totalQuantity;
- }
- },
- calcMixRationTotalQuantity(mList,pTotal){ //计算组成物的总消耗量
- for (let subG of mList) {
- subG.rationItemQuantity = scMathUtil.roundForObj(subG.rationItemQuantity, getDecimal("glj.quantity"));
- subG.totalQuantity = scMathUtil.roundToString(subG.rationItemQuantity * pTotal, getDecimal("glj.quantity"));
- }
- },
- addMixRatioToShow: function () {
- var newList = [];
- _.remove(this.sheetData, {'isMixRatio': true});
- for (var i = 0; i < this.sheetData.length; i++) {
- newList.push(this.sheetData[i]);
- if (this.sheetData[i].hasOwnProperty('subList')) {
- newList = newList.concat(this.sheetData[i].subList);
- }
- }
- this.sheetData = newList;
- },
- combineWithProjectGlj: function (ration_gljs,needRatio=true) {
- var projectGLJData = projectObj.project.projectGLJ.datas;
- var projectGljs = projectGLJData.gljList;
- var mixRatioMap = projectGLJData.mixRatioMap;
- if (ration_gljs && ration_gljs.length > 0 && projectGljs && projectGljs.length > 0) {
- for (var i = 0; i < ration_gljs.length; i++) {
- var glj = _.find(projectGljs, {'id': ration_gljs[i].projectGLJID});
- if (glj) {
- if(projectObj.project.projectGLJ.isEstimateType(ration_gljs[i].type )){
- ration_gljs[i].isEstimate = glj.is_evaluate;
- }
- ration_gljs[i].shortName =projectObj.project.projectGLJ.getShortNameByID(ration_gljs[i].type);
- ration_gljs[i].isAdd = glj.unit_price.is_add;
- ration_gljs[i]=this.setGLJPrice(ration_gljs[i],glj);//设置工料机价格
- var connect_index = this.getIndex(glj, gljKeyArray);
- if (needRatio==true&&mixRatioMap.hasOwnProperty(connect_index)) {
- var mixRatios = this.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
- ration_gljs[i].subList = mixRatios;
- }
- }
- }
- }
- return ration_gljs;
- },
- setGLJPrice:function (data,glj,isRadio = false) {//isRadio 标记是否算组成物的价格
- let proGLJ = projectObj.project.projectGLJ;
- let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
- let decimalObj = projectInfoObj.projectInfo.property.decimal;
- let labourCoeDatas = projectObj.project.labourCoe.datas;
- glj = glj?glj:_.find(proGLJ.datas.gljList, {'id': data.projectGLJID});
- let result = gljUtil.getGLJPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
- data.marketPrice = result.marketPrice;
- data.basePrice = result.basePrice;
- data.adjustPrice = result.adjustPrice;
- data.marketUnitFee = data.marketPrice;//更新树节点市场单价列的值
- return data;
- },
- getBasePrice:function (treeNode) {//造价书中的工料机修改的节点要用到
- let proGLJ = projectObj.project.projectGLJ;
- let glj =_.find(proGLJ.datas.gljList, {'id': treeNode.data.projectGLJID});
- if(this.calcPriceDiff(glj)==true){
- return proGLJ.getBasePrice(glj);
- }else {
- return scMathUtil.roundForObj(treeNode.data.marketUnitFee,getDecimal("glj.unitPrice"));
- }
- },
- calcPriceDiff:function (glj) {
- let calcOptions=projectInfoObj.projectInfo.property.calcOptions;
- return gljUtil.calcPriceDiff(glj,calcOptions);
- },
- getIndex(obj, pops){
- let t_index = '';
- let k_arr = [];
- for (let p of pops) {
- let tmpK = (obj[p] == undefined || obj[p] == null || obj[p] == '') ? 'null' : obj[p];
- k_arr.push(tmpK);
- }
- t_index = k_arr.join("|-|");
- return t_index;
- },
- getConditionByKey(conKey){//将连接字符串转换成对象
- let valueArray = conKey.split("|-|");
- let obj ={};
- for(let i = 0;i<valueArray.length;i++){
- if(valueArray[i]!='null'){
- if(gljKeyArray[i]=='type'){
- valueArray[i] = parseInt(valueArray[i]);
- }
- obj[gljKeyArray[i]]=valueArray[i];
- }
- }
- return obj;
- },
- getMixRationShowDatas: function (mixRatioList, projectGljs) {
- var temRationGLJs = [];
- for (var i = 0; i < mixRatioList.length; i++) {
- var pg = _.find(projectGljs, {
- 'code': mixRatioList[i].code,
- 'name': mixRatioList[i].name,
- 'specs': mixRatioList[i].specs,
- 'type': mixRatioList[i].type,
- 'unit': mixRatioList[i].unit
- });//改关联关系
- var tem = {
- projectGLJID: pg.id,
- code: pg.code,
- name: pg.name,
- specs: pg.specs,
- unit: pg.unit,
- type:mixRatioList[i].type,
- shortName: projectObj.project.projectGLJ.getShortNameByID(mixRatioList[i].type),
- consumption:mixRatioList[i].consumption,
- rationItemQuantity: mixRatioList[i].consumption,
- // quantity:mixRatioList[i].consumption,
- /* basePrice: pg.unit_price.base_price,
- marketPrice: pg.unit_price.market_price,
- adjustPrice: pg.adjust_price,*/
- //isEstimate: pg.is_evaluate,
- isMixRatio: true,
- isAdd: pg.unit_price.is_add,
- GLJID: pg.glj_id
- };
- if(projectObj.project.projectGLJ.isEstimateType(pg.type)){
- tem.isEstimate = pg.is_evaluate;
- }
- this.setGLJPrice(tem,pg);
- temRationGLJs.push(tem);
- }
- temRationGLJs = _.sortBy(temRationGLJs, 'code');
- return temRationGLJs;
- },
- showQuantityDetailData: function (node) {
- var details = [];
- node = node ? node : projectObj.project.mainTree.selected;
- var quantity_detail = projectObj.project.quantity_detail;
- if (node.sourceType == ModuleNames.ration) {
- details = _.filter(quantity_detail.datas, {'rationID': node.data.ID});
- } else if (node.sourceType == ModuleNames.bills) {
- details = _.filter(quantity_detail.datas, {'billID': node.data.ID});
- }
- details = _.sortBy(details, 'seq');
- sheetCommonObj.showData(this.detailSheet, this.detailSetting, details);
- this.detailData = details;
- if (MainTreeCol.readOnly.forQuantifyDetail(node)) {
- this.detailSheet.getRange(-1, 0, -1, this.detailSetting.header.length).locked(true);
- }
- },
- clearSheetData: function () {
- if($('#linkGLJ').hasClass('active')){
- sheetCommonObj.showData(this.sheet, this.setting, []);
- }
- if($('#linkAZZJF').hasClass('active')){
- installationFeeObj.rationInstallSheet.setRowCount(0);//清除combobox cell
- sheetCommonObj.showData(installationFeeObj.rationInstallSheet, installationFeeObj.rationInstallSetting, []);
- }
- // sheetCommonObj.showData(this.detailSheet,this.detailSetting,[]);
- this.sheetData = [];
- installationFeeObj.rationInstallData = [];
- //this.detailData=[];
- },
- updateRationGLJ: function (args) {
- var me = this;
- var updateField = me.setting.header[args.col].dataCode;
- var recode = me.sheetData[args.row];
- var newval;
- if (updateField == 'marketPrice' || updateField == 'customQuantity' || updateField == 'basePrice') {
- if (args.editingText == null) {
- updateField == 'marketPrice' ? newval = 0 : newval = "";
- } else {
- var decimal = updateField == 'customQuantity' ? getDecimal("glj.quantity") : getDecimal("glj.unitPrice");
- newval = number_util.checkNumberValue(args.editingText, decimal);
- if (newval == null) {
- me.sheet.getCell(args.row, args.col).value(recode[updateField]);
- return;
- }
- }
- } else {
- if (updateField == 'name' || updateField == 'unit') {
- if (args.editingText === null) {
- alert(me.setting.header[args.col].headerName + '不能为空!');
- me.sheet.getCell(args.row, args.col).value(recode[updateField]);
- return;
- }
- }
- newval = args.editingText == null ? "" : args.editingText;
- }
- if (newval === recode[updateField]) {//如果值完全相等,则不需要更新
- return
- }
- if (updateField == 'marketPrice' || updateField == 'basePrice') {
- projectObj.project.projectGLJ.updatePriceFromRG(recode, updateField, newval);
- } else {
- projectObj.project.ration_glj.updateRationGLJByEdit(recode, updateField, newval);
- }
- },
- updateRationTypeGLJ: function (value, node, fieldName,editingText) {
- let newval;
- let updatePrice = false;
- if (fieldName == "marketUnitFee") {
- updatePrice = true;
- if (value == null) {
- newval = 0;
- } else {
- var decimal = getDecimal("glj.unitPrice");
- newval = number_util.checkNumberValue(value, decimal);
- }
- } else {
- if (value != null) {
- projectObj.project.projectGLJ.updatePropertyFromMainSpread(node, fieldName, value,editingText);
- return;
- //update
- }
- }
- if (newval && updatePrice == true) {
- projectObj.project.projectGLJ.updatePriceFromRG(node.data, "marketPrice", newval);
- return
- }
- projectObj.mainController.refreshTreeNode([node]);
- },
- updateIsEstimate:function (args, newval) {
- var me = gljOprObj;
- if(me.setting.header[args.col].dataCode=="isEstimate"){
- var pspread= new ProjectGLJSpread();
- var recode = me.sheetData[args.row];
- let projectGljs = projectObj.project.projectGLJ.datas.gljList;
- let glj = _.find(projectGljs, {'id': recode.projectGLJID});
- if(glj){
- glj["is_evaluate"]=newval;
- args.fromRG=true;
- pspread.postUpdate(recode.projectGLJID,"is_evaluate",newval,args,null,successTrigger);
- }
- }
- },
- showLibGLJSheetData: function () {
- this.gljLibSheetData = _.sortBy(this.gljLibSheetData, 'code');
- sheetCommonObj.showData(this.gljLibSheet, this.gljLibSheetSetting, this.gljLibSheetData, gljOprObj.distTypeTree);
- this.gljLibSheet.setRowCount(this.gljLibSheetData.length);
- },
- filterLibGLJSheetData: function () {
- let me = this;
- let val = $("input[name='glj']:checked").val();
- if (val == 'allGljs') {
- me.gljLibSheetData = me.stdGLJ.concat(me.complementaryGLJs);
- } else {
- me.gljLibSheetData = me[val];
- }
- if ($('#actionType').val() == 'replace' || $('#actionType').val() == 'm_replace') {
- me.filterLibGLJByType();
- }else if($('#actionType').val() == 'addMix'){
- projectGljObject.filterLibGLJForMixRatio();
- }
- //文本筛选
- let searchStr = $('#gljSearchKeyword').val();
- if(searchStr && searchStr.trim() != ''){
- let reg = new RegExp(searchStr);
- me.gljLibSheetData = _.filter(me.gljLibSheetData, function (data) {
- return reg.test(data.code) || reg.test(data.name);
- });
- }
- if (me.gljCurTypeId == undefined) {
- return;
- }
- if (me.parentNodeIds["_pNodeId_" + me.gljCurTypeId]) {
- me.gljLibSheetData = _.filter(me.gljLibSheetData, function (n) {
- return _.includes(me.parentNodeIds["_pNodeId_" + me.gljCurTypeId], n.gljClass);
- });
- } else {
- me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljClass': me.gljCurTypeId});
- }
- },
- setGLJSelection: function (args, newVal) {
- if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert'|| $('#actionType').val() == 'addMix') {
- this.addGLJsSelection(args, newVal);
- } else {
- this.replaceGLJSelection(args, newVal);
- }
- },
- addGLJsSelection: function (args, newVal) {
- var con_key = this.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray);
- if (newVal == 1) {
- this.GLJSelection.push(con_key);
- this.gljLibSheetData[args.row].select = 1;
- } else if (newVal == 0) {
- _.pull(this.GLJSelection, con_key);
- this.gljLibSheetData[args.row].select = 0;
- }
- },
- replaceGLJSelection: function (args, newVal) {
- var me = this;
- var oldSelection = this.GLJSelection[0];
- if (newVal == 0) {
- args.sheet.getCell(args.row, args.col).value(1);
- return;
- }
- this.GLJSelection = [me.getIndex(this.gljLibSheetData[args.row], gljLibKeyArray)];
- this.gljLibSheetData[args.row].select = 1;
- var oindex = _.findIndex(this.gljLibSheetData, function (item) {
- var i_key = me.getIndex(item, gljLibKeyArray);
- return oldSelection == i_key;
- });
- if (oindex != -1) {
- args.sheet.getCell(oindex, args.col).value(0);
- this.gljLibSheetData[oindex].select = 0;
- } else {
- var oldData = _.find(gljOprObj.AllRecode, function (item) {
- var i_key = me.getIndex(item, gljLibKeyArray);
- return oldSelection == i_key;
- });
- oldData ? oldData.select = 0 : "";
- }
- },
- filterLibGLJByType: function () {
- var me = this;
- var selected = me.sheetData[gljContextMenu.selectedRow];
- me.gljLibSheetData = _.filter(me.gljLibSheetData, {'gljType': selected.type});
- },
- getComboData: function (gljDistType) {
- let me = this;
- let distType;
- let distTypeTree = {
- prefix: 'gljType',
- distTypes: {},
- comboDatas: [],
- distTypesArr: []
- };
- gljDistType.forEach(function (typeData) {
- let typeObj = {
- data: typeData,
- children: [],
- parent: null
- }
- distTypeTree.distTypes[distTypeTree.prefix + typeData.ID] = typeObj;
- distTypeTree.distTypesArr.push(typeObj);
- });
- gljDistType.forEach(function (typeData) {
- distType = distTypeTree.distTypes[distTypeTree.prefix + typeData.ID];
- let parent = distTypeTree.distTypes[distTypeTree.prefix + typeData.ParentID];
- if (parent) {
- distType.parent = parent;
- parent.children.push(distType);
- }
- });
- distTypeTree.distTypesArr.forEach(function (distTypeObj) {
- if (distTypeObj.data.fullName !== '材料' && distTypeObj.data.fullName !== '机械') {
- distTypeTree.comboDatas.push({text: distTypeObj.data.fullName, value: distTypeObj.data.ID});
- }
- });
- return distTypeTree;
- },
- doInsertGLJ: function () {
- var me = this;
- var selected = projectObj.project.mainTree.selected;
- var project = projectObj.project;
- if (me.GLJSelection.length <= 0) {
- return;
- }
- $("#glj_tree_div").modal('hide');
- $.bootstrapLoading.start();
- project.ration_glj.insertGLJAsRation(me.GLJSelection, selected, function (parentNodeID,nextNodeID,data) {
- let newNode=null;
- for (let r_glj of data) {
- r_glj.quantity = r_glj.quantity + "";
- project.Ration.datas.push(r_glj);
- }//要先更新树节点工程量,加载项目工料机并计算消耗量才有值
- project.projectGLJ.loadData(function () {
- for(let r_glj of data){
- r_glj = me.setGLJPrice(r_glj);//设置工料机价格
- newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
- newNode.source = r_glj;
- newNode.sourceType = project.Ration.getSourceType();
- newNode.data = r_glj;
- ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
- }
- project.calcProgram.calcLeafAndSave(newNode.parent);//计算父级清单的所有子节点
- projectObj.mainController.refreshTreeNode([newNode]);
- if(me.hasComposition(newNode.data,true)){
- me.showMixRatio(newNode);
- }else {
- me.showRationGLJSheetData();
- }
- $.bootstrapLoading.end();
- });
- })
- },
- doAddGLJ: function () {
- var selected = projectObj.project.mainTree.selected;
- var project = projectObj.project;
- gljOprObj.GLJSelection = _.filter(gljOprObj.GLJSelection, function (n) {
- var rg = _.find(gljOprObj.sheetData, function (item) {
- var i_key = gljOprObj.getIndex(item, gljKeyArray);
- return n == i_key
- })
- return rg ? false : true;
- })
- if (gljOprObj.GLJSelection.length > 0 && selected && selected.sourceType == ModuleNames.ration) {
- $("#glj_tree_div").modal('hide');
- project.ration_glj.addGLJByLib(gljOprObj.GLJSelection, selected.data, function (result) {
- if (result) {
- selected.data.adjustState = result.adjustState;
- //project.ration_glj.datas = project.ration_glj.datas.concat(result.newRecodes);//显示和缓存统一,这样的话就不用更新两个位置了
- project.ration_glj.datas = project.ration_glj.datas.concat(result.showData);
- gljOprObj.sheetData = gljOprObj.sheetData.concat(result.showData);
- project.projectGLJ.loadData(function () {
- project.ration_glj.addToMainTree(result.showData);
- gljOprObj.showRationGLJSheetData();
- project.calcProgram.calcAndSave(selected);
- projectObj.mainController.refreshTreeNode([selected]);
- $.bootstrapLoading.end();
- });
- }
- });//doc.rationID=selected.data.ID;
- } else {
- $("#glj_tree_div").modal('hide');
- }
- },
- doReplaceGLJ: function () {
- var me = this;
- var oldData = me.sheetData[gljContextMenu.selectedRow];
- var project = projectObj.project;
- var selectCode = gljOprObj.GLJSelection[0];
- var selected = projectObj.project.mainTree.selected;
- $("#glj_tree_div").modal('hide');
- project.ration_glj.replaceGLJ(selectCode, oldData, function (result) {
- if (result) {
- //result.adjustState;
- var glj_list = projectObj.project.ration_glj.datas;
- var data = result.data;
- var index = _.findIndex(gljOprObj.sheetData, {'ID': data.ID});
- var list_index = _.findIndex(glj_list, {'ID': data.ID});
- var nodes = [selected];
- gljOprObj.sheetData[index] = data;
- glj_list[list_index] = data;
- project.projectGLJ.loadData(function () {//加载完项目工料机再计算
- gljOprObj.showRationGLJSheetData();
- if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
- var node = project.ration_glj.findGLJNodeByID(data.ID);
- if (node) {
- project.ration_glj.transferToNodeData(data);
- node.source = data;
- node.data = data;
- }
- node ? nodes.push(node) : "";
- }
- //project.ration_glj.addToMainTree(data);
- selected.data.adjustState = result.adjustState;
- projectObj.mainController.refreshTreeNode(nodes);
- project.calcProgram.calcAndSave(selected);
- $.bootstrapLoading.end();
- });
- }
- })
- },
- doMReplaceGLJ: function () {
- let me = this;
- let oldData = me.sheetData[gljContextMenu.selectedRow];
- let project = projectObj.project;
- let selectCode = me.GLJSelection[0];
- $("#glj_tree_div").modal('hide');
- project.ration_glj.mReplaceGLJ(selectCode, oldData, function (result,updateMap) {
- if(result == null){
- return;
- }
- let data = result.data;
- let stateList = result.stateList;
- //let n_index = me.getIndex(data.query, gljKeyArray);
- let nodes = [];
- _.forEach(project.ration_glj.datas, function (t) {
- // let t_index = me.getIndex(t, gljKeyArray);
- if (updateMap[t.ID]) {
- me.updateProperty(t, data.doc);
- me.updateProperty(t, updateMap[t.ID]);
- if (project.ration_glj.needShowToTree(t)) {//如果是造价书中的树节点,则也须刷新
- project.ration_glj.transferToNodeData(t);
- var node = project.ration_glj.findGLJNodeByID(t.ID);
- node ? nodes.push(node):'';
- }
- }
- })
- project.projectGLJ.loadData(function () {
- me.showRationGLJSheetData();
- var rationNodes = me.refreshStateAfterMreplace(stateList, nodes);
- project.calcProgram.calcNodesAndSave(rationNodes);
- $.bootstrapLoading.end();
- });
- })
- },
- updateProperty: function (obj, doc) {
- _.forEach(doc, function (n, key) {
- obj[key] = n;
- });
- },
- refreshStateAfterMreplace: function (stateList, gljNodes) {
- var nodes = [];
- var rationNodes = [];
- _.forEach(stateList, function (s) {
- var node = _.find(projectObj.project.mainTree.items, function (n) {
- return n.sourceType == ModuleNames.ration && n.data.ID == s.rationID;
- })
- if (node) {
- node.data.adjustState = s.adjustState;
- nodes.push(node);
- rationNodes.push(node);
- }
- });
- gljNodes.length > 0 ? nodes = nodes.concat(gljNodes) : "";
- projectObj.mainController.refreshTreeNode(nodes);
- return rationNodes;
- },
- refreshView: function () {
- let node = projectObj.project.mainTree.selected;
- this.showDataIfRationSelect(node,"111111");
- //this.showRationGLJData();
- },
- //
- refreshTreeNode: function (obj) {
- if (!obj) {
- return;
- }
- var objectArray = [];
- var nodes = [];
- if (obj instanceof Array) {
- objectArray.concat(obj);
- } else {
- objectArray.push(obj);
- }
- for (let o of objectArray) {
- var node = _.find(projectObj.project.mainTree.items, function (n) {
- return n.sourceType == o.type && n.data.ID == o.ID;
- })
- if (node) {
- for (var k in o.data) {
- node.data[k] = o.data[k];
- }
- nodes.push(node);
- }
- }
- projectObj.mainController.refreshTreeNode(nodes);
- return nodes;
- },
- getTreeNodeCellType: function (data) {
- var ns = GC.Spread.Sheets;
- var rectW = 10;
- var rectH = 10;
- var margin = 3;
- function TreeNodeCellType() {
- }
- function drowRect(ctx, x, y, w, h) {
- ctx.save();
- ctx.strokeStyle = "gray";
- ctx.translate(0.5, 0.5);
- ctx.beginPath();
- var rectX = x + margin;
- var rectY = y + Math.round(h / 2) - rectH / 2;
- ctx.moveTo(rectX, rectY);
- ctx.lineTo(rectX, rectY + rectH);
- ctx.lineTo(rectX + rectW, rectY + rectH);
- ctx.lineTo(rectX + rectW, rectY);
- ctx.lineTo(rectX, rectY);
- ctx.moveTo(rectX + rectW, y + Math.round(h / 2));
- ctx.lineTo(rectX + rectW + 5, y + Math.round(h / 2));
- ctx.stroke();
- ctx.restore();
- }
- function drowSymbol(ctx, x, y, w, h, collapsed) {
- ctx.save();
- ctx.strokeStyle = "#000000";
- ctx.translate(0.5, 0.5);
- ctx.beginPath();
- ctx.moveTo(x + margin + 2, y + Math.round(h / 2));
- ctx.lineTo(x + margin + 8, y + Math.round(h / 2));
- var rectY = y + Math.round(h / 2) - rectH / 2;
- if (collapsed) {
- ctx.moveTo(x + margin + rectW / 2, rectY + 2);
- ctx.lineTo(x + margin + rectW / 2, rectY + 2 + 6);
- }
- ctx.stroke();
- ctx.restore();
- }
- function drowSubItem(ctx, x, y, w, h, offset, nextItem) {
- offset += 6;
- ctx.save();
- ctx.strokeStyle = "gray";
- ctx.translate(0.5, 0.5);
- ctx.beginPath();
- ctx.moveTo(x + offset, y);
- ctx.lineTo(x + offset, y + Math.round(h / 2));
- offset += 9;
- ctx.lineTo(x + offset, y + Math.round(h / 2));
- if (nextItem && nextItem.isMixRatio) {
- ctx.moveTo(x + offset - 9, y + Math.round(h / 2));
- ctx.lineTo(x + offset - 9, y + h);
- }
- ctx.stroke();
- ctx.restore();
- return offset;
- }
- TreeNodeCellType.prototype = new ns.CellTypes.Text();
- TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) {
- if (value != null) {
- var offset = margin + rectW + 6;
- var recode = data[options.row];
- if (recode && recode.hasOwnProperty('subList')) {
- drowRect(ctx, x, y, w, h);
- var collapsed = recode.collapsed == undefined ? true : recode.collapsed;//options.sheet.getTag(options.row,options.col);
- drowSymbol(ctx, x, y, w, h, collapsed);
- } else if (recode && recode.isMixRatio) {
- offset = drowSubItem(ctx, x, y, w, h, offset, data[options.row + 1]);
- offset += 1;
- }
- arguments[2] = x + offset;
- arguments[4] = w - offset;
- //x = x + offset;
- //w = w - offset;
- GC.Spread.Sheets.CellTypes.Text.prototype.paint.apply(this, arguments);
- }
- };
- // override getHitInfo to allow cell type get mouse messages
- TreeNodeCellType.prototype.getHitInfo = function (x, y, cellStyle, cellRect, context) {
- return {
- x: x,
- y: y,
- row: context.row,
- col: context.col,
- cellStyle: cellStyle,
- cellRect: cellRect,
- sheetArea: context.sheetArea
- };
- };
- TreeNodeCellType.prototype.processMouseDown = function (hitinfo) {
- var recode = data[hitinfo.row];
- if (recode && recode.hasOwnProperty('subList')) {
- var hoffset = hitinfo.cellRect.x + 3;
- if (hitinfo.x > hoffset && hitinfo.x < hoffset + 10) {
- var collapsed = recode.collapsed == undefined ? true : recode.collapsed;
- collapsed = !collapsed
- recode.collapsed = collapsed;
- //hitinfo.sheet.setTag(hitinfo.row,hitinfo.col,collapsed);
- hitinfo.sheet.getRange(hitinfo.row + 1, -1, recode.subList.length, -1).visible(!collapsed);
- hitinfo.sheet.invalidateLayout();
- hitinfo.sheet.repaint();
- }
- }
- };
- return new TreeNodeCellType()
- },
- marketPriceReadOnly: function (node) {
- let hasCom = false;
- if(node.sourceType==ModuleNames.ration&&node.data.type==rationType.gljRation){
- hasCom = this.hasComposition(node.data,true);
- }else {
- hasCom = this.hasComposition(node.data);
- }
- return hasCom|| node.data.isEstimate == 1;
- }
- }
- $(function () {
- $('#glj_tree_div').on('shown.bs.modal', function (e) {
- if (gljOprObj.gljLibSpresd == undefined) {
- gljOprObj.gljLibSpresd = sheetCommonObj.buildSheet($('#gljLibSheet')[0], gljOprObj.gljLibSheetSetting, gljOprObj.stdGLJ.length + gljOprObj.complementaryGLJs.length);
- gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked, gljOprObj.onButtonClick);
- gljOprObj.gljLibSheet = gljOprObj.gljLibSpresd.getSheet(0);
- gljOprObj.gljLibSheet.options.isProtected = true;
- gljOprObj.gljLibSheet.name('glj_lib');
- }
- gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
- let selections = [],selectMap = {};
- if ($('#actionType').val() == 'add' || $('#actionType').val() == 'insert') {//插入,添加
- gljOprObj.GLJSelection = [];
- } else if($('#actionType').val() =='m_replace' || $('#actionType').val() == 'replace'){//替换、批量替换
- let selected = gljOprObj.sheetData[gljContextMenu.selectedRow];
- var connect_key = gljOprObj.getIndex(selected, gljKeyArray);
- gljOprObj.GLJSelection = [connect_key];
- selectMap[connect_key] = true;
- gljOprObj.filterLibGLJByType();
- }else if($('#actionType').val() =='addMix'){//添加组成物
- gljOprObj.GLJSelection = [];
- projectGljObject.filterLibGLJForMixRatio();
- /*selections = projectGljObject.mixRatioData; 添加组成物的时候先不选中
- gljOprObj.GLJSelection = [];
- for(let s of selections){
- let s_key = gljOprObj.getIndex(s, gljKeyArray);
- selectMap[s_key] = true;
- gljOprObj.GLJSelection.push(s_key);
- }*/
- }
- for(let item of gljOprObj.gljLibSheetData){
- let item_key = gljOprObj.getIndex(item, gljLibKeyArray);
- if(selectMap[item_key]){
- item.select = 1 ;
- }
- }
- gljOprObj.showLibGLJSheetData();
- });
- $('#glj_tree_div').on('hidden.bs.modal', function () {
- $('#gljSearchKeyword').val('');
- });
- $('.glj-radio').change(function () {
- let val = $("input[name='glj']:checked").val();
- if (val == 'allGljs') {
- gljOprObj.gljLibSheetData = gljOprObj.AllRecode;
- gljOprObj.filterLibGLJSheetData();
- gljOprObj.showLibGLJSheetData();
- } else {
- gljOprObj.gljLibSheetData = gljOprObj[val];
- gljOprObj.filterLibGLJSheetData();
- gljOprObj.showLibGLJSheetData();
- }
- })
- //工料机搜索
- $('#gljSearchKeyword').change(function () {
- gljOprObj.filterLibGLJSheetData();
- gljOprObj.showLibGLJSheetData();
- });
- $('#gljSearchKeyword').bind('keypress', function (e) {
- if(e.keyCode === 13){
- $(this).blur();
- return false;
- }
- });
- $('#glj_selected_conf').click(function () {
- if (gljOprObj.GLJSelection.length < 1) {
- return;
- }
- if ($('#actionType').val() == 'insert') { //造价书页面中插入定额类型的工料机
- gljOprObj.doInsertGLJ();
- } else if ($('#actionType').val() == 'add') { //添加工料机
- gljOprObj.doAddGLJ();
- } else if ($('#actionType').val() == 'replace') {//替换工料机
- gljOprObj.doReplaceGLJ();
- } else if ($('#actionType').val() == 'm_replace') {//批量替换工料机
- gljOprObj.doMReplaceGLJ();
- }else if($('#actionType').val() == 'addMix'){
- projectGljObject.addMixRatio();
- }
- })
- $('#class_selected_conf').click(function () {
- var gljClass = $('#selected_class').val();
- var glj = gljOprObj.selectedGLJClass;
- if (glj && gljClass && gljClass != "") {
- //保存到我的工料机库
- /*1 检查是否有组成物
- * 2 如果有,则检查组成物中是否有新增的记录,如果有,查看是否已经保存了,没有的话,要先添加组成物到补充工料机库
- * 3 保存
- * */
- var newItem = {
- code: glj.code,
- name: glj.name,
- specs: glj.specs,
- unit: glj.unit,
- basePrice: glj.basePrice,
- gljType: glj.type,
- shortName: glj.shortName,
- component: [],
- gljClass: gljClass
- };
- if (glj.hasOwnProperty("subList") && glj.subList.length > 0) {//有组成物,检查组成物信息,目前组成物不允许修改,所以暂时不用考虑组成物是新增的情况
- for (var i = 0; i < glj.subList.length; i++) {
- let tem = {
- ID: glj.subList[i].GLJID,
- consumeAmt: glj.rationItemQuantity,
- isStd: true
- }
- newItem.component.push(tem);
- }
- }
- var data = getcmpUpdateData([newItem]);
- $.bootstrapLoading.start();
- var callback = function (data) {
- $("#glj_class_div").modal('hide');
- $.bootstrapLoading.end();
- }
- CommonAjax.post("complementartGlj/api/mixUpdateGljItems", data, callback, function () {
- $.bootstrapLoading.end();
- });
- }
- })
- $('#glj_class_div').on('hidden.bs.modal', function (e) {
- gljOprObj.selectedGLJClass = null;
- $('#class_selected_conf').attr("disabled", "disabled");
- $('#selected_class').val("");
- })
- function getcmpUpdateData(items) {
- var data = {
- "updateItems": [],
- "removeIds": []
- }
- data.addItems = items;
- return data;
- }
- })
- function operationWithRound(value1,value2,field,symble) {
- let decimal = getDecimal(field);
- value1 = scMathUtil.roundForObj(value1,decimal);
- value2 = scMathUtil.roundForObj(value2,decimal);
- let result;
- switch (symble){
- case "+" :
- result=scMathUtil.roundForObj(value1 + value2,decimal);
- break;
- case "-":
- result=scMathUtil.roundForObj(value1 - value2,decimal);
- break;
- case "*":
- result=scMathUtil.roundForObj(value1 * value2,decimal);
- break;
- case "/":
- result=scMathUtil.roundForObj(value1 / value2,decimal);
- break
- }
- return result;
- }
- function getDecimal(fieldID, node) {
- if (node) {
- return decimalObj.decimal(fieldID, node);
- } else if (fieldID.indexOf(".") != -1) {
- var keyArray = fieldID.split(".");
- return decimalObj[keyArray[0]][keyArray[1]];
- } else {
- return decimalObj.decimal(fieldID);
- }
- }
- function sortRationGLJ(list) {
- list = _.sortByAll(list, [function (item) {
- return item.type + "";
- }, "code"])
- return list;
- }
- function compareRationGLJ(a, b) {
- if ((a.type + "") < (b.type + "")) {
- return true
- }
- if ((a.type + "") == (b.type + "")) {
- if (a.code < b.code) {
- return true
- }
- }
- return false;
- }
|