ration_coe.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. zmhs_obj.showCoeData();
  38. };
  39. ration_coe.prototype.addDatasToList = function (datas) {
  40. let me = projectObj.project.ration_coe;
  41. if(datas&&datas.length>0){
  42. if (me.datas && Array.isArray(me.datas)) {
  43. me.datas = me.datas.concat(datas);
  44. } else {
  45. me.datas = datas;
  46. }
  47. }
  48. };
  49. ration_coe.prototype.getCoeByRationID = function (rationID) {
  50. let coeList = _.filter(this.datas, {'rationID': rationID});
  51. return coeList;
  52. };
  53. ration_coe.prototype.refreshAfterUpdate=function(data){
  54. var coe_list = projectObj.project.ration_coe.datas;
  55. var coe_index= _.findIndex(coe_list,function(coe){
  56. return coe.ID==data.query.ID&&coe.projectID==data.query.projectID;
  57. })
  58. _.forEach(data.doc, function(n, key) {
  59. coe_list[coe_index][key] = n;
  60. });
  61. zmhs_obj.showCoeData();
  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. zmhs_obj.showCoeData();
  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. console.log('enterrrrrrrrrrrrrrrrrrrrrr');
  95. console.log(criteria);
  96. return criteria;
  97. };
  98. ration_coe.prototype.getCustomerCoeData = function () {
  99. var coeList = [];
  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. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'主材'});
  105. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'设备'});
  106. return coeList;
  107. };
  108. ration_coe.prototype.getUpdateData=function(type,query,doc,callfunction){
  109. var updateData = [];
  110. var newobj = {
  111. 'updateType': type,
  112. 'query': query,
  113. }
  114. if(doc){
  115. newobj['doc']=doc;
  116. }
  117. if(callfunction){
  118. newobj['updateFunction']=callfunction;
  119. }
  120. updateData.push(newobj);
  121. return updateData;
  122. };
  123. ration_coe.prototype.adjustCoeClick = function(recode,newval){
  124. let me=this,codesList = [],add=[],replace=[];
  125. var updateData = {
  126. 'ID':recode.ID,
  127. 'projectID': recode.projectID,
  128. 'rationID':recode.rationID,
  129. 'doc':{
  130. isAdjust:newval
  131. },
  132. add:[],
  133. delete:[],
  134. replace:[]
  135. };
  136. let gljList = project.ration_glj.getGLJListByRationID(recode.rationID);
  137. for(let coe of recode.coes){//做单个、替换等检查
  138. if(coe.coeType == "单个工料机"){ //单个工料机的情况
  139. let glj = _.find(gljList,{"code":coe.gljCode});
  140. if(newval == 1){ //单个工料机,选中时,如果能找到则不管,如果没找到,则需自动插入
  141. if(glj) continue;
  142. add.push(coe.gljCode);
  143. codesList.push(coe.gljCode);
  144. }else {//取消勾选时,要删除添加的工料机记录
  145. if(glj && glj.createType == "add") updateData.delete.push(glj.ID);
  146. }
  147. }
  148. //替换工料机的情况
  149. }
  150. project.ration_glj.getGLJDataByCodes(codesList,function (gljList) {//统一从后端按编号查找标准工料机信息
  151. let gljMap = _.indexBy(gljList, 'code');
  152. console.log(gljMap);
  153. for(let a of add){
  154. if(gljMap[a]){
  155. let tem = project.ration_glj.getAddDataByStd(gljMap[a],recode.rationID,project.mainTree.selected.data.billsItemID,recode.projectID);
  156. updateData.add.push(tem);
  157. }
  158. }
  159. $.bootstrapLoading.start();
  160. CommonAjax.post("/ration/updateCoeAdjust",updateData,function (result) {
  161. $.bootstrapLoading.end();
  162. me.refreshAfterUpdate(result.coe);
  163. zmhs_obj.refreshAfterUpdate(result,true)
  164. })
  165. });
  166. /* ;*/
  167. //var updateData = this.getUpdateData('ut_update',query,doc,'adjustUpdate');
  168. // project.pushNow('updateRationCOE',[this.getSourceType()],updateData);
  169. };
  170. ration_coe.prototype.updateCustomerCoe = function (data) {
  171. var updateData = this.getUpdateData('ut_update',data.query,data.doc,'updateCustomerCoe');
  172. project.pushNow('updateCustomerCoe',[this.getSourceType()],updateData);
  173. };
  174. ration_coe.prototype.deleteByRation = function(ration){
  175. var coe_list = projectObj.project.ration_coe.datas;
  176. _.remove(coe_list,{'rationID':ration.ID});
  177. };
  178. return new ration_coe(project);
  179. }
  180. };