ration_glj.js 11 KB

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