/** * Created by Mai on 2017/4/1. */ var ration_glj = { createNew: function (project) { // 用户定义private方法 var tools = {}; // 所有通过this访问的属性,都不应在此单元外部进行写入操作 var ration_glj = function (proj) { this.gljTree = cacheTree.createNew(this); // this.project = proj; this.datas = []; var sourceType = ModuleNames.ration_glj; this.getSourceType = function () { return sourceType; } proj.registerModule(ModuleNames.ration_glj, this); }; // 从后台获取数据 /*glj.prototype.pullData = function (){ this.project.pullData( '/glj/getData', {projectID: this.project.ID}, function(result){ if (result.error ===0){ this.loadDatas(result.data); } else { // to do: 错误处理需要细化 alert(result.message); } }, function (){}//to do: 错误处理需要细化 ) };*/ // prototype用于定义public方法 ration_glj.prototype.loadData = function (datas) { this.datas = datas; }; ration_glj.prototype.getGljArrByRation = function (rationID) { return this.datas.filter(function (data) { return data.rationID === rationID; }) }; ration_glj.prototype.getGatherGljArrByRations = function (rations) { let result = []; let clone = function (obj) { if (obj === null) return null; var o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {}; for (var i in obj) { o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? clone(obj[i]) : obj[i]); } return o; } let findGlj = function (sourceGlj, gljArr) { for (let glj of gljArr) { if (glj.projectGLJID === sourceGlj.projectGLJID) { return glj; } } return null; } for (let ration of rations) { let rationGljs = this.getGljArrByRation(ration.ID); for (let glj of rationGljs) { let sameGlj = findGlj(glj, result); if (!sameGlj) { sameGlj = clone(glj); sameGlj.quantity = (sameGlj.quantity * ration.quantity).toDecimal(4); result.push(sameGlj); } else { sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4); } } }; result = gljOprObj.combineWithProjectGlj(result); return result; } // 提交数据后返回数据处理 ration_glj.prototype.doAfterUpdate = function(err, data){ if(!err){ if(data.updateTpye=='ut_update'){ this.refreshAfterUpdate(data); }else if(data.updateTpye=='ut_delete'){ this.refreshAfterDelete(data); } else { this.refreshAfterSave(data); } projectObj.project.projectGLJ.loadData(); } }; ration_glj.prototype.refreshAfterSave=function(data){ let neRecodes=[]; if(data){ neRecodes=data.newRecords; gljOprObj.sheetData=data.showDatas; } if(projectObj.project.ration_glj.datas&&Array.isArray(projectObj.project.ration_glj.datas)){ if(data){ projectObj.project.ration_glj.datas = projectObj.project.ration_glj.datas.concat(neRecodes); } }else { projectObj.project.ration_glj.datas = neRecodes; } gljOprObj.showRationGLJSheetData(); }; ration_glj.prototype.refreshAfterUpdate=function(data){ var me = this; if(data.quantityRefresh){ data.glj_result.forEach(function (item) { me.refreshEachItme(item.doc,item.query); }) }else { me.refreshEachItme(data.doc,data.query); } gljOprObj.showRationGLJSheetData(); }; ration_glj.prototype.refreshEachItme = function (doc,query) { var glj_list = projectObj.project.ration_glj.datas; var glj_index= _.findIndex(glj_list,(glj)=>{ return glj.ID==query.ID; }) var sheet_index= _.findIndex(gljOprObj.sheetData,(sd)=>{ return sd.ID==query.ID; }) _.forEach(doc, function(n, key) { glj_list[glj_index][key] = n; gljOprObj.sheetData[sheet_index][key]=n; }); return glj_list[glj_index].rationID; }; ration_glj.prototype.refreshAfterDelete=function(data){ var glj_list = projectObj.project.ration_glj.datas; _.remove(glj_list,data.query); _.remove(gljOprObj.sheetData,data.query); gljOprObj.showRationGLJSheetData(); projectObj.project.projectGLJ.loadData(); var selected = projectObj.project.mainTree.selected; selected.data.adjustState=data.adjustState; projectObj.mainController.refreshTreeNode([selected]); }; // CSL,2017.05.09 ration_glj.prototype.modifyQuantity = function (data, newQuantity) { this.project.beginUpdate('modifyQuantity'); data.quantity = newQuantity; data.customQuantity = newQuantity; data.updateType = 'ut_update'; this.project.push(this.getSourceType, data); this.project.endUpdate(); }; ration_glj.prototype.modifyPrice = function (data, newPrice) { this.project.beginUpdate('modifyPrice'); data.price = newPrice; data.updateType = 'ut_update'; this.project.push(this.getSourceType, data); this.project.endUpdate(); }; ration_glj.prototype.deleteGLJ = function (data) { this.project.beginUpdate('deleteGLJ'); data.customQuantity = 0; data.quantity = 0; data.rationItemQuantity = 0; data.updateType = 'ut_update'; this.project.push(this.getSourceType, data); this.project.endUpdate(); }; ration_glj.prototype.addRationGLJ = function (newRation,data) { var souceTypeList=[]; var criteriaDataList = []; if(data.hasOwnProperty('rationGljList')&&data.rationGljList.length>0){ let criteria= {}; criteria.ration_glj_list = []; for(let i=0;i{ return glj.rationID!=ration.ID; }); if(newList!=undefined){ projectObj.project.ration_glj.datas = newList; } }; ration_glj.prototype.deleteByBills=function(deleteData){ var rationList = projectObj.project.Ration.datas; var deleteRationList = []; for(var i=0;i{ return ration.billsItemID==billID; }); deleteRationList = deleteRationList.concat(raList); } } for(var i=0;i