/** * Created by chen on 2017/8/1. */ var feeRateObject={ mainViews:null, datas:null, canEdit:false, activateFeeRate:null, needCascadeSet:false, selectionLoad:false, changeInfo:null, feeRateSpreads:null, editingCell:null, sheetSetting: { header: [ {headerName: "专业名称", headerWidth: 200, dataCode: "name", dataType: "String"}, {headerName: "值%", headerWidth: 150, dataCode: "rate", dataType: "String",hAlign: "right"}, {headerName: "备注", dataCode: "memo", dataType: "String"} ], view: { comboBox: [], lockColumns: [0, 1, 2] } }, columns: [ { id: 'name', caption: '专业名称', dataField: 'name', width: 450, allowEditing: false }, { id: 'rate', caption: '值%', dataField: 'rate', format: '0.000', width: 120, minWidth: 50, allowEditing: true }, { id: 'memo', caption: '备注', dataField: 'memo', minWidth: 120, allowEditing: true }, { id: 'ID', caption: 'ID', dataField: 'ID', width: 80, visible: false, allowEditing: false }, { id: 'subFeeRate', caption: '子费率', dataField: 'subFeeRate', width: 80, visible: false, allowEditing: false }, { id: '_id', caption: '自动ID', dataField: '_id', width: 80, visible: false, allowEditing: false }, { id: 'ParentID', caption: '父结点ID', dataField: 'ParentID', width: 80, visible: false, allowEditing: false } ], options :{ allowSorting: false, showRowHeader: true, colMinWidth: 80, rowHeight: 30, allowEditing: true, editMode: 'inline', editUnit: 'cell', selectionUnit: "row", hierarchy: { keyField: 'ID', parentField: 'ParentID', collapsed: false, column: 'name' } }, dataSource : { loadRange: function(params) { params.success(feeRateObject.datas); }, update: function(params) { if(!params.hasOwnProperty('sourceIndex')){ var selected = feeRateObject.mainViews.getSelections()[0]; params.sourceIndex = selected.sourceRow; } params.success(); if(!$('#cascadeSet').prop('checked')||params.hasOwnProperty('viewIndex')){ projectObj.project.FeeRate.updateFeeRateByEdit(params,feeRateObject.activateFeeRate); } } }, createSheet:function(){ var feeRateFile = projectObj.project.FeeRate.getActivateFeeRate(); feeRateObject.feeRateSpreads=sheetCommonObj.buildSheet($('#fee_rate_sheet')[0], feeRateObject.sheetSetting,feeRateFile.rates.length); //gljOprObj.gljLibSpresd.bind(GC.Spread.Sheets.Events.ButtonClicked,gljOprObj.onButtonClick); feeRateObject.feeRateSheet = feeRateObject.feeRateSpreads.getSheet(0); feeRateObject.feeRateSheet.selectionUnit(1)//0 cell,1 row,2 col; feeRateObject.feeRateSheet.options.isProtected = true; feeRateObject.feeRateSheet.name('fee_rate'); }, showSelectTree:function () { var sheet= feeRateObject.feeRateSheet; var setting=feeRateObject.sheetSetting; var data = projectObj.project.FeeRate.getActivateFeeRate().rates; var ch = GC.Spread.Sheets.SheetArea.viewport; var groups=[]; sheet.suspendPaint(); sheet.suspendEvent(); sheet.rowOutlines.direction(GC.Spread.Sheets.Outlines.OutlineDirection.backward); sheet.getRange(-1, 0, -1, 1).cellType(feeRateObject.getTreeNodeCellType()); for (var col = 0; col < setting.header.length; col++) { var hAlign = "left", vAlign = "center"; if (setting.header[col].hAlign) { hAlign = setting.header[col].hAlign; } else if (setting.header[col].dataType !== "String"){ hAlign = "right"; } vAlign = setting.header[col].vAlign?setting.header[col].vAlign:vAlign; sheetCommonObj.setAreaAlign(sheet.getRange(-1, col, -1, 1), hAlign, vAlign); if (setting.header[col].formatter) { sheet.setFormatter(-1, col, setting.header[col].formatter, GC.Spread.Sheets.SheetArea.viewport); } for (var row = 0; row < data.length; row++) { var val = data[row][setting.header[col].dataCode]; if(val&&setting.header[col].dataType === "Number"){ if(setting.header[col].hasOwnProperty('tofix')){ val =parseFloat(val).toFixed(setting.header[col].tofix); }else { val =parseFloat(val).toFixed(2); } } sheet.setValue(row, col, val, ch); if(col==0){ feeRateObject.setSheetGroup(data[row],data,groups,row+1); } } } //this.lockCells(sheet,setting); console.log(groups); _.forEach(groups,function (g) { for(var k in g){ sheet.rowOutlines.group(parseInt(k), g[k]); } }) /* sheet.rowOutlines.group(1, 6); sheet.rowOutlines.group(8, 6); sheet.rowOutlines.group(15, 6); sheet.rowOutlines.group(22, 6);*/ // sheet.getRange(-1, 0, -1, 1).width(300); sheet.showRowOutline(false); sheet.resumeEvent(); sheet.resumePaint(false); }, getTreeNodeCellType:function () { var ns = GC.Spread.Sheets; function TreeNodeCellType() { } TreeNodeCellType.prototype = new ns.CellTypes.Text(); TreeNodeCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) { var level = options.sheet.rowOutlines.getLevel(options.row); var nlevel = -1; if (options.row < options.sheet.getRowCount() - 1) { nlevel = options.sheet.rowOutlines.getLevel(options.row + 1); } var hoffset = (level + 2) * 12; x += hoffset; w -= hoffset; GC.Spread.Sheets.CellTypes.Base.prototype.paint.apply(this, arguments); if (options.row == options.sheet.getRowCount() - 1) return; //last row if (nlevel > level) { var collapsed = options.sheet.rowOutlines.isCollapsed(options.row + 1); x--; y += h / 2 - 3; ctx.save(); ctx.fillStyle = "black"; ctx.beginPath(); if (collapsed) { ctx.moveTo(x - 5, y); ctx.lineTo(x, y + 3); ctx.lineTo(x - 5, y + 6); } else { ctx.moveTo(x, y); ctx.lineTo(x, y + 5); ctx.lineTo(x - 5, y + 5); } ctx.fill(); ctx.restore(); } else { x--; y += h / 2 - 3; ctx.save(); ctx.restore(); } }; // 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 level = hitinfo.sheet.rowOutlines.getLevel(hitinfo.row); var hoffset = (level + 2) * 12 + hitinfo.cellRect.x; if (hitinfo.x < hoffset && hitinfo.x > hoffset - 10) { var collapsed = hitinfo.sheet.rowOutlines.isCollapsed(hitinfo.row + 1); hitinfo.sheet.rowOutlines.setCollapsed(hitinfo.row, !collapsed); hitinfo.sheet.invalidateLayout(); hitinfo.sheet.repaint(); } }; return new TreeNodeCellType() }, getFeeRateEditCellType:function () { var ns = GC.Spread.Sheets; function FeeRateEditCellType() { var init=false; } FeeRateEditCellType.prototype = new ns.CellTypes.Text(); FeeRateEditCellType.prototype.paint = function (ctx, value, x, y, w, h, style, options) { if(value!=null){ ctx.fillText(value,x+3+ctx.measureText(value).width,y+h-3); } if(feeRateObject.editingCell){ if(feeRateObject.editingCell.row==options.row&&feeRateObject.editingCell.col==options.col){ var image = document.getElementById('f_btn'),imageMagin = 3; var imageHeight = h-2*imageMagin; var imageWidth = imageHeight* 4/3; var imageX = x + w - imageWidth- imageMagin, imageY = y + h / 2 - imageHeight / 2; ctx.save(); ctx.drawImage(image, imageX, imageY,imageWidth,imageHeight); ctx.beginPath(); ctx.arc(imageX+imageWidth/2,imageY+imageHeight/2,1,0,360,false); ctx.arc(imageX+imageWidth/2-4,imageY+imageHeight/2,1,0,360,false); ctx.arc(imageX+imageWidth/2+4,imageY+imageHeight/2,1,0,360,false); ctx.fillStyle="black";//填充颜色,默认是黑色 ctx.fill();//画实心圆 ctx.closePath(); ctx.restore(); } } }; FeeRateEditCellType.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 }; }; FeeRateEditCellType.prototype.processMouseDown = function (hitinfo) { if(feeRateObject.editingCell==null){ feeRateObject.editingCell={ row:hitinfo.row, col:hitinfo.col } hitinfo.sheet.invalidateLayout(); hitinfo.sheet.repaint(); }else if(hitinfo.row==feeRateObject.editingCell.row){ var offset=hitinfo.cellRect.x+hitinfo.cellRect.width-6; var imageMagin=3; var imageHeight = hitinfo.cellRect.height-2*imageMagin; var imageWidth = imageHeight* 4/3; if(hitinfo.xoffset-imageWidth){ feeRateObject.showSelectModal(hitinfo); } } }; FeeRateEditCellType.prototype.processMouseLeave = function (hitinfo) { feeRateObject.editingCell=null; hitinfo.sheet.invalidateLayout(); hitinfo.sheet.repaint(); } return new FeeRateEditCellType(); }, showSelectModal:function (hitinfo) { $("#fee_rate_tree").modal({show:true}); $('#edit_from').val(hitinfo.sheet.name()); $('#edit_row').val(hitinfo.row); }, setSheetGroup:function (rate,data,groups,row) { var me=this; var group={}; var count=me.getChildrenCount(rate.ID,data); if(count>0){ group[row]=count; groups.push(group); } return groups; }, getChildrenCount:function (id,data) { var me=this; var sum=0; var children=_.filter(data,{'ParentID':id}); if(children&&children.length==0){ return 0; } for(var i=0;i").val(data.ID).text(data.libName); $('#inlineFormCustomSelect').append(option); if(data.status=='activate'){ selectedID=data.ID; } }) $('#inlineFormCustomSelect').val(selectedID); } }, getFeeRateStandards:function (callback) { CommonAjax.post('/feeRates/getFeeRateStandards', {"projectID": projectObj.project.ID()}, function (data) { if (data) { callback(data); } }); }, changeFeeRateStandard:function(newVal){ var callback=function () { feeRateObject.createSpreadView(); feeRateObject.loadPageContent(); projectObj.project.FeeRate.synchronizeFeeRate(); subRateObject.destorySpreadView(); }; projectObj.project.FeeRate.changeFeeRateStandard(newVal,callback); }, checkFeeRateName:function (newVal) { if(!newVal||newVal==""){ $('#saveAsConfirm').attr("disabled","disabled"); $('#nameError').text("请输入文件名称。").show(); return; } var callback=function (data) { if(data){ $('#saveAsConfirm').attr("disabled","disabled"); $('#nameError').text("已存在同名费率文件。").show(); $('#valid_name').val(''); }else { $('#valid_name').val(newVal); $('#saveAsConfirm').removeAttr("disabled"); $('#nameError').hide(); } console.log(data); }; projectObj.project.FeeRate.checkFeeRateName(newVal,callback); }, feeRateFileSaveAs:function (newName) { if(!newName||newName==""){ $('#saveAsConfirm').attr("disabled","disabled"); $('#nameError').text("请输入文件名称。").show(); return; } var valideName = $('#valid_name').val(); if(valideName==''||valideName!==newName){ var callback=function (data) { if(data){ $('#saveAsConfirm').attr("disabled","disabled"); $('#nameError').text("已存在同名费率文件。").show(); $('#valid_name').val(''); }else { feeRateObject.submitSaveAs(newName); } } projectObj.project.FeeRate.checkFeeRateName(newName,callback) }else { feeRateObject.submitSaveAs(newName); } }, submitSaveAs:function (newName) { this.activateFeeRate = projectObj.project.FeeRate.feeRateFileSaveAs(newName); feeRateObject.loadPageContent(); $('#copy-lv').modal('hide'); }, getChangeInfo:function () { var me = this; var callback=function (data) { me.changeInfo=data; me.loadChangePageContent(data); console.log(data); }; projectObj.project.FeeRate.getChangeInfo(callback); }, loadChangePageContent:function (data) { $('#currentProject').text(data.currentProject.name); $('#currentOptions').empty(); _.forEach(data.currentProject.currentOptions,function (s) { var option = $("