ration_glj.js 38 KB

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