ration_glj.js 36 KB

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