ration_glj.js 34 KB

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