ration_glj.js 38 KB

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