project_glj.js 34 KB

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