ration_glj.js 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. let ration_glj = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. let tools = {};
  8. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  9. let ration_glj = function (proj) {
  10. this.gljTree = cacheTree.createNew(this);
  11. // this.project = proj;
  12. this.datas = [];
  13. let 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. let o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {};
  65. for (let 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. let 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. let me = this;
  221. let 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. let glj = this.refreshByID(query.ID,doc);
  234. return glj.rationID;
  235. };
  236. ration_glj.prototype.refreshByID=function (ID,doc) {
  237. let glj_list = projectObj.project.ration_glj.datas;
  238. let glj_index = _.findIndex(glj_list,{"ID":ID});
  239. _.forEach(doc, function (n, key) {
  240. glj_list[glj_index][key] = n;
  241. });
  242. return glj_list[glj_index]
  243. };
  244. ration_glj.prototype.refreshAfterDelete = function (data) {
  245. let me = projectObj.project.ration_glj;
  246. let glj_list = me.datas;
  247. let oldData = _.remove(glj_list, data.query);
  248. _.remove(gljOprObj.sheetData, data.query);
  249. gljOprObj.showRationGLJSheetData();
  250. projectObj.project.projectGLJ.loadData();
  251. let rationNode = null;
  252. let next = null;
  253. let selected = projectObj.project.mainTree.selected;
  254. if (selected.sourceType == ModuleNames.ration) { //如果选中的是定额,说明是右键删除工料机操作,如果选中的是定额工料机,则说明是在造价书主界面中点击了删除按钮
  255. rationNode = selected;
  256. } else if (selected.sourceType == ModuleNames.ration_glj) {
  257. rationNode = selected.parent;
  258. next = true;
  259. }
  260. rationNode.data.adjustState = data.adjustState;
  261. projectObj.mainController.refreshTreeNode([rationNode]);
  262. for (let o of oldData) {
  263. if (this.needShowToTree(o)) {
  264. let node = me.findGLJNodeByID(o.ID); //找到对应的树节点
  265. projectObj.mainController.deleteNode(node, next);
  266. }
  267. }
  268. project.calcProgram.calcAndSave(rationNode,function () {
  269. installationFeeObj.calcInstallationFee();
  270. });
  271. };
  272. // CSL,2017.05.09
  273. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  274. this.project.beginUpdate('modifyQuantity');
  275. data.quantity = newQuantity;
  276. data.customQuantity = newQuantity;
  277. data.updateType = 'ut_update';
  278. this.project.push(this.getSourceType, data);
  279. this.project.endUpdate();
  280. };
  281. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  282. this.project.beginUpdate('modifyPrice');
  283. data.price = newPrice;
  284. data.updateType = 'ut_update';
  285. this.project.push(this.getSourceType, data);
  286. this.project.endUpdate();
  287. };
  288. ration_glj.prototype.deleteGLJ = function (data) {
  289. this.project.beginUpdate('deleteGLJ');
  290. data.customQuantity = 0;
  291. data.quantity = 0;
  292. data.rationItemQuantity = 0;
  293. data.updateType = 'ut_update';
  294. this.project.push(this.getSourceType, data);
  295. this.project.endUpdate();
  296. };
  297. ration_glj.prototype.addRationGLJ = function (newRation, data) {
  298. let souceTypeList = [];
  299. let criteriaDataList = [];
  300. if (data.hasOwnProperty('rationGljList') && data.rationGljList.length > 0) {
  301. let criteria = {};
  302. criteria.ration_glj_list = [];
  303. for (let i = 0; i < data.rationGljList.length; i++) {
  304. let temdata = data.rationGljList[i];
  305. let newGLJ = {};
  306. newGLJ.projectID = parseInt(newRation.projectID);
  307. newGLJ.GLJID = temdata.gljId;
  308. newGLJ.rationID = newRation.ID;
  309. newGLJ.billsItemID = newRation.billsItemID;
  310. newGLJ.rationItemQuantity = temdata.consumeAmt;
  311. newGLJ.quantity = temdata.consumeAmt;
  312. newGLJ.glj_repository_id = data.rationRepId;
  313. criteria.ration_glj_list.push(newGLJ);
  314. }
  315. criteria.updateType = 'ut_create';
  316. souceTypeList.push(this.getSourceType());
  317. criteriaDataList.push(criteria);
  318. }
  319. let ration_coe = projectObj.project.ration_coe;
  320. let rationCoeData = ration_coe.getRationCoedata(newRation, data);
  321. souceTypeList.push(ration_coe.getSourceType());
  322. criteriaDataList.push(rationCoeData);
  323. project.pushNow('addRationGLJAndRationCoe', souceTypeList, criteriaDataList);
  324. };
  325. ration_glj.prototype.getDeleteDataByRation = function (rationData) {
  326. let updateData = [];
  327. updateData.push({
  328. 'deleteType': 'RATION',
  329. 'updateType': 'ut_delete',
  330. 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}
  331. });
  332. return updateData;
  333. };
  334. ration_glj.prototype.getDeleteDataByBills = function (datas) {
  335. let updateData = [];
  336. datas.forEach(function (deleteData) {
  337. if (deleteData.type == 'delete') {
  338. let billData = deleteData.data;
  339. updateData.push({
  340. 'deleteType': 'BILL',
  341. 'updateType': 'ut_delete',
  342. 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}
  343. });
  344. }
  345. })
  346. return updateData;
  347. };
  348. ration_glj.prototype.deleteByRation = function (ration) {
  349. let glj_list = projectObj.project.ration_glj.datas;
  350. _.remove(glj_list,{'rationID':ration.ID});
  351. };
  352. ration_glj.prototype.deleteByBills = function (deleteData) {
  353. let rationList = projectObj.project.Ration.datas;
  354. let deleteRationList = [];
  355. for (let i = 0; i < deleteData.length; i++) {
  356. if (deleteData[i].type == 'delete') {
  357. let billID = deleteData[i].data.ID;
  358. let raList = _.filter(rationList, (ration) => {
  359. return ration.billsItemID == billID;
  360. });
  361. deleteRationList = deleteRationList.concat(raList);
  362. }
  363. }
  364. for (let i = 0; i < deleteRationList.length; i++) {
  365. this.deleteByRation(deleteRationList[i]);
  366. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  367. projectObj.project.quantity_detail.deleteByRation(deleteRationList[i]);
  368. projectObj.project.ration_installation.deleteByRation(deleteRationList[i]);
  369. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  370. }
  371. }
  372. ration_glj.prototype.updataOrdelete = function (row) {
  373. let updateData = null;
  374. if (row.rationItemQuantity == 0) {
  375. updateData = this.getUpdateData('ut_delete', {
  376. 'ID': row.ID,
  377. 'projectID': row.projectID
  378. }, {rationID: row.rationID});
  379. project.pushNow('updateRationGLJ', [this.getSourceType()], updateData)
  380. } else {
  381. this.updateRationGLJByEdit(row, 'customQuantity', 0);
  382. //('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  383. }
  384. };
  385. ration_glj.prototype.getUpdateData = function (type, query, doc, callfunction) {
  386. let updateData = [];
  387. let newobj = {
  388. 'updateType': type,
  389. 'query': query,
  390. }
  391. if (doc) {
  392. newobj['doc'] = doc;
  393. }
  394. if (callfunction) {
  395. newobj['updateFunction'] = callfunction;
  396. }
  397. updateData.push(newobj);
  398. return updateData;
  399. };
  400. ration_glj.prototype.updateRationGLJByEdit = function (recode, updateField, newval, node) {
  401. let me = this,doc = {};
  402. doc[updateField] = newval;
  403. me.submitChange(recode,doc,updateField,node);
  404. };
  405. ration_glj.prototype.submitChange = function(recode,updateData,updateField,node){
  406. let me = this;
  407. let query = {
  408. 'ID': recode.ID,
  409. 'projectID': recode.projectID,
  410. 'rationID': recode.rationID
  411. };
  412. let priceInfo = {
  413. base_price: recode.basePrice,
  414. market_price: recode.marketPrice
  415. };
  416. if(updateData['type'] != undefined || updateData['type'] != null){
  417. updateData.shortName = projectObj.project.projectGLJ.getShortNameByID(updateData['type']);
  418. }
  419. let callback = function (data) {
  420. if (updateField == 'customQuantity') {
  421. me.refreshAfterQuantityUpdate(data, node);
  422. } else {
  423. let doc = data.doc;
  424. for (let key in doc) {
  425. recode[key] = doc[key];
  426. }
  427. me.refreshRationAfterEdit(data,recode.rationID, node);//更新名称和定额调整状态
  428. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  429. if (updateField == "type" && !(updateData['type'] == gljType.MAIN_MATERIAL || updateData['type'] == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  430. projectObj.mainController.deleteNode(node, true);
  431. }
  432. }
  433. }
  434. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  435. gljOprObj.refreshView();
  436. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  437. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  438. $.bootstrapLoading.end();
  439. installationFeeObj.calcInstallationFee();
  440. });
  441. };
  442. $.bootstrapLoading.start();
  443. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  444. query: query,
  445. doc: updateData,
  446. priceInfo: priceInfo
  447. }, callback, function (err) {
  448. $.bootstrapLoading.end();
  449. });
  450. };
  451. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  452. let me = this;
  453. data.glj_result.forEach(function (item) {
  454. me.refreshEachItme(item.doc, item.query);
  455. });
  456. me.refreshRationAfterEdit(data, data.rationID, node);
  457. };
  458. ration_glj.prototype.refreshRationAfterEdit= function(data,rationID,rnode){
  459. let nodes = [];
  460. let node = this.refreshRationNode(data.name,data.adjustState,rationID);
  461. if (node) nodes.push(node);
  462. if (rnode) nodes.push(rnode);
  463. projectObj.mainController.refreshTreeNode(nodes);
  464. };
  465. ration_glj.prototype.refreshRationNode = function(name,adjustState,rationID){
  466. let node = projectObj.project.mainTree.findNode(rationID);
  467. if (!node) return null;
  468. if(gljUtil.isDef(adjustState)){
  469. node.data.adjustState = adjustState;
  470. }
  471. if(gljUtil.isDef(name)){
  472. node.data.name = name;
  473. }
  474. return node
  475. };
  476. ration_glj.prototype.getGLJData = function (cb) {
  477. let engineerID = projectInfoObj.projectInfo.property.engineering_id;
  478. CommonAjax.get('/rationGlj/getGLJData/'+engineerID, function (data) {
  479. cb(data);
  480. })
  481. };
  482. ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
  483. let gljList = [];
  484. let allGLJ = gljOprObj.AllRecode;
  485. let billsItemID = null, serialNo = 0,selectedSerialNo = null,nextNodeID = null, parentNodeID = null, billNode = null;
  486. let pEngineer = projectInfoObj.projectInfo.property.projectEngineering;
  487. let children = [];
  488. if (selected.sourceType === project.Bills.getSourceType()) {
  489. billsItemID = selected.data.ID;
  490. parentNodeID = selected.getID();
  491. nextNodeID = selected.tree.rootID();
  492. billNode = selected;
  493. } else {
  494. billsItemID = selected.data.billsItemID;
  495. serialNo = selected.data.serialNo;
  496. selectedSerialNo = selected.data.serialNo;
  497. nextNodeID = selected.getNextSiblingID();
  498. parentNodeID = selected.getParentID();
  499. billNode = selected.parent;
  500. }
  501. children = project.Ration.getBillsSortRation(billsItemID);
  502. serialNo == 0 ? serialNo = children.length : "";
  503. for (let con_key of GLJSelection) {
  504. let glj = _.find(allGLJ, function (item) {
  505. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  506. return i_key == con_key;
  507. });
  508. if (glj) {
  509. serialNo += 1;
  510. let new_glj = {
  511. ID: project.Ration.getNewRationID(),
  512. projectID: parseInt(project.ID()),
  513. billsItemID: billsItemID,
  514. type: rationType.gljRation,
  515. code: glj.code,
  516. name: glj.name,
  517. quantity: 0,
  518. unit: glj.unit,
  519. specs: glj.specs,
  520. subType: glj.gljType,
  521. model:glj.model,
  522. basePrice: glj.basePrice,
  523. marketPrice:glj.basePrice,
  524. original_code: glj.code,
  525. shortName: glj.shortName,
  526. serialNo: serialNo,
  527. GLJID: glj.ID,
  528. adjCoe: glj.adjCoe,
  529. materialType:glj.materialType,
  530. materialCoe:glj.materialCoe,
  531. repositoryId: glj.repositoryId
  532. };
  533. if(pEngineer) new_glj.programID = pEngineer;
  534. if (glj.hasOwnProperty("compilationId")) {
  535. new_glj.from = "cpt";
  536. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  537. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  538. }
  539. }
  540. if(optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')){//需要根据清单转换工程量
  541. new_glj.quantityEXP="QDL";
  542. if(billNode.data.quantity){
  543. new_glj.quantity = scMathUtil.roundForObj(billNode.data.quantity/FilterNumberFromUnit(glj.unit),getDecimal("glj.quantity"));
  544. new_glj.contain = scMathUtil.roundForObj(new_glj.quantity/billNode.data.quantity,6);
  545. }
  546. }
  547. gljList.push(new_glj);
  548. }
  549. }
  550. if (gljList.length == 0) {
  551. return;
  552. }
  553. let postData = {
  554. gljList: gljList,
  555. projectID: parseInt(project.ID()),
  556. billsItemID: billsItemID,
  557. rationCount: project.Ration.maxRationID()
  558. }
  559. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  560. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  561. // 更新兄弟节点的序列号
  562. if (selectedSerialNo != null) {
  563. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  564. if (selectIndex + 1 < children.length) {
  565. for (let i = selectIndex + 1; i < children.length; i++) {
  566. children[i].serialNo += gljList.length;
  567. }
  568. }
  569. }
  570. callback(parentNodeID,nextNodeID,data);
  571. }, function () {
  572. $.bootstrapLoading.end();
  573. });
  574. };
  575. ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
  576. let gljList = [];
  577. let allGLJ = gljOprObj.AllRecode;
  578. GLJSelection.sort();
  579. _.forEach(GLJSelection, function (g) {
  580. let glj = _.find(allGLJ, function (item) {
  581. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  582. return i_key == g;
  583. });
  584. let ration_glj = {
  585. projectID: ration.projectID,
  586. GLJID: glj.ID,
  587. rationID: ration.ID,
  588. billsItemID: ration.billsItemID,
  589. rationItemQuantity: 0,
  590. quantity: 0,
  591. name: glj.name,
  592. code: glj.code,
  593. original_code: glj.code,
  594. unit: glj.unit,
  595. specs: glj.specs,
  596. basePrice: glj.basePrice,
  597. marketPrice:glj.basePrice,
  598. shortName: glj.shortName,
  599. type: glj.gljType,
  600. model:glj.model,
  601. adjCoe: glj.adjCoe,
  602. createType: 'add',
  603. materialType:glj.materialType,
  604. materialCoe:glj.materialCoe,
  605. repositoryId: glj.repositoryId
  606. }
  607. if (glj.hasOwnProperty("compilationId")) {
  608. ration_glj.from = "cpt";
  609. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  610. ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  611. }
  612. }
  613. gljList.push(ration_glj);
  614. });
  615. $.bootstrapLoading.start();
  616. CommonAjax.post("/rationGlj/addGLJ", gljList, callback, function () {
  617. $.bootstrapLoading.end();
  618. });
  619. };
  620. ration_glj.prototype.updateRationGLJByChangeCode = function (recode, updateField, newval) {
  621. let me = this;
  622. let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
  623. let priceObj = priceMap[newval];
  624. if(priceObj){
  625. if (recode.createType===undefined || recode.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  626. recode.rcode = recode.code;
  627. recode.createType = 'replace';
  628. }
  629. recode.code = priceObj.code;
  630. recode.name = priceObj.name;
  631. recode.type = priceObj.type;
  632. recode.unit = priceObj.unit;
  633. recode.shortName = priceObj.short_name;
  634. recode.specs = priceObj.specs;
  635. recode.GLJID=priceObj.glj_id;
  636. recode.original_code = priceObj.original_code;
  637. recode.basePrice = priceObj.base_price;
  638. recode.marketPrice = priceObj.market_price;
  639. }
  640. $.bootstrapLoading.start();
  641. CommonAjax.post("/rationGlj/replaceGLJ", recode, function (result) {
  642. if (result) {
  643. //result.adjustState;
  644. let glj_list = me.datas;
  645. let data = result.data;
  646. let list_index = _.findIndex(glj_list, {'ID': data.ID});
  647. let rationNode = projectObj.project.mainTree.findNode(data.rationID);
  648. let nodes = [rationNode];
  649. glj_list[list_index] = data;
  650. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  651. gljOprObj.refreshView();
  652. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  653. let node = project.ration_glj.findGLJNodeByID(data.ID);
  654. if (node) {
  655. project.ration_glj.transferToNodeData(data);
  656. node.source = data;
  657. node.data = data;
  658. }
  659. node ? nodes.push(node) : "";
  660. }
  661. rationNode.data.adjustState = result.adjustState;
  662. rationNode.data.name = result.name;
  663. projectObj.mainController.refreshTreeNode(nodes);
  664. project.calcProgram.calcAndSave(rationNode);
  665. $.bootstrapLoading.end();
  666. });
  667. }
  668. }, function () {
  669. $.bootstrapLoading.end();
  670. });
  671. };
  672. ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
  673. let allGLJ = gljOprObj.AllRecode;
  674. let glj = _.find(allGLJ, function (item) {
  675. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  676. return i_key == selectCode;
  677. });
  678. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  679. return callback(null);
  680. }
  681. if (oldData.createType===undefined || oldData.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  682. oldData.rcode = oldData.code;
  683. oldData.createType = 'replace';
  684. }
  685. oldData.GLJID = glj.ID;
  686. oldData.name = glj.name;
  687. oldData.code = glj.code;
  688. oldData.original_code = glj.code;
  689. oldData.unit = glj.unit;
  690. oldData.specs = glj.specs;
  691. oldData.model = glj.model;
  692. oldData.basePrice = glj.basePrice;
  693. oldData.marketPrice = glj.basePrice;
  694. oldData.repositoryId = glj.repositoryId;
  695. oldData.materialType = glj.materialType;
  696. oldData. materialCoe = glj.materialCoe;
  697. if (glj.hasOwnProperty("compilationId")) {
  698. oldData.from = "cpt";
  699. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  700. oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  701. }
  702. } else {
  703. oldData.from = "std";
  704. }
  705. $.bootstrapLoading.start();
  706. CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
  707. $.bootstrapLoading.end();
  708. });
  709. };
  710. ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
  711. let allGLJ = gljOprObj.AllRecode,tasks = [],updateMap={};
  712. let oldIndex = gljOprObj.getIndex(oldData, gljKeyArray);
  713. let glj = _.find(allGLJ, function (item) {
  714. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  715. return i_key == selectCode;
  716. });
  717. if (selectCode == oldIndex) {
  718. return callback(null);
  719. }
  720. let query = {
  721. projectID: oldData.projectID,
  722. code: oldData.code,
  723. name: oldData.name,
  724. unit: oldData.unit,
  725. type: oldData.type
  726. }
  727. if (oldData.specs && oldData.specs != '') {
  728. query.specs = oldData.specs;
  729. }
  730. let doc = {
  731. GLJID: glj.ID,
  732. createType: 'replace',
  733. rationItemQuantity: 0,
  734. name: glj.name,
  735. code: glj.code,
  736. original_code: glj.code,
  737. unit: glj.unit,
  738. specs: glj.specs,
  739. type: glj.gljType,
  740. model:glj.model,
  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. let 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. let projectGLJData = projectObj.project.projectGLJ.datas;
  798. let projectGljs = projectGLJData.gljList;
  799. let mixRatioMap = projectGLJData.mixRatioMap;
  800. let 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. let connect_index = gljOprObj.getIndex(glj, gljKeyArray);
  808. if (mixRatioMap.hasOwnProperty(connect_index)) {
  809. let 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. let decimal = getDecimal("glj.unitPrice");
  820. let 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. let 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. };