project_glj.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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. this.quantityChangeMap=null;
  12. this.getRatioId = null;
  13. }
  14. /**
  15. * 加载数据
  16. *
  17. * @param {function} callback
  18. * @return {boolean}
  19. */
  20. ProjectGLJ.prototype.loadData = function (callback = null) {
  21. let self = this;
  22. if (self.isLoading) {
  23. return false;
  24. }
  25. // 加载工料机数据
  26. $.ajax({
  27. url: '/glj/getData',
  28. type: 'post',
  29. dataType: 'json',
  30. data: {project_id: scUrlUtil.GetQueryString('project')},
  31. error: function () {
  32. // alert('数据传输错误');
  33. },
  34. beforeSend: function () {
  35. self.isLoading = true;
  36. },
  37. success: function (response) {
  38. self.isLoading = false;
  39. if (response.err === 1) {
  40. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '读取人材机数据失败!';
  41. alert(msg);
  42. return false;
  43. }
  44. self.refreshByDatas(response.data);
  45. // 回调函数
  46. if (callback !== null) {
  47. callback(response.data);
  48. }
  49. // 存入缓存
  50. projectObj.project.projectGLJ = self;
  51. }
  52. });
  53. };
  54. ProjectGLJ.prototype.loadDataSync = async function () {
  55. if (this.isLoading) {
  56. return false;
  57. }
  58. this.isLoading = true;
  59. const project_id = projectObj.project.ID();
  60. try {
  61. const rst = await ajaxPost('/glj/getData', { project_id }, true);
  62. this.isLoading = false;
  63. this.refreshByDatas(rst);
  64. projectObj.project.projectGLJ = this;
  65. } catch (err) {
  66. this.isLoading = false;
  67. throw new Error('获取项目人材机数据错误');
  68. }
  69. }
  70. //更新项目工料机数据和缓存
  71. ProjectGLJ.prototype.refreshByDatas = function(datas){
  72. this.datas = datas;
  73. this.calcQuantity();
  74. this.datas.gljMap = {};
  75. for(let g of this.datas.gljList){
  76. this.datas.gljMap[gljUtil.getIndex(g)]=g;
  77. }
  78. };
  79. ProjectGLJ.prototype.loadToCache = function (data) {
  80. this.datas = data;
  81. this.datas.gljMap = {};
  82. for(let g of this.datas.gljList){
  83. this.datas.gljMap[gljUtil.getIndex(g)]=g;
  84. }
  85. }
  86. /**
  87. * 获取对应工料机数据
  88. *
  89. * @param {String} code
  90. * @return {Object}
  91. */
  92. ProjectGLJ.prototype.getDataByID = function (ID) {//根据项目工料机ID取工料机信息
  93. return _.find(this.datas.gljList, {'id': ID});
  94. };
  95. // CSL, 2018-02-08 甲供、甲定。
  96. ProjectGLJ.prototype.getGLJsBySupply = function (supplyTypeArr, gljTypeArr) {
  97. // 项目工料机采用了内部绑定数据源方式,能够双向同步,但同时带来难干预控制问题。supply值存在混杂情况,如:“2”和“部分甲供”同时存在。
  98. // 所以这里要合并处理。
  99. let mixSupply = [];
  100. for (let s of supplyTypeArr){
  101. switch (s) {
  102. case 1:
  103. mixSupply.push('部分甲供');
  104. break;
  105. case 2:
  106. mixSupply.push('完全甲供');
  107. break;
  108. case 3:
  109. mixSupply.push('甲定乙供');
  110. break;
  111. default:
  112. mixSupply.push('自行采购');
  113. }
  114. };
  115. mixSupply = mixSupply.concat(supplyTypeArr);
  116. return _.filter(this.datas.gljList, function (glj) {
  117. return mixSupply.includes(glj.supply) && gljTypeArr.includes(glj.type);
  118. });
  119. };
  120. ProjectGLJ.prototype.testGLJs = function () {
  121. let gljs = [];
  122. for (let glj of this.datas.gljList){
  123. let o = new Object();
  124. o.name = glj.name;
  125. o.supply = glj.supply;
  126. o.quantity = glj.quantity;
  127. o.supply_quantity = glj.supply_quantity;
  128. gljs.push(o);
  129. };
  130. return gljs;
  131. };
  132. /**
  133. * 修改工料机数据
  134. *
  135. * @param {Number} id
  136. * @param {Object} data
  137. * @return {boolean}
  138. */
  139. ProjectGLJ.prototype.updateData = function (id, data) {
  140. let result = false;
  141. if (this.datas === null) {
  142. return result;
  143. }
  144. let gljList = this.datas.gljList;
  145. if (gljList === undefined) {
  146. return result;
  147. }
  148. // 查找对应的index
  149. let index = -1;
  150. for (let tmp in gljList) {
  151. if (gljList[tmp].id === id) {
  152. index = tmp;
  153. break;
  154. }
  155. }
  156. if (index < 0) {
  157. return result;
  158. }
  159. // 修改数据
  160. for (let tmpIndex in data) {
  161. if (tmpIndex.indexOf('_price') >= 0) {
  162. // 修改unit_price中的对象
  163. this.datas.gljList[index]['unit_price'][tmpIndex] = data[tmpIndex];
  164. } else {
  165. this.datas.gljList[index][tmpIndex] = data[tmpIndex];
  166. }
  167. }
  168. };
  169. /**
  170. * 加载缓存数据到spread
  171. *
  172. * @return {void}
  173. */
  174. ProjectGLJ.prototype.loadCacheData = function (resort) {
  175. // 加载工料机数据
  176. let data = this.datas === null ? null : this.datas;
  177. if (data === null) {
  178. return;
  179. }
  180. jsonData = data.gljList !== undefined && data.gljList.length > 0 ? data.gljList : [];
  181. console.log("filter start");
  182. jsonData = filterProjectGLJ(jsonData);
  183. console.log("filter end");
  184. jsonData = sortProjectGLJ(jsonData);
  185. console.log("sort end");
  186. if(projectGLJSheet&&projectGLJSpread){
  187. setTimeout(spreadInit, 1);
  188. /*projectGLJSheet.setData(jsonData);
  189. projectGLJSpread.specialColumn(jsonData);*/
  190. }
  191. };
  192. ProjectGLJ.prototype.updatePriceFromRG = function (recode, updateField, newval,callback) {
  193. if (updateField == 'marketPrice') {
  194. this.updatePrice(recode, "market_price", newval,"rg",null,callback);
  195. }
  196. if (updateField == 'basePrice') {
  197. this.updatePrice(recode, "base_price", newval,"rg",null,callback);
  198. }
  199. };
  200. ProjectGLJ.prototype.updatePropertyFromMainSpread = function (node, updateField, newval,editingText) {
  201. if (updateField == "contain") {//更新含量和工程量时,要走定额更新的逻辑
  202. projectObj.project.Ration.updateContain(newval,node);
  203. }if(updateField == "quantity"){
  204. projectObj.project.quantity_detail.editMainTreeNodeQuantity(newval,node,updateField,editingText);
  205. } else {
  206. this.updateGLJProperty(node, updateField, newval);
  207. }
  208. };
  209. ProjectGLJ.prototype.updateGLJProperty = function (node, updateField, newval) {
  210. let rationTypeGLJ = node.data;
  211. let postData = {};
  212. if (rationTypeGLJ[updateField] == newval) {
  213. projectObj.mainController.refreshTreeNode([node]);
  214. return;
  215. }
  216. let data = {
  217. glj_id: rationTypeGLJ.GLJID,
  218. project_id: rationTypeGLJ.projectID,
  219. code: rationTypeGLJ.code,
  220. original_code: rationTypeGLJ.original_code,
  221. name: rationTypeGLJ.name,
  222. shortName: rationTypeGLJ.shortName,
  223. specs: rationTypeGLJ.specs,
  224. unit: rationTypeGLJ.unit,
  225. type: rationTypeGLJ.subType,
  226. type_of_work: rationTypeGLJ.subType,
  227. base_price: rationTypeGLJ.basePrice,
  228. market_price: rationTypeGLJ.basePrice,
  229. repositoryId: rationTypeGLJ.repositoryId,
  230. adjCoe: rationTypeGLJ.adjCoe,
  231. from: rationTypeGLJ.from ? rationTypeGLJ.from : 'std'//std:标准工料机库, cpt:补充工料机库
  232. };
  233. if (updateField == 'subType') {
  234. data.type = newval;
  235. data.type_of_work = newval;
  236. data.shortName = this.getShortNameByID(newval);
  237. } else {
  238. data[updateField] = newval;
  239. }
  240. postData.ration = {
  241. ID: rationTypeGLJ.ID,
  242. projectID: rationTypeGLJ.projectID
  243. };
  244. postData.updateData = data;
  245. $.bootstrapLoading.start();
  246. CommonAjax.post("/glj/modifyKeyValue", postData, function (result) {
  247. console.log(result); //更新节点信息
  248. rationTypeGLJ[updateField] = newval;
  249. rationTypeGLJ.projectGLJID = result.id;
  250. rationTypeGLJ.code = result.code;
  251. rationTypeGLJ.basePrice = result.unit_price.base_price;
  252. rationTypeGLJ.marketUnitFee = result.unit_price.market_price;
  253. rationTypeGLJ.isAdd = result.unit_price.is_add;
  254. rationTypeGLJ.isEstimate = result.is_evaluate;
  255. rationTypeGLJ.shortName = result.unit_price.short_name;
  256. //触发计算并更新节点信息
  257. node.changed = true;
  258. projectObj.project.projectGLJ.loadData(function () {
  259. projectObj.project.calcProgram.calcAndSave(node);
  260. $.bootstrapLoading.end();
  261. });//重新加载项目工料机数据
  262. //上面两步都是异步操作,这句应该是要等上面两步做完了再执行的
  263. }, function (err) {
  264. $.bootstrapLoading.end();
  265. });
  266. }
  267. ProjectGLJ.prototype.getPriceDecimal = function (glj) {//价格的小数位数,有无组成物,取值不同
  268. if(gljUtil.notEditType.indexOf(glj.unit_price.type)!=-1&&glj.ratio_data.length>0){
  269. return getDecimal("glj.unitPriceHasMix");
  270. }else {
  271. return getDecimal('glj.unitPrice');
  272. }
  273. };
  274. ProjectGLJ.prototype.doAfterPriceChange=function(gljs){
  275. //更新回传的父节点项目工料机价格
  276. projectGljObject.refreshDataSheet(true);//更新工料机汇总缓存和显示
  277. gljOprObj.showRationGLJSheetData();
  278. let nodes = this.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  279. projectObj.project.calcProgram.calcNodesAndSave(nodes, async function () {
  280. await OVER_HEIGHT.reCalcOverHeightFee();
  281. await itemIncreaseFeeObj.calcItemIncreaseFeeByNodes(nodes);
  282. });//触发计算程序
  283. projectGljObject.onUnitFileChange(gljs);
  284. }
  285. ProjectGLJ.prototype.updatePrice = function (recode, updateField, newval,from,tdoc,cb) {
  286. let me = this;
  287. let projectGljs = this.datas.gljList;
  288. let pgljID = from=="rg"?recode.projectGLJID:recode.id;//和定额工料机统一接口,项目工料机ID取值不一样
  289. let glj = _.find(projectGljs, {'id': pgljID});
  290. let udoc = tdoc?tdoc:{"priceFrom":""};//20200728 新增价格来源,默认为空
  291. if (glj) {
  292. if(glj.unit_price[updateField] == newval){
  293. return;
  294. }
  295. newval = scMathUtil.roundForObj(newval,this.getPriceDecimal(glj));
  296. let data = {id: glj.unit_price.id, field: updateField, newval: newval,project_id:glj.project_id,unit_price_file_id:glj.unit_price.unit_price_file_id};
  297. if(updateField == 'market_price') data.udoc=udoc;
  298. let callback = function (data) {
  299. if (updateField == 'base_price') {
  300. glj.unit_price.base_price = newval;
  301. me.setAdjustPrice(glj);
  302. } else {
  303. glj.unit_price.market_price = newval;
  304. gljUtil.setProperty(glj.unit_price,udoc);
  305. }
  306. //更新回传的父节点项目工料机价格
  307. let gljs = me.getProjectGLJs(data);
  308. gljs.push(glj);
  309. me.refreshTreeNodePriceIfNeed(glj);//刷新造价书中主树上的定额工料机;
  310. projectObj.project.projectGLJ.doAfterPriceChange(gljs);//更新工料机汇总缓存和显示
  311. if(cb){
  312. cb(gljs);
  313. }
  314. $.bootstrapLoading.end();
  315. }
  316. $.bootstrapLoading.start();
  317. CommonAjax.post("/glj/updatePrice", data, callback, function (err) {
  318. $.bootstrapLoading.end();
  319. });
  320. } else {
  321. gljOprObj.showRationGLJSheetData();
  322. }
  323. };
  324. ProjectGLJ.prototype.batchUpdateGLJProperty = function (updateMap,callback) {
  325. let me = this;
  326. //更新是否暂估和供货方式时,要做特殊处理
  327. $.bootstrapLoading.start();
  328. CommonAjax.post("/glj/batchUpdateGLJProperty", updateMap,function (result) {
  329. $.bootstrapLoading.end();
  330. let supplyChangeIDs = [],evaluate_gljs = [],rationNodes = [];
  331. console.log(updateMap);
  332. let needCalcQuantity = false;
  333. for(let idKey in updateMap){
  334. let gljID = parseInt(idKey);
  335. let glj = me.getByID(gljID);
  336. let doc = updateMap[idKey];
  337. for(let property in doc){
  338. glj[property] = doc[property];
  339. }
  340. if(doc.hasOwnProperty("supply")||doc.hasOwnProperty("supply_quantity")){
  341. supplyChangeIDs.push(gljID);
  342. }
  343. if(doc.hasOwnProperty("is_evaluate")) evaluate_gljs.push(glj);
  344. if(doc.hasOwnProperty("is_adjust_price")) needCalcQuantity = true;
  345. }
  346. if(supplyChangeIDs.length>0){
  347. let temRationNodes = calcTools.getRationsByProjectGLJ(supplyChangeIDs);
  348. if (temRationNodes.length > 0) rationNodes = rationNodes.concat(temRationNodes);
  349. }
  350. if(evaluate_gljs.length > 0){
  351. let [impactRationNodes,impactGLJs] = me.batchChangeIsEvaluate(evaluate_gljs);
  352. rationNodes = rationNodes.concat(impactRationNodes);
  353. }
  354. if(rationNodes.length > 0){
  355. rationNodes = _.uniq(rationNodes,'data');
  356. projectObj.project.calcProgram.calcNodesAndSave(rationNodes, function () {
  357. projectObj.mainController.refreshTreeNode(projectObj.project.mainTree.roots);
  358. });
  359. }
  360. if(needCalcQuantity) me.calcQuantity();
  361. if(callback){
  362. callback();
  363. }
  364. })
  365. };
  366. ProjectGLJ.prototype.mutiApplyInfoPrice = async function(pgljMap,condition,priceFrom) {
  367. try {
  368. $.bootstrapLoading.start();
  369. let taxType = projectObj.project.property.taxType;
  370. let projectGLJMap = await ajaxPost("/infoPrice/mutiApplyInfoPrice",{pgljMap:pgljMap,condition:condition,taxType:taxType,decimal:getDecimal('glj.unitPrice'),priceFrom:priceFrom});
  371. let parentKeyMap = {};
  372. let gljs = [];
  373. if(!_.isEmpty(projectGLJMap)){
  374. for(let id in projectGLJMap){//先整理出受影响的父工料机
  375. let mixRatioKey = projectGLJMap[id].index;
  376. let parentArray = this.datas.mixRatioConnectData[mixRatioKey];
  377. if(!parentArray) continue;
  378. for(pk of parentArray){
  379. parentKeyMap[pk] = true;
  380. }
  381. }
  382. for(let glj of this.datas.gljList){
  383. if(projectGLJMap[glj.id]){
  384. gljUtil.setProperty(glj.unit_price,projectGLJMap[glj.id].doc);
  385. gljs.push(glj);
  386. }else if(parentKeyMap[gljUtil.getIndex(glj)]){
  387. gljs.push(glj);
  388. }
  389. }
  390. this.doAfterPriceChange(gljs);
  391. }
  392. } catch (error) {
  393. console.log(error);
  394. }
  395. $.bootstrapLoading.end();
  396. }
  397. ProjectGLJ.prototype.batchUpdatePrice = function (changeInfo,sheetName,callback) {
  398. let me = this;
  399. let projectGljs = me.datas.gljList;
  400. let updateData = [];
  401. let newValueMap = {};
  402. let gljs=[];
  403. let setting = sheetName =="materialTreeSheet"?projectGljObject.materialSetting:projectGljObject.projectGljSetting;
  404. if(changeInfo.length<=0){
  405. callback?callback():'';
  406. return
  407. }
  408. for(let ci of changeInfo){
  409. let dataCode = setting.header[ci.col].dataCode;
  410. let recode = sheetName =="materialTreeSheet"?projectGljObject.materialTree.items[ci.row].data:projectGljObject.projectGljSheetData[ci.row];
  411. if(dataCode=='basePrice'||dataCode=='marketPrice'){
  412. let editField = dataCode === 'basePrice'?"base_price":"market_price";
  413. let glj = _.find(projectGljs, {'id': recode.id});
  414. let newValue = ci.value;
  415. if(glj&&glj.unit_price[editField]!=newValue){
  416. newValue= scMathUtil.roundForObj(ci.value,this.getPriceDecimal(glj));
  417. updateData.push({unit_price: glj.unit_price, field: editField, newval: newValue,project_id:glj.project_id});
  418. newValueMap[glj.id]={field:editField,value:newValue};
  419. gljs.push(glj);
  420. }
  421. }
  422. }
  423. if(updateData.length > 0){
  424. $.bootstrapLoading.start();
  425. CommonAjax.post("/glj/batchUpdatePrices", updateData, function (result) {
  426. let parentData = [];
  427. //更新缓存
  428. for(let g of gljs){
  429. g.unit_price[newValueMap[g.id].field] = newValueMap[g.id].value;
  430. me.refreshTreeNodePriceIfNeed(g);//刷新造价书中主树上的定额工料机;
  431. }
  432. //更新父工料机价格
  433. for(let r of result){
  434. let pdata = r.updateOne.filter;
  435. let set = r.updateOne.update.$set;
  436. for(let skey in set){
  437. pdata[skey] = set[skey];
  438. }
  439. parentData.push(pdata);
  440. }
  441. let pgljs = me.getProjectGLJs(parentData);
  442. gljs = gljs.concat(pgljs);
  443. me.doAfterPriceChange(gljs);
  444. if(callback){
  445. callback(gljs);
  446. }
  447. $.bootstrapLoading.end();
  448. }, function (err) {
  449. $.bootstrapLoading.end();
  450. });
  451. }
  452. };
  453. ProjectGLJ.prototype.batchUpdateConsumption = function (updateData,updateMap,callback) {
  454. let me = this;
  455. $.bootstrapLoading.start();
  456. CommonAjax.post("/glj/batchUpdateConsumption", updateData, function (result) {
  457. let parent = updateData[updateData.length - 1];
  458. let parentGlj = me.getByConKey(parent.connect_key);
  459. for(let u of updateData){
  460. if(u.type == 'mix_ratio'){
  461. let tem = updateMap[u.query.id];
  462. tem.record.consumption = u.doc.consumption;//更新组成物表格的缓存
  463. let subData = _.find(parentGlj.ratio_data,{"id":u.query.id});
  464. if(subData){
  465. subData.consumption = u.doc.consumption;
  466. }
  467. let m_list = me.datas.mixRatioMap[parent.connect_key];
  468. let m_ratioData = _.find(m_list,{"id":u.query.id});
  469. if(m_ratioData){
  470. m_ratioData.consumption = u.doc.consumption;
  471. }
  472. }
  473. }
  474. parentGlj.unit_price.market_price = parent.market_price;
  475. parentGlj.unit_price.base_price = parent.base_price;
  476. me.calcQuantity();
  477. if(callback){
  478. callback();
  479. }
  480. $.bootstrapLoading.end();
  481. },function () {
  482. $.bootstrapLoading.end();
  483. })
  484. };
  485. ProjectGLJ.prototype.pGljUpdate= function (data,callback) {
  486. let me = this;
  487. let glj = me.getByID(data.id);
  488. if(data.field == 'taxRate'){
  489. data.field = "unit_price.taxRate";
  490. data.id = glj.unit_price.id;
  491. }
  492. $.bootstrapLoading.start();
  493. CommonAjax.specialPost( '/glj/update',data,function (result) {
  494. let impactList = [];
  495. _.set(glj,data.field,data.value);//更新缓存
  496. // glj[data.field] = data.value;
  497. if(data.extend&&data.extend!=""){
  498. let extend = JSON.parse(data.extend);
  499. for (let key in extend) {
  500. glj[key] = extend[key];
  501. }
  502. }
  503. if(data.field == 'is_evaluate'){
  504. impactList = me.changeIsEvaluate(data.id);
  505. }
  506. if(data.field == "is_adjust_price") me.calcQuantity();
  507. if(callback){
  508. callback(impactList);
  509. }
  510. $.bootstrapLoading.end();
  511. });
  512. };
  513. ProjectGLJ.prototype.getRatioData=function(id,callback){
  514. this.getRatioId = id;
  515. if(id){
  516. CommonAjax.specialPost( '/glj/get-ratio',{id: id, project_id: scUrlUtil.GetQueryString('project')},function (response) {
  517. let ratios = JSON.parse(response.data);
  518. if(callback){
  519. callback(ratios);
  520. }
  521. },function () {//取不到组成物的情况
  522. callback([]);
  523. })
  524. }else {
  525. if(callback){
  526. callback([]);
  527. }
  528. }
  529. };
  530. ProjectGLJ.prototype.changeFile = function (changeData,callback) {
  531. $.bootstrapLoading.start();
  532. CommonAjax.specialPost('/glj/change-file',changeData,function (response) {
  533. projectObj.project.property.unitPriceFile = response.unitFile;
  534. projectObj.project.projectGLJ.loadData(function () {
  535. if(callback){
  536. callback();
  537. }
  538. $.bootstrapLoading.end();
  539. });
  540. }, function (err) {
  541. if($.bootstrapLoading.isLoading()){
  542. $.bootstrapLoading.end();
  543. }
  544. alert(err.msg);
  545. });
  546. };
  547. ProjectGLJ.prototype.addMixRatio = function(selections,callback){
  548. let gljList = [],allGLJ = gljOprObj.AllRecode;
  549. $("#glj_tree_div").modal('hide');
  550. if(selections.length == 0) {
  551. return;
  552. }
  553. for(let glj of allGLJ){
  554. let i_key = gljOprObj.getIndex(glj, gljLibKeyArray);
  555. if(_.includes(selections,i_key)){
  556. let pglj = {
  557. project_id: projectObj.project.ID(),
  558. glj_id: glj.ID,
  559. name: glj.name,
  560. code: glj.code,
  561. original_code: glj.code,
  562. unit: glj.unit,
  563. specs: glj.specs,
  564. base_price: glj.basePrice,
  565. market_price: glj.basePrice,
  566. shortName: glj.shortName,
  567. type: glj.gljType,
  568. model:glj.model,
  569. adjCoe: glj.adjCoe,
  570. from:'std',
  571. repositoryId:glj.repositoryId,
  572. materialType:glj.materialType,
  573. materialCoe:glj.materialCoe,
  574. materialIndexType:glj.materialIndexType,
  575. materialIndexUnit:glj.materialIndexUnit,
  576. materialIndexCoe:glj.materialIndexCoe
  577. };
  578. if (glj.hasOwnProperty("compilationId")) {
  579. pglj.from = "cpt";
  580. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  581. pglj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  582. }
  583. }
  584. gljList.push(pglj);
  585. }
  586. }
  587. gljList = _.sortByAll(gljList, ['type', 'code']);
  588. if(gljList.length == 0) return;
  589. let praentInfo = {
  590. unit_price_file_id:projectObj.project.property.unitPriceFile.id,
  591. connect_key:gljOprObj.getIndex(projectGljObject.selectedProjectGLJ,gljKeyArray)
  592. };
  593. $.bootstrapLoading.start();
  594. CommonAjax.post("/glj/add-ratio", {gljList:gljList,parentInfo:praentInfo}, function (data) {
  595. $.bootstrapLoading.end();
  596. if(callback){
  597. callback(data);
  598. }
  599. }, function () {
  600. $.bootstrapLoading.end();
  601. });
  602. }
  603. ProjectGLJ.prototype.checkUnitFileName = function(newVal,callback){
  604. let property = projectObj.project.projectInfo.property;
  605. let data = {
  606. name:newVal,
  607. rootProjectID:property.rootProjectID
  608. }
  609. CommonAjax.post('/glj/checkUnitFileName', data, function (data) {
  610. callback(data);
  611. });
  612. };
  613. ProjectGLJ.prototype.saveAs = function (saveData,callback) {
  614. $.bootstrapLoading.start();
  615. CommonAjax.specialPost('/glj/save-as',saveData,function () {
  616. projectObj.project.projectGLJ.loadData(function () {
  617. if(callback){
  618. callback();
  619. }
  620. $.bootstrapLoading.end();
  621. });
  622. },function (response) {
  623. let msg = response.msg !== undefined && response.msg !== '' ? response.msg : '另存为失败!';
  624. $("#save-as-tips").text(msg).show();
  625. $.bootstrapLoading.end();
  626. });
  627. };
  628. //更新是否暂估
  629. ProjectGLJ.prototype.changeIsEvaluate=function (id){
  630. let projectGLJ = projectObj.project.projectGLJ;
  631. let datas = projectGLJ.datas;
  632. let gljList = datas.gljList;
  633. let glj = _.find(gljList, {'id': id});
  634. if(glj){//与批量更新调用相同的方法
  635. /* let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  636. let pratioM =datas.mixRatioConnectData[con_key];//找到父key
  637. let conditions = [];
  638. if(pratioM&&pratioM.length>0){
  639. for(let p_key of pratioM ){
  640. conditions.push(gljOprObj.getConditionByKey(p_key));
  641. }
  642. }
  643. let gljs = projectGLJ.getProjectGLJs(conditions,false);
  644. gljs.push(glj);
  645. let nodes = projectGLJ.getImpactRationNodes(gljs);//取到因为改变工料机价格而受影响的定额
  646. //更新对应的工料机类型的定额
  647. let rations =_.filter(projectObj.project.Ration.datas,{'type':rationType.gljRation,'projectGLJID':glj.id});
  648. let ration_nodes = [];
  649. for(r of rations){
  650. if(r){
  651. r.isEstimate =glj.is_evaluate?1:0;
  652. let ration_node = projectObj.project.mainTree.getNodeByID(r.ID);
  653. ration_node?ration_nodes.push(ration_node):'';
  654. }
  655. }
  656. let ration_glj_nodes = projectGLJ.getMainAndEquGLJNodeByID(glj.id);//取显示在造价书界面上的主材和设备节点
  657. for(rg of ration_glj_nodes){
  658. rg.data.isEstimate =glj.is_evaluate?1:0;
  659. ration_nodes.push(rg);
  660. }
  661. ration_nodes.length>0?projectObj.mainController.refreshTreeNode(ration_nodes):"";*/
  662. let [nodes,gljs] = projectGLJ.batchChangeIsEvaluate([glj]);
  663. projectObj.project.calcProgram.calcNodesAndSave(nodes);//触发计算程序
  664. return gljs;
  665. }
  666. };
  667. /**
  668. * 批量更新是否暂估
  669. *传入项目工料机数组
  670. */
  671. ProjectGLJ.prototype.batchChangeIsEvaluate=function (gljs){
  672. let impactGLJs = [], changeArray =_.map(gljs,'id'),changeMap = _.indexBy(gljs,'id');;
  673. for(let glj of gljs){
  674. let con_key = gljOprObj.getIndex(glj,gljKeyArray);
  675. let pratioM =this.datas.mixRatioConnectData[con_key];//找到父key
  676. let conditions = [];
  677. if(pratioM&&pratioM.length>0){
  678. for(let p_key of pratioM ){
  679. conditions.push(gljOprObj.getConditionByKey(p_key));
  680. }
  681. }
  682. let tem_gljs = this.getProjectGLJs(conditions,false);
  683. if(tem_gljs.length > 0) impactGLJs = impactGLJs.concat(tem_gljs);
  684. }
  685. impactGLJs = impactGLJs.concat(gljs);
  686. impactGLJs = _.uniq(impactGLJs,'id');//去重复
  687. let impactRationNodes = this.getImpactRationNodes(impactGLJs);
  688. let neeRefreshNode = [];
  689. //更新对应的工料机类型的定额
  690. for(let item of projectObj.project.Ration.datas){
  691. if(item.type == rationType.gljRation && changeArray.indexOf(item.projectGLJID) != -1){
  692. let tem_g = changeMap[item.projectGLJID];
  693. item.isEstimate =tem_g.is_evaluate?1:0;
  694. let ration_node = projectObj.project.mainTree.getNodeByID(item.ID);
  695. neeRefreshNode?neeRefreshNode.push(ration_node):'';
  696. }
  697. }
  698. let ration_glj_nodes = this.getMainAndEquGLJNodeByID(changeArray);//取显示在造价书界面上的主材和设备节点
  699. for(let rg of ration_glj_nodes){
  700. let tem_g = changeMap[rg.data.projectGLJID];
  701. rg.data.isEstimate =tem_g.is_evaluate?1:0;
  702. neeRefreshNode.push(rg);
  703. }
  704. neeRefreshNode.length>0?projectObj.mainController.refreshTreeNode(neeRefreshNode):"";
  705. return [impactRationNodes,impactGLJs];
  706. };
  707. ProjectGLJ.prototype.getByID = function (ID) {
  708. return _.find(this.datas.gljList,{'id':ID});
  709. };
  710. ProjectGLJ.prototype.getByConKey = function (conkey) {//根据5个连接属性取对应的工料机
  711. return _.find(this.datas.gljList,function (item) {
  712. let tem_key = gljOprObj.getIndex(item,gljKeyArray);
  713. return tem_key == conkey
  714. })
  715. };
  716. ProjectGLJ.prototype.refreshTreeNodePriceIfNeed = function (data) {
  717. if ((data.unit_price.type == gljType.MAIN_MATERIAL || data.unit_price.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  718. let me = this;
  719. var nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  720. if (tem.sourceType == ModuleNames.ration_glj && tem.data.projectGLJID == data.id) {
  721. tem.data.marketUnitFee = me.getMarketPrice(data);//data.unit_price.market_price;
  722. tem.data.marketPrice = me.getMarketPrice(data);//data.unit_price.market_price;
  723. return true;
  724. }
  725. })
  726. projectObj.mainController.refreshTreeNode(nodes);
  727. }
  728. }
  729. ProjectGLJ.prototype.getMainAndEquGLJNodeByID = function (id) {//通过ID取显示到主树上的主材和设备节点
  730. let nodes = [];
  731. let ids = [];
  732. if(Array.isArray(id)){
  733. ids = id;
  734. }else {
  735. ids = [id];
  736. }
  737. if(projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true){
  738. nodes = _.filter(projectObj.project.mainTree.items, function (tem) {
  739. return tem.sourceType == ModuleNames.ration_glj && ids.indexOf(tem.data.projectGLJID) !== -1
  740. })
  741. }
  742. return nodes;
  743. };
  744. //根据工料机,取得所有受影响的定额节点
  745. ProjectGLJ.prototype.getImpactRationNodes = function (gljs) {
  746. let nodes = [];
  747. let rationMap = {};
  748. let idArray = _.map(gljs,'id');
  749. let gljMap = _.indexBy(gljs,'id');
  750. //先根据项目工料机ID,找到受影响定额的ID
  751. let ration_glj_list = projectObj.project.ration_glj.datas; //取定额工料机数据
  752. for (let rg of ration_glj_list) {
  753. if (_.indexOf(idArray,rg.projectGLJID)!=-1) {
  754. rationMap[rg.rationID] = true; //取所有定额ID,用MAP方式去重
  755. }
  756. }
  757. for (let item of projectObj.project.mainTree.items) {
  758. if (item.sourceType == ModuleNames.ration) {
  759. if (item.data.type == rationType.gljRation) {//取定额类型的工料机
  760. let tem_g = gljMap[item.data.projectGLJID];
  761. if(tem_g){
  762. item.data.marketUnitFee = this.getMarketPrice(tem_g);//这里要按计算的市场价为准,不能直接取
  763. item.data.marketPrice = this.getMarketPrice(tem_g);
  764. nodes.push(item);
  765. }
  766. } else if (rationMap[item.data.ID] == true) { //受影响的定额
  767. nodes.push(item)
  768. }
  769. }
  770. }
  771. return nodes;
  772. };
  773. ProjectGLJ.prototype.refreshRationGLJPrice = function (glj) {
  774. for (let ration_glj of gljOprObj.sheetData) {
  775. if (ration_glj.projectGLJID == glj.id) {
  776. ration_glj.basePrice = this.getBasePrice(glj);
  777. ration_glj.marketPrice = this.getMarketPrice(glj);
  778. ration_glj.adjustPrice = this.getAdjustPrice(glj);
  779. }
  780. }
  781. }
  782. ProjectGLJ.prototype.refreshRationTypeGLJ = function (glj) {
  783. }
  784. ProjectGLJ.prototype.getProjectGLJs = function (data,refreshPrice=true) {
  785. let parentGlj = [];
  786. //
  787. let projectGljs = this.datas.gljList;
  788. let indexList = gljKeyArray;
  789. for (let d of data) {
  790. if (d) {
  791. let glj = _.find(projectGljs, function (item) {
  792. return gljOprObj.getIndex(item,indexList) == gljOprObj.getIndex(d,indexList);
  793. });
  794. if (glj) {
  795. if(refreshPrice==true){
  796. d.base_price?glj.unit_price.base_price = d.base_price:'';
  797. d.market_price?glj.unit_price.market_price = d.market_price:'';
  798. this.setAdjustPrice(glj);
  799. this.refreshRationGLJPrice(glj);
  800. this.refreshTreeNodePriceIfNeed(glj);
  801. }
  802. parentGlj.push(glj);
  803. }
  804. }
  805. }
  806. return parentGlj;
  807. }
  808. ProjectGLJ.prototype.setAdjustPrice = function (glj) {
  809. switch (glj.unit_price.type + '') {
  810. // 人工: 调整基价=基价单价*调整系数
  811. case GLJTypeConst.LABOUR:
  812. case GLJTypeConst.MACHINE_LABOUR:
  813. glj.adjust_price = this.getAdjustPrice(glj);
  814. break;
  815. // 机械类型的算法
  816. case GLJTypeConst.MACHINE:
  817. console.log('机械');
  818. break;
  819. // 材料、主材、设备
  820. default:
  821. glj.adjust_price = glj.unit_price.base_price;
  822. }
  823. }
  824. ProjectGLJ.prototype.getAdjustPrice = function (glj,isRadio) {
  825. let proGLJ = projectObj.project.projectGLJ;
  826. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  827. let decimalObj = projectObj.project.projectInfo.property.decimal;
  828. let labourCoeDatas = projectObj.project.labourCoe.datas;
  829. return gljUtil.getAdjustPrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  830. };
  831. ProjectGLJ.prototype.getBasePrice = function(glj,isRadio){
  832. let proGLJ = projectObj.project.projectGLJ;
  833. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  834. let decimalObj = projectObj.project.projectInfo.property.decimal;
  835. let labourCoeDatas = projectObj.project.labourCoe.datas;
  836. return gljUtil.getBasePrice(glj,proGLJ.datas,calcOptions,labourCoeDatas,decimalObj,isRadio,_,scMathUtil);
  837. };
  838. ProjectGLJ.prototype.getMarketPrice = function (glj,isRadio) {
  839. let proGLJ = projectObj.project.projectGLJ;
  840. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  841. let decimalObj = projectObj.project.projectInfo.property.decimal;
  842. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,decimalObj,isRadio,_,scMathUtil);
  843. };
  844. ProjectGLJ.prototype.getTenderMarketPrice = function (glj,isRadio) {
  845. let proGLJ = projectObj.project.projectGLJ;
  846. let calcOptions=projectObj.project.projectInfo.property.calcOptions;
  847. let decimalObj = projectObj.project.projectInfo.property.decimal;
  848. let tenderCoe = this.getTenderPriceCoe(glj);
  849. return gljUtil.getMarketPrice(glj,proGLJ.datas,calcOptions,decimalObj,isRadio,_,scMathUtil,tenderCoe);
  850. };
  851. ProjectGLJ.prototype.getTenderPriceCoe = function(glj,tproperty){
  852. return gljUtil.getTenderPriceCoe(glj,tproperty);
  853. };
  854. ProjectGLJ.prototype.isEstimateType = function(type){
  855. let typeString = type + "";
  856. if (typeString.startsWith("2")||typeString=='4'||typeString=='5') {//只有材料、主材、设备类型才显示是否暂估
  857. return type;
  858. }
  859. return false;
  860. };
  861. ProjectGLJ.prototype.getShortNameByID = function (ID) {
  862. let gljTypeMap = this.datas.constData.gljTypeMap;
  863. return gljTypeMap["typeId" + ID]?gljTypeMap["typeId" + ID].shortName:'';
  864. };
  865. ProjectGLJ.prototype.calcQuantity = function (init=false){
  866. let project_gljs = this.datas.gljList;
  867. let changeArray=[];
  868. let rationGLJDatas = projectObj.project.ration_glj.datas;
  869. let rationDatas = projectObj.project.Ration.datas;
  870. let billsDatas = projectObj.project.Bills.datas;
  871. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil);
  872. if(init == true || this.quantityChangeMap == null){//如果是初始化,建立一个映射表
  873. this.quantityChangeMap = {};
  874. for(let pglj of project_gljs){
  875. this.quantityChangeMap[pglj.id] = pglj.quantity;
  876. }
  877. }else if(this.quantityChangeMap != null){
  878. for(let pglj of project_gljs){
  879. if(this.quantityChangeMap[pglj.id] != undefined|| this.quantityChangeMap[pglj.id] != null){
  880. if(this.quantityChangeMap[pglj.id] != pglj.quantity){
  881. changeArray.push(pglj);
  882. this.quantityChangeMap[pglj.id] = pglj.quantity;
  883. }
  884. }else { //映射表没有,说明是新添加的项目工料机
  885. changeArray.push(pglj);
  886. this.quantityChangeMap[pglj.id] = pglj.quantity;
  887. }
  888. }
  889. }
  890. changeArray.length > 0 && projectGljObject.calcPartASupplyFeeByProjectGLJs ?projectGljObject.calcPartASupplyFeeByProjectGLJs(changeArray):'';
  891. };
  892. ProjectGLJ.prototype.calcTenderQuantity = function (){
  893. let rationGLJDatas = projectObj.project.ration_glj.datas;
  894. let rationDatas = projectObj.project.Ration.datas;
  895. let billsDatas = projectObj.project.Bills.datas;
  896. gljUtil.calcProjectGLJQuantity(this.datas,rationGLJDatas,rationDatas,billsDatas,getDecimal("glj.quantity"),_,scMathUtil,true);
  897. };
  898. ProjectGLJ.prototype.loadNewProjectGLJToCaches = function (datas,calquantity = false) {
  899. if(!datas) return;
  900. let gljIDMap = {};
  901. for (let d of datas){
  902. if(d) this.loadNewProjectGLJToCache(d,gljIDMap);
  903. }
  904. if(datas.length > 0 && calquantity) this.calcQuantity();
  905. };
  906. ProjectGLJ.prototype.loadNewProjectGLJToCache = function (data,tIDMap) {//把新插入的项目工料机数据增加至缓存中
  907. if(!data) return;
  908. let project_gljs = this.datas.gljList;
  909. let unitPriceMap = this.datas.unitPriceMap;
  910. let mixRatioMap = this.datas.mixRatioMap;
  911. let mixRatioConnectData = this.datas.mixRatioConnectData;
  912. let IDMap = !_.isEmpty(tIDMap)?tIDMap:_.indexBy(project_gljs,'id');
  913. let tem = IDMap[data.id];
  914. if(tem) return; //判断该工料机是否已经存在,是的话不用再次添加
  915. //查看是否有组成物,有组成物的话先添加组成物信息
  916. data.ratio_data=[];
  917. if(data.subList && data.subList.length){
  918. for(let s of data.subList){
  919. let ratio = s.ratio_data;
  920. data.ratio_data.push(ratio);
  921. mixRatioMap[ratio.connect_key]?mixRatioMap[ratio.connect_key].push(ratio):mixRatioMap[ratio.connect_key] = [ratio];
  922. let rIndex = gljUtil.getIndex(ratio);
  923. mixRatioConnectData[rIndex]?mixRatioConnectData[rIndex].push(ratio.connect_key):mixRatioConnectData[rIndex] = [ratio.connect_key];
  924. this.loadNewProjectGLJToCache(s,IDMap);
  925. }
  926. delete data.subList;
  927. }
  928. //添加unitPriceMap
  929. let uIndex = gljUtil.getIndex(data.unit_price);
  930. if(!unitPriceMap[uIndex]) unitPriceMap[uIndex] = data.unit_price;
  931. this.datas.gljList.push(data);
  932. this.datas.gljMap[gljUtil.getIndex(data)]= data;
  933. IDMap[data.id] = data;
  934. return data;
  935. };
  936. class EvaluateList {
  937. constructor (project) {
  938. this.project = project;
  939. this.datas = [];
  940. project.registerModule(ModuleNames.evaluate_list, this);
  941. };
  942. loadData (datas) {
  943. this.datas = datas;
  944. };
  945. }
  946. class BidEvaluationList {
  947. constructor (project) {
  948. this.project = project;
  949. this.datas = [];
  950. project.registerModule(ModuleNames.bid_evaluation_list, this);
  951. };
  952. loadData (datas) {
  953. this.datas = datas;
  954. };
  955. }
  956. class ContractorList {
  957. constructor (project) {
  958. this.project = project;
  959. this.datas = [];
  960. project.registerModule(ModuleNames.contractor_list, this);
  961. };
  962. loadData (datas) {
  963. this.datas = datas;
  964. };
  965. }
  966. class EquipmentPurchase {
  967. constructor (project) {
  968. this.project = project;
  969. this.datas = {};
  970. project.registerModule(ModuleNames.equipment_purchase, this);
  971. };
  972. loadData (data) {
  973. this.datas = data;
  974. };
  975. }