ration_glj.js 41 KB

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