/** * Created by zhang on 2018/5/30. */ let zmhs_obj = { coeSpread:null, coeSheet:null, coeSheetData:[], coeSetting: { header: [ {headerName: "调整", headerWidth: 45, dataCode: "isAdjust", dataType: "String", cellType: "checkBox"}, {headerName: "条件", headerWidth: 150, dataCode: "name", dataType: "String", cellType: "button"}, {headerName: "内容", headerWidth: 350, dataCode: "content", dataType: "String", hAlign: "left"} ], view: { lockColumns: [0,1,2] } }, assSpread:null, assSheet:null, assSheetData: [], assSetting: { header: [ {headerName: "调整名称", headerWidth: 100, dataCode: "name", dataType: "String"}, {headerName: "定额值", headerWidth: 120, dataCode: "stdValue", hAlign: "right", dataType: "String"}, {headerName: "实际值", headerWidth: 120, dataCode: "actualValue", hAlign: "right", dataType: "String"} ], view: { lockColumns: [0, 1] } }, initSpread:function () { this.coeSpread = SheetDataHelper.createNewSpread($("#coeSpread")[0]); this.assSpread = SheetDataHelper.createNewSpread($("#assSpread")[0]); 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); }, 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); this.coeSheet.floatingObjects.remove("customerCoe"); if (coeList.length > 0) { var cus_index = _.findIndex(coeList, function (item) { return item.coeID == -1; }) if (cus_index != -1) { this.addDropDownList(); this.addCusButton(cus_index, 1, coeList[cus_index].name); } } 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); //hide floatingObject var floatingObject = this.coeSheet.floatingObjects.get('customerCoe'); if (floatingObject) { floatingObject.isVisible(false); } } }, onCoeCellClick: function (sender, args) { let me = zmhs_obj; let floatingObject = me.coeSheet.floatingObjects.get('customerCoe'); if(floatingObject){ let isVisable = floatingObject.isVisible(); if (isVisable) { let result = me.checkIfNeedUpdate(); if (result.isNeed) { projectObj.project.ration_coe.updateCustomerCoe(result); } floatingObject.isVisible(false); } } }, 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.sheet.isEditing()){ args.sheet.endEdit(); } if (cellType instanceof GC.Spread.Sheets.CellTypes.Button) { if(args.sheetName == 'ration_coe'){ me.onCusButtonClick(sender, args); } } else { me.onCoeCheckBoxClick(sender, args) } }, onCusButtonClick: function (sender, args) { var me = zmhs_obj; var floatingObject = me.coeSheet.floatingObjects.get('customerCoe'); var isVisable = floatingObject.isVisible(); if (!isVisable) { me.coeSheet.getCell(args.row, args.col, GC.Spread.Sheets.SheetArea.viewport).locked(false); me.showFloationObject(floatingObject, me.coeSheetData[args.row]); } else { var result = me.checkIfNeedUpdate(); if (result.isNeed) { projectObj.project.ration_coe.updateCustomerCoe(result); } floatingObject.isVisible(false); } }, showFloationObject(floatingObject, data){ floatingObject.isVisible(true); var sheet = this.coeSheet; var startRow = this.coeSheetData.length; var endRow = startRow + 7; floatingObject.startRow(startRow); floatingObject.startColumn(1); floatingObject.endColumn(2); floatingObject.endRow(endRow); this.bindFloadingObjectValue(data); sheet.repaint(); }, bindFloadingObjectValue(data){ $('#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); }, onInputChange(id, name){ var coe = _.find(zmhs_obj.coeSheetData, function (c) { return c.coeID == -1; }); var newValue = zmhs_obj.numberValueChecking($('#' + id).val()); if (newValue) { newValue = _.round(newValue, 2); if (newValue == coe.coes[name].amount) return; if (id == 'coe_ration') { $('#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(){ var data = _.find(zmhs_obj.coeSheetData, function (c) { return c.coeID == -1; }); var result = { isNeed: false } var coe_ration = $('#coe_ration').val(); var manual = $('#manual').val(); var material = $('#material').val(); var manchine = $('#manchine').val(); var mainM = $('#mainM').val(); var equipment = $('#equipment').val(); if (coe_ration != data.coes[0].amount) { result.isNeed = true; data.coes[0].amount = coe_ration; } if (manual != data.coes[1].amount) { result.isNeed = true; data.coes[1].amount = manual; } if (material != data.coes[2].amount) { result.isNeed = true; data.coes[2].amount = material; } if (manchine != data.coes[3].amount) { result.isNeed = true; data.coes[3].amount = manchine; } if (mainM != data.coes[4].amount) { result.isNeed = true; data.coes[4].amount = mainM; } if (equipment != data.coes[5].amount) { result.isNeed = true; data.coes[5].amount = equipment; } 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); }, addCusButton: function (row, col, text) { zmhs_obj.coeSheet.suspendPaint(); var cus_button = new GC.Spread.Sheets.CellTypes.Button(); zmhs_obj.coeSheet.setCellType(row, col, cus_button, GC.Spread.Sheets.SheetArea.viewport); cus_button.marginLeft(0); cus_button.marginTop(0); cus_button.marginRight(-2); cus_button.marginBottom(-2); cus_button.text(text); cus_button.buttonBackColor('white'); zmhs_obj.coeSheet.resumePaint(); //zmhs_obj.coeSheet.repaint(); }, addDropDownList: function () { var sheet = this.coeSheet; sheet.suspendPaint(); var customFloatingObject = new GC.Spread.Sheets.FloatingObjects.FloatingObject("customerCoe"); var div = document.createElement('div'); div.innerHTML = this.generateHtmlString(); customFloatingObject.startRow(1); customFloatingObject.startColumn(1); customFloatingObject.endColumn(2); customFloatingObject.endRow(2); $(div).css('background', 'white'); customFloatingObject.content(div); sheet.floatingObjects.add(customFloatingObject); customFloatingObject.isVisible(false); sheet.resumePaint(); }, generateHtmlString: function () { var newString = "