ration_glj.js 36 KB

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