project_glj.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. /**
  2. * 工料机汇总相关数据
  3. *
  4. * @author CaiAoLin
  5. * @date 2017/9/14
  6. * @version
  7. */
  8. function ProjectGLJ() {
  9. this.datas = null;
  10. this.isLoading = false;
  11. }
  12. /**
  13. * 加载数据
  14. *
  15. * @param {function} callback
  16. * @return {boolean}
  17. */
  18. ProjectGLJ.prototype.loadData = function (callback = null) {
  19. let self = this;
  20. if (self.isLoading) {
  21. return false;
  22. }
  23. // 加载工料机数据
  24. $.ajax({
  25. url: '/glj/getData',
  26. type: 'post',
  27. dataType: 'json',
  28. data: {project_id: scUrlUtil.GetQueryString('project')},
  29. error: function() {
  30. // alert('数据传输错误');
  31. },
  32. beforeSend: function() {
  33. self.isLoading = true;
  34. },
  35. success: function(response) {
  36. self.isLoading = false;
  37. if (response.err === 1) {
  38. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取工料机数据失败!';
  39. alert(msg);
  40. return false;
  41. }
  42. self.datas = response.data;
  43. // 回调函数
  44. if (callback !== null) {
  45. callback(response.data);
  46. }
  47. // 存入缓存
  48. projectObj.project.projectGLJ = self;
  49. }
  50. });
  51. };
  52. ProjectGLJ.prototype.loadToCache = function (data) {
  53. this.datas = data;
  54. projectObj.project.projectGLJ=this;
  55. }
  56. /**
  57. * 获取对应工料机数据
  58. *
  59. * @param {String} code
  60. * @return {Object}
  61. */
  62. ProjectGLJ.prototype.getDataByCode = function (code) {
  63. let result = {};
  64. if (this.datas === null) {
  65. return result;
  66. }
  67. let gljList = this.datas.gljList;
  68. if (gljList === undefined) {
  69. return result;
  70. }
  71. for(let tmp of gljList) {
  72. if (tmp.code === code) {
  73. result = tmp;
  74. break;
  75. }
  76. }
  77. return result;
  78. };
  79. /**
  80. * 修改工料机数据
  81. *
  82. * @param {Number} id
  83. * @param {Object} data
  84. * @return {boolean}
  85. */
  86. ProjectGLJ.prototype.updateData = function(id, data) {
  87. let result = false;
  88. if (this.datas === null) {
  89. return result;
  90. }
  91. let gljList = this.datas.gljList;
  92. if (gljList === undefined) {
  93. return result;
  94. }
  95. // 查找对应的index
  96. let index = -1;
  97. for(let tmp in gljList) {
  98. if (gljList[tmp].id === id) {
  99. index = tmp;
  100. break;
  101. }
  102. }
  103. if (index < 0) {
  104. return result;
  105. }
  106. // 修改数据
  107. for(let tmpIndex in data) {
  108. if(tmpIndex.indexOf('_price') >= 0) {
  109. // 修改unit_price中的对象
  110. this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
  111. } else {
  112. this.datas.gljList[index][tmpIndex] = data[tmpIndex];
  113. }
  114. }
  115. };
  116. /**
  117. * 加载缓存数据到spread
  118. *
  119. * @return {void}
  120. */
  121. ProjectGLJ.prototype.loadCacheData = function() {
  122. // 加载工料机数据
  123. let data = this.datas === null ? null : this.datas;
  124. if (data === null) {
  125. return;
  126. }
  127. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  128. jsonData=filterProjectGLJ(jsonData);
  129. jsonData = sortProjectGLJ(jsonData);
  130. projectGLJSheet.setData(jsonData);
  131. projectGLJSpread.specialColumn(jsonData);
  132. };
  133. ProjectGLJ.prototype.updatePriceFromRG=function(recode,updateField,newval){
  134. if(updateField=='marketPrice'){
  135. this.updateBasePriceFromRG(recode,"market_price",newval);
  136. }
  137. if(updateField=='basePrice'){
  138. this.updateBasePriceFromRG(recode,"base_price",newval);
  139. }
  140. };
  141. ProjectGLJ.prototype.updateBasePriceFromRG=function(recode,updateField,newval){
  142. let me = this;
  143. let projectGljs = this.datas.gljList;
  144. let glj = _.find(projectGljs,{'id':recode.projectGLJID});
  145. if(glj){
  146. let data = {id:glj.unit_price.id,field:updateField,newval:newval};
  147. let callback =function (data) {
  148. if(updateField=='base_price'){
  149. glj.unit_price.base_price=newval;
  150. me.setAdjustPrice(glj);
  151. }else {
  152. glj.unit_price.market_price=newval;
  153. }
  154. //更新项目工料机价格
  155. me.refreshProjectGLJPrice(data);
  156. me.refreshRationGLJPrice(glj);
  157. gljOprObj.showRationGLJSheetData();
  158. me.refreshTreeNodePriceIfNeed(glj);
  159. $.bootstrapLoading.end();
  160. }
  161. $.bootstrapLoading.start();
  162. CommonAjax.post("/glj/updatePrice",data,callback,function (err) {
  163. $.bootstrapLoading.end();
  164. });
  165. }else {
  166. gljOprObj.showRationGLJSheetData();
  167. }
  168. }
  169. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  170. if((data.unit_price.type = gljType.MAIN_MATERIAL||data.type==gljType.EQUIPMENT)&&projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial==true){
  171. var nodes = _.filter(projectObj.project.mainTree.items,function (tem) {
  172. if(tem.sourceType==ModuleNames.ration_glj&&tem.data.projectGLJID ==data.id){
  173. tem.data.marketUnitFee = data.unit_price.market_price;
  174. return true;
  175. }
  176. })
  177. projectObj.mainController.refreshTreeNode(nodes);
  178. }
  179. }
  180. ProjectGLJ.prototype.refreshRationGLJPrice=function (glj) {
  181. for(let ration_glj of gljOprObj.sheetData){
  182. if(ration_glj.projectGLJID ==glj.id){
  183. ration_glj.basePrice=glj.unit_price.base_price;
  184. ration_glj.marketPrice=glj.unit_price.market_price;
  185. ration_glj.adjustPrice=this.getAdjustPrice(glj);
  186. }
  187. }
  188. }
  189. ProjectGLJ.prototype.refreshProjectGLJPrice=function(data){
  190. let projectGljs = this.datas.gljList;
  191. let indexList = ['code','name','specs','unit','type'];
  192. for(let d of data){
  193. if(d){
  194. let condition = {};
  195. for(let index of indexList){
  196. if(d[index]!=null&&d[index]!=undefined&&d[index]!=''){
  197. condition[index]=d[index]
  198. }
  199. }
  200. let glj = _.find(projectGljs,condition);
  201. if(glj){
  202. glj.unit_price.base_price = d.base_price;
  203. glj.unit_price.market_price = d.market_price;
  204. this.setAdjustPrice(glj);
  205. this.refreshRationGLJPrice(glj);
  206. this.refreshTreeNodePriceIfNeed(glj);
  207. }
  208. }
  209. }
  210. }
  211. ProjectGLJ.prototype.setAdjustPrice=function(glj){
  212. switch (glj.unit_price.type + '') {
  213. // 人工: 调整基价=基价单价*调整系数
  214. case GLJTypeConst.LABOUR:
  215. case GLJTypeConst.MACHINE_LABOUR:
  216. glj.adjust_price = this.getAdjustPrice(glj);
  217. break;
  218. // 机械类型的算法
  219. case GLJTypeConst.MACHINE:
  220. console.log('机械');
  221. break;
  222. // 材料、主材、设备
  223. default:
  224. glj.adjust_price = glj.unit_price.base_price;
  225. }
  226. }
  227. ProjectGLJ.prototype.getAdjustPrice = function (glj) {
  228. GLJTypeConst = this.datas.constData.GLJTypeConst !== undefined ? JSON.parse(this.datas.constData.GLJTypeConst) : GLJTypeConst;
  229. if(glj.unit_price.type==GLJTypeConst.LABOUR||glj.unit_price.type==GLJTypeConst.MACHINE_LABOUR){
  230. let labour = projectObj.project.calcProgram.compiledLabourCoes[glj.adjCoe];
  231. //let labour=1;
  232. let coe = labour&&labour.coe?labour.coe:1;
  233. let decimal = getDecimal("glj.unitPrice");
  234. return scMathUtil.roundTo(parseFloat(coe*glj.unit_price.base_price),-decimal);
  235. }else {
  236. return glj.unit_price.base_price
  237. }
  238. }