ration_glj.js 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  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 (rationID) {
  41. let result = this.datas.filter(function (data) {
  42. return data.rationID === rationID;
  43. })
  44. result = gljOprObj.combineWithProjectGlj(result);
  45. return result;
  46. };
  47. ration_glj.prototype.getGatherGljArrByRations = function (rations, billQuantity) {
  48. let result = [];
  49. let clone = function (obj) {
  50. if (obj === null) return null;
  51. var o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {};
  52. for (var i in obj) {
  53. o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? clone(obj[i]) : obj[i]);
  54. }
  55. return o;
  56. }
  57. let findGlj = function (sourceGlj, gljArr) {
  58. for (let glj of gljArr) {
  59. if (glj.projectGLJID === sourceGlj.projectGLJID) {
  60. return glj;
  61. }
  62. }
  63. return null;
  64. }
  65. for (let ration of rations) {
  66. if (ration.type == rationType.volumePrice || ration.type == rationType.gljRation){
  67. result.push(ration);
  68. }
  69. else{
  70. let rationGljs = this.getGljArrByRation(ration.ID);
  71. for (let glj of rationGljs) {
  72. let sameGlj = findGlj(glj, result);
  73. if (!sameGlj) {
  74. sameGlj = clone(glj);
  75. sameGlj.quantity = (sameGlj.quantity * ration.quantity).toDecimal(4);
  76. result.push(sameGlj);
  77. } else {
  78. sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4);
  79. }
  80. }
  81. }
  82. }
  83. result = gljOprObj.combineWithProjectGlj(result);
  84. // 上面取的是清单下所有工料机的总量,我要算清单单价,所以要取单位清单的工料机数量,所以下面要除以清单数量。
  85. let oneBill = JSON.parse(JSON.stringify(result));
  86. for (let glj of oneBill){
  87. if (glj.type == rationType.volumePrice){ // 量价、工料机形式的定额要进行数据变换才能参与基数计算。
  88. glj.type = glj.subType;
  89. glj.basePrice = glj.marketUnitFee;
  90. glj.marketPrice = glj.marketUnitFee;
  91. glj.adjustPrice = glj.marketUnitFee;
  92. }
  93. else if (glj.type == rationType.gljRation){
  94. glj.type = glj.subType;
  95. };
  96. glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.glj.quantity);
  97. };
  98. return oneBill;
  99. }
  100. // 提交数据后返回数据处理
  101. ration_glj.prototype.doAfterUpdate = function (err, data) {
  102. var me = this;
  103. if (!err) {
  104. if (data.updateTpye == 'ut_update') {
  105. me.refreshAfterUpdate(data);
  106. } else if (data.updateTpye == 'ut_delete') {
  107. me.refreshAfterDelete(data);
  108. } else {
  109. me.refreshAfterSave(data);
  110. }
  111. }
  112. projectObj.project.projectGLJ.loadData();
  113. };
  114. ration_glj.prototype.getDataByID = function (ID) {
  115. return _.find(this.datas,{'ID':ID});
  116. };
  117. ration_glj.prototype.refreshAfterSave = function (data) {
  118. let me = projectObj.project.ration_glj;
  119. let neRecodes = [];
  120. if (data) {
  121. // neRecodes=data.newRecords;//原来是显示和缓存分开的,后来发现会导致数据不一致的问题所以改成统一的了,这里也只是会作为显示。
  122. neRecodes = data.showDatas;
  123. gljOprObj.sheetData = neRecodes;
  124. me.addDatasToList(neRecodes);
  125. }
  126. project.projectGLJ.loadData(function () {
  127. gljOprObj.showRationGLJSheetData(true);
  128. //add to mainTree;
  129. me.addToMainTree(neRecodes);
  130. let rationID = neRecodes[0].rationID;
  131. let node = project.mainTree.nodes['id_' + rationID];
  132. if(isDef(node)){
  133. project.calcProgram.calcAndSave(node);
  134. }
  135. if (activeSubSheetIs(subSheetIndex.ssiCalcProgram)) {
  136. calcProgramObj.showData(node, false);
  137. }
  138. });
  139. };
  140. ration_glj.prototype.getGljByRationID = function(rationID){
  141. return _.filter(this.datas, {'rationID': rationID});
  142. };
  143. ration_glj.prototype.addDatasToList = function (datas) {
  144. let me = projectObj.project.ration_glj;
  145. if(datas&&datas.length>0){
  146. if (me.datas && Array.isArray(me.datas)) {
  147. me.datas = me.datas.concat(datas);
  148. } else {
  149. me.datas = datas;
  150. }
  151. }
  152. };
  153. ration_glj.prototype.addToMainTree = function (datas) {
  154. datas = sortRationGLJ(datas);
  155. for (let data of datas) {
  156. if (this.needShowToTree(data)) {
  157. gljOprObj.setGLJPrice(data);
  158. this.transferToNodeData(data);
  159. let parentNode = _.find(projectObj.project.mainTree.items, function (n) {//找父节点
  160. return n.sourceType == ModuleNames.ration && n.data.ID == data.rationID;
  161. });
  162. if (parentNode) {
  163. let nextNodeID = null;
  164. if (parentNode.children.length > 0) {
  165. for (let br of parentNode.children) {
  166. if (compareRationGLJ(data, br.data)) {//如果有兄弟节点则找到添加位置。
  167. nextNodeID = br.getID();
  168. }
  169. }
  170. }
  171. nextNodeID = nextNodeID ? nextNodeID : parentNode.tree.rootID();
  172. let newNode = projectObj.project.mainTree.insert(parentNode.getID(), nextNodeID,data.ID);
  173. newNode.source = data;
  174. newNode.sourceType = this.getSourceType();
  175. newNode.data = data;
  176. ProjectController.syncDisplayNewRationGljNode(projectObj.mainController, newNode);
  177. }
  178. }
  179. }
  180. };
  181. ration_glj.prototype.refreshAfterUpdate = function (data) {
  182. var me = this;
  183. var rationID=null;
  184. if (data.quantityRefresh) {
  185. data.glj_result.forEach(function (item) {
  186. rationID = me.refreshEachItme(item.doc, item.query);
  187. })
  188. } else {
  189. rationID = me.refreshEachItme(data.doc, data.query);
  190. }
  191. gljOprObj.showRationGLJSheetData(true);
  192. this.reCalcWhenGLJChange({rationID:rationID});
  193. };
  194. ration_glj.prototype.refreshEachItme = function (doc, query) {
  195. var glj_list = projectObj.project.ration_glj.datas;
  196. var glj_index = _.findIndex(glj_list, (glj) => {
  197. return glj.ID == query.ID;
  198. })
  199. /*var sheet_index= _.findIndex(gljOprObj.sheetData,(sd)=>{
  200. return sd.ID==query.ID;
  201. })*/
  202. _.forEach(doc, function (n, key) {
  203. glj_list[glj_index][key] = n;
  204. });
  205. return glj_list[glj_index].rationID;
  206. };
  207. ration_glj.prototype.refreshAfterDelete = function (data) {
  208. var me = projectObj.project.ration_glj;
  209. var glj_list = me.datas;
  210. var oldData = _.remove(glj_list, data.query);
  211. _.remove(gljOprObj.sheetData, data.query);
  212. gljOprObj.showRationGLJSheetData();
  213. projectObj.project.projectGLJ.loadData();
  214. var rationNode = null;
  215. var next = null;
  216. var selected = projectObj.project.mainTree.selected;
  217. if (selected.sourceType == ModuleNames.ration) { //如果选中的是定额,说明是右键删除工料机操作,如果选中的是定额工料机,则说明是在造价书主界面中点击了删除按钮
  218. rationNode = selected;
  219. } else if (selected.sourceType == ModuleNames.ration_glj) {
  220. rationNode = selected.parent;
  221. next = true;
  222. }
  223. rationNode.data.adjustState = data.adjustState;
  224. projectObj.mainController.refreshTreeNode([rationNode]);
  225. for (let o of oldData) {
  226. if (this.needShowToTree(o)) {
  227. let node = me.findGLJNodeByID(o.ID); //找到对应的树节点
  228. projectObj.mainController.deleteNode(node, next);
  229. }
  230. }
  231. };
  232. // CSL,2017.05.09
  233. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  234. this.project.beginUpdate('modifyQuantity');
  235. data.quantity = newQuantity;
  236. data.customQuantity = newQuantity;
  237. data.updateType = 'ut_update';
  238. this.project.push(this.getSourceType, data);
  239. this.project.endUpdate();
  240. };
  241. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  242. this.project.beginUpdate('modifyPrice');
  243. data.price = newPrice;
  244. data.updateType = 'ut_update';
  245. this.project.push(this.getSourceType, data);
  246. this.project.endUpdate();
  247. };
  248. ration_glj.prototype.deleteGLJ = function (data) {
  249. this.project.beginUpdate('deleteGLJ');
  250. data.customQuantity = 0;
  251. data.quantity = 0;
  252. data.rationItemQuantity = 0;
  253. data.updateType = 'ut_update';
  254. this.project.push(this.getSourceType, data);
  255. this.project.endUpdate();
  256. };
  257. ration_glj.prototype.addRationGLJ = function (newRation, data) {
  258. var souceTypeList = [];
  259. var criteriaDataList = [];
  260. if (data.hasOwnProperty('rationGljList') && data.rationGljList.length > 0) {
  261. let criteria = {};
  262. criteria.ration_glj_list = [];
  263. for (let i = 0; i < data.rationGljList.length; i++) {
  264. let temdata = data.rationGljList[i];
  265. let newGLJ = {};
  266. newGLJ.projectID = parseInt(newRation.projectID);
  267. newGLJ.GLJID = temdata.gljId;
  268. newGLJ.rationID = newRation.ID;
  269. newGLJ.billsItemID = newRation.billsItemID,
  270. newGLJ.rationItemQuantity = temdata.consumeAmt;
  271. newGLJ.quantity = temdata.consumeAmt;
  272. newGLJ.glj_repository_id = data.rationRepId;
  273. criteria.ration_glj_list.push(newGLJ);
  274. }
  275. criteria.updateType = 'ut_create';
  276. souceTypeList.push(this.getSourceType());
  277. criteriaDataList.push(criteria);
  278. }
  279. var ration_coe = projectObj.project.ration_coe;
  280. var rationCoeData = ration_coe.getRationCoedata(newRation, data);
  281. souceTypeList.push(ration_coe.getSourceType());
  282. criteriaDataList.push(rationCoeData);
  283. project.pushNow('addRationGLJAndRationCoe', souceTypeList, criteriaDataList);
  284. };
  285. ration_glj.prototype.getDeleteDataByRation = function (rationData) {
  286. var updateData = [];
  287. updateData.push({
  288. 'deleteType': 'RATION',
  289. 'updateType': 'ut_delete',
  290. 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}
  291. });
  292. return updateData;
  293. };
  294. ration_glj.prototype.getDeleteDataByBills = function (datas) {
  295. var updateData = [];
  296. datas.forEach(function (deleteData) {
  297. if (deleteData.type == 'delete') {
  298. var billData = deleteData.data;
  299. updateData.push({
  300. 'deleteType': 'BILL',
  301. 'updateType': 'ut_delete',
  302. 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}
  303. });
  304. }
  305. })
  306. return updateData;
  307. };
  308. ration_glj.prototype.deleteByRation = function (ration) {
  309. var glj_list = projectObj.project.ration_glj.datas;
  310. _.remove(glj_list,{'rationID':ration.ID});
  311. };
  312. ration_glj.prototype.deleteByBills = function (deleteData) {
  313. var rationList = projectObj.project.Ration.datas;
  314. var deleteRationList = [];
  315. for (var i = 0; i < deleteData.length; i++) {
  316. if (deleteData[i].type == 'delete') {
  317. var billID = deleteData[i].data.ID;
  318. var raList = _.filter(rationList, (ration) => {
  319. return ration.billsItemID == billID;
  320. });
  321. deleteRationList = deleteRationList.concat(raList);
  322. }
  323. }
  324. for (var i = 0; i < deleteRationList.length; i++) {
  325. this.deleteByRation(deleteRationList[i]);
  326. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  327. projectObj.project.quantity_detail.deleteByRation(deleteRationList[i]);
  328. projectObj.project.ration_installation.deleteByRation(deleteRationList[i]);
  329. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  330. }
  331. }
  332. ration_glj.prototype.updataOrdelete = function (row) {
  333. var updateData = null;
  334. if (row.rationItemQuantity == 0) {
  335. updateData = this.getUpdateData('ut_delete', {
  336. 'ID': row.ID,
  337. 'projectID': row.projectID
  338. }, {rationID: row.rationID});
  339. project.pushNow('updateRationGLJ', [this.getSourceType()], updateData)
  340. } else {
  341. this.updateRationGLJByEdit(row, 'customQuantity', 0);
  342. //('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  343. }
  344. };
  345. ration_glj.prototype.getUpdateData = function (type, query, doc, callfunction) {
  346. var updateData = [];
  347. var newobj = {
  348. 'updateType': type,
  349. 'query': query,
  350. }
  351. if (doc) {
  352. newobj['doc'] = doc;
  353. }
  354. if (callfunction) {
  355. newobj['updateFunction'] = callfunction;
  356. }
  357. updateData.push(newobj);
  358. return updateData;
  359. };
  360. ration_glj.prototype.updateRationGLJByEdit = function (recode, updateField, newval, node) {
  361. var me = this;
  362. $.bootstrapLoading.start();
  363. var callback = function (data) {
  364. let initShow = false;//是否需要表格初始化显示
  365. if (updateField == 'customQuantity') {
  366. me.refreshAfterQuantityUpdate(data, node);
  367. } else {
  368. var doc = data.doc;
  369. for (var key in doc) {
  370. recode[key] = doc[key];
  371. }
  372. if (data.hasOwnProperty('adjustState')) {//更新定额调整状态
  373. me.updateRationAdjustState(data.adjustState, recode.rationID, node);
  374. }
  375. if (recode.subList && recode.subList.length > 0) {
  376. initShow = true;
  377. }
  378. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  379. if (updateField == "type" && !(newval == gljType.MAIN_MATERIAL || newval == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  380. projectObj.mainController.deleteNode(node, true);
  381. }
  382. }
  383. }
  384. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  385. if (initShow == false) {//不需要初始化,只需耍新当前显示就可以了
  386. gljOprObj.showRationGLJSheetData();
  387. }
  388. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  389. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  390. if (initShow == true) {
  391. gljOprObj.refreshView();
  392. }
  393. $.bootstrapLoading.end();
  394. });
  395. }
  396. var query = {
  397. 'ID': recode.ID,
  398. 'projectID': recode.projectID,
  399. 'rationID': recode.rationID
  400. };
  401. var priceInfo = {
  402. base_price: recode.basePrice,
  403. market_price: recode.marketPrice
  404. }
  405. var doc = {};
  406. doc[updateField] = newval;
  407. if (updateField == "type") {
  408. doc.shortName = projectObj.project.projectGLJ.getShortNameByID(newval);
  409. }
  410. CommonAjax.post("/rationGlj/updateRationGLJByEdit", {
  411. query: query,
  412. doc: doc,
  413. priceInfo: priceInfo
  414. }, callback, function (err) {
  415. $.bootstrapLoading.end();
  416. });
  417. }
  418. ration_glj.prototype.refreshAfterQuantityUpdate = function (data, node) {
  419. var me = this;
  420. data.glj_result.forEach(function (item) {
  421. me.refreshEachItme(item.doc, item.query);
  422. })
  423. me.updateRationAdjustState(data.adjustState, data.rationID, node);
  424. };
  425. ration_glj.prototype.updateRationAdjustState = function (adjustState, rationID, rnode) {
  426. var nodes = [];
  427. var node = _.find(projectObj.project.mainTree.items, function (n) {
  428. return n.sourceType == ModuleNames.ration && n.data.ID == rationID;
  429. })
  430. if (node) {
  431. node.data.adjustState = adjustState;
  432. nodes.push(node);
  433. }
  434. if (rnode) {
  435. nodes.push(rnode);
  436. }
  437. projectObj.mainController.refreshTreeNode(nodes);
  438. };
  439. ration_glj.prototype.getGLJData = function (cb) {
  440. CommonAjax.get('/rationGlj/getGLJData', function (data) {
  441. cb(data);
  442. })
  443. };
  444. ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
  445. let gljList = [];
  446. let allGLJ = gljOprObj.AllRecode;
  447. let billsItemID = null;
  448. let serialNo = 0;
  449. let selectedSerialNo = null;
  450. let nextNodeID = null;
  451. let parentNodeID = null;
  452. let children = [];
  453. if (selected.sourceType === project.Bills.getSourceType()) {
  454. billsItemID = selected.data.ID;
  455. parentNodeID = selected.getID();
  456. nextNodeID = selected.tree.rootID();
  457. } else {
  458. billsItemID = selected.data.billsItemID;
  459. serialNo = selected.data.serialNo;
  460. selectedSerialNo = selected.data.serialNo;
  461. nextNodeID = selected.getNextSiblingID();
  462. parentNodeID = selected.getParentID();
  463. }
  464. children = project.Ration.getBillsSortRation(billsItemID);
  465. serialNo == 0 ? serialNo = children.length : "";
  466. for (let con_key of GLJSelection) {
  467. var glj = _.find(allGLJ, function (item) {
  468. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  469. return i_key == con_key;
  470. });
  471. if (glj) {
  472. serialNo += 1;
  473. let new_glj = {
  474. ID: project.Ration.getNewRationID(),
  475. projectID: parseInt(project.ID()),
  476. billsItemID: billsItemID,
  477. type: rationType.gljRation,
  478. code: glj.code,
  479. name: glj.name,
  480. quantity: 0,
  481. unit: glj.unit,
  482. specs: glj.specs,
  483. subType: glj.gljType,
  484. basePrice: glj.basePrice,
  485. original_code: glj.code,
  486. shortName: glj.shortName,
  487. serialNo: serialNo,
  488. GLJID: glj.ID,
  489. adjCoe: glj.adjCoe,
  490. repositoryId: glj.repositoryId
  491. }
  492. if (glj.hasOwnProperty("compilationId")) {
  493. new_glj.from = "cpt";
  494. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  495. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  496. }
  497. }
  498. gljList.push(new_glj);
  499. }
  500. }
  501. if (gljList.length == 0) {
  502. return;
  503. }
  504. let postData = {
  505. gljList: gljList,
  506. projectID: parseInt(project.ID()),
  507. billsItemID: billsItemID,
  508. rationCount: project.Ration.maxRationID()
  509. }
  510. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  511. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  512. // 更新兄弟节点的序列号
  513. if (selectedSerialNo != null) {
  514. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  515. if (selectIndex + 1 < children.length) {
  516. for (let i = selectIndex + 1; i < children.length; i++) {
  517. children[i].serialNo += gljList.length;
  518. }
  519. }
  520. }
  521. /* let newNode=null;
  522. for (let r_glj of data) {
  523. r_glj.marketUnitFee = r_glj.marketPrice;
  524. r_glj.quantity = r_glj.quantity + "";
  525. project.Ration.datas.push(r_glj);
  526. newNode = project.mainTree.insert(parentNodeID, nextNodeID, r_glj.ID);
  527. newNode.source = r_glj;
  528. newNode.sourceType = project.Ration.getSourceType();
  529. newNode.data = r_glj;
  530. ProjectController.syncDisplayNewNode(projectObj.mainController, newNode);
  531. }*/
  532. //this.nodes[this.prefix + parentID];
  533. callback(parentNodeID,nextNodeID,data);
  534. }, function () {
  535. $.bootstrapLoading.end();
  536. });
  537. };
  538. ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
  539. var gljList = [];
  540. var allGLJ = gljOprObj.AllRecode;
  541. GLJSelection.sort();
  542. _.forEach(GLJSelection, function (g) {
  543. var glj = _.find(allGLJ, function (item) {
  544. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  545. return i_key == g;
  546. });
  547. var ration_glj = {
  548. projectID: ration.projectID,
  549. GLJID: glj.ID,
  550. rationID: ration.ID,
  551. billsItemID: ration.billsItemID,
  552. rationItemQuantity: 0,
  553. quantity: 0,
  554. name: glj.name,
  555. code: glj.code,
  556. original_code: glj.code,
  557. unit: glj.unit,
  558. specs: glj.specs,
  559. basePrice: glj.basePrice,
  560. shortName: glj.shortName,
  561. type: glj.gljType,
  562. adjCoe: glj.adjCoe,
  563. createType: 'add',
  564. repositoryId: glj.repositoryId
  565. }
  566. if (glj.hasOwnProperty("compilationId")) {
  567. ration_glj.from = "cpt";
  568. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  569. ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  570. }
  571. }
  572. gljList.push(ration_glj);
  573. });
  574. $.bootstrapLoading.start();
  575. CommonAjax.post("/rationGlj/addGLJ", gljList, callback, function () {
  576. $.bootstrapLoading.end();
  577. });
  578. };
  579. ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
  580. var allGLJ = gljOprObj.AllRecode;
  581. var glj = _.find(allGLJ, function (item) {
  582. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  583. return i_key == selectCode;
  584. });
  585. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  586. return callback(null);
  587. }
  588. if (oldData.createType != 'replace') {
  589. oldData.rcode = oldData.code;
  590. oldData.createType = 'replace';
  591. }
  592. oldData.GLJID = glj.ID;
  593. oldData.name = glj.name;
  594. oldData.code = glj.code;
  595. oldData.original_code = glj.code;
  596. oldData.unit = glj.unit;
  597. oldData.specs = glj.specs;
  598. oldData.basePrice = glj.basePrice;
  599. oldData.repositoryId = glj.repositoryId;
  600. if (glj.hasOwnProperty("compilationId")) {
  601. oldData.from = "cpt";
  602. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  603. oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  604. }
  605. } else {
  606. oldData.from = "std";
  607. }
  608. $.bootstrapLoading.start();
  609. CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
  610. $.bootstrapLoading.end();
  611. });
  612. };
  613. ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
  614. var allGLJ = gljOprObj.AllRecode;
  615. var glj = _.find(allGLJ, function (item) {
  616. var i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  617. return i_key == selectCode;
  618. });
  619. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  620. return callback(null);
  621. }
  622. var query = {
  623. projectID: oldData.projectID,
  624. code: oldData.code,
  625. name: oldData.name,
  626. unit: oldData.unit,
  627. type: oldData.type
  628. }
  629. if (oldData.specs && oldData.specs != '') {
  630. query.specs = oldData.specs;
  631. }
  632. var doc = {
  633. GLJID: glj.ID,
  634. createType: 'replace',
  635. rationItemQuantity: 0,
  636. name: glj.name,
  637. code: glj.code,
  638. original_code: glj.code,
  639. unit: glj.unit,
  640. specs: glj.specs,
  641. type: glj.gljType,
  642. basePrice: glj.basePrice,
  643. repositoryId: glj.repositoryId,
  644. projectID: oldData.projectID
  645. }
  646. if (oldData.createType == 'replace') {
  647. doc.rcode = oldData.rcode;
  648. } else {
  649. doc.rcode = oldData.code;
  650. }
  651. if (glj.hasOwnProperty("compilationId")) {
  652. doc.from = "cpt";
  653. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  654. doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  655. }
  656. } else {
  657. doc.from = "std";
  658. }
  659. $.bootstrapLoading.start();
  660. CommonAjax.post("/rationGlj/mReplaceGLJ", {query: query, doc: doc}, callback, function () {
  661. $.bootstrapLoading.end();
  662. });
  663. };
  664. ration_glj.prototype.getMainAndEquGLJ = function (rationID) {
  665. var gljList = _.filter(this.datas, function (n) {
  666. return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
  667. });
  668. gljList = sortRationGLJ(gljList);
  669. return gljOprObj.combineWithProjectGlj(gljList);
  670. };
  671. ration_glj.prototype.transferToNodeData = function (data) {
  672. data.contain=scMathUtil.roundForObj(data.quantity,getDecimal('glj.quantity'));
  673. data.subType = data.type;
  674. data.marketUnitFee = data.marketPrice;
  675. };
  676. ration_glj.prototype.combineRationAndGLJ = function (ration) {
  677. if (ration) {
  678. var projectGLJData = projectObj.project.projectGLJ.datas;
  679. var projectGljs = projectGLJData.gljList;
  680. var mixRatioMap = projectGLJData.mixRatioMap;
  681. var glj = _.find(projectGljs, {'id': ration.projectGLJID});
  682. if (glj) {
  683. if(projectObj.project.projectGLJ.isEstimateType(glj.type)){
  684. ration.isEstimate = glj.is_evaluate;
  685. }
  686. ration = gljOprObj.setGLJPrice(ration,glj);
  687. ration.basePrice = glj.unit_price.base_price;
  688. ration.marketUnitFee = glj.unit_price.market_price;
  689. ration.isAdd = glj.unit_price.is_add;
  690. var connect_index = gljOprObj.getIndex(glj, gljKeyArray);
  691. if (mixRatioMap.hasOwnProperty(connect_index)) {
  692. var mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  693. ration.subList = mixRatios;
  694. }
  695. }
  696. }
  697. return ration;
  698. };
  699. ration_glj.prototype.updateFromMainSpread = function (value, node, fieldName) {
  700. if (node.data[fieldName] === value) {
  701. return;
  702. }
  703. if (fieldName == "marketUnitFee") {
  704. var decimal = getDecimal("glj.unitPrice");
  705. var newval = number_util.checkNumberValue(value, decimal);
  706. if (newval) {
  707. fieldName = "marketPrice";
  708. projectObj.project.projectGLJ.updatePriceFromRG(node.data, fieldName, newval);
  709. return;
  710. }
  711. } else {
  712. if(fieldName == "contain"){
  713. if(value==null){
  714. value="";
  715. }else {
  716. var decimal = getDecimal("glj.quantity");
  717. value = number_util.checkNumberValue(value, decimal);
  718. fieldName="customQuantity";//填入自定义消耗
  719. }
  720. }
  721. if (value !== undefined && value !== null) {
  722. if (fieldName == "subType") {
  723. node.data.subType = value;
  724. fieldName = "type";//转换成更新工料机类型
  725. }
  726. this.updateRationGLJByEdit(node.data, fieldName, value, node);
  727. return;
  728. }
  729. }
  730. // node.data.subType = value;
  731. projectObj.mainController.refreshTreeNode([node]);
  732. };
  733. ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
  734. if (this.needShowToTree(data)) {
  735. this.transferToNodeData(data);
  736. gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
  737. }
  738. };
  739. ration_glj.prototype.needShowToTree = function (data) {
  740. if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectInfoObj.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  741. return true
  742. }
  743. return false
  744. };
  745. ration_glj.prototype.findGLJNodeByID = function (ID) {
  746. let node = _.find(projectObj.project.mainTree.items, function (n) {//找到对应的树节点
  747. return n.sourceType == ModuleNames.ration_glj && n.data.ID == ID;
  748. });
  749. return node;
  750. };
  751. ration_glj.prototype.findRationNodeByID = function (ID) {
  752. let node = _.find(projectObj.project.mainTree.items, function (n) {//找到对应定额的树节点
  753. return n.sourceType == ModuleNames.ration && n.data.ID == ID;
  754. });
  755. return node;
  756. };
  757. ration_glj.prototype.reCalcWhenGLJChange = function (ration_glj) {//当改变定额工料机时,重新计算定额以及其父节点
  758. let node = this.findRationNodeByID(ration_glj.rationID);
  759. if (node) {
  760. node.changed = true;
  761. project.calcProgram.calcAndSave(node);
  762. }
  763. };
  764. return new ration_glj(project);
  765. }
  766. };