ration_coe.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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.showDatas();
  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. $('#coeSpread').is(':visible'),
  62. zmhs_obj.showDatas();
  63. };
  64. ration_coe.prototype.refreshAfterDelete=function(data){
  65. var glj_list = projectObj.project.ration_coe.datas;
  66. _.remove(glj_list,data.query);
  67. _.remove(gljOprObj.sheetData,data.query);
  68. zmhs_obj.showDatas();
  69. };
  70. ration_coe.prototype.getRationCoedata=function(newRation,data){
  71. var criteria= {};
  72. criteria.ration_coe_list = [];
  73. var dataLength = 0;
  74. if(data.hasOwnProperty('rationCoeList')&&data.rationCoeList.length>0){
  75. dataLength = data.rationCoeList.length
  76. }
  77. for(var i=0;i<=dataLength;i++){;
  78. var newCoe = {
  79. libID :data.rationRepId,
  80. rationID:newRation.ID,
  81. projectID : newRation.projectID
  82. }
  83. if(i==dataLength){
  84. newCoe.coeID=-1;
  85. newCoe.name = '自定义系数';
  86. newCoe.content='人工×1,材料×1,机械×1,主材×1,设备×1';
  87. newCoe.isAdjust=0;
  88. newCoe.coes = this.getCustomerCoeData();
  89. }else {
  90. newCoe.coeID= data.rationCoeList[i].ID;
  91. }
  92. criteria.ration_coe_list.push(newCoe);
  93. }
  94. criteria.updateType = 'ut_create';
  95. console.log('enterrrrrrrrrrrrrrrrrrrrrr');
  96. console.log(criteria);
  97. return criteria;
  98. };
  99. ration_coe.prototype.getCustomerCoeData = function () {
  100. var coeList = [];
  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. coeList.push({ amount:1, operator:'*', gljCode:null, coeType:'设备'});
  107. return coeList;
  108. };
  109. ration_coe.prototype.getUpdateData=function(type,query,doc,callfunction){
  110. var updateData = [];
  111. var newobj = {
  112. 'updateType': type,
  113. 'query': query,
  114. }
  115. if(doc){
  116. newobj['doc']=doc;
  117. }
  118. if(callfunction){
  119. newobj['updateFunction']=callfunction;
  120. }
  121. updateData.push(newobj);
  122. return updateData;
  123. };
  124. ration_coe.prototype.adjustCoeClick = function(record,newval,ext){
  125. let me=this,codesList = [],add=[],replace=[];
  126. let doc = ext?ext:{};
  127. doc['isAdjust'] = newval;
  128. var updateData = {
  129. 'ID':record.ID,
  130. 'projectID': record.projectID,
  131. 'rationID':record.rationID,
  132. 'doc':doc,
  133. add:[],
  134. delete:[],
  135. replace:[]
  136. };
  137. let gljList = project.ration_glj.getGLJListByRationID(record.rationID);
  138. if(gljUtil.isDef(record.option_codes)&&record.option_codes!=""){ //说明编辑的是下拉选择编号的类型
  139. //勾选而不是下拉的情况下,默认选择下拉框中的第一个
  140. if(newval == 1 && (!gljUtil.isDef(doc.select_code)||doc.select_code == '')){
  141. if(record.option_list&&record.option_list.length > 0) doc.select_code = record.option_list[0].value;
  142. }
  143. this.prepareDataForOptionType(record,newval,gljList,updateData,replace,codesList,doc);
  144. }
  145. for(let coe of record.coes){//做单个、替换等检查
  146. if(coe.coeType == "单个工料机"){ //单个工料机的情况
  147. let glj = _.find(gljList,{"code":coe.gljCode});
  148. if(newval == 1){ //单个工料机,选中时,如果能找到则不管,如果没找到,则需自动插入
  149. if(glj) continue;
  150. add.push(coe.gljCode);
  151. codesList.push(coe.gljCode);
  152. }else {//取消勾选时,要删除添加的工料机记录
  153. if(glj && glj.createType == "add") updateData.delete.push(glj.ID);
  154. }
  155. }
  156. //替换工料机的情况
  157. if(coe.coeType == "替换人材机"){
  158. let glj = _.find(gljList,{"rcode":coe.gljCode,'code':coe.replaceCode});//两个条件都满足,则表示已找到对应的记录
  159. if(newval == 1){
  160. if(glj) continue;
  161. let r_glj = _.find(gljList,function (g) {
  162. return (g.code == coe.gljCode && (g.createType===undefined || g.createType == 'normal')) || g.rcode == coe.gljCode //这两个满足一个说明要替换
  163. });
  164. if(r_glj){
  165. replace.push({code:coe.replaceCode,oldData:r_glj});
  166. codesList.push(coe.replaceCode);
  167. }
  168. }
  169. if(newval == 0 && glj){//取消勾选并找到的情况,要恢复成原来的
  170. replace.push({code:coe.gljCode,oldData:glj});
  171. codesList.push(coe.gljCode);
  172. }
  173. }
  174. }
  175. project.ration_glj.getGLJDataByCodes(codesList,function (gljList) {//统一从后端按编号查找标准工料机信息
  176. let gljMap = _.indexBy(gljList, 'code');
  177. for(let a of add){
  178. if(gljMap[a]){
  179. let tem = project.ration_glj.getAddDataByStd(gljMap[a],record.rationID,project.mainTree.selected.data.billsItemID,record.projectID);
  180. updateData.add.push(tem);
  181. }
  182. }
  183. for(let r of replace){
  184. if(gljMap[r.code]){
  185. let r_tem = project.ration_glj.getReplaceDataByStd(r.oldData,gljMap[r.code]);
  186. updateData.replace.push(r_tem);
  187. }
  188. }
  189. $.bootstrapLoading.start();
  190. CommonAjax.post("/ration/updateCoeAdjust",updateData,function (result) {
  191. $.bootstrapLoading.end();
  192. me.refreshAfterUpdate(result.coe);
  193. zmhs_obj.refreshAfterUpdate(result);
  194. })
  195. });
  196. };
  197. ration_coe.prototype.prepareDataForOptionType = function (record,newval,gljList,updateData,replace,codesList,ext) {
  198. let select_code = record.select_code;
  199. if(ext && gljUtil.isDef(ext.select_code)&&ext.select_code!=""){//是下拉框选择了人材机编号进来的
  200. select_code = ext.select_code;
  201. }
  202. if(gljUtil.isDef(select_code) && select_code!=""){//有选中编号的情况下,才会做这些操作
  203. let glj = _.find(gljList,{"rcode":record.original_code,'code':select_code});//两个条件都满足,则表示已找到对应的记录
  204. if(newval == 1){
  205. if(!glj){//在没找到的情况下,要替换
  206. let r_glj = _.find(gljList,function (g) {
  207. return (g.code == record.original_code && (g.createType===undefined || g.createType == 'normal')) || g.rcode == record.original_code //这两个满足一个说明要替换
  208. });
  209. if(r_glj){
  210. replace.push({code:select_code,oldData:r_glj});
  211. codesList.push(select_code);
  212. }
  213. }
  214. }else {
  215. updateData.doc['select_code'] = ""; //取消勾选,选中值要恢复为空
  216. if(glj){//如果找到工料机,还需要恢复成原来的
  217. replace.push({code:record.original_code,oldData:glj});
  218. codesList.push(record.original_code);
  219. }
  220. }
  221. }
  222. };
  223. ration_coe.prototype.updateCustomerCoe = function (data) {
  224. var updateData = this.getUpdateData('ut_update',data.query,data.doc,'updateCustomerCoe');
  225. project.pushNow('updateCustomerCoe',[this.getSourceType()],updateData);
  226. };
  227. ration_coe.prototype.deleteByRation = function(ration){
  228. var coe_list = projectObj.project.ration_coe.datas;
  229. _.remove(coe_list,{'rationID':ration.ID});
  230. };
  231. return new ration_coe(project);
  232. }
  233. };