ration_glj.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907
  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 = projectObj.project.mainTree.findNode(data.rationID);
  181. if (parentNode) {
  182. let nextNodeID = null;
  183. if (parentNode.children.length > 0) {
  184. for (let br of parentNode.children) {
  185. if (compareRationGLJ(data, br.data)) {//如果有兄弟节点则找到添加位置。
  186. nextNodeID = br.getID();
  187. }
  188. }
  189. }
  190. nextNodeID = nextNodeID ? nextNodeID : parentNode.tree.rootID();
  191. let newNode = projectObj.project.mainTree.insert(parentNode.getID(), nextNodeID,data.ID);
  192. newNode.source = data;
  193. newNode.sourceType = this.getSourceType();
  194. newNode.data = data;
  195. ProjectController.syncDisplayNewRationGljNode(projectObj.mainController, newNode);
  196. }
  197. }
  198. }
  199. };
  200. ration_glj.prototype.removeNodeByRation = function(ration,controller){//删除主材或设备节点
  201. let glj_list = _.filter(projectObj.project.ration_glj.datas,{'rationID':ration.ID});
  202. let deleteNodes = [];
  203. for(let rg of glj_list){
  204. if(this.needShowToTree(rg)){
  205. let r_node = projectObj.project.mainTree.getNodeByID(rg.ID);
  206. deleteNodes.push(r_node);
  207. }
  208. }
  209. if(deleteNodes.length > 0){
  210. let rowIndex = deleteNodes[0].serialNo();
  211. if(controller.tree.m_delete(deleteNodes)){
  212. TREE_SHEET_HELPER.massOperationSheet(controller.sheet, function () {
  213. let rowCount = deleteNodes.length;
  214. controller.sheet.deleteRows(rowIndex, rowCount);
  215. });
  216. }
  217. }
  218. };
  219. ration_glj.prototype.refreshAfterUpdate = function (data) {
  220. var me = this;
  221. var rationID=null;
  222. if (data.quantityRefresh) {
  223. data.glj_result.forEach(function (item) {
  224. rationID = me.refreshEachItme(item.doc, item.query);
  225. })
  226. } else {
  227. rationID = me.refreshEachItme(data.doc, data.query);
  228. }
  229. gljOprObj.showRationGLJSheetData(true);
  230. this.reCalcWhenGLJChange({rationID:rationID});
  231. };
  232. ration_glj.prototype.refreshEachItme = function (doc, query) {
  233. var glj_list = projectObj.project.ration_glj.datas;
  234. var glj_index = _.findIndex(glj_list, (glj) => {
  235. return glj.ID == query.ID;
  236. })
  237. /*var sheet_index= _.findIndex(gljOprObj.sheetData,(sd)=>{
  238. return sd.ID==query.ID;
  239. })*/
  240. _.forEach(doc, function (n, key) {
  241. glj_list[glj_index][key] = n;
  242. });
  243. return glj_list[glj_index].rationID;
  244. };
  245. ration_glj.prototype.refreshAfterDelete = function (data) {
  246. var me = projectObj.project.ration_glj;
  247. var glj_list = me.datas;
  248. var oldData = _.remove(glj_list, data.query);
  249. _.remove(gljOprObj.sheetData, data.query);
  250. gljOprObj.showRationGLJSheetData();
  251. projectObj.project.projectGLJ.loadData();
  252. var rationNode = null;
  253. var next = null;
  254. var selected = projectObj.project.mainTree.selected;
  255. if (selected.sourceType == ModuleNames.ration) { //如果选中的是定额,说明是右键删除工料机操作,如果选中的是定额工料机,则说明是在造价书主界面中点击了删除按钮
  256. rationNode = selected;
  257. } else if (selected.sourceType == ModuleNames.ration_glj) {
  258. rationNode = selected.parent;
  259. next = true;
  260. }
  261. rationNode.data.adjustState = data.adjustState;
  262. projectObj.mainController.refreshTreeNode([rationNode]);
  263. for (let o of oldData) {
  264. if (this.needShowToTree(o)) {
  265. let node = me.findGLJNodeByID(o.ID); //找到对应的树节点
  266. projectObj.mainController.deleteNode(node, next);
  267. }
  268. }
  269. project.calcProgram.calcAndSave(rationNode,function () {
  270. installationFeeObj.calcInstallationFee();
  271. });
  272. };
  273. // CSL,2017.05.09
  274. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  275. this.project.beginUpdate('modifyQuantity');
  276. data.quantity = newQuantity;
  277. data.customQuantity = newQuantity;
  278. data.updateType = 'ut_update';
  279. this.project.push(this.getSourceType, data);
  280. this.project.endUpdate();
  281. };
  282. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  283. this.project.beginUpdate('modifyPrice');
  284. data.price = newPrice;
  285. data.updateType = 'ut_update';
  286. this.project.push(this.getSourceType, data);
  287. this.project.endUpdate();
  288. };
  289. ration_glj.prototype.deleteGLJ = function (data) {
  290. this.project.beginUpdate('deleteGLJ');
  291. data.customQuantity = 0;
  292. data.quantity = 0;
  293. data.rationItemQuantity = 0;
  294. data.updateType = 'ut_update';
  295. this.project.push(this.getSourceType, data);
  296. this.project.endUpdate();
  297. };
  298. ration_glj.prototype.addRationGLJ = function (newRation, data) {
  299. var souceTypeList = [];
  300. var criteriaDataList = [];
  301. if (data.hasOwnProperty('rationGljList') && data.rationGljList.length > 0) {
  302. let criteria = {};
  303. criteria.ration_glj_list = [];
  304. for (let i = 0; i < data.rationGljList.length; i++) {
  305. let temdata = data.rationGljList[i];
  306. let newGLJ = {};
  307. newGLJ.projectID = parseInt(newRation.projectID);
  308. newGLJ.GLJID = temdata.gljId;
  309. newGLJ.rationID = newRation.ID;
  310. newGLJ.billsItemID = newRation.billsItemID,
  311. newGLJ.rationItemQuantity = temdata.consumeAmt;
  312. newGLJ.quantity = temdata.consumeAmt;
  313. newGLJ.glj_repository_id = data.rationRepId;
  314. criteria.ration_glj_list.push(newGLJ);
  315. }
  316. criteria.updateType = 'ut_create';
  317. souceTypeList.push(this.getSourceType());
  318. criteriaDataList.push(criteria);
  319. }
  320. var ration_coe = projectObj.project.ration_coe;
  321. var rationCoeData = ration_coe.getRationCoedata(newRation, data);
  322. souceTypeList.push(ration_coe.getSourceType());
  323. criteriaDataList.push(rationCoeData);
  324. project.pushNow('addRationGLJAndRationCoe', souceTypeList, criteriaDataList);
  325. };
  326. ration_glj.prototype.getDeleteDataByRation = function (rationData) {
  327. var updateData = [];
  328. updateData.push({
  329. 'deleteType': 'RATION',
  330. 'updateType': 'ut_delete',
  331. 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}
  332. });
  333. return updateData;
  334. };
  335. ration_glj.prototype.getDeleteDataByBills = function (datas) {
  336. var updateData = [];
  337. datas.forEach(function (deleteData) {
  338. if (deleteData.type == 'delete') {
  339. var billData = deleteData.data;
  340. updateData.push({
  341. 'deleteType': 'BILL',
  342. 'updateType': 'ut_delete',
  343. 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}
  344. });
  345. }
  346. })
  347. return updateData;
  348. };
  349. ration_glj.prototype.deleteByRation = function (ration) {
  350. var glj_list = projectObj.project.ration_glj.datas;
  351. _.remove(glj_list,{'rationID':ration.ID});
  352. };
  353. ration_glj.prototype.deleteByBills = function (deleteData) {
  354. var rationList = projectObj.project.Ration.datas;
  355. var deleteRationList = [];
  356. for (var i = 0; i < deleteData.length; i++) {
  357. if (deleteData[i].type == 'delete') {
  358. var billID = deleteData[i].data.ID;
  359. var raList = _.filter(rationList, (ration) => {
  360. return ration.billsItemID == billID;
  361. });
  362. deleteRationList = deleteRationList.concat(raList);
  363. }
  364. }
  365. for (var i = 0; i < deleteRationList.length; i++) {
  366. this.deleteByRation(deleteRationList[i]);
  367. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  368. projectObj.project.quantity_detail.deleteByRation(deleteRationList[i]);
  369. projectObj.project.ration_installation.deleteByRation(deleteRationList[i]);
  370. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  371. }
  372. }
  373. ration_glj.prototype.updataOrdelete = function (row) {
  374. var updateData = null;
  375. if (row.rationItemQuantity == 0) {
  376. updateData = this.getUpdateData('ut_delete', {
  377. 'ID': row.ID,
  378. 'projectID': row.projectID
  379. }, {rationID: row.rationID});
  380. project.pushNow('updateRationGLJ', [this.getSourceType()], updateData)
  381. } else {
  382. this.updateRationGLJByEdit(row, 'customQuantity', 0);
  383. //('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  384. }
  385. };
  386. ration_glj.prototype.getUpdateData = function (type, query, doc, callfunction) {
  387. var updateData = [];
  388. var newobj = {
  389. 'updateType': type,
  390. 'query': query,
  391. }
  392. if (doc) {
  393. newobj['doc'] = doc;
  394. }
  395. if (callfunction) {
  396. newobj['updateFunction'] = callfunction;
  397. }
  398. updateData.push(newobj);
  399. return updateData;
  400. };
  401. ration_glj.prototype.updateRationGLJByEdit = function (recode, updateField, newval, node) {
  402. var me = this;
  403. $.bootstrapLoading.start();
  404. var callback = function (data) {
  405. let initShow = false;//是否需要表格初始化显示
  406. if (updateField == 'customQuantity') {
  407. me.refreshAfterQuantityUpdate(data, node);
  408. } else {
  409. var doc = data.doc;
  410. for (var key in doc) {
  411. recode[key] = doc[key];
  412. }
  413. me.refreshRationAfterEdit(data,recode.rationID, node);//更新名称和定额调整状态
  414. if (recode.subList && recode.subList.length > 0) {
  415. initShow = true;
  416. }
  417. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  418. if (updateField == "type" && !(newval == gljType.MAIN_MATERIAL || newval == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  419. projectObj.mainController.deleteNode(node, true);
  420. }
  421. }
  422. }
  423. if (initShow == false) {//不需要初始化,只需耍新当前显示就可以了
  424. gljOprObj.showRationGLJSheetData();
  425. }
  426. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  427. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  428. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  429. if (initShow == true) {
  430. gljOprObj.refreshView();
  431. }
  432. $.bootstrapLoading.end();
  433. installationFeeObj.calcInstallationFee();
  434. });
  435. }
  436. var query = {
  437. 'ID': recode.ID,
  438. 'projectID': recode.projectID,
  439. 'rationID': recode.rationID
  440. };
  441. var priceInfo = {
  442. base_price: recode.basePrice,
  443. market_price: recode.marketPrice
  444. }
  445. var doc = {};
  446. doc[updateField] = newval;
  447. if (updateField == "type") {
  448. doc.shortName = projectObj.project.projectGLJ.getShortNameByID(newval);
  449. }
  450. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  451. query: query,
  452. doc: doc,
  453. priceInfo: priceInfo
  454. }, callback, function (err) {
  455. $.bootstrapLoading.end();
  456. });
  457. }
  458. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  459. var me = this;
  460. data.glj_result.forEach(function (item) {
  461. me.refreshEachItme(item.doc, item.query);
  462. });
  463. me.refreshRationAfterEdit(data, data.rationID, node);
  464. };
  465. ration_glj.prototype.refreshRationAfterEdit= function(data,rationID,rnode){
  466. let nodes = [];
  467. let node = projectObj.project.mainTree.findNode(rationID);
  468. if (node) {
  469. if(data.adjustState){
  470. node.data.adjustState = data.adjustState;
  471. }
  472. if(data.name){
  473. node.data.name = data.name;
  474. }
  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.updateRationGLJByChangeCode = function (recode, updateField, newval) {
  623. let me = this;
  624. let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
  625. let priceObj = priceMap[newval];
  626. if(priceObj){
  627. if (recode.createType===undefined || recode.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  628. recode.rcode = recode.code;
  629. recode.createType = 'replace';
  630. }
  631. recode.code = priceObj.code;
  632. recode.name = priceObj.name;
  633. recode.type = priceObj.type;
  634. recode.unit = priceObj.unit;
  635. recode.shortName = priceObj.short_name;
  636. recode.specs = priceObj.specs;
  637. recode.GLJID=priceObj.glj_id;
  638. recode.original_code = priceObj.original_code;
  639. recode.basePrice = priceObj.base_price;
  640. recode.marketPrice = priceObj.market_price;
  641. }
  642. $.bootstrapLoading.start();
  643. CommonAjax.post("/rationGlj/replaceGLJ", recode, function (result) {
  644. if (result) {
  645. //result.adjustState;
  646. var glj_list = me.datas;
  647. var data = result.data;
  648. var list_index = _.findIndex(glj_list, {'ID': data.ID});
  649. let rationNode = projectObj.project.mainTree.findNode(data.rationID);
  650. var nodes = [rationNode];
  651. glj_list[list_index] = data;
  652. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  653. gljOprObj.refreshView();
  654. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  655. var node = project.ration_glj.findGLJNodeByID(data.ID);
  656. if (node) {
  657. project.ration_glj.transferToNodeData(data);
  658. node.source = data;
  659. node.data = data;
  660. }
  661. node ? nodes.push(node) : "";
  662. }
  663. rationNode.data.adjustState = result.adjustState;
  664. rationNode.data.name = result.name;
  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. };