ration_glj.js 11 KB

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