123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- /**
- * 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 findGlj = function (sourceGlj, gljArr) {
- gljArr.forEach(function (glj) {
- 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) {
- result.push(glj);
- } else {
- sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4);
- }
- }
- }
- 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);
- }
- }
- };
- 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);
- gljOprObj.sheetData=data;
- // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
- };
- 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);
- }
- var selected = projectObj.project.mainTree.selected
- if(selected==null){
- return;
- }
- if(selected.sourceType==ModuleNames.ration){
- var showList = _.filter(projectObj.project.ration_glj.datas,{'rationID':selected.data.ID});
- gljOprObj.sheetData=showList;
- sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,showList);
- }
- };
- 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&&glj.projectID==query.projectID;
- })
- _.forEach(doc, function(n, key) {
- glj_list[glj_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);
- 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) {
- var souceTypeList=[];
- var criteriaDataList = [];
- if(data.hasOwnProperty('rationGljList')&&data.rationGljList.length>0){
- let criteria= {};
- criteria.ration_glj_list = [];
- for(let i=0;i<data.rationGljList.length;i++){
- let temdata = data.rationGljList[i];
- let newGLJ = {};
- newGLJ.projectID = newRation.projectID;
- newGLJ.GLJID = temdata.gljId;
- newGLJ.rationID = newRation.ID;
- newGLJ.rationItemQuantity= temdata.consumeAmt;
- newGLJ.quantity=temdata.consumeAmt;
- newGLJ.glj_repository_id=data.rationRepId;
- criteria.ration_glj_list.push(newGLJ);
- }
- criteria.updateType = 'ut_create';
- souceTypeList.push(this.getSourceType());
- criteriaDataList.push(criteria);
- }
- var ration_coe = projectObj.project.ration_coe;
- var rationCoeData = ration_coe.getRationCoedata(newRation,data);
- souceTypeList.push(ration_coe.getSourceType());
- criteriaDataList.push(rationCoeData);
- project.pushNow('addRationGLJAndRationCoe',souceTypeList,criteriaDataList);
- };
- ration_glj.prototype.getDeleteDataByRation=function(rationData){
- var updateData = [];
- updateData.push({'deleteType':'RATION','updateType': 'ut_delete', 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}});
- return updateData;
- };
- ration_glj.prototype.getDeleteDataByBills=function(datas){
- var updateData = [];
- datas.forEach(function (deleteData) {
- var billData = deleteData.data;
- updateData.push({'deleteType':'BILL','updateType': 'ut_delete', 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}});
- })
- return updateData;
- };
- ration_glj.prototype.deleteByRation = function(ration){
- var glj_list = projectObj.project.ration_glj.datas;
- var newList =_.filter(glj_list,(glj)=>{
- 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<deleteData.length;i++){
- var billID = deleteData[i].data.ID;
- var raList =_.filter(rationList,(ration)=>{
- return ration.billsItemID==billID;
- });
- deleteRationList = deleteRationList.concat(raList);
- }
- for(var i=0;i<deleteRationList.length;i++){
- this.deleteByRation(deleteRationList[i]);
- projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
- projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
- }
- }
- ration_glj.prototype.updataOrdelete=function(row){
- var updateData = null;
- if(row.rationItemQuantity==0){
- updateData=this.getUpdateData('ut_delete',{'ID': row.ID, 'projectID': row.projectID});
- project.pushNow('updateRationGLJ',[this.getSourceType()],updateData)
- }else {
- this.customQuantityUpdate(row,0,0);//('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
- }
- };
- ration_glj.prototype.getUpdateData=function(type,query,doc,callfunction){
- var updateData = [];
- var newobj = {
- 'updateType': type,
- 'query': query,
- }
- if(doc){
- newobj['doc']=doc;
- }
- if(callfunction){
- newobj['updateFunction']=callfunction;
- }
- updateData.push(newobj);
- return updateData;
- };
- ration_glj.prototype.customQuantityUpdate = function(recode,newVal,text){
- newVal = _.round(newVal,3);
- var query = {
- 'ID':recode.ID,
- 'projectID': recode.projectID,
- 'rationID':recode.rationID
- };
- var doc;
- if(text===null){
- doc ={
- customQuantity:null
- };
- }else {
- doc ={
- customQuantity:newVal,
- quantity:newVal
- };
- }
- var updateData = this.getUpdateData('ut_update',query,doc,'customQuantityUpdate');
- project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
- };
- ration_glj.prototype.marketPriceAdjustUpdate = function (recode,newVal,text) {
- newVal = _.round(newVal,2);
- if(text===null){
- newVal=null;
- }
- var query = {
- 'ID':recode.ID,
- 'projectID': recode.projectID,
- 'rationID':recode.rationID
- };
- var doc ={
- base_price:Number(recode.basePrice),
- market_price:newVal,
- code:recode.code,
- name:recode.name,
- project_id:recode.projectID
- };
- /* code: '01010101',
- market_price: '40',
- name: '水泥',
- project_id: projectId*/
- var updateData = this.getUpdateData('ut_update',query,doc,'marketPriceAdjustUpdate');
- project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
- };
- return new ration_glj(project);
- }
- };
|