|
@@ -0,0 +1,384 @@
|
|
|
+/**
|
|
|
+ * Created by zhang on 2018/5/30.
|
|
|
+ */
|
|
|
+
|
|
|
+let zmhs_obj = {
|
|
|
+ coeSpread:null,
|
|
|
+ coeSheet:null,
|
|
|
+ coeSheetData:[],
|
|
|
+ coeSetting: {
|
|
|
+ header: [
|
|
|
+ {headerName: "调整", headerWidth: 100, dataCode: "isAdjust", dataType: "String", cellType: "checkBox"},
|
|
|
+ {headerName: "条件", headerWidth: 120, 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) {
|
|
|
+ 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);
|
|
|
+
|
|
|
+ },
|
|
|
+ refresh:function () {
|
|
|
+ this.coeSpread?this.coeSpread.refresh():'';
|
|
|
+ this.assSpread?this.assSpread.refresh():'';
|
|
|
+ },
|
|
|
+ showZMHSData:function (node) {
|
|
|
+ if(this.coeSpread&& this.assSpread){
|
|
|
+ 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) {
|
|
|
+ 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(0);
|
|
|
+ cus_button.marginBottom(0);
|
|
|
+ cus_button.text(text);
|
|
|
+ cus_button.buttonBackColor('white');
|
|
|
+ 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 = "<form ><table border='1px' bordercolor='#CCCCCC' cellspacing='0px' style='border-collapse:collapse;font-size: 10px;>";
|
|
|
+ newString += this.getOneRow('定额', 0, 'coe_ration');
|
|
|
+ newString += this.getOneRow('人工', 1, 'manual');
|
|
|
+ newString += this.getOneRow('材料', 2, 'material');
|
|
|
+ newString += this.getOneRow('机械', 3, 'manchine');
|
|
|
+ newString += this.getOneRow('主材', 4, 'mainM');
|
|
|
+ newString += this.getOneRow('设备', 5, 'equipment');
|
|
|
+ newString += "</table></form>";
|
|
|
+ return newString;
|
|
|
+ },
|
|
|
+ getOneRow: function (text, name, id) {
|
|
|
+ var rowstr = "<tr style='height:10px'><td style='width: 50px'>" + text
|
|
|
+ + ":</td><td style='width: 70px' align='right'><input type='text'value='1' name=" + name
|
|
|
+ + " style='width:30px;border:0;height:14px' align='right' id=" + id + " onchange='zmhs_obj.onInputChange(this.id,this.name)'></td></tr>";
|
|
|
+ return rowstr;
|
|
|
+
|
|
|
+ },
|
|
|
+ onAssEditEnded:function (e,args) {
|
|
|
+ var me = zmhs_obj;
|
|
|
+ if (args.row >= me.assSheetData.length) {
|
|
|
+ me.assSheet.getCell(args.row, args.col).value(null);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (me.assSetting.header[args.col].dataCode == 'actualValue') {//实际值
|
|
|
+ me.updateRationAss(args);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onAssRangeChanged:function (e,args) {
|
|
|
+ let me = zmhs_obj;
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+ if (args.sheetName == 'ration_ass') {
|
|
|
+ me.updateRationAss(args);
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ updateRationAss: function (args) {
|
|
|
+ var me = zmhs_obj;
|
|
|
+ var newval;
|
|
|
+ newval = me.numberValueChecking(args.editingText);
|
|
|
+ var recode = me.assSheetData[args.row];
|
|
|
+ if (args.editingText === null) {
|
|
|
+ newval = parseFloat(recode.stdValue);
|
|
|
+ }
|
|
|
+ var isValidate = false;
|
|
|
+ if (newval) {
|
|
|
+ isValidate = me.checkingActualValue(recode, newval)
|
|
|
+ }
|
|
|
+ if (isValidate) {
|
|
|
+ newval = scMathUtil.roundTo(newval, -2);
|
|
|
+ projectObj.project.ration_ass.updateActualValue(me.assSheetData, args.row, newval)
|
|
|
+ } else {
|
|
|
+ newval = recode.actualValue;
|
|
|
+ me.assSheet.getCell(args.row, args.col).value(newval);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ checkingActualValue(record, newval){
|
|
|
+ let minExist = record.minValue && record.minValue != '0' ? true : false;
|
|
|
+ let maxExist = record.maxValue && record.maxValue != '0' ? true : false;
|
|
|
+ let minValue = parseFloat(record.minValue);
|
|
|
+ let maxValue = parseFloat(record.maxValue);
|
|
|
+
|
|
|
+ if (!maxExist && minExist) {
|
|
|
+ if (newval < minValue) {
|
|
|
+ alert('实际值应≥' + minValue);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (maxExist && !minExist) {
|
|
|
+ if (newval > maxValue) {
|
|
|
+ alert('实际值应≤' + maxValue);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (maxExist && minExist) {
|
|
|
+ if (newval < minValue || newval > maxValue) {
|
|
|
+ alert('实际值应介于' + minValue + '~' + maxValue + '之间');
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+$(function () {
|
|
|
+ $('#linkZMHS').on('shown.bs.tab', function (e) {
|
|
|
+ if(zmhs_obj.coeSpread == null || zmhs_obj.assSpread == null){
|
|
|
+ zmhs_obj.initSpread();
|
|
|
+ }
|
|
|
+ zmhs_obj.refresh();
|
|
|
+ zmhs_obj.showZMHSData();
|
|
|
+ })
|
|
|
+});
|