ration_glj.js 34 KB

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