/** * 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) } }); }; // isInit: 是否是初始化,导出接口用到getData,但是非初始化,多次调用getData不会覆盖原有缓存数据 tools.doAfterLoad = function(result, isInit, callback){ var counter; //必须要先load ProjectInfo的信息 let projectInfoModule = result.find(data => data.moduleName === ModuleNames.projectInfo); if (projectInfoModule) { me._project.projectInfo = projectInfoModule.data; OVER_HEIGHT.init(me._project.projectInfo.property.overHeight); } result.forEach(function(item){ if (item.moduleName !== ModuleNames.projectInfo) { if (me.modules[item.moduleName]){ me.modules[item.moduleName].loadData(item.data, isInit); } 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]); } } if (isInit) { projectInfoObj.showProjectInfo(me._project.projectInfo); } me._project.loadMainTree(); //me.test(result[0].data[0]); if (callback) { 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.ration_template = ration_template.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.evaluate_list = new EvaluateList(this); this.bid_evaluation_list = new BidEvaluationList(this); this.contractor_list = new ContractorList(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 0 && pnode.children[0].sourceType == ModuleNames.bills){//设置子项不包括定额 for(let c of pnode.children){ let data = { type:c.sourceType, data:{ID:c.data.ID} }; setData(data.data,newval,fieldName); datas.push(data); setChildren(c,newValue,datas) } } } function setParent(cnode,newValue,datas) { let diferrent = false; if(cnode.parent && !projectObj.project.Bills.isMeasureNode(cnode.parent)){//排除措施项目节点 for(b of cnode.parent.children){ if(b == cnode) continue if(b.data[fieldName]!== newValue){//有兄弟节点的值和本节点不一样,则父节点设置为null diferrent = true; break; } } let pvalue = diferrent === true?null:newValue; let data = { type:cnode.parent.sourceType, data:{ID:cnode.parent.data.ID} }; setData(data.data,pvalue,fieldName); datas.push(data); setParent(cnode.parent,pvalue,datas); } } function setData(data,avalue,fieldName) { data[fieldName] = avalue; if(fieldName == "outPutMaxPrice") data.maxPrice = null; } }; project.prototype.updateNodesAndRefresh=function (datas,callback) { let me = this; this.updateNodes(datas,function () { let nodes = me.updateNodesCache(datas); if(callback) callback(nodes); }) }; project.prototype.updateNodes = function (datas,callback) { /* let datas = [ { type:'ration', data:{ projectID:1605, ID:"7b962fb0-1131-11e8-b3da-af725dadd7ae", name:'testRation' } }, { type:'bills', data:{ projectID:1605, ID:"af9f0081-1127-11e8-99a8-2fc02230b6e7", name:'安全文明施工专项费用123' } } ]*/ $.bootstrapLoading.start(); CommonAjax.post("/project/updateNodes",datas,function (data) { if(callback){ callback(data); $.bootstrapLoading.end(); } }) }; project.prototype.updateNodesCache =function (datas) { let refreshNode = []; for(let d of datas){ let temObj = null; if(d.type == ModuleNames.bills || d.type == ModuleNames.ration){//如果是树节点类型,直接取树节点更新 let temNode = this.mainTree.getNodeByID(d.data.ID); if(temNode){ temObj = temNode.data; refreshNode.push(temNode); } }else {//其它类型,更新datas temObj = _.find(this[d.type].datas,{"ID":d.data.ID}); } if(temObj){ for(let key in d.data){ if(key == 'ID' || key == 'id'){ continue; } this.setValue(temObj,key,d.data[key]) } } } return refreshNode; }; project.prototype.setValue=function (obj,key,value) { let keyArray = key.split('.'); t_set(obj,value,keyArray,0); function t_set(obj,value,arr,index) { let nextIndex = index + 1; let tkey = arr[index]; if(nextIndex < arr.length){ if(obj[tkey]==undefined){ obj[tkey] = {}; } t_set(obj[tkey],value,arr,nextIndex) }else if(nextIndex == arr.length){ obj[tkey] = value; } } } project.prototype.updateEvalproject = function (evalProject,data,callback){ let programID = null; if(evalProject ==1){//当打勾估价项目选项后,该定额取费专业读取计算程序名称为“估价项目”的计算程序,且为只读状态 programID = this.calcProgram.compiledTemplateMaps["估价项目"]; if(callback) callback(programID); }else {//如果evalProject==0,则是去掉勾选估价项目选项,需要获取定额默认的取费专业。 let libID = data.from == 'cpt'?"compleRationLib":data.libID; let query = {code:data.code,projectID:data.projectID,libID:libID}; CommonAjax.post("/ration/getDefaultProgramID",query,function (result) { if(callback) callback(result); }) } }; //判断项目是否安装工程 project.prototype.isInstall = function () { return projectObj.project.projectInfo.property.isInstall?true:false;//如果是undefinded 就也返回false }; // 判断项目能否使用超高降效相关功能 (是否含有超高降效库数据) project.prototype.isOverHeightProject = function () { const overHeight = projectObj.project.projectInfo.property.overHeight; return Array.isArray(overHeight) && overHeight.length; } /* project.prototype.setBillsCalcMode = function (calcMode) { this.property.billsCalcMode = calcMode; this.initCalcFields(); };*/ /*project.prototype.initCalcFields = function () { // let settingConst = this.projSetting.settingConst; if (this.calcFields) { for (let field of this.calcFields) { // unitFeeCalcFlag if (field.type === 'zangu') { field.unitFeeFlag = converseUnitFeeFlag; } else { // if (this.projSetting.billsCalcMode === settingConst.billsCalcMode.rationContent) { if (this.property.billsCalcMode === leafBillGetFeeType.rationContent) { field.unitFeeFlag = rationContentUnitFeeFlag; // } else if ( this.projSetting.billsCalcMode === settingConst.billsCalcMode.billsPrice) { } else if ( this.property.billsCalcMode === leafBillGetFeeType.billsPrice) { field.unitFeeFlag = billsPriceUnitFeeFlag; } else { field.unitFeeFlag = averageQtyUnitFeeFlag; } } // totalFeeCalcFlag if (field.type === 'common') { // if (this.projSetting.billsCalcMode === settingConst.billsCalcMode.rationPriceConverse) { if (this.property.billsCalcMode === leafBillGetFeeType.rationPriceConverse) { field.totalFeeFlag = sumTotalFeeFlag; } else { field.totalFeeFlag = totalFeeFlag; } } else { field.totalFeeFlag = sumTotalFeeFlag; } } } }*/ return new project(); } };