/** * Created by zhang on 2018/5/30. */ let zmhs_obj = { coeSpread:null, coeSheet:null, coeSheetData:[], coeSetting: { header: [ {headerName: "调整", headerWidth: 35, dataCode: "isAdjust", dataType: "String", cellType: "checkBox"}, {headerName: "条件", headerWidth: 250, dataCode: "name", dataType: "String", cellType: "button"}, {headerName: "内容", headerWidth: 160, dataCode: "content", dataType: "String", hAlign: "left"} ], view: { lockColumns:[0,1,2], rowHeaderWidth:25 } }, assSpread:null, assSheet:null, assSheetData: [], assSetting: { header: [ {headerName: "调整名称", headerWidth: 100, dataCode: "name", dataType: "String"}, {headerName: "定额值", headerWidth: 80, dataCode: "stdValue", hAlign: "right", dataType: "String"}, {headerName: "实际值", headerWidth: 80, dataCode: "actualValue", hAlign: "right", dataType: "String"} ], view: { lockColumns: [0, 1], rowHeaderWidth:25 } }, initSpread:function () { this.coeSpread = SheetDataHelper.createNewSpread($("#coeSpread")[0]); sheetCommonObj.spreadDefaultStyle(this.coeSpread); this.assSpread = SheetDataHelper.createNewSpread($("#assSpread")[0]); sheetCommonObj.spreadDefaultStyle(this.assSpread); this.coeSheet = this.coeSpread.getSheet(0); sheetCommonObj.initSheet(this.coeSheet, this.coeSetting, 30); this.coeSheet.name('ration_coe'); this.coeSheet.bind(GC.Spread.Sheets.Events.CellClick, this.onCoeCellClick); this.coeSpread.bind(GC.Spread.Sheets.Events.ButtonClicked, this.onButtonClick); this.coeSheet.bind(GC.Spread.Sheets.Events.EditStarting, function (e,args) { //args.cancel = true; }); this.assSheet = this.assSpread.getSheet(0); sheetCommonObj.initSheet(this.assSheet, this.assSetting, 30); this.assSheet.bind(GC.Spread.Sheets.Events.EditEnded, this.onAssEditEnded); this.assSheet.bind(GC.Spread.Sheets.Events.RangeChanged, this.onAssRangeChanged); this.assSheet.name('ration_ass'); SheetDataHelper.protectdSheet(this.coeSheet); if(projectReadOnly){ disableSpread(zmhs_obj.coeSpread); } }, showCoeData:function (node) { let selected = node?node:projectObj.project.mainTree.selected; let ration_coe = projectObj.project.ration_coe; let coeList = []; if(selected&&selected.sourceType == "ration"){ let ration = selected.data; coeList = ration_coe.getCoeByRationID(ration.ID); } sheetCommonObj.showData(this.coeSheet, this.coeSetting,coeList); if (coeList.length > 0) { var cus_index = _.findIndex(coeList, function (item) { return item.coeID == -1; }) if (cus_index != -1) { this.coeSheet.getCell(cus_index, 1, GC.Spread.Sheets.SheetArea.viewport).locked(false); this.coeSheet.setCellType(cus_index, 1, sheetCommonObj.getCustomerCoeCellType(this.generateHtmlString,this.bindCusEditorValue,this.updateCusCoeAfterEditor), GC.Spread.Sheets.SheetArea.viewport); } } this.coeSheetData = coeList; }, showAssData:function (node) { this.assSheet.suspendPaint(); this.assSheet.suspendEvent(); let selected = node?node:projectObj.project.mainTree.selected; let assList = selected&&selected.data.rationAssList ? selected.data.rationAssList : []; this.assSheet.setRowCount(0); sheetCommonObj.showData(this.assSheet, this.assSetting, assList); this.assSheetData = assList; this.assSheet.getRange(assList.length,-1,this.assSheet.getRowCount()-assList.length, -1, GC.Spread.Sheets.SheetArea.viewport).locked(true); this.assSheet.resumePaint(); this.assSheet.resumeEvent(); }, refresh:function () { this.coeSpread?this.coeSpread.refresh():''; this.assSpread?this.assSpread.refresh():''; }, showZMHSData:function (node) { if(this.coeSpread&& this.assSpread && $('#linkZMHS').hasClass('active')){ this.showCoeData(node); this.showAssData(node); } }, onCoeCellClick: function (sender, args) { let me = zmhs_obj; let sheet = args.sheet, row = args.row, col = args.col; if(sheet.getCell(row, col).locked() !=true){ if(!sheet.isEditing()) sheet.startEdit(); } }, onButtonClick:function (sender, args) { let me = zmhs_obj; let sheet = args.sheet, row = args.row, col = args.col; let cellType = sheet.getCellType(row, col); if (args.sheetName == 'ration_coe' && cellType instanceof GC.Spread.Sheets.CellTypes.CheckBox) { me.onCoeCheckBoxClick(sender, args) } }, bindCusEditorValue:function(context){ let me = zmhs_obj; if(me.coeSheetData[context.row]){ let data = me.coeSheetData[context.row]; for(let c of data.coes){ $("#"+ c.coeType).val(c.amount); } /*$('#coe_ration').val(data.coes[0].amount); $('#manual').val(data.coes[1].amount); $('#material').val(data.coes[2].amount); $('#manchine').val(data.coes[3].amount); $('#mainM').val(data.coes[4].amount); $('#equipment').val(data.coes[5].amount);*/ } }, updateCusCoeAfterEditor:function(){ let me = zmhs_obj; let result = me.checkIfNeedUpdate(); if (result.isNeed) { projectObj.project.ration_coe.updateCustomerCoe(result); } }, onInputChange(id, name){ var coe = _.find(zmhs_obj.coeSheetData, function (c) { return c.coeID == -1; }); if(coe){ let newValue = zmhs_obj.numberValueChecking($('#' + id).val()); if (newValue) { newValue = _.round(newValue, 2); if (newValue == coe.coes[name].amount) return; if (id == '定额') { for(let c of coe.coes){ $('#'+c.coeType).val(newValue) } /*$('#coe_ration').val(newValue); $('#manual').val(newValue); $('#material').val(newValue); $('#manchine').val(newValue); $('#mainM').val(newValue); $('#equipment').val(newValue);*/ } else { $('#' + id).val(newValue); } } else { $('#' + id).val(coe.coes[name].amount); } } }, checkIfNeedUpdate(){ let data = _.find(zmhs_obj.coeSheetData, function (c) { return c.coeID == -1; }); let result = {isNeed: false}; if(data){ for(let c of data.coes){ let amount = $("#"+c.coeType).val(); if(amount!=c.amount){ result.isNeed = true; c.amount = amount; } } if (result.isNeed) { result.doc = { coes: data.coes }; result.query = { projectID: data.projectID, ID: data.ID, rationID: data.rationID }; } } return result; }, numberValueChecking: function (val) { var newval = Number(val); if (number_util.isNumber(newval)) { return newval; } else { if (val) { alert('您输入的数据类型不正确,请重新输入。'); } newval = null; } return newval; }, onCoeCheckBoxClick:function (sender, args) { let me = zmhs_obj; let checkboxValue = args.sheet.getCell(args.row, args.col).value(); 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); } let recode = me.coeSheetData[args.row]; projectObj.project.ration_coe.adjustCoeClick(recode, newval); }, generateHtmlString: function (context,cellRect,$editor) {//这里要改成动态的了,根据自定义系数内容生成对应的输入框 let me = zmhs_obj; let height = cellRect.height; let offect = 0; let newString = "