ration_glj.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var ration_glj = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. var tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. var ration_glj = function (proj) {
  10. this.gljTree = cacheTree.createNew(this);
  11. // this.project = proj;
  12. this.datas = [];
  13. var sourceType = ModuleNames.ration_glj;
  14. this.getSourceType = function () {
  15. return sourceType;
  16. }
  17. proj.registerModule(ModuleNames.ration_glj, this);
  18. };
  19. // 从后台获取数据
  20. /*glj.prototype.pullData = function (){
  21. this.project.pullData(
  22. '/glj/getData',
  23. {projectID: this.project.ID},
  24. function(result){
  25. if (result.error ===0){
  26. this.loadDatas(result.data);
  27. }
  28. else {
  29. // to do: 错误处理需要细化
  30. alert(result.message);
  31. }
  32. },
  33. function (){}//to do: 错误处理需要细化
  34. )
  35. };*/
  36. // prototype用于定义public方法
  37. ration_glj.prototype.loadData = function (datas) {
  38. this.datas = datas;
  39. };
  40. // 提交数据后返回数据处理
  41. ration_glj.prototype.doAfterUpdate = function(err, data){
  42. if(!err){
  43. if(data.updateTpye=='ut_update'){
  44. this.refreshAfterUpdate(data);
  45. }else if(data.updateTpye=='ut_delete'){
  46. this.refreshAfterDelete(data);
  47. } else {
  48. this.refreshAfterSave(data);
  49. }
  50. }
  51. };
  52. ration_glj.prototype.refreshAfterSave=function(data){
  53. if(projectObj.project.ration_glj.datas&&Array.isArray(projectObj.project.ration_glj.datas)){
  54. projectObj.project.ration_glj.datas = projectObj.project.ration_glj.datas.concat(data);
  55. }else {
  56. projectObj.project.ration_glj.datas = data;
  57. }
  58. sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,data);
  59. // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  60. };
  61. ration_glj.prototype.refreshAfterUpdate=function(data){
  62. var glj_list = projectObj.project.ration_glj.datas;
  63. var glj_index= _.findIndex(glj_list,(glj)=>{
  64. return glj.ID==data.query.ID&&glj.projectID==data.query.projectID;
  65. })
  66. _.forEach(data.doc, function(n, key) {
  67. glj_list[glj_index][key] = n;
  68. });
  69. var showList = _.filter(glj_list,{'projectID':data.query.projectID,'rationID':glj_list[glj_index].rationID});
  70. gljOprObj.sheetData=showList;
  71. sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,showList);
  72. };
  73. ration_glj.prototype.refreshAfterDelete=function(data){
  74. var glj_list = projectObj.project.ration_glj.datas;
  75. _.remove(glj_list,data.query);
  76. _.remove(gljOprObj.sheetData,data.query);
  77. sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,gljOprObj.sheetData);
  78. };
  79. // CSL,2017.05.09
  80. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  81. this.project.beginUpdate('modifyQuantity');
  82. data.quantity = newQuantity;
  83. data.customQuantity = newQuantity;
  84. data.updateType = 'ut_update';
  85. this.project.push(this.getSourceType, data);
  86. this.project.endUpdate();
  87. };
  88. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  89. this.project.beginUpdate('modifyPrice');
  90. data.price = newPrice;
  91. data.updateType = 'ut_update';
  92. this.project.push(this.getSourceType, data);
  93. this.project.endUpdate();
  94. };
  95. ration_glj.prototype.deleteGLJ = function (data) {
  96. this.project.beginUpdate('deleteGLJ');
  97. data.customQuantity = 0;
  98. data.quantity = 0;
  99. data.rationItemQuantity = 0;
  100. data.updateType = 'ut_update';
  101. this.project.push(this.getSourceType, data);
  102. this.project.endUpdate();
  103. };
  104. ration_glj.prototype.replaceGLJ = function (data, newGLJID) {
  105. this.project.beginUpdate('replaceGLJ');
  106. data.GLJID = newGLJID;
  107. data.updateType = 'ut_update';
  108. this.project.push(this.getSourceType, data);
  109. this.project.endUpdate();
  110. };
  111. ration_glj.prototype.addRationGLJ = function (newRation,data) {
  112. var souceTypeList=[];
  113. var criteriaDataList = [];
  114. if(data.hasOwnProperty('rationGljList')&&data.rationGljList.length>0){
  115. let criteria= {};
  116. criteria.ration_glj_list = [];
  117. for(let i=0;i<data.rationGljList.length;i++){
  118. let temdata = data.rationGljList[i];
  119. let newGLJ = {};
  120. newGLJ.projectID = newRation.projectID;
  121. newGLJ.GLJID = temdata.gljId;
  122. newGLJ.rationID = newRation.ID;
  123. newGLJ.rationItemQuantity= temdata.consumeAmt;
  124. newGLJ.quantity=temdata.consumeAmt;
  125. newGLJ.glj_repository_id=data.rationRepId;
  126. criteria.ration_glj_list.push(newGLJ);
  127. }
  128. criteria.updateType = 'ut_create';
  129. souceTypeList.push(this.getSourceType());
  130. criteriaDataList.push(criteria);
  131. }
  132. var ration_coe = projectObj.project.ration_coe;
  133. var rationCoeData = ration_coe.getRationCoedata(newRation,data);
  134. souceTypeList.push(ration_coe.getSourceType());
  135. criteriaDataList.push(rationCoeData);
  136. project.pushNow('addRationGLJAndRationCoe',souceTypeList,criteriaDataList);
  137. };
  138. ration_glj.prototype.getDeleteDataByRation=function(rationData){
  139. var updateData = [];
  140. updateData.push({'deleteType':'RATION','updateType': 'ut_delete', 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}});
  141. return updateData;
  142. };
  143. ration_glj.prototype.getDeleteDataByBills=function(datas){
  144. var updateData = [];
  145. datas.forEach(function (deleteData) {
  146. var billData = deleteData.data;
  147. updateData.push({'deleteType':'BILL','updateType': 'ut_delete', 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}});
  148. })
  149. return updateData;
  150. };
  151. ration_glj.prototype.deleteByRation = function(ration){
  152. var glj_list = projectObj.project.ration_glj.datas;
  153. var newList =_.filter(glj_list,(glj)=>{
  154. return glj.rationID!=ration.ID;
  155. });
  156. if(newList!=undefined){
  157. projectObj.project.ration_glj.datas = newList;
  158. }
  159. };
  160. ration_glj.prototype.deleteByBills=function(deleteData){
  161. var rationList = projectObj.project.Ration.datas;
  162. var deleteRationList = [];
  163. for(var i=0;i<deleteData.length;i++){
  164. var billID = deleteData[i].data.ID;
  165. var raList =_.filter(rationList,(ration)=>{
  166. return ration.billsItemID==billID;
  167. });
  168. deleteRationList = deleteRationList.concat(raList);
  169. }
  170. for(var i=0;i<deleteRationList.length;i++){
  171. this.deleteByRation(deleteRationList[i]);
  172. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  173. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  174. }
  175. }
  176. ration_glj.prototype.updataOrdelete=function(row){
  177. var updateData = null;
  178. if(row.rationItemQuantity==0){
  179. updateData=this.getUpdateData('ut_delete',{'ID': row.ID, 'projectID': row.projectID});
  180. }else {
  181. updateData= this.getUpdateData('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  182. }
  183. project.pushNow('updateRationGLJ',[this.getSourceType()],updateData)
  184. };
  185. ration_glj.prototype.getUpdateData=function(type,query,doc,callfunction){
  186. var updateData = [];
  187. var newobj = {
  188. 'updateType': type,
  189. 'query': query,
  190. }
  191. if(doc){
  192. newobj['doc']=doc;
  193. }
  194. if(callfunction){
  195. newobj['updateFunction']=callfunction;
  196. }
  197. updateData.push(newobj);
  198. return updateData;
  199. };
  200. ration_glj.prototype.customQuantityUpdate = function(recode,newVal){
  201. var query = {
  202. 'ID':recode.ID,
  203. 'projectID': recode.projectID
  204. };
  205. var doc ={
  206. customQuantity:newVal,
  207. quantity:newVal
  208. };
  209. var updateData = this.getUpdateData('ut_update',query,doc);
  210. project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
  211. };
  212. ration_glj.prototype.marketPriceAdjustUpdate = function (recode,newVal) {
  213. var query = {
  214. 'ID':recode.ID,
  215. 'projectID': recode.projectID
  216. };
  217. var doc ={
  218. market_price:newVal,
  219. code:recode.code,
  220. name:recode.name,
  221. project_id:recode.projectID
  222. };
  223. /* code: '01010101',
  224. market_price: '40',
  225. name: '水泥',
  226. project_id: projectId*/
  227. var updateData = this.getUpdateData('ut_update',query,doc,'marketPriceAdjustUpdate');
  228. project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
  229. };
  230. return new ration_glj(project);
  231. }
  232. };