/** * Created by chen on 2017/8/1. */ /*var rate_data = [ {"ID":1,"ParentID":null,"name":"企业管理费","rate":null,"memo":""}, {"ID":101,"ParentID":1,"name":"建筑工程","rate":16.36,"memo":""}, {"ID":102,"ParentID":1,"name":"市政工程","rate":17.43,"memo":""}, {"ID":103,"ParentID":1,"name":"机械土石方","rate":10.82,"memo":""}, {"ID":104,"ParentID":1,"name":"仿古建筑工程","rate":12,"memo":""}, {"ID":105,"ParentID":1,"name":"建筑修缮工程","rate":12.47,"memo":""}, {"ID":106,"ParentID":1,"name":"炉窑砌筑工程","rate":10.8,"memo":""}, {"ID":2, "ParentID":null,"name":"夜间施工费","rate":null,"memo":""}, {"ID":201,"ParentID":2,"name":"建筑工程","rate":0.45,"memo":""}, {"ID":202,"ParentID":2,"name":"市政工程","rate":0.4,"memo":""}, {"ID":203,"ParentID":2,"name":"机械土石方","rate":0.7,"memo":""}, {"ID":204,"ParentID":2,"name":"仿古建筑工程","rate":0.2,"memo":""}, {"ID":205,"ParentID":2,"name":"建筑修缮工程","rate":0.35,"memo":""}, {"ID":206,"ParentID":2,"name":"炉窑砌筑工程","rate":0.4,"memo":""}, {"ID":3, "ParentID":null,"name":"规费","rate":null,"memo":""}, {"ID":301,"ParentID":3,"name":"建筑工程","rate":16.03,"memo":""}, {"ID":302,"ParentID":3,"name":"市政工程","rate":16.33,"memo":""}, {"ID":303,"ParentID":3,"name":"机械土石方","rate":15.5,"memo":""}, {"ID":304,"ParentID":3,"name":"仿古建筑工程","rate":12,"memo":""}, {"ID":305,"ParentID":3,"name":"建筑修缮工程","rate":12.47,"memo":""}, {"ID":306,"ParentID":3,"name":"炉窑砌筑工程","rate":10.8,"memo":""}, {"ID":4,"ParentID":null,"name":"利润","rate":null,"memo":""}, {"ID":401,"ParentID":4,"name":"建筑工程","rate":8.73,"memo":""}, {"ID":402,"ParentID":4,"name":"市政工程","rate":9.2,"memo":""}, {"ID":403,"ParentID":4,"name":"机械土石方","rate":6.5,"memo":""}, {"ID":404,"ParentID":4,"name":"仿古建筑工程","rate":7,"memo":""}, {"ID":405,"ParentID":4,"name":"建筑修缮工程","rate":3.72,"memo":""}, {"ID":406,"ParentID":4,"name":"炉窑砌筑工程","rate":4.9,"memo":""}, {"ID":5,"ParentID":null,"name":"税金","rate":11,"memo":""}];*/ var feeRateObject={ mainViews:null, datas:null, canEdit:false, activateFeeRate:null, needCascadeSet:false, selectionLoad:false, 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; } if(!$('#cascadeSet').prop('checked')||params.hasOwnProperty('viewIndex')){ projectObj.project.FeeRate.updateFeeRateByEdit(params,feeRateObject.activateFeeRate); } params.success(); } }, createSpreadView:function () { if (this.mainViews) { this.mainViews.destroy(); this.mainViews = null; } this.activateFeeRate = projectObj.project.FeeRate.getActivateFeeRate(); this.datas = this.activateFeeRate.rates; this.mainViews = new GC.Spread.Views.DataView($('#divFee')[0], this.dataSource, this.columns, new GC.Spread.Views.Plugins.GridLayout(this.options)); this.mainViews["rowClick"].addHandler(subRateObject.reFreshRateViews); this.mainViews .invalidate(); document.querySelector('#divFee').focus(); }, reFreshRateViews:function() { if(this.mainViews){ this.mainViews.refresh() }else { setTimeout("feeRateObject.createSpreadView()",100); } }, updateBySelect:function (rate,selectMap,mapID) { var selected = this.mainViews.getSelections()[0]; var item = this.datas[selected.sourceRow]; item.rate = rate; _.forEach(selectMap,function (value,key) { var recode = item.subFeeRate.recodes[key]; var optionList = recode.optionList; _.forEach(optionList,function (o) { if(o.value==value){ o.selected=true; }else { o.selected = false; } }) }) if($('#cascadeSet').prop('checked')){ this.cascadeSetRates(item,selected.sourceRow,mapID,selectMap) }else { this.mainViews.data.updateItem(selected.sourceRow,item); } //this.views.data.updateItem() }, cascadeSetRates:function(selectedItem,sourceRow,mapID,selectMap){ var items=[]; items.push({rateIndex:sourceRow,rate:selectedItem}); _.forEach(this.datas,function (recode,Index) { if(Index!=sourceRow&&recode.subFeeRate){ var valueMaps = recode.subFeeRate.valueMaps; var valueMap = _.find(valueMaps,{ID:mapID}); if(valueMap){//选项完全一样的情况 if(valueMap.value==recode.rate){ return; }else { recode.rate = valueMap.value; _.forEach(selectMap,function (value,key) { var tempRecode = recode.subFeeRate.recodes[key]; var optionList = tempRecode.optionList; _.forEach(optionList,function (o) { if(o.value==value){ o.selected=true; }else { o.selected = false; } }) }) items.push({rateIndex:Index,rate:recode}); } }else {//某条选项一样的情况 var needUpdate = false; var selectList = mapID.split('-'); var newList=[]; _.forEach(recode.subFeeRate.recodes,function (r) { var oList = r.optionList; var oldSelectIndex=0; var hasChange=false; _.forEach(oList,function (o,key) { if(o.selected){ oldSelectIndex = key; } if(_.includes(selectList,o.value)){ needUpdate=true; o.selected=true; hasChange=true; newList.push(o.value); }else { o.selected=false; } }) if(!hasChange){ oList[oldSelectIndex].selected=true; newList.push(oList[oldSelectIndex].value) } }) if(needUpdate){ var newValue = _.find(valueMaps,{ID:newList.join("-")})//取出费率值并更新 if(newValue){ if(recode.rate != newValue.value){ recode.rate = newValue.value items.push({rateIndex:Index,rate:recode}); } } } } } }) _.forEach(items,function (t) { feeRateObject.mainViews.data.updateItem(t.rateIndex,t.rate); }) projectObj.project.FeeRate.batchUpdateFeeRate(items,feeRateObject.activateFeeRate); }, loadFeeRateSelection:function() { if(!this.selectionLoad){ var selectedID=0; _.forEach(projectObj.project.FeeRate.datas,function (data) { var option = $("