ration_glj.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  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_list = projectObj.project.ration_glj.datas;
  234. let 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. let me = projectObj.project.ration_glj;
  247. let glj_list = me.datas;
  248. let oldData = _.remove(glj_list, data.query);
  249. _.remove(gljOprObj.sheetData, data.query);
  250. gljOprObj.showRationGLJSheetData();
  251. projectObj.project.projectGLJ.loadData();
  252. let rationNode = null;
  253. let next = null;
  254. let 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. let souceTypeList = [];
  300. let 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. let ration_coe = projectObj.project.ration_coe;
  321. let 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. let 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. let updateData = [];
  337. datas.forEach(function (deleteData) {
  338. if (deleteData.type == 'delete') {
  339. let 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. let glj_list = projectObj.project.ration_glj.datas;
  351. _.remove(glj_list,{'rationID':ration.ID});
  352. };
  353. ration_glj.prototype.deleteByBills = function (deleteData) {
  354. let rationList = projectObj.project.Ration.datas;
  355. let deleteRationList = [];
  356. for (let i = 0; i < deleteData.length; i++) {
  357. if (deleteData[i].type == 'delete') {
  358. let billID = deleteData[i].data.ID;
  359. let raList = _.filter(rationList, (ration) => {
  360. return ration.billsItemID == billID;
  361. });
  362. deleteRationList = deleteRationList.concat(raList);
  363. }
  364. }
  365. for (let 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. let 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. let updateData = [];
  388. let 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. let me = this,doc = {};
  403. doc[updateField] = newval;
  404. me.submitChange(recode,doc,updateField,node);
  405. };
  406. ration_glj.prototype.submitChange = function(recode,updateData,updateField,node){
  407. let me = this;
  408. let query = {
  409. 'ID': recode.ID,
  410. 'projectID': recode.projectID,
  411. 'rationID': recode.rationID
  412. };
  413. let priceInfo = {
  414. base_price: recode.basePrice,
  415. market_price: recode.marketPrice
  416. };
  417. if(updateData['type'] != undefined || updateData['type'] != null){
  418. updateData.shortName = projectObj.project.projectGLJ.getShortNameByID(updateData['type']);
  419. }
  420. let callback = function (data) {
  421. if (updateField == 'customQuantity') {
  422. me.refreshAfterQuantityUpdate(data, node);
  423. } else {
  424. let doc = data.doc;
  425. for (let key in doc) {
  426. recode[key] = doc[key];
  427. }
  428. me.refreshRationAfterEdit(data,recode.rationID, node);//更新名称和定额调整状态
  429. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  430. if (updateField == "type" && !(updateData['type'] == gljType.MAIN_MATERIAL || updateData['type'] == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  431. projectObj.mainController.deleteNode(node, true);
  432. }
  433. }
  434. }
  435. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  436. gljOprObj.refreshView();
  437. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  438. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  439. $.bootstrapLoading.end();
  440. installationFeeObj.calcInstallationFee();
  441. });
  442. };
  443. $.bootstrapLoading.start();
  444. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  445. query: query,
  446. doc: updateData,
  447. priceInfo: priceInfo
  448. }, callback, function (err) {
  449. $.bootstrapLoading.end();
  450. });
  451. };
  452. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  453. let me = this;
  454. data.glj_result.forEach(function (item) {
  455. me.refreshEachItme(item.doc, item.query);
  456. });
  457. me.refreshRationAfterEdit(data, data.rationID, node);
  458. };
  459. ration_glj.prototype.refreshRationAfterEdit= function(data,rationID,rnode){
  460. let nodes = [];
  461. let node = projectObj.project.mainTree.findNode(rationID);
  462. if (node) {
  463. if(data.adjustState){
  464. node.data.adjustState = data.adjustState;
  465. }
  466. if(data.name){
  467. node.data.name = data.name;
  468. }
  469. nodes.push(node);
  470. }
  471. if (rnode) {
  472. nodes.push(rnode);
  473. }
  474. projectObj.mainController.refreshTreeNode(nodes);
  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 children = [];
  487. if (selected.sourceType === project.Bills.getSourceType()) {
  488. billsItemID = selected.data.ID;
  489. parentNodeID = selected.getID();
  490. nextNodeID = selected.tree.rootID();
  491. billNode = selected;
  492. } else {
  493. billsItemID = selected.data.billsItemID;
  494. serialNo = selected.data.serialNo;
  495. selectedSerialNo = selected.data.serialNo;
  496. nextNodeID = selected.getNextSiblingID();
  497. parentNodeID = selected.getParentID();
  498. billNode = selected.parent;
  499. }
  500. children = project.Ration.getBillsSortRation(billsItemID);
  501. serialNo == 0 ? serialNo = children.length : "";
  502. for (let con_key of GLJSelection) {
  503. let glj = _.find(allGLJ, function (item) {
  504. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  505. return i_key == con_key;
  506. });
  507. if (glj) {
  508. serialNo += 1;
  509. let new_glj = {
  510. ID: project.Ration.getNewRationID(),
  511. projectID: parseInt(project.ID()),
  512. billsItemID: billsItemID,
  513. type: rationType.gljRation,
  514. code: glj.code,
  515. name: glj.name,
  516. quantity: 0,
  517. unit: glj.unit,
  518. specs: glj.specs,
  519. subType: glj.gljType,
  520. basePrice: glj.basePrice,
  521. marketPrice:glj.basePrice,
  522. original_code: glj.code,
  523. shortName: glj.shortName,
  524. serialNo: serialNo,
  525. GLJID: glj.ID,
  526. adjCoe: glj.adjCoe,
  527. materialType:glj.materialType,
  528. materialCoe:glj.materialCoe,
  529. repositoryId: glj.repositoryId
  530. };
  531. if (glj.hasOwnProperty("compilationId")) {
  532. new_glj.from = "cpt";
  533. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  534. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  535. }
  536. }
  537. if(optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')){//需要根据清单转换工程量
  538. new_glj.quantityEXP="QDL";
  539. if(billNode.data.quantity){
  540. new_glj.quantity = scMathUtil.roundForObj(billNode.data.quantity/FilterNumberFromUnit(glj.unit),getDecimal("glj.quantity"));
  541. new_glj.contain = scMathUtil.roundForObj(new_glj.quantity/billNode.data.quantity,6);
  542. }
  543. }
  544. gljList.push(new_glj);
  545. }
  546. }
  547. if (gljList.length == 0) {
  548. return;
  549. }
  550. let postData = {
  551. gljList: gljList,
  552. projectID: parseInt(project.ID()),
  553. billsItemID: billsItemID,
  554. rationCount: project.Ration.maxRationID()
  555. }
  556. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  557. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  558. // 更新兄弟节点的序列号
  559. if (selectedSerialNo != null) {
  560. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  561. if (selectIndex + 1 < children.length) {
  562. for (let i = selectIndex + 1; i < children.length; i++) {
  563. children[i].serialNo += gljList.length;
  564. }
  565. }
  566. }
  567. callback(parentNodeID,nextNodeID,data);
  568. }, function () {
  569. $.bootstrapLoading.end();
  570. });
  571. };
  572. ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
  573. let gljList = [];
  574. let allGLJ = gljOprObj.AllRecode;
  575. GLJSelection.sort();
  576. _.forEach(GLJSelection, function (g) {
  577. let glj = _.find(allGLJ, function (item) {
  578. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  579. return i_key == g;
  580. });
  581. let ration_glj = {
  582. projectID: ration.projectID,
  583. GLJID: glj.ID,
  584. rationID: ration.ID,
  585. billsItemID: ration.billsItemID,
  586. rationItemQuantity: 0,
  587. quantity: 0,
  588. name: glj.name,
  589. code: glj.code,
  590. original_code: glj.code,
  591. unit: glj.unit,
  592. specs: glj.specs,
  593. basePrice: glj.basePrice,
  594. marketPrice:glj.basePrice,
  595. shortName: glj.shortName,
  596. type: glj.gljType,
  597. adjCoe: glj.adjCoe,
  598. createType: 'add',
  599. materialType:glj.materialType,
  600. materialCoe:glj.materialCoe,
  601. repositoryId: glj.repositoryId
  602. }
  603. if (glj.hasOwnProperty("compilationId")) {
  604. ration_glj.from = "cpt";
  605. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  606. ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  607. }
  608. }
  609. gljList.push(ration_glj);
  610. });
  611. $.bootstrapLoading.start();
  612. CommonAjax.post("/rationGlj/addGLJ", gljList, callback, function () {
  613. $.bootstrapLoading.end();
  614. });
  615. };
  616. ration_glj.prototype.updateRationGLJByChangeCode = function (recode, updateField, newval) {
  617. let me = this;
  618. let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
  619. let priceObj = priceMap[newval];
  620. if(priceObj){
  621. if (recode.createType===undefined || recode.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  622. recode.rcode = recode.code;
  623. recode.createType = 'replace';
  624. }
  625. recode.code = priceObj.code;
  626. recode.name = priceObj.name;
  627. recode.type = priceObj.type;
  628. recode.unit = priceObj.unit;
  629. recode.shortName = priceObj.short_name;
  630. recode.specs = priceObj.specs;
  631. recode.GLJID=priceObj.glj_id;
  632. recode.original_code = priceObj.original_code;
  633. recode.basePrice = priceObj.base_price;
  634. recode.marketPrice = priceObj.market_price;
  635. }
  636. $.bootstrapLoading.start();
  637. CommonAjax.post("/rationGlj/replaceGLJ", recode, function (result) {
  638. if (result) {
  639. //result.adjustState;
  640. let glj_list = me.datas;
  641. let data = result.data;
  642. let list_index = _.findIndex(glj_list, {'ID': data.ID});
  643. let rationNode = projectObj.project.mainTree.findNode(data.rationID);
  644. let nodes = [rationNode];
  645. glj_list[list_index] = data;
  646. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  647. gljOprObj.refreshView();
  648. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  649. let node = project.ration_glj.findGLJNodeByID(data.ID);
  650. if (node) {
  651. project.ration_glj.transferToNodeData(data);
  652. node.source = data;
  653. node.data = data;
  654. }
  655. node ? nodes.push(node) : "";
  656. }
  657. rationNode.data.adjustState = result.adjustState;
  658. rationNode.data.name = result.name;
  659. projectObj.mainController.refreshTreeNode(nodes);
  660. project.calcProgram.calcAndSave(rationNode);
  661. $.bootstrapLoading.end();
  662. });
  663. }
  664. }, function () {
  665. $.bootstrapLoading.end();
  666. });
  667. };
  668. ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
  669. let allGLJ = gljOprObj.AllRecode;
  670. let glj = _.find(allGLJ, function (item) {
  671. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  672. return i_key == selectCode;
  673. });
  674. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  675. return callback(null);
  676. }
  677. if (oldData.createType===undefined || oldData.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  678. oldData.rcode = oldData.code;
  679. oldData.createType = 'replace';
  680. }
  681. oldData.GLJID = glj.ID;
  682. oldData.name = glj.name;
  683. oldData.code = glj.code;
  684. oldData.original_code = glj.code;
  685. oldData.unit = glj.unit;
  686. oldData.specs = glj.specs;
  687. oldData.basePrice = glj.basePrice;
  688. oldData.marketPrice = glj.basePrice;
  689. oldData.repositoryId = glj.repositoryId;
  690. oldData.materialType = glj.materialType;
  691. oldData. materialCoe = glj.materialCoe;
  692. if (glj.hasOwnProperty("compilationId")) {
  693. oldData.from = "cpt";
  694. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  695. oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  696. }
  697. } else {
  698. oldData.from = "std";
  699. }
  700. $.bootstrapLoading.start();
  701. CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
  702. $.bootstrapLoading.end();
  703. });
  704. };
  705. ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
  706. let allGLJ = gljOprObj.AllRecode,tasks = [],updateMap={};
  707. let oldIndex = gljOprObj.getIndex(oldData, gljKeyArray);
  708. let glj = _.find(allGLJ, function (item) {
  709. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  710. return i_key == selectCode;
  711. });
  712. if (selectCode == oldIndex) {
  713. return callback(null);
  714. }
  715. let query = {
  716. projectID: oldData.projectID,
  717. code: oldData.code,
  718. name: oldData.name,
  719. unit: oldData.unit,
  720. type: oldData.type
  721. }
  722. if (oldData.specs && oldData.specs != '') {
  723. query.specs = oldData.specs;
  724. }
  725. let doc = {
  726. GLJID: glj.ID,
  727. createType: 'replace',
  728. rationItemQuantity: 0,
  729. name: glj.name,
  730. code: glj.code,
  731. original_code: glj.code,
  732. unit: glj.unit,
  733. specs: glj.specs,
  734. type: glj.gljType,
  735. basePrice: glj.basePrice,
  736. marketPrice:glj.basePrice,
  737. repositoryId: glj.repositoryId,
  738. materialType: glj.materialType, //三材类别
  739. materialCoe: glj.materialCoe,
  740. projectID: oldData.projectID
  741. };
  742. if (glj.hasOwnProperty("compilationId")) {
  743. doc.from = "cpt";
  744. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  745. doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  746. }
  747. } else {
  748. doc.from = "std";
  749. }
  750. for(let d of this.datas){//查询出所有需替换的工料机
  751. let tem_index = gljOprObj.getIndex(d, gljKeyArray);
  752. if(tem_index == oldIndex){
  753. let tem_doc = _.cloneDeep(doc);
  754. if(d.createType == 'replace'){
  755. tem_doc.rcode = d.rcode;
  756. }else if(d.createType == 'add'){//对于添加的类型,替换后还是添加类型
  757. tem_doc.createType = 'add';
  758. }else {
  759. tem_doc.rcode = d.code
  760. }
  761. let task = {
  762. updateOne:{
  763. filter : {ID:d.ID},
  764. update : tem_doc
  765. }
  766. };
  767. tasks.push(task);
  768. updateMap[d.ID] = tem_doc;
  769. }
  770. }
  771. $.bootstrapLoading.start();
  772. CommonAjax.post("/rationGlj/mReplaceGLJ", {query: query, doc: doc,tasks:tasks}, function (result) {
  773. callback(result,updateMap);
  774. }, function () {
  775. $.bootstrapLoading.end();
  776. });
  777. };
  778. ration_glj.prototype.getMainAndEquGLJ = function (rationID) {
  779. let gljList = _.filter(this.datas, function (n) {
  780. return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
  781. });
  782. gljList = sortRationGLJ(gljList);
  783. return gljOprObj.combineWithProjectGlj(gljList);
  784. };
  785. ration_glj.prototype.transferToNodeData = function (data) {
  786. data.contain=scMathUtil.roundForObj(data.quantity,getDecimal('glj.quantity'));
  787. data.subType = data.type;
  788. };
  789. ration_glj.prototype.combineRationAndGLJ = function (ration) {
  790. if (ration) {
  791. let projectGLJData = projectObj.project.projectGLJ.datas;
  792. let projectGljs = projectGLJData.gljList;
  793. let mixRatioMap = projectGLJData.mixRatioMap;
  794. let glj = _.find(projectGljs, {'id': ration.projectGLJID});
  795. if (glj) {
  796. if(projectObj.project.projectGLJ.isEstimateType(glj.type)){
  797. ration.isEstimate = glj.is_evaluate;
  798. }
  799. ration = gljOprObj.setGLJPrice(ration,glj);
  800. ration.isAdd = glj.unit_price.is_add;
  801. let connect_index = gljOprObj.getIndex(glj, gljKeyArray);
  802. if (mixRatioMap.hasOwnProperty(connect_index)) {
  803. let mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  804. ration.subList = mixRatios;
  805. }
  806. }
  807. }
  808. return ration;
  809. };
  810. ration_glj.prototype.updateFromMainSpread = function (value, node, fieldName) {
  811. if (node.data[fieldName] !== value) {
  812. if (fieldName == "marketUnitFee") {
  813. let decimal = getDecimal("glj.unitPrice");
  814. let newval = number_util.checkNumberValue(value, decimal);
  815. if (newval) {
  816. fieldName = "marketPrice";
  817. projectObj.project.projectGLJ.updatePriceFromRG(node.data, fieldName, newval);
  818. return;
  819. }
  820. } else {
  821. if(fieldName == "contain"){
  822. if(value==null){
  823. value="";
  824. }else {
  825. let decimal = getDecimal("glj.quantity");
  826. value = number_util.checkNumberValue(value, decimal);
  827. fieldName="customQuantity";//填入自定义消耗
  828. }
  829. }
  830. if (value !== undefined && value !== null) {
  831. if (fieldName == "subType") {
  832. node.data.subType = value;
  833. fieldName = "type";//转换成更新工料机类型
  834. }
  835. this.updateRationGLJByEdit(node.data, fieldName, value, node);
  836. return;
  837. }
  838. }
  839. }
  840. // node.data.subType = value;
  841. projectObj.mainController.refreshTreeNode([node]);
  842. };
  843. ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
  844. if (this.needShowToTree(data)) {
  845. this.transferToNodeData(data);
  846. gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
  847. }
  848. };
  849. ration_glj.prototype.needShowToTree = function (data) {
  850. if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  851. return true
  852. }
  853. return false
  854. };
  855. ration_glj.prototype.findGLJNodeByID = function (ID) {
  856. return projectObj.project.mainTree.findNode(ID);
  857. };
  858. ration_glj.prototype.findRationNodeByID = function (ID) {
  859. return projectObj.project.mainTree.findNode(ID);
  860. };
  861. ration_glj.prototype.reCalcWhenGLJChange = function (ration_glj) {//当改变定额工料机时,重新计算定额以及其父节点
  862. let node = this.findRationNodeByID(ration_glj.rationID);
  863. if (node) {
  864. node.changed = true;
  865. project.calcProgram.calcAndSave(node);
  866. }
  867. };
  868. return new ration_glj(project);
  869. }
  870. };