ration_glj.js 38 KB

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