/** * Created by Mai on 2017/4/1. */ var PROJECT = { createNew: function (projectID, userID) { // 定义private方法 var tools = { _project: null, _ID: parseInt(projectID), _userID: userID, updateLock: 0, updateData: [], operation: '', modules: {}, projCounter: 'projCounter', projSetting: 'proj_setting' }; var me = tools; tools.doAfterUpdate = function(result){ if (!result) { return } result.forEach(function(item){ if(_.isArray(item)){ item.forEach(function (e) { me.eachItem(e); }) }else { me.eachItem(item) } }); }; tools.doAfterLoad = function(result, callback){ var counter; result.forEach(function(item){ if (me.modules[item.moduleName]){ me.modules[item.moduleName].loadData(item.data); } else if (item.moduleName === me.projCounter) { counter = item.data; } else if (item.moduleName === me.projSetting) { me._project.projSetting = item.data; me._project.projSetting.moduleName = me.projSetting; }else if(item.moduleName === ModuleNames.projectGLJ){ me._project.projectGLJ.loadToCache(item.data); } }); for (module in counter) { if (me.modules[module]) { me.modules[module].setMaxID(counter[module]); } } me._project.loadMainTree(); //me.test(result[0].data[0]); callback(0); }; tools.eachItem=function(item){ if (me.modules[item.moduleName]){ me.modules[item.moduleName].doAfterUpdate(item.err, item.data); } }; /*tools.test = function(data){ me._project.beginUpdate('修改名称'); data.name = 'test'; data['updateType'] = 'ut_update'; me._project.push(ModuleNames.bills, [data]); me._project.endUpdate(); };*/ // 所有通过this访问的属性,都不应在此单元外部进行写入操作 var project = function () { tools._project = this; this.mainTree = cacheTree.createNew(this); this.Bills = Bills.createNew(this); this.Ration = Ration.createNew(this); this.GLJ = GLJ.createNew(this); this.ration_glj = ration_glj.createNew(this); this.ration_coe = ration_coe.createNew(this); this.ration_ass = ration_ass.createNew(this); this.ration_installation = ration_installation.createNew(this); this.quantity_detail = quantity_detail.createNew(this); this.installation_fee = installation_fee.createNew(this); this.FeeRate = FeeRate.createNew(this); // this.VolumePrice = VolumePrice.createNew(this); this.projectGLJ = new ProjectGLJ(); // this.projectGLJ.loadData(); this.composition = new Composition(); this.composition.loadData(); this.labourCoe = new LabourCoe(this); this.calcProgram = new CalcProgram(this); this.calcBase = calcBase; // this.masterField = {ration: 'billsItemID', volumePrice: 'billsItemID'}; this.masterField = {ration: 'billsItemID'}; }; // prototype用于定义public方法 project.prototype.modify = function (modifyDatas, callback) { // To Do }; // prototype用于定义public方法 project.prototype.ID = function () { return tools._ID; }; project.prototype.projCounter = function () { return tools.projCounter; }; project.prototype.getDecimal = function (fullName) { let names = fullName.split('.'), decimal = this.Decimal; for (let name of names) { if (decimal[name]) { decimal = decimal[name]; } else { return null; } } if (Object.prototype.toString.apply(decimal) === '[object Number]') { return decimal; } else { return null; } }; project.prototype.loadMainTree = function () { var that = this; let loadRationGLJNode = function (cacheNode) { var newNode, bj = that.ration_glj.getMainAndEquGLJ(cacheNode.source.ID), i; for(i=0;i