ration_coe.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var ration_coe = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. var tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. var ration_coe = function (proj) {
  10. this.gljTree = cacheTree.createNew(this);
  11. // this.project = proj;
  12. this.datas = [];
  13. var sourceType = ModuleNames.ration_coe;
  14. this.getSourceType = function () {
  15. return sourceType;
  16. }
  17. proj.registerModule(ModuleNames.ration_coe, this);
  18. };
  19. // prototype用于定义public方法
  20. ration_coe.prototype.loadData = function (datas) {
  21. this.datas = datas;
  22. };
  23. // 提交数据后返回数据处理
  24. ration_coe.prototype.doAfterUpdate = function(err, data){
  25. if(!err){
  26. if(data.updateTpye=='ut_update'){
  27. this.refreshAfterUpdate(data);
  28. }else if(data.updateTpye=='ut_delete'){
  29. this.refreshAfterDelete(data);
  30. } else {
  31. this.refreshAfterSave(data);
  32. }
  33. }
  34. };
  35. ration_coe.prototype.refreshAfterSave=function(data){
  36. projectObj.project.ration_coe.addDatasToList(data);
  37. gljOprObj.showCoeData(gljOprObj.coeSheet,gljOprObj.coeSetting,data);
  38. gljOprObj.coeSheetData=data;
  39. // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  40. };
  41. ration_coe.prototype.addDatasToList = function (datas) {
  42. let me = projectObj.project.ration_coe;
  43. if(datas&&datas.length>0){
  44. if (me.datas && Array.isArray(me.datas)) {
  45. me.datas = me.datas.concat(datas);
  46. } else {
  47. me.datas = datas;
  48. }
  49. }
  50. };
  51. ration_coe.prototype.refreshAfterUpdate=function(data){
  52. var coe_list = projectObj.project.ration_coe.datas;
  53. var coe_index= _.findIndex(coe_list,function(coe){
  54. return coe.ID==data.query.ID&&coe.projectID==data.query.projectID;
  55. })
  56. _.forEach(data.doc, function(n, key) {
  57. coe_list[coe_index][key] = n;
  58. });
  59. var showList = _.filter(coe_list,{'projectID':data.query.projectID,'rationID':coe_list[coe_index].rationID});
  60. gljOprObj.coeSheetData=showList;
  61. gljOprObj.showCoeData(gljOprObj.coeSheet,gljOprObj.coeSetting,showList);
  62. };
  63. ration_coe.prototype.refreshAfterDelete=function(data){
  64. var glj_list = projectObj.project.ration_coe.datas;
  65. _.remove(glj_list,data.query);
  66. _.remove(gljOprObj.sheetData,data.query);
  67. gljOprObj.showCoeData(gljOprObj.coeSheet,gljOprObj.coeSetting,gljOprObj.sheetData);
  68. };
  69. ration_coe.prototype.getRationCoedata=function(newRation,data){
  70. var criteria= {};
  71. criteria.ration_coe_list = [];
  72. var dataLength = 0;
  73. if(data.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
  74. dataLength = data.rationCoeList.length
  75. }
  76. for(var i=0;i<=dataLength;i++){;
  77. var newCoe = {
  78. libID :data.rationRepId,
  79. rationID:newRation.ID,
  80. projectID : newRation.projectID
  81. }
  82. if(i==dataLength){
  83. newCoe.coeID=-1;
  84. newCoe.name = '自定义系数';
  85. newCoe.content='人工×1,材料×1,机械×1,主材×1,设备×1';
  86. newCoe.isAdjust=0;
  87. newCoe.coes = this.getCustomerCoeData();
  88. }else {
  89. newCoe.coeID= data.rationCoeList[i].ID;
  90. }
  91. criteria.ration_coe_list.push(newCoe);
  92. }
  93. criteria.updateType = 'ut_create';
  94. return criteria;
  95. };
  96. ration_coe.prototype.getCustomerCoeData = function () {
  97. var coeList = [];
  98. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'定额'});
  99. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'人工'});
  100. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'材料'});
  101. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'机械'});
  102. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'主材'});
  103. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'设备'});
  104. return coeList;
  105. };
  106. ration_coe.prototype.getUpdateData=function(type,query,doc,callfunction){
  107. var updateData = [];
  108. var newobj = {
  109. 'updateType': type,
  110. 'query': query,
  111. }
  112. if(doc){
  113. newobj['doc']=doc;
  114. }
  115. if(callfunction){
  116. newobj['updateFunction']=callfunction;
  117. }
  118. updateData.push(newobj);
  119. return updateData;
  120. };
  121. ration_coe.prototype.adjustCoeClick = function(recode,newval){
  122. var query = {
  123. 'ID':recode.ID,
  124. 'projectID': recode.projectID,
  125. 'rationID':recode.rationID
  126. };
  127. var doc ={
  128. isAdjust:newval,
  129. };
  130. var updateData = this.getUpdateData('ut_update',query,doc,'adjustUpdate');
  131. project.pushNow('updateRationCOE',[this.getSourceType()],updateData);
  132. };
  133. ration_coe.prototype.updateCustomerCoe = function (data) {
  134. var updateData = this.getUpdateData('ut_update',data.query,data.doc,'updateCustomerCoe');
  135. project.pushNow('updateCustomerCoe',[this.getSourceType()],updateData);
  136. };
  137. ration_coe.prototype.deleteByRation = function(ration){
  138. var coe_list = projectObj.project.ration_coe.datas;
  139. _.remove(coe_list,{'rationID':ration.ID});
  140. };
  141. return new ration_coe(project);
  142. }
  143. };