ration_glj.js 36 KB

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