ration_glj.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var ration_glj = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. var tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. var ration_glj = function (proj) {
  10. this.gljTree = cacheTree.createNew(this);
  11. // this.project = proj;
  12. this.datas = [];
  13. var sourceType = ModuleNames.ration_glj;
  14. this.getSourceType = function () {
  15. return sourceType;
  16. }
  17. proj.registerModule(ModuleNames.ration_glj, this);
  18. };
  19. // 从后台获取数据
  20. /*glj.prototype.pullData = function (){
  21. this.project.pullData(
  22. '/glj/getData',
  23. {projectID: this.project.ID},
  24. function(result){
  25. if (result.error ===0){
  26. this.loadDatas(result.data);
  27. }
  28. else {
  29. // to do: 错误处理需要细化
  30. alert(result.message);
  31. }
  32. },
  33. function (){}//to do: 错误处理需要细化
  34. )
  35. };*/
  36. // prototype用于定义public方法
  37. ration_glj.prototype.loadData = function (datas) {
  38. this.datas = datas;
  39. };
  40. ration_glj.prototype.getGljArrByRation = function (ration) {
  41. if (ration.type == rationType.gljRation){
  42. let glj = JSON.parse(JSON.stringify(ration));
  43. glj.type = glj.subType;
  44. glj.quantity = 1;
  45. glj.totalQuantity = parseFloatPlus(ration.quantity);
  46. return [glj];
  47. }
  48. else{
  49. let result = this.datas.filter(function (data) {
  50. if(data.rationID === ration.ID){
  51. gljOprObj.getTotalQuantity(data, ration);
  52. return true;
  53. }
  54. return false;
  55. })
  56. result = gljOprObj.combineWithProjectGlj(result);
  57. return result;
  58. }
  59. };
  60. ration_glj.prototype.getGatherGljArrByRations = function (rations, needOneBill, billQuantity) {
  61. let result = [];
  62. let clone = function (obj) {
  63. if (obj === null) return null;
  64. var o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {};
  65. for (var i in obj) {
  66. o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? clone(obj[i]) : obj[i]);
  67. }
  68. return o;
  69. }
  70. let findGlj = function (sourceGlj, gljArr) {
  71. for (let glj of gljArr) {
  72. if (glj.projectGLJID === sourceGlj.projectGLJID) {
  73. return glj;
  74. }
  75. }
  76. return null;
  77. }
  78. for (let ration of rations) {
  79. if (ration.type == rationType.volumePrice || ration.type == rationType.gljRation){
  80. let glj = JSON.parse(JSON.stringify(ration));
  81. glj.type = glj.subType;
  82. glj.totalQuantity = parseFloatPlus(ration.quantity);
  83. glj.markertPrice = glj.marketUnitFee;
  84. glj.basePrice = glj.marketUnitFee;
  85. glj.adjustPrice = glj.marketUnitFee;
  86. result.push(glj);
  87. }
  88. else{
  89. let rationGljs = this.getGljArrByRation(ration);
  90. for (let glj of rationGljs) {
  91. let sameGlj = findGlj(glj, result);
  92. if (!sameGlj) {
  93. sameGlj = clone(glj);
  94. sameGlj.quantity = (sameGlj.quantity * ration.quantity).toDecimal(4);
  95. result.push(sameGlj);
  96. } else {
  97. sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4);
  98. sameGlj.totalQuantity = (parseFloat(sameGlj.totalQuantity) + parseFloat(glj.totalQuantity)).toDecimal(4);
  99. }
  100. }
  101. }
  102. }
  103. result = gljOprObj.combineWithProjectGlj(result);
  104. if (!needOneBill) return result;
  105. // 上面取的是清单下所有工料机的总量,我要算清单单价,所以要取单位清单的工料机数量,所以下面要除以清单数量。
  106. let oneBill = JSON.parse(JSON.stringify(result));
  107. for (let glj of oneBill){
  108. if (glj.type == rationType.volumePrice){ // 量价、工料机形式的定额要进行数据变换才能参与基数计算。
  109. glj.type = glj.subType;
  110. glj.basePrice = glj.marketUnitFee;
  111. glj.marketPrice = glj.marketUnitFee;
  112. glj.adjustPrice = glj.marketUnitFee;
  113. }
  114. else if (glj.type == rationType.gljRation){
  115. glj.type = glj.subType;
  116. };
  117. // glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.glj.quantity);
  118. glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.process); // 广联达这里没有取舍
  119. };
  120. return oneBill;
  121. }
  122. // 提交数据后返回数据处理
  123. ration_glj.prototype.doAfterUpdate = function (err, data) {
  124. var me = this;
  125. if (!err) {
  126. if (data.updateTpye == 'ut_update') {
  127. me.refreshAfterUpdate(data);
  128. } else if (data.updateTpye == 'ut_delete') {
  129. me.refreshAfterDelete(data);
  130. } else {
  131. me.refreshAfterSave(data);
  132. }
  133. }
  134. projectObj.project.projectGLJ.loadData();
  135. };
  136. ration_glj.prototype.getDataByID = function (ID) {
  137. return _.find(this.datas,{'ID':ID});
  138. };
  139. ration_glj.prototype.refreshAfterSave = function (data) {
  140. let me = projectObj.project.ration_glj;
  141. let neRecodes = [];
  142. if (data) {
  143. // neRecodes=data.newRecords;//原来是显示和缓存分开的,后来发现会导致数据不一致的问题所以改成统一的了,这里也只是会作为显示。
  144. neRecodes = data.showDatas;
  145. gljOprObj.sheetData = neRecodes;
  146. me.addDatasToList(neRecodes);
  147. }
  148. project.projectGLJ.loadData(function () {
  149. gljOprObj.showRationGLJSheetData(true);
  150. //add to mainTree;
  151. me.addToMainTree(neRecodes);
  152. let rationID = neRecodes[0].rationID;
  153. let node = project.mainTree.nodes['id_' + rationID];
  154. if(isDef(node)){
  155. project.calcProgram.calcAndSave(node);
  156. }
  157. if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
  158. calcProgramObj.showData(node, false);
  159. }
  160. });
  161. };
  162. ration_glj.prototype.getGljByRationID = function(rationID){
  163. return _.filter(this.datas, {'rationID': rationID});
  164. };
  165. ration_glj.prototype.addDatasToList = function (datas) {
  166. let me = projectObj.project.ration_glj;
  167. if(datas&&datas.length>0){
  168. if (me.datas && Array.isArray(me.datas)) {
  169. me.datas = me.datas.concat(datas);
  170. } else {
  171. me.datas = datas;
  172. }
  173. }
  174. };
  175. ration_glj.prototype.addToMainTree = function (datas) {
  176. datas = sortRationGLJ(datas);
  177. for (let data of datas) {
  178. if (this.needShowToTree(data)) {
  179. gljOprObj.setGLJPrice(data);
  180. this.transferToNodeData(data);
  181. let parentNode = _.find(projectObj.project.mainTree.items, function (n) {//找父节点
  182. return n.sourceType == ModuleNames.ration && n.data.ID == data.rationID;
  183. });
  184. if (parentNode) {
  185. let nextNodeID = null;
  186. if (parentNode.children.length > 0) {
  187. for (let br of parentNode.children) {
  188. if (compareRationGLJ(data, br.data)) {//如果有兄弟节点则找到添加位置。
  189. nextNodeID = br.getID();
  190. }
  191. }
  192. }
  193. nextNodeID = nextNodeID ? nextNodeID : parentNode.tree.rootID();
  194. let newNode = projectObj.project.mainTree.insert(parentNode.getID(), nextNodeID,data.ID);
  195. newNode.source = data;
  196. newNode.sourceType = this.getSourceType();
  197. newNode.data = data;
  198. ProjectController.syncDisplayNewRationGljNode(projectObj.mainController, newNode);
  199. }
  200. }
  201. }
  202. };
  203. ration_glj.prototype.removeNodeByRation = function(ration,controller){//删除主材或设备节点
  204. let glj_list = _.filter(projectObj.project.ration_glj.datas,{'rationID':ration.ID});
  205. let deleteNodes = [];
  206. for(let rg of glj_list){
  207. if(this.needShowToTree(rg)){
  208. let r_node = projectObj.project.mainTree.getNodeByID(rg.ID);
  209. deleteNodes.push(r_node);
  210. }
  211. }
  212. if(deleteNodes.length > 0){
  213. let rowIndex = deleteNodes[0].serialNo();
  214. if(controller.tree.m_delete(deleteNodes)){
  215. TREE_SHEET_HELPER.massOperationSheet(controller.sheet, function () {
  216. let rowCount = deleteNodes.length;
  217. controller.sheet.deleteRows(rowIndex, rowCount);
  218. });
  219. }
  220. }
  221. };
  222. ration_glj.prototype.refreshAfterUpdate = function (data) {
  223. var me = this;
  224. var rationID=null;
  225. if (data.quantityRefresh) {
  226. data.glj_result.forEach(function (item) {
  227. rationID = me.refreshEachItme(item.doc, item.query);
  228. })
  229. } else {
  230. rationID = me.refreshEachItme(data.doc, data.query);
  231. }
  232. gljOprObj.showRationGLJSheetData(true);
  233. this.reCalcWhenGLJChange({rationID:rationID});
  234. };
  235. ration_glj.prototype.refreshEachItme = function (doc, query) {
  236. var glj_list = projectObj.project.ration_glj.datas;
  237. var glj_index = _.findIndex(glj_list, (glj) => {
  238. return glj.ID == query.ID;
  239. })
  240. /*var sheet_index= _.findIndex(gljOprObj.sheetData,(sd)=>{
  241. return sd.ID==query.ID;
  242. })*/
  243. _.forEach(doc, function (n, key) {
  244. glj_list[glj_index][key] = n;
  245. });
  246. return glj_list[glj_index].rationID;
  247. };
  248. ration_glj.prototype.refreshAfterDelete = function (data) {
  249. var me = projectObj.project.ration_glj;
  250. var glj_list = me.datas;
  251. var oldData = _.remove(glj_list, data.query);
  252. _.remove(gljOprObj.sheetData, data.query);
  253. gljOprObj.showRationGLJSheetData();
  254. projectObj.project.projectGLJ.loadData();
  255. var rationNode = null;
  256. var next = null;
  257. var selected = projectObj.project.mainTree.selected;
  258. if (selected.sourceType == ModuleNames.ration) { //如果选中的是定额,说明是右键删除工料机操作,如果选中的是定额工料机,则说明是在造价书主界面中点击了删除按钮
  259. rationNode = selected;
  260. } else if (selected.sourceType == ModuleNames.ration_glj) {
  261. rationNode = selected.parent;
  262. next = true;
  263. }
  264. rationNode.data.adjustState = data.adjustState;
  265. projectObj.mainController.refreshTreeNode([rationNode]);
  266. for (let o of oldData) {
  267. if (this.needShowToTree(o)) {
  268. let node = me.findGLJNodeByID(o.ID); //找到对应的树节点
  269. projectObj.mainController.deleteNode(node, next);
  270. }
  271. }
  272. project.calcProgram.calcAndSave(rationNode,function () {
  273. installationFeeObj.calcInstallationFee();
  274. });
  275. };
  276. // CSL,2017.05.09
  277. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  278. this.project.beginUpdate('modifyQuantity');
  279. data.quantity = newQuantity;
  280. data.customQuantity = newQuantity;
  281. data.updateType = 'ut_update';
  282. this.project.push(this.getSourceType, data);
  283. this.project.endUpdate();
  284. };
  285. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  286. this.project.beginUpdate('modifyPrice');
  287. data.price = newPrice;
  288. data.updateType = 'ut_update';
  289. this.project.push(this.getSourceType, data);
  290. this.project.endUpdate();
  291. };
  292. ration_glj.prototype.deleteGLJ = function (data) {
  293. this.project.beginUpdate('deleteGLJ');
  294. data.customQuantity = 0;
  295. data.quantity = 0;
  296. data.rationItemQuantity = 0;
  297. data.updateType = 'ut_update';
  298. this.project.push(this.getSourceType, data);
  299. this.project.endUpdate();
  300. };
  301. ration_glj.prototype.addRationGLJ = function (newRation, data) {
  302. var souceTypeList = [];
  303. var criteriaDataList = [];
  304. if (data.hasOwnProperty('rationGljList') && data.rationGljList.length > 0) {
  305. let criteria = {};
  306. criteria.ration_glj_list = [];
  307. for (let i = 0; i < data.rationGljList.length; i++) {
  308. let temdata = data.rationGljList[i];
  309. let newGLJ = {};
  310. newGLJ.projectID = parseInt(newRation.projectID);
  311. newGLJ.GLJID = temdata.gljId;
  312. newGLJ.rationID = newRation.ID;
  313. newGLJ.billsItemID = newRation.billsItemID,
  314. newGLJ.rationItemQuantity = temdata.consumeAmt;
  315. newGLJ.quantity = temdata.consumeAmt;
  316. newGLJ.glj_repository_id = data.rationRepId;
  317. criteria.ration_glj_list.push(newGLJ);
  318. }
  319. criteria.updateType = 'ut_create';
  320. souceTypeList.push(this.getSourceType());
  321. criteriaDataList.push(criteria);
  322. }
  323. var ration_coe = projectObj.project.ration_coe;
  324. var rationCoeData = ration_coe.getRationCoedata(newRation, data);
  325. souceTypeList.push(ration_coe.getSourceType());
  326. criteriaDataList.push(rationCoeData);
  327. project.pushNow('addRationGLJAndRationCoe', souceTypeList, criteriaDataList);
  328. };
  329. ration_glj.prototype.getDeleteDataByRation = function (rationData) {
  330. var updateData = [];
  331. updateData.push({
  332. 'deleteType': 'RATION',
  333. 'updateType': 'ut_delete',
  334. 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}
  335. });
  336. return updateData;
  337. };
  338. ration_glj.prototype.getDeleteDataByBills = function (datas) {
  339. var updateData = [];
  340. datas.forEach(function (deleteData) {
  341. if (deleteData.type == 'delete') {
  342. var billData = deleteData.data;
  343. updateData.push({
  344. 'deleteType': 'BILL',
  345. 'updateType': 'ut_delete',
  346. 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}
  347. });
  348. }
  349. })
  350. return updateData;
  351. };
  352. ration_glj.prototype.deleteByRation = function (ration) {
  353. var glj_list = projectObj.project.ration_glj.datas;
  354. _.remove(glj_list,{'rationID':ration.ID});
  355. };
  356. ration_glj.prototype.deleteByBills = function (deleteData) {
  357. var rationList = projectObj.project.Ration.datas;
  358. var deleteRationList = [];
  359. for (var i = 0; i < deleteData.length; i++) {
  360. if (deleteData[i].type == 'delete') {
  361. var billID = deleteData[i].data.ID;
  362. var raList = _.filter(rationList, (ration) => {
  363. return ration.billsItemID == billID;
  364. });
  365. deleteRationList = deleteRationList.concat(raList);
  366. }
  367. }
  368. for (var i = 0; i < deleteRationList.length; i++) {
  369. this.deleteByRation(deleteRationList[i]);
  370. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  371. projectObj.project.quantity_detail.deleteByRation(deleteRationList[i]);
  372. projectObj.project.ration_installation.deleteByRation(deleteRationList[i]);
  373. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  374. }
  375. }
  376. ration_glj.prototype.updataOrdelete = function (row) {
  377. var updateData = null;
  378. if (row.rationItemQuantity == 0) {
  379. updateData = this.getUpdateData('ut_delete', {
  380. 'ID': row.ID,
  381. 'projectID': row.projectID
  382. }, {rationID: row.rationID});
  383. project.pushNow('updateRationGLJ', [this.getSourceType()], updateData)
  384. } else {
  385. this.updateRationGLJByEdit(row, 'customQuantity', 0);
  386. //('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  387. }
  388. };
  389. ration_glj.prototype.getUpdateData = function (type, query, doc, callfunction) {
  390. var updateData = [];
  391. var newobj = {
  392. 'updateType': type,
  393. 'query': query,
  394. }
  395. if (doc) {
  396. newobj['doc'] = doc;
  397. }
  398. if (callfunction) {
  399. newobj['updateFunction'] = callfunction;
  400. }
  401. updateData.push(newobj);
  402. return updateData;
  403. };
  404. ration_glj.prototype.updateRationGLJByEdit = function (recode, updateField, newval, node) {
  405. var me = this;
  406. $.bootstrapLoading.start();
  407. var callback = function (data) {
  408. let initShow = false;//是否需要表格初始化显示
  409. if (updateField == 'customQuantity') {
  410. me.refreshAfterQuantityUpdate(data, node);
  411. } else {
  412. var doc = data.doc;
  413. for (var key in doc) {
  414. recode[key] = doc[key];
  415. }
  416. if (data.hasOwnProperty('adjustState')) {//更新定额调整状态
  417. me.updateRationAdjustState(data.adjustState, recode.rationID, node);
  418. }
  419. if (recode.subList && recode.subList.length > 0) {
  420. initShow = true;
  421. }
  422. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  423. if (updateField == "type" && !(newval == gljType.MAIN_MATERIAL || newval == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  424. projectObj.mainController.deleteNode(node, true);
  425. }
  426. }
  427. }
  428. if (initShow == false) {//不需要初始化,只需耍新当前显示就可以了
  429. gljOprObj.showRationGLJSheetData();
  430. }
  431. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  432. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  433. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  434. if (initShow == true) {
  435. gljOprObj.refreshView();
  436. }
  437. $.bootstrapLoading.end();
  438. installationFeeObj.calcInstallationFee();
  439. });
  440. }
  441. var query = {
  442. 'ID': recode.ID,
  443. 'projectID': recode.projectID,
  444. 'rationID': recode.rationID
  445. };
  446. var priceInfo = {
  447. base_price: recode.basePrice,
  448. market_price: recode.marketPrice
  449. }
  450. var doc = {};
  451. doc[updateField] = newval;
  452. if (updateField == "type") {
  453. doc.shortName = projectObj.project.projectGLJ.getShortNameByID(newval);
  454. }
  455. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  456. query: query,
  457. doc: doc,
  458. priceInfo: priceInfo
  459. }, callback, function (err) {
  460. $.bootstrapLoading.end();
  461. });
  462. }
  463. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  464. var me = this;
  465. data.glj_result.forEach(function (item) {
  466. me.refreshEachItme(item.doc, item.query);
  467. })
  468. me.updateRationAdjustState(data.adjustState, data.rationID, node);
  469. };
  470. ration_glj.prototype.updateRationAdjustState = function (adjustState, rationID, rnode) {
  471. var nodes = [];
  472. var node = _.find(projectObj.project.mainTree.items, function (n) {
  473. return n.sourceType == ModuleNames.ration && n.data.ID == rationID;
  474. })
  475. if (node) {
  476. node.data.adjustState = adjustState;
  477. nodes.push(node);
  478. }
  479. if (rnode) {
  480. nodes.push(rnode);
  481. }
  482. projectObj.mainController.refreshTreeNode(nodes);
  483. };
  484. ration_glj.prototype.getGLJData = function (cb) {
  485. let engineerID = projectInfoObj.projectInfo.property.engineering_id;
  486. CommonAjax.get('/rationGlj/getGLJData/'+engineerID, function (data) {
  487. cb(data);
  488. })
  489. };
  490. ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
  491. let gljList = [];
  492. let allGLJ = gljOprObj.AllRecode;
  493. let billsItemID = null, serialNo = 0,selectedSerialNo = null,nextNodeID = null, parentNodeID = null, billNode = null;
  494. let children = [];
  495. if (selected.sourceType === project.Bills.getSourceType()) {
  496. billsItemID = selected.data.ID;
  497. parentNodeID = selected.getID();
  498. nextNodeID = selected.tree.rootID();
  499. billNode = selected;
  500. } else {
  501. billsItemID = selected.data.billsItemID;
  502. serialNo = selected.data.serialNo;
  503. selectedSerialNo = selected.data.serialNo;
  504. nextNodeID = selected.getNextSiblingID();
  505. parentNodeID = selected.getParentID();
  506. billNode = selected.parent;
  507. }
  508. children = project.Ration.getBillsSortRation(billsItemID);
  509. serialNo == 0 ? serialNo = children.length : "";
  510. for (let con_key of GLJSelection) {
  511. var glj = _.find(allGLJ, function (item) {
  512. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  513. return i_key == con_key;
  514. });
  515. if (glj) {
  516. serialNo += 1;
  517. let new_glj = {
  518. ID: project.Ration.getNewRationID(),
  519. projectID: parseInt(project.ID()),
  520. billsItemID: billsItemID,
  521. type: rationType.gljRation,
  522. code: glj.code,
  523. name: glj.name,
  524. quantity: 0,
  525. unit: glj.unit,
  526. specs: glj.specs,
  527. subType: glj.gljType,
  528. basePrice: glj.basePrice,
  529. marketPrice:glj.basePrice,
  530. original_code: glj.code,
  531. shortName: glj.shortName,
  532. serialNo: serialNo,
  533. GLJID: glj.ID,
  534. adjCoe: glj.adjCoe,
  535. materialType:glj.materialType,
  536. materialCoe:glj.materialCoe,
  537. repositoryId: glj.repositoryId
  538. };
  539. if (glj.hasOwnProperty("compilationId")) {
  540. new_glj.from = "cpt";
  541. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  542. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  543. }
  544. }
  545. if(optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')){//需要根据清单转换工程量
  546. new_glj.quantityEXP="QDL";
  547. if(billNode.data.quantity){
  548. new_glj.quantity = scMathUtil.roundForObj(billNode.data.quantity/FilterNumberFromUnit(glj.unit),getDecimal("glj.quantity"));
  549. new_glj.contain = scMathUtil.roundForObj(new_glj.quantity/billNode.data.quantity,6);
  550. }
  551. }
  552. gljList.push(new_glj);
  553. }
  554. }
  555. if (gljList.length == 0) {
  556. return;
  557. }
  558. let postData = {
  559. gljList: gljList,
  560. projectID: parseInt(project.ID()),
  561. billsItemID: billsItemID,
  562. rationCount: project.Ration.maxRationID()
  563. }
  564. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  565. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  566. // 更新兄弟节点的序列号
  567. if (selectedSerialNo != null) {
  568. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  569. if (selectIndex + 1 < children.length) {
  570. for (let i = selectIndex + 1; i < children.length; i++) {
  571. children[i].serialNo += gljList.length;
  572. }
  573. }
  574. }
  575. callback(parentNodeID,nextNodeID,data);
  576. }, function () {
  577. $.bootstrapLoading.end();
  578. });
  579. };
  580. ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
  581. var gljList = [];
  582. var allGLJ = gljOprObj.AllRecode;
  583. GLJSelection.sort();
  584. _.forEach(GLJSelection, function (g) {
  585. var glj = _.find(allGLJ, function (item) {
  586. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  587. return i_key == g;
  588. });
  589. var ration_glj = {
  590. projectID: ration.projectID,
  591. GLJID: glj.ID,
  592. rationID: ration.ID,
  593. billsItemID: ration.billsItemID,
  594. rationItemQuantity: 0,
  595. quantity: 0,
  596. name: glj.name,
  597. code: glj.code,
  598. original_code: glj.code,
  599. unit: glj.unit,
  600. specs: glj.specs,
  601. basePrice: glj.basePrice,
  602. marketPrice:glj.basePrice,
  603. shortName: glj.shortName,
  604. type: glj.gljType,
  605. adjCoe: glj.adjCoe,
  606. createType: 'add',
  607. materialType:glj.materialType,
  608. materialCoe:glj.materialCoe,
  609. repositoryId: glj.repositoryId
  610. }
  611. if (glj.hasOwnProperty("compilationId")) {
  612. ration_glj.from = "cpt";
  613. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  614. ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  615. }
  616. }
  617. gljList.push(ration_glj);
  618. });
  619. $.bootstrapLoading.start();
  620. CommonAjax.post("/rationGlj/addGLJ", gljList, callback, function () {
  621. $.bootstrapLoading.end();
  622. });
  623. };
  624. ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
  625. var allGLJ = gljOprObj.AllRecode;
  626. var glj = _.find(allGLJ, function (item) {
  627. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  628. return i_key == selectCode;
  629. });
  630. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  631. return callback(null);
  632. }
  633. if (oldData.createType===undefined || oldData.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  634. oldData.rcode = oldData.code;
  635. oldData.createType = 'replace';
  636. }
  637. oldData.GLJID = glj.ID;
  638. oldData.name = glj.name;
  639. oldData.code = glj.code;
  640. oldData.original_code = glj.code;
  641. oldData.unit = glj.unit;
  642. oldData.specs = glj.specs;
  643. oldData.basePrice = glj.basePrice;
  644. oldData.marketPrice = glj.basePrice;
  645. oldData.repositoryId = glj.repositoryId;
  646. oldData.materialType = glj.materialType;
  647. oldData. materialCoe = glj.materialCoe;
  648. if (glj.hasOwnProperty("compilationId")) {
  649. oldData.from = "cpt";
  650. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  651. oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  652. }
  653. } else {
  654. oldData.from = "std";
  655. }
  656. $.bootstrapLoading.start();
  657. CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
  658. $.bootstrapLoading.end();
  659. });
  660. };
  661. ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
  662. let allGLJ = gljOprObj.AllRecode,tasks = [],updateMap={};
  663. let oldIndex = gljOprObj.getIndex(oldData, gljKeyArray);
  664. let glj = _.find(allGLJ, function (item) {
  665. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  666. return i_key == selectCode;
  667. });
  668. if (selectCode == oldIndex) {
  669. return callback(null);
  670. }
  671. let query = {
  672. projectID: oldData.projectID,
  673. code: oldData.code,
  674. name: oldData.name,
  675. unit: oldData.unit,
  676. type: oldData.type
  677. }
  678. if (oldData.specs && oldData.specs != '') {
  679. query.specs = oldData.specs;
  680. }
  681. let doc = {
  682. GLJID: glj.ID,
  683. createType: 'replace',
  684. rationItemQuantity: 0,
  685. name: glj.name,
  686. code: glj.code,
  687. original_code: glj.code,
  688. unit: glj.unit,
  689. specs: glj.specs,
  690. type: glj.gljType,
  691. basePrice: glj.basePrice,
  692. marketPrice:glj.basePrice,
  693. repositoryId: glj.repositoryId,
  694. materialType: glj.materialType, //三材类别
  695. materialCoe: glj.materialCoe,
  696. projectID: oldData.projectID
  697. };
  698. if (glj.hasOwnProperty("compilationId")) {
  699. doc.from = "cpt";
  700. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  701. doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  702. }
  703. } else {
  704. doc.from = "std";
  705. }
  706. for(let d of this.datas){//查询出所有需替换的工料机
  707. let tem_index = gljOprObj.getIndex(d, gljKeyArray);
  708. if(tem_index == oldIndex){
  709. let tem_doc = _.cloneDeep(doc);
  710. if(d.createType == 'replace'){
  711. tem_doc.rcode = d.rcode;
  712. }else if(d.createType == 'add'){//对于添加的类型,替换后还是添加类型
  713. tem_doc.createType = 'add';
  714. }else {
  715. tem_doc.rcode = d.code
  716. }
  717. let task = {
  718. updateOne:{
  719. filter : {ID:d.ID},
  720. update : tem_doc
  721. }
  722. };
  723. tasks.push(task);
  724. updateMap[d.ID] = tem_doc;
  725. }
  726. }
  727. $.bootstrapLoading.start();
  728. CommonAjax.post("/rationGlj/mReplaceGLJ", {query: query, doc: doc,tasks:tasks}, function (result) {
  729. callback(result,updateMap);
  730. }, function () {
  731. $.bootstrapLoading.end();
  732. });
  733. };
  734. ration_glj.prototype.getMainAndEquGLJ = function (rationID) {
  735. var gljList = _.filter(this.datas, function (n) {
  736. return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
  737. });
  738. gljList = sortRationGLJ(gljList);
  739. return gljOprObj.combineWithProjectGlj(gljList);
  740. };
  741. ration_glj.prototype.transferToNodeData = function (data) {
  742. data.contain=scMathUtil.roundForObj(data.quantity,getDecimal('glj.quantity'));
  743. data.subType = data.type;
  744. };
  745. ration_glj.prototype.combineRationAndGLJ = function (ration) {
  746. if (ration) {
  747. var projectGLJData = projectObj.project.projectGLJ.datas;
  748. var projectGljs = projectGLJData.gljList;
  749. var mixRatioMap = projectGLJData.mixRatioMap;
  750. var glj = _.find(projectGljs, {'id': ration.projectGLJID});
  751. if (glj) {
  752. if(projectObj.project.projectGLJ.isEstimateType(glj.type)){
  753. ration.isEstimate = glj.is_evaluate;
  754. }
  755. ration = gljOprObj.setGLJPrice(ration,glj);
  756. ration.isAdd = glj.unit_price.is_add;
  757. var connect_index = gljOprObj.getIndex(glj, gljKeyArray);
  758. if (mixRatioMap.hasOwnProperty(connect_index)) {
  759. var mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  760. ration.subList = mixRatios;
  761. }
  762. }
  763. }
  764. return ration;
  765. };
  766. ration_glj.prototype.updateFromMainSpread = function (value, node, fieldName) {
  767. if (node.data[fieldName] !== value) {
  768. if (fieldName == "marketUnitFee") {
  769. var decimal = getDecimal("glj.unitPrice");
  770. var newval = number_util.checkNumberValue(value, decimal);
  771. if (newval) {
  772. fieldName = "marketPrice";
  773. projectObj.project.projectGLJ.updatePriceFromRG(node.data, fieldName, newval);
  774. return;
  775. }
  776. } else {
  777. if(fieldName == "contain"){
  778. if(value==null){
  779. value="";
  780. }else {
  781. var decimal = getDecimal("glj.quantity");
  782. value = number_util.checkNumberValue(value, decimal);
  783. fieldName="customQuantity";//填入自定义消耗
  784. }
  785. }
  786. if (value !== undefined && value !== null) {
  787. if (fieldName == "subType") {
  788. node.data.subType = value;
  789. fieldName = "type";//转换成更新工料机类型
  790. }
  791. this.updateRationGLJByEdit(node.data, fieldName, value, node);
  792. return;
  793. }
  794. }
  795. }
  796. // node.data.subType = value;
  797. projectObj.mainController.refreshTreeNode([node]);
  798. };
  799. ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
  800. if (this.needShowToTree(data)) {
  801. this.transferToNodeData(data);
  802. gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
  803. }
  804. };
  805. ration_glj.prototype.needShowToTree = function (data) {
  806. if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  807. return true
  808. }
  809. return false
  810. };
  811. ration_glj.prototype.findGLJNodeByID = function (ID) {
  812. return projectObj.project.mainTree.findNode(ID);
  813. };
  814. ration_glj.prototype.findRationNodeByID = function (ID) {
  815. return projectObj.project.mainTree.findNode(ID);
  816. };
  817. ration_glj.prototype.reCalcWhenGLJChange = function (ration_glj) {//当改变定额工料机时,重新计算定额以及其父节点
  818. let node = this.findRationNodeByID(ration_glj.rationID);
  819. if (node) {
  820. node.changed = true;
  821. project.calcProgram.calcAndSave(node);
  822. }
  823. };
  824. return new ration_glj(project);
  825. }
  826. };