/** * 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.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); } } }; ration_glj.prototype.refreshAfterSave=function(data){ if(projectObj.project.ration_glj.datas&&Array.isArray(projectObj.project.ration_glj.datas)){ projectObj.project.ration_glj.datas = projectObj.project.ration_glj.datas.concat(data); }else { projectObj.project.ration_glj.datas = data; } sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,data); // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas); }; ration_glj.prototype.refreshAfterUpdate=function(data){ var glj_list = projectObj.project.ration_glj.datas; var glj_index= _.findIndex(glj_list,(glj)=>{ return glj.ID==data.query.ID&&glj.projectID==data.query.projectID; }) glj_list[glj_index].customQuantity=data.doc.customQuantity; glj_list[glj_index].quantity=data.doc.quantity; var showList = _.filter(glj_list,{'projectID':data.query.projectID,'rationID':glj_list[glj_index].rationID}); gljOprObj.sheetData=showList; sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,showList); }; ration_glj.prototype.refreshAfterDelete=function(data){ var glj_list = projectObj.project.ration_glj.datas; _.remove(glj_list,data.query); _.remove(gljOprObj.sheetData,data.query); sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,gljOprObj.sheetData); }; // 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.replaceGLJ = function (data, newGLJID) { this.project.beginUpdate('replaceGLJ'); data.GLJID = newGLJID; data.updateType = 'ut_update'; this.project.push(this.getSourceType, data); this.project.endUpdate(); }; ration_glj.prototype.addRationGLJ = function (newRation,data) { 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.updataOrdelete=function(row){ var updateData = []; if(row.rationItemQuantity==0){ updateData.push({'updateType': 'ut_delete', 'query': {'ID': row.ID, 'projectID': row.projectID}}); }else { updateData.push({'updateType': 'ut_update','query': {'ID': row.ID, 'projectID': row.projectID},'doc':{'quantity':0,'customQuantity':0}}); } project.pushNow('addRationGLJ',[this.getSourceType()],updateData) } return new ration_glj(project); } };