project_glj.js 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. projectGLJSheet.setData(jsonData);
  130. projectGLJSpread.specialColumn(jsonData);
  131. };
  132. ProjectGLJ.prototype.updatePriceFromRG=function(recode,updateField,newval){
  133. if(updateField=='marketPrice'){
  134. this.updateBasePriceFromRG(recode,"market_price",newval);
  135. }
  136. if(updateField=='basePrice'){
  137. this.updateBasePriceFromRG(recode,"base_price",newval);
  138. }
  139. };
  140. ProjectGLJ.prototype.updateBasePriceFromRG=function(recode,updateField,newval){
  141. let me = this;
  142. let projectGljs = this.datas.gljList;
  143. let glj = _.find(projectGljs,{'id':recode.projectGLJID});
  144. if(glj){
  145. let data = {id:glj.unit_price.id,field:updateField,newval:newval};
  146. let callback =function (data) {
  147. if(updateField=='base_price'){
  148. glj.unit_price.base_price=newval;
  149. me.setAdjustPrice(glj);
  150. }else {
  151. glj.unit_price.market_price=newval;
  152. }
  153. //更新项目工料机价格
  154. me.refreshProjectGLJPrice(data);
  155. me.refreshRationGLJPrice(glj);
  156. gljOprObj.showRationGLJSheetData();
  157. $.bootstrapLoading.end();
  158. }
  159. $.bootstrapLoading.start();
  160. CommonAjax.post("/glj/updatePrice",data,callback,function (err) {
  161. $.bootstrapLoading.end();
  162. });
  163. }else {
  164. gljOprObj.showRationGLJSheetData();
  165. }
  166. }
  167. ProjectGLJ.prototype.refreshRationGLJPrice=function (glj) {
  168. for(let ration_glj of gljOprObj.sheetData){
  169. if(ration_glj.projectGLJID ==glj.id){
  170. ration_glj.basePrice=glj.unit_price.base_price;
  171. ration_glj.marketPrice=glj.unit_price.market_price;
  172. ration_glj.adjustPrice=this.getAdjustPrice(glj);
  173. }
  174. }
  175. }
  176. ProjectGLJ.prototype.refreshProjectGLJPrice=function(data){
  177. let projectGljs = this.datas.gljList;
  178. let indexList = ['code','name','specs','unit','type'];
  179. for(let d of data){
  180. if(d){
  181. let condition = {};
  182. for(let index of indexList){
  183. if(d[index]!=null&&d[index]!=undefined&&d[index]!=''){
  184. condition[index]=d[index]
  185. }
  186. }
  187. let glj = _.find(projectGljs,condition);
  188. if(glj){
  189. glj.unit_price.base_price = d.base_price;
  190. glj.unit_price.market_price = d.market_price;
  191. this.setAdjustPrice(glj);
  192. this.refreshRationGLJPrice(glj);
  193. }
  194. }
  195. }
  196. }
  197. ProjectGLJ.prototype.setAdjustPrice=function(glj){
  198. switch (glj.unit_price.type + '') {
  199. // 人工: 调整基价=基价单价*调整系数
  200. case GLJTypeConst.LABOUR:
  201. case GLJTypeConst.MACHINE_LABOUR:
  202. glj.adjust_price = this.getAdjustPrice(glj);
  203. break;
  204. // 机械类型的算法
  205. case GLJTypeConst.MACHINE:
  206. console.log('机械');
  207. break;
  208. // 材料、主材、设备
  209. default:
  210. glj.adjust_price = glj.unit_price.base_price;
  211. }
  212. }
  213. ProjectGLJ.prototype.getAdjustPrice = function (glj) {
  214. GLJTypeConst = this.datas.constData.GLJTypeConst !== undefined ? JSON.parse(this.datas.constData.GLJTypeConst) : GLJTypeConst;
  215. if(glj.unit_price.type==GLJTypeConst.LABOUR||glj.unit_price.type==GLJTypeConst.MACHINE_LABOUR){
  216. let labour = projectObj.project.calcProgram.compiledLabourCoes[glj.adjCoe];
  217. //let labour=1;
  218. let coe = labour&&labour.coe?labour.coe:1;
  219. let decimal = getDecimal("glj.unitPrice");
  220. return scMathUtil.roundTo(parseFloat(coe*glj.unit_price.base_price),-decimal);
  221. }else {
  222. return glj.unit_price.base_price
  223. }
  224. }