project_glj.js 37 KB

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