ration_glj.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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. gljOprObj.sheetData=data;
  60. // SheetDataHelper.loadSheetData(setting, rationLibObj.sectionRationsSpread.getActiveSheet(), datas);
  61. };
  62. ration_glj.prototype.refreshAfterUpdate=function(data){
  63. var glj_list = projectObj.project.ration_glj.datas;
  64. var glj_index= _.findIndex(glj_list,(glj)=>{
  65. return glj.ID==data.query.ID&&glj.projectID==data.query.projectID;
  66. })
  67. _.forEach(data.doc, function(n, key) {
  68. glj_list[glj_index][key] = n;
  69. });
  70. var showList = _.filter(glj_list,{'projectID':data.query.projectID,'rationID':glj_list[glj_index].rationID});
  71. gljOprObj.sheetData=showList;
  72. sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,showList);
  73. };
  74. ration_glj.prototype.refreshAfterDelete=function(data){
  75. var glj_list = projectObj.project.ration_glj.datas;
  76. _.remove(glj_list,data.query);
  77. _.remove(gljOprObj.sheetData,data.query);
  78. sheetCommonObj.showData(gljOprObj.sheet,gljOprObj.setting,gljOprObj.sheetData);
  79. };
  80. // CSL,2017.05.09
  81. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  82. this.project.beginUpdate('modifyQuantity');
  83. data.quantity = newQuantity;
  84. data.customQuantity = newQuantity;
  85. data.updateType = 'ut_update';
  86. this.project.push(this.getSourceType, data);
  87. this.project.endUpdate();
  88. };
  89. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  90. this.project.beginUpdate('modifyPrice');
  91. data.price = newPrice;
  92. data.updateType = 'ut_update';
  93. this.project.push(this.getSourceType, data);
  94. this.project.endUpdate();
  95. };
  96. ration_glj.prototype.deleteGLJ = function (data) {
  97. this.project.beginUpdate('deleteGLJ');
  98. data.customQuantity = 0;
  99. data.quantity = 0;
  100. data.rationItemQuantity = 0;
  101. data.updateType = 'ut_update';
  102. this.project.push(this.getSourceType, data);
  103. this.project.endUpdate();
  104. };
  105. ration_glj.prototype.replaceGLJ = function (data, newGLJID) {
  106. this.project.beginUpdate('replaceGLJ');
  107. data.GLJID = newGLJID;
  108. data.updateType = 'ut_update';
  109. this.project.push(this.getSourceType, data);
  110. this.project.endUpdate();
  111. };
  112. ration_glj.prototype.addRationGLJ = function (newRation,data) {
  113. var souceTypeList=[];
  114. var criteriaDataList = [];
  115. if(data.hasOwnProperty('rationGljList')&&data.rationGljList.length>0){
  116. let criteria= {};
  117. criteria.ration_glj_list = [];
  118. for(let i=0;i<data.rationGljList.length;i++){
  119. let temdata = data.rationGljList[i];
  120. let newGLJ = {};
  121. newGLJ.projectID = newRation.projectID;
  122. newGLJ.GLJID = temdata.gljId;
  123. newGLJ.rationID = newRation.ID;
  124. newGLJ.rationItemQuantity= temdata.consumeAmt;
  125. newGLJ.quantity=temdata.consumeAmt;
  126. newGLJ.glj_repository_id=data.rationRepId;
  127. criteria.ration_glj_list.push(newGLJ);
  128. }
  129. criteria.updateType = 'ut_create';
  130. souceTypeList.push(this.getSourceType());
  131. criteriaDataList.push(criteria);
  132. }
  133. var ration_coe = projectObj.project.ration_coe;
  134. var rationCoeData = ration_coe.getRationCoedata(newRation,data);
  135. souceTypeList.push(ration_coe.getSourceType());
  136. criteriaDataList.push(rationCoeData);
  137. project.pushNow('addRationGLJAndRationCoe',souceTypeList,criteriaDataList);
  138. };
  139. ration_glj.prototype.getDeleteDataByRation=function(rationData){
  140. var updateData = [];
  141. updateData.push({'deleteType':'RATION','updateType': 'ut_delete', 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}});
  142. return updateData;
  143. };
  144. ration_glj.prototype.getDeleteDataByBills=function(datas){
  145. var updateData = [];
  146. datas.forEach(function (deleteData) {
  147. var billData = deleteData.data;
  148. updateData.push({'deleteType':'BILL','updateType': 'ut_delete', 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}});
  149. })
  150. return updateData;
  151. };
  152. ration_glj.prototype.deleteByRation = function(ration){
  153. var glj_list = projectObj.project.ration_glj.datas;
  154. var newList =_.filter(glj_list,(glj)=>{
  155. return glj.rationID!=ration.ID;
  156. });
  157. if(newList!=undefined){
  158. projectObj.project.ration_glj.datas = newList;
  159. }
  160. };
  161. ration_glj.prototype.deleteByBills=function(deleteData){
  162. var rationList = projectObj.project.Ration.datas;
  163. var deleteRationList = [];
  164. for(var i=0;i<deleteData.length;i++){
  165. var billID = deleteData[i].data.ID;
  166. var raList =_.filter(rationList,(ration)=>{
  167. return ration.billsItemID==billID;
  168. });
  169. deleteRationList = deleteRationList.concat(raList);
  170. }
  171. for(var i=0;i<deleteRationList.length;i++){
  172. this.deleteByRation(deleteRationList[i]);
  173. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  174. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  175. }
  176. }
  177. ration_glj.prototype.updataOrdelete=function(row){
  178. var updateData = null;
  179. if(row.rationItemQuantity==0){
  180. updateData=this.getUpdateData('ut_delete',{'ID': row.ID, 'projectID': row.projectID});
  181. }else {
  182. updateData= this.getUpdateData('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  183. }
  184. project.pushNow('updateRationGLJ',[this.getSourceType()],updateData)
  185. };
  186. ration_glj.prototype.getUpdateData=function(type,query,doc,callfunction){
  187. var updateData = [];
  188. var newobj = {
  189. 'updateType': type,
  190. 'query': query,
  191. }
  192. if(doc){
  193. newobj['doc']=doc;
  194. }
  195. if(callfunction){
  196. newobj['updateFunction']=callfunction;
  197. }
  198. updateData.push(newobj);
  199. return updateData;
  200. };
  201. ration_glj.prototype.customQuantityUpdate = function(recode,newVal){
  202. var query = {
  203. 'ID':recode.ID,
  204. 'projectID': recode.projectID
  205. };
  206. var doc ={
  207. customQuantity:newVal,
  208. quantity:newVal
  209. };
  210. var updateData = this.getUpdateData('ut_update',query,doc);
  211. project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
  212. };
  213. ration_glj.prototype.marketPriceAdjustUpdate = function (recode,newVal) {
  214. var query = {
  215. 'ID':recode.ID,
  216. 'projectID': recode.projectID
  217. };
  218. var doc ={
  219. market_price:newVal,
  220. code:recode.code,
  221. name:recode.name,
  222. project_id:recode.projectID
  223. };
  224. /* code: '01010101',
  225. market_price: '40',
  226. name: '水泥',
  227. project_id: projectId*/
  228. var updateData = this.getUpdateData('ut_update',query,doc,'marketPriceAdjustUpdate');
  229. project.pushNow('updateRationGLJ',[this.getSourceType()],updateData);
  230. };
  231. return new ration_glj(project);
  232. }
  233. };