ration_glj.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017
  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.getGLJListByRationID = function (rationID) {
  41. return _.filter(this.datas, {'rationID': rationID})
  42. };
  43. ration_glj.prototype.getGatherGljArrByRations = function (rations, needOneBill, billQuantity) {
  44. let result = [];
  45. let clone = function (obj) {
  46. if (obj === null) return null;
  47. let o = Object.prototype.toString.apply(obj) === "[object Array]" ? [] : {};
  48. for (let i in obj) {
  49. o[i] = (obj[i] instanceof Date) ? new Date(obj[i].getTime()) : (typeof obj[i] === "object" ? clone(obj[i]) : obj[i]);
  50. }
  51. return o;
  52. }
  53. let findGlj = function (sourceGlj, gljArr) {
  54. for (let glj of gljArr) {
  55. if (glj.projectGLJID === sourceGlj.projectGLJID) {
  56. return glj;
  57. }
  58. }
  59. return null;
  60. }
  61. for (let ration of rations) {
  62. if (ration.type == rationType.volumePrice || ration.type == rationType.gljRation){
  63. let glj = JSON.parse(JSON.stringify(ration));
  64. glj.type = glj.subType;
  65. glj.totalQuantity = parseFloatPlus(ration.quantity);
  66. glj.markertPrice = glj.marketUnitFee;
  67. glj.basePrice = glj.marketUnitFee;
  68. glj.adjustPrice = glj.marketUnitFee;
  69. result.push(glj);
  70. }
  71. else{
  72. let rationGljs = projectObj.project.calcProgram.getGljArrByRation(ration);
  73. for (let glj of rationGljs) {
  74. let sameGlj = findGlj(glj, result);
  75. if (!sameGlj) {
  76. sameGlj = clone(glj);
  77. sameGlj.quantity = (sameGlj.quantity * ration.quantity).toDecimal(4);
  78. result.push(sameGlj);
  79. } else {
  80. sameGlj.quantity = sameGlj.quantity + (glj.quantity * ration.quantity).toDecimal(4);
  81. sameGlj.totalQuantity = (parseFloat(sameGlj.totalQuantity) + parseFloat(glj.totalQuantity)).toDecimal(4);
  82. }
  83. }
  84. }
  85. }
  86. result = gljOprObj.combineWithProjectGlj(result);
  87. if (!needOneBill) return result;
  88. // 上面取的是清单下所有工料机的总量,我要算清单单价,所以要取单位清单的工料机数量,所以下面要除以清单数量。
  89. let oneBill = JSON.parse(JSON.stringify(result));
  90. for (let glj of oneBill){
  91. if (glj.type == rationType.volumePrice){ // 量价、工料机形式的定额要进行数据变换才能参与基数计算。
  92. glj.type = glj.subType;
  93. glj.basePrice = glj.marketUnitFee;
  94. glj.marketPrice = glj.marketUnitFee;
  95. glj.adjustPrice = glj.marketUnitFee;
  96. }
  97. else if (glj.type == rationType.gljRation){
  98. glj.type = glj.subType;
  99. };
  100. // glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.glj.quantity);
  101. glj.quantity = (glj.quantity / billQuantity).toDecimal(decimalObj.process); // 广联达这里没有取舍
  102. };
  103. return oneBill;
  104. }
  105. // 提交数据后返回数据处理
  106. ration_glj.prototype.doAfterUpdate = function (err, data) {
  107. let me = this;
  108. if (!err) {
  109. if (data.updateTpye == 'ut_update') {
  110. me.refreshAfterUpdate(data);
  111. } else if (data.updateTpye == 'ut_delete') {
  112. me.refreshAfterDelete(data);
  113. } else {
  114. me.refreshAfterSave(data);
  115. }
  116. }
  117. projectObj.project.projectGLJ.loadData();
  118. };
  119. ration_glj.prototype.getDataByID = function (ID) {
  120. return _.find(this.datas,{'ID':ID});
  121. };
  122. ration_glj.prototype.refreshAfterSave = function (data) {
  123. let me = projectObj.project.ration_glj;
  124. let neRecodes = [];
  125. if (data) {
  126. // neRecodes=data.newRecords;//原来是显示和缓存分开的,后来发现会导致数据不一致的问题所以改成统一的了,这里也只是会作为显示。
  127. neRecodes = data.showDatas;
  128. gljOprObj.sheetData = neRecodes;
  129. me.addDatasToList(neRecodes);
  130. }
  131. project.projectGLJ.loadData(function () {
  132. gljOprObj.showRationGLJSheetData(true);
  133. //add to mainTree;
  134. me.addToMainTree(neRecodes);
  135. let rationID = neRecodes[0].rationID;
  136. let node = project.mainTree.nodes['id_' + rationID];
  137. if(isDef(node)){
  138. project.calcProgram.calcAndSave(node);
  139. }
  140. if (activeSubSheetIsCalcProgram())
  141. calcProgramObj.refreshCalcProgram(node, 1);
  142. });
  143. };
  144. ration_glj.prototype.getGljByRationID = function(rationID){
  145. return _.filter(this.datas, {'rationID': rationID});
  146. };
  147. ration_glj.prototype.addDatasToList = function (datas) {
  148. let me = projectObj.project.ration_glj;
  149. if(datas&&datas.length>0){
  150. if (me.datas && Array.isArray(me.datas)) {
  151. me.datas = me.datas.concat(datas);
  152. } else {
  153. me.datas = datas;
  154. }
  155. }
  156. };
  157. ration_glj.prototype.updateGLJNodeAfterReplace = function(data){
  158. if (this.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  159. var node = this.findGLJNodeByID(data.ID);
  160. if (node) {
  161. this.transferToNodeData(data);
  162. node.source = data;
  163. node.data = data;
  164. }
  165. return node;
  166. }
  167. };
  168. ration_glj.prototype.addToMainTree = function (datas) {
  169. datas = gljUtil.sortRationGLJ(datas);
  170. for (let data of datas) {
  171. if (this.needShowToTree(data)) {
  172. gljOprObj.setGLJPrice(data);
  173. this.transferToNodeData(data);
  174. let parentNode = projectObj.project.mainTree.findNode(data.rationID);
  175. if (parentNode) {
  176. let nextNodeID = null;
  177. if (parentNode.children.length > 0) {
  178. for (let br of parentNode.children) {
  179. if (compareRationGLJ(data, br.data)) {//如果有兄弟节点则找到添加位置。
  180. nextNodeID = br.getID();
  181. }
  182. }
  183. }
  184. nextNodeID = nextNodeID ? nextNodeID : parentNode.tree.rootID();
  185. let newNode = projectObj.project.mainTree.insert(parentNode.getID(), nextNodeID,data.ID);
  186. newNode.source = data;
  187. newNode.sourceType = this.getSourceType();
  188. newNode.data = data;
  189. ProjectController.syncDisplayNewRationGljNode(projectObj.mainController, newNode);
  190. }
  191. }
  192. }
  193. };
  194. ration_glj.prototype.removeNodeByRation = function(ration,controller){//删除主材或设备节点
  195. let glj_list = _.filter(projectObj.project.ration_glj.datas,{'rationID':ration.ID});
  196. let deleteNodes = [];
  197. for(let rg of glj_list){
  198. if(this.needShowToTree(rg)){
  199. let r_node = projectObj.project.mainTree.getNodeByID(rg.ID);
  200. deleteNodes.push(r_node);
  201. }
  202. }
  203. if(deleteNodes.length > 0){
  204. let rowIndex = deleteNodes[0].serialNo();
  205. if(controller.tree.m_delete(deleteNodes)){
  206. TREE_SHEET_HELPER.massOperationSheet(controller.sheet, function () {
  207. let rowCount = deleteNodes.length;
  208. controller.sheet.deleteRows(rowIndex, rowCount);
  209. });
  210. }
  211. }
  212. };
  213. ration_glj.prototype.refreshAfterUpdate = function (data) {
  214. let me = this;
  215. let rationID= me.updateCacheAfterAdjust(data);
  216. gljOprObj.showRationGLJSheetData(true);
  217. this.reCalcWhenGLJChange({rationID:rationID});
  218. };
  219. ration_glj.prototype.updateCacheAfterAdjust=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. return rationID;
  230. };
  231. ration_glj.prototype.refreshEachItme = function (doc, query) {
  232. let glj = this.refreshByID(query.ID,doc);
  233. return glj.rationID;
  234. };
  235. ration_glj.prototype.refreshByID=function (ID,doc) {
  236. let glj_list = projectObj.project.ration_glj.datas;
  237. let glj_index = _.findIndex(glj_list,{"ID":ID});
  238. _.forEach(doc, function (n, key) {
  239. glj_list[glj_index][key] = n;
  240. });
  241. return glj_list[glj_index]
  242. };
  243. ration_glj.prototype.refreshAfterDelete = function (data) {
  244. let me = projectObj.project.ration_glj;
  245. let glj_list = me.datas;
  246. let oldData = _.remove(glj_list, data.query);
  247. _.remove(gljOprObj.sheetData, data.query);
  248. gljOprObj.showRationGLJSheetData();
  249. projectObj.project.projectGLJ.loadData();
  250. let rationNode = null;
  251. let next = null;
  252. let selected = projectObj.project.mainTree.selected;
  253. if (selected.sourceType == ModuleNames.ration) { //如果选中的是定额,说明是右键删除工料机操作,如果选中的是定额工料机,则说明是在造价书主界面中点击了删除按钮
  254. rationNode = selected;
  255. } else if (selected.sourceType == ModuleNames.ration_glj) {
  256. rationNode = selected.parent;
  257. next = true;
  258. }
  259. rationNode.data.adjustState = data.adjustState;
  260. projectObj.mainController.refreshTreeNode([rationNode]);
  261. for (let o of oldData) {
  262. if (this.needShowToTree(o)) {
  263. let node = me.findGLJNodeByID(o.ID); //找到对应的树节点
  264. projectObj.mainController.deleteNode(node, next);
  265. }
  266. }
  267. project.calcProgram.calcAndSave(rationNode,function () {
  268. installationFeeObj.calcInstallationFee();
  269. OVER_HEIGHT.reCalcOverHeightFee();
  270. });
  271. };
  272. // CSL,2017.05.09
  273. ration_glj.prototype.modifyQuantity = function (data, newQuantity) {
  274. this.project.beginUpdate('modifyQuantity');
  275. data.quantity = newQuantity;
  276. data.customQuantity = newQuantity;
  277. data.updateType = 'ut_update';
  278. this.project.push(this.getSourceType, data);
  279. this.project.endUpdate();
  280. };
  281. ration_glj.prototype.modifyPrice = function (data, newPrice) {
  282. this.project.beginUpdate('modifyPrice');
  283. data.price = newPrice;
  284. data.updateType = 'ut_update';
  285. this.project.push(this.getSourceType, data);
  286. this.project.endUpdate();
  287. };
  288. ration_glj.prototype.deleteGLJ = function (data) {
  289. this.project.beginUpdate('deleteGLJ');
  290. data.customQuantity = 0;
  291. data.quantity = 0;
  292. data.rationItemQuantity = 0;
  293. data.updateType = 'ut_update';
  294. this.project.push(this.getSourceType, data);
  295. this.project.endUpdate();
  296. };
  297. ration_glj.prototype.addRationGLJ = function (newRation, data) {
  298. let souceTypeList = [];
  299. let criteriaDataList = [];
  300. if (data.hasOwnProperty('rationGljList') && data.rationGljList.length > 0) {
  301. let criteria = {};
  302. criteria.ration_glj_list = [];
  303. for (let i = 0; i < data.rationGljList.length; i++) {
  304. let temdata = data.rationGljList[i];
  305. let newGLJ = {};
  306. newGLJ.projectID = parseInt(newRation.projectID);
  307. newGLJ.GLJID = temdata.gljId;
  308. newGLJ.rationID = newRation.ID;
  309. newGLJ.billsItemID = newRation.billsItemID;
  310. newGLJ.rationItemQuantity = temdata.consumeAmt;
  311. newGLJ.quantity = temdata.consumeAmt;
  312. newGLJ.glj_repository_id = data.rationRepId;
  313. criteria.ration_glj_list.push(newGLJ);
  314. }
  315. criteria.updateType = 'ut_create';
  316. souceTypeList.push(this.getSourceType());
  317. criteriaDataList.push(criteria);
  318. }
  319. let ration_coe = projectObj.project.ration_coe;
  320. let rationCoeData = ration_coe.getRationCoedata(newRation, data);
  321. souceTypeList.push(ration_coe.getSourceType());
  322. criteriaDataList.push(rationCoeData);
  323. project.pushNow('addRationGLJAndRationCoe', souceTypeList, criteriaDataList);
  324. };
  325. ration_glj.prototype.getDeleteDataByRation = function (rationData) {
  326. let updateData = [];
  327. updateData.push({
  328. 'deleteType': 'RATION',
  329. 'updateType': 'ut_delete',
  330. 'updateData': {'ID': rationData.ID, 'projectID': rationData.projectID}
  331. });
  332. return updateData;
  333. };
  334. ration_glj.prototype.getDeleteDataByBills = function (datas) {
  335. let updateData = [];
  336. datas.forEach(function (deleteData) {
  337. if (deleteData.type == 'delete') {
  338. let billData = deleteData.data;
  339. updateData.push({
  340. 'deleteType': 'BILL',
  341. 'updateType': 'ut_delete',
  342. 'updateData': {'ID': billData.ID, 'projectID': billData.projectID}
  343. });
  344. }
  345. })
  346. return updateData;
  347. };
  348. ration_glj.prototype.deleteByRation = function (ration) {
  349. let glj_list = projectObj.project.ration_glj.datas;
  350. _.remove(glj_list,{'rationID':ration.ID});
  351. };
  352. ration_glj.prototype.deleteByBills = function (deleteData) {
  353. let rationList = projectObj.project.Ration.datas;
  354. let deleteRationList = [];
  355. for (let i = 0; i < deleteData.length; i++) {
  356. if (deleteData[i].type == 'delete') {
  357. let billID = deleteData[i].data.ID;
  358. let raList = _.filter(rationList, (ration) => {
  359. return ration.billsItemID == billID;
  360. });
  361. deleteRationList = deleteRationList.concat(raList);
  362. }
  363. }
  364. for (let i = 0; i < deleteRationList.length; i++) {
  365. this.deleteByRation(deleteRationList[i]);
  366. projectObj.project.ration_coe.deleteByRation(deleteRationList[i]);
  367. projectObj.project.quantity_detail.deleteByRation(deleteRationList[i]);
  368. projectObj.project.ration_installation.deleteByRation(deleteRationList[i]);
  369. projectObj.project.Ration.datas.splice(projectObj.project.Ration.datas.indexOf(deleteRationList[i]), 1);
  370. }
  371. }
  372. ration_glj.prototype.updataOrdelete = function (row) {
  373. let updateData = null;
  374. if (row.rationItemQuantity == 0) {
  375. updateData = this.getUpdateData('ut_delete', {
  376. 'ID': row.ID,
  377. 'projectID': row.projectID
  378. }, {rationID: row.rationID});
  379. project.pushNow('updateRationGLJ', [this.getSourceType()], updateData)
  380. } else {
  381. this.updateRationGLJByEdit(row, 'customQuantity', 0);
  382. //('ut_update',{'ID': row.ID, 'projectID': row.projectID},{'quantity':0,'customQuantity':0});
  383. }
  384. };
  385. ration_glj.prototype.getUpdateData = function (type, query, doc, callfunction) {
  386. let updateData = [];
  387. let newobj = {
  388. 'updateType': type,
  389. 'query': query,
  390. }
  391. if (doc) {
  392. newobj['doc'] = doc;
  393. }
  394. if (callfunction) {
  395. newobj['updateFunction'] = callfunction;
  396. }
  397. updateData.push(newobj);
  398. return updateData;
  399. };
  400. ration_glj.prototype.updateRationGLJByEdit = function (recode, updateField, newval, node) {
  401. let me = this,doc = {};
  402. doc[updateField] = newval;
  403. me.submitChange(recode,doc,updateField,node);
  404. };
  405. ration_glj.prototype.submitChange = function(recode,updateData,updateField,node){
  406. let me = this;
  407. let query = {
  408. 'ID': recode.ID,
  409. 'projectID': recode.projectID,
  410. 'rationID': recode.rationID
  411. };
  412. let priceInfo = {
  413. base_price: recode.basePrice,
  414. market_price: recode.marketPrice
  415. };
  416. if(updateData['type'] != undefined || updateData['type'] != null){
  417. updateData.shortName = projectObj.project.projectGLJ.getShortNameByID(updateData['type']);
  418. }
  419. let callback = function (data) {
  420. if (updateField == 'customQuantity') {
  421. me.refreshAfterQuantityUpdate(data, node);
  422. } else {
  423. let doc = data.doc;
  424. for (let key in doc) {
  425. recode[key] = doc[key];
  426. }
  427. me.refreshRationAfterEdit(data,recode.rationID, node);//更新名称和定额调整状态
  428. if (node) {//如果不是在造价书页面直接编辑,则不用刷新
  429. if (updateField == "type" && !(updateData['type'] == gljType.MAIN_MATERIAL || updateData['type'] == gljType.EQUIPMENT)) {//如果改变类型后不是主材或设备,则在造价书树中移除
  430. projectObj.mainController.deleteNode(node, true);
  431. }
  432. }
  433. }
  434. projectObj.project.projectGLJ.loadData(function () {//等项目工料机加载完成后再给用户编辑
  435. gljOprObj.refreshView();
  436. me.refreshTreeNodeIfNeeded(recode);//刷新造价书上的树节点(如果需要)
  437. me.reCalcWhenGLJChange(recode);//触发计算定额以及父节点
  438. $.bootstrapLoading.end();
  439. installationFeeObj.calcInstallationFee();
  440. OVER_HEIGHT.reCalcOverHeightFee();
  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 = this.refreshRationNode(data.name,data.adjustState,rationID);
  462. if (node) nodes.push(node);
  463. if (rnode) nodes.push(rnode);
  464. projectObj.mainController.refreshTreeNode(nodes);
  465. };
  466. ration_glj.prototype.refreshRationNode = function(name,adjustState,rationID){
  467. let node = projectObj.project.mainTree.findNode(rationID);
  468. if (!node) return null;
  469. if(gljUtil.isDef(adjustState)){
  470. node.data.adjustState = adjustState;
  471. }
  472. if(gljUtil.isDef(name)){
  473. node.data.name = name;
  474. }
  475. return node
  476. };
  477. ration_glj.prototype.getGLJDataPaging = function (condition, cb) {
  478. gljOprObj.loadingPagination = true;
  479. const property = projectObj.project.projectInfo.property;
  480. const engineerID = property.engineering_id;
  481. CommonAjax.post('/rationGlj/getGLJDataPaging', {engineerID, condition}, function (data) {
  482. gljOprObj.curPageTotal = data.total;
  483. data.complementaryGLJs.forEach(glj => {
  484. glj.isComplementary = true;
  485. });
  486. const gljType = condition.type === gljOprObj.pagingType.stdGLJ
  487. ? 'stdGLJ'
  488. : 'complementaryGLJs';
  489. const newData = data[gljType];
  490. if (condition.init) {
  491. gljOprObj.treeData = data.treeData;
  492. gljOprObj.distTypeTree = gljOprObj.getComboData(data.distTypeTree);
  493. }
  494. // 需要重置当前页面数据(点击了分类树、搜索等等)
  495. if (condition.reset) {
  496. gljOprObj.stdGLJ = data.stdGLJ;
  497. gljOprObj.complementaryGLJs = data.complementaryGLJs;
  498. gljOprObj.AllRecode = [...gljOprObj.stdGLJ, ...gljOprObj.complementaryGLJs];
  499. } else {
  500. gljOprObj[gljType].splice(condition.index, 0, ...newData);
  501. gljOprObj.AllRecode.splice(condition.index, 0, ...newData);
  502. }
  503. // 根据缓存选中数据,设置人材机是否选中
  504. newData.forEach(item => {
  505. const connectKey = gljOprObj.getIndex(item, gljLibKeyArray);
  506. if (gljOprObj.GLJSelection.includes(connectKey)) {
  507. item.select = 1;
  508. }
  509. });
  510. // 设置人材机类型名称
  511. gljOprObj.setTypeName(gljOprObj.distTypeTree.comboDatas, newData);
  512. if (data.priceProperties && data.priceProperties.length > 0) {
  513. let tmp = _.find(data.priceProperties, {region: property.region, taxModel: parseInt(property.taxType)});
  514. if (tmp) {
  515. let dataCode = tmp.price.dataCode;
  516. for (let glj of data.stdGLJ) {
  517. if (glj.priceProperty && gljUtil.isDef(glj.priceProperty[dataCode])) {
  518. glj.basePrice = glj.priceProperty[dataCode];
  519. }
  520. }
  521. }
  522. }
  523. cb(data[gljType]);
  524. gljOprObj.loadingPagination = false;
  525. }, function () {
  526. if ($.bootstrapLoading.isLoading()) {
  527. $.bootstrapLoading.end();
  528. }
  529. });
  530. };
  531. ration_glj.prototype.getGLJData = function (cb) {
  532. let property = projectObj.project.projectInfo.property;
  533. let engineerID = property.engineering_id;
  534. CommonAjax.get('/rationGlj/getGLJData/'+engineerID, function (data) {
  535. //编办中有多单价设置
  536. if(data.datas.priceProperties && data.datas.priceProperties.length > 0){
  537. let tem = _.find(data.datas.priceProperties,{region:property.region,taxModel:parseInt(property.taxType)});
  538. if(tem){
  539. let dataCode = tem.price.dataCode;
  540. for(let glj of data.datas.stdGLJ){
  541. if(glj.priceProperty && gljUtil.isDef(glj.priceProperty[dataCode])) glj.basePrice = glj.priceProperty[dataCode];
  542. }
  543. }
  544. };
  545. cb(data);
  546. })
  547. };
  548. ration_glj.prototype.insertGLJAsRation = function (GLJSelection, selected, callback) {
  549. let gljList = [];
  550. let allGLJ = gljOprObj.AllRecode;
  551. let billsItemID = null, serialNo = 0,selectedSerialNo = null,nextNodeID = null, parentNodeID = null, billNode = null;
  552. let pEngineer = projectObj.project.projectInfo.property.projectEngineering;
  553. let children = [];
  554. if (selected.sourceType === project.Bills.getSourceType()) {
  555. billsItemID = selected.data.ID;
  556. parentNodeID = selected.getID();
  557. nextNodeID = selected.tree.rootID();
  558. billNode = selected;
  559. } else {
  560. billsItemID = selected.data.billsItemID;
  561. serialNo = selected.data.serialNo;
  562. selectedSerialNo = selected.data.serialNo;
  563. nextNodeID = selected.getNextSiblingID();
  564. parentNodeID = selected.getParentID();
  565. billNode = selected.parent;
  566. }
  567. children = project.Ration.getBillsSortRation(billsItemID);
  568. serialNo == 0 ? serialNo = children.length : "";
  569. for (let con_key of GLJSelection) {
  570. let glj = _.find(allGLJ, function (item) {
  571. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  572. return i_key == con_key;
  573. });
  574. if (glj) {
  575. serialNo += 1;
  576. let new_glj = {
  577. ID: project.Ration.getNewRationID(),
  578. projectID: parseInt(project.ID()),
  579. billsItemID: billsItemID,
  580. type: rationType.gljRation,
  581. code: glj.code,
  582. name: glj.name,
  583. quantity: 0,
  584. unit: glj.unit,
  585. specs: glj.specs,
  586. subType: glj.gljType,
  587. model:glj.model,
  588. basePrice: glj.basePrice,
  589. marketPrice:glj.basePrice,
  590. original_code: glj.code,
  591. shortName: glj.shortName,
  592. serialNo: serialNo,
  593. GLJID: glj.ID,
  594. adjCoe: glj.adjCoe,
  595. materialType:glj.materialType,
  596. materialCoe:glj.materialCoe,
  597. materialIndexType:glj.materialIndexType,
  598. materialIndexUnit:glj.materialIndexUnit,
  599. materialIndexCoe:glj.materialIndexCoe,
  600. repositoryId: glj.repositoryId
  601. };
  602. if(pEngineer) new_glj.programID = pEngineer;
  603. if (glj.hasOwnProperty("compilationId")) {
  604. new_glj.from = "cpt";
  605. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  606. new_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  607. }
  608. }
  609. if(optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')){//需要根据清单转换工程量
  610. new_glj.quantityEXP="QDL";
  611. if(billNode.data.quantity){
  612. new_glj.quantity = scMathUtil.roundForObj(billNode.data.quantity/FilterNumberFromUnit(glj.unit),getDecimal("glj.quantity"));
  613. new_glj.contain = scMathUtil.roundForObj(new_glj.quantity/billNode.data.quantity,6);
  614. }
  615. }
  616. gljList.push(new_glj);
  617. }
  618. }
  619. if (gljList.length == 0) {
  620. return;
  621. }
  622. let postData = {
  623. gljList: gljList,
  624. projectID: parseInt(project.ID()),
  625. billsItemID: billsItemID,
  626. rationCount: project.Ration.maxRationID()
  627. }
  628. selectedSerialNo == null ? "" : postData.selectedSerialNo = selectedSerialNo;
  629. CommonAjax.post("/ration/insertGLJAsRation", postData, function (data) {
  630. // 更新兄弟节点的序列号
  631. if (selectedSerialNo != null) {
  632. let selectIndex = _.findIndex(children, {"serialNo": selectedSerialNo});
  633. if (selectIndex + 1 < children.length) {
  634. for (let i = selectIndex + 1; i < children.length; i++) {
  635. children[i].serialNo += gljList.length;
  636. }
  637. }
  638. }
  639. callback(parentNodeID,nextNodeID,data);
  640. }, function () {
  641. $.bootstrapLoading.end();
  642. });
  643. };
  644. ration_glj.prototype.getGLJDataByCodes = function (codes,callback) {
  645. if(!gljUtil.isDef(codes)||codes.length ==0) {
  646. if(callback) callback([]);
  647. return
  648. }
  649. $.bootstrapLoading.start();
  650. CommonAjax.post("/rationGlj/getGLJDataByCodes", { 'engineerID':projectObj.project.projectInfo.property.engineering_id,projectID:projectObj.project.ID(),codes:codes}, function (result) {
  651. $.bootstrapLoading.end();
  652. callback(result)
  653. });
  654. };
  655. ration_glj.prototype.getAddDataByStd = function (glj,rationID,billsItemID,projectID) {//生成添加类型的定额工料机数据
  656. let ration_glj = {
  657. projectID: projectID,
  658. GLJID: glj.ID,
  659. rationID: rationID,
  660. billsItemID: billsItemID,
  661. rationItemQuantity: 0,
  662. quantity: 0,
  663. name: glj.name,
  664. code: glj.code,
  665. original_code: glj.code,
  666. unit: glj.unit,
  667. specs: glj.specs,
  668. basePrice: glj.basePrice,
  669. marketPrice:glj.basePrice,
  670. shortName: glj.shortName,
  671. type: glj.gljType,
  672. model:glj.model,
  673. adjCoe: glj.adjCoe,
  674. createType: 'add',
  675. materialType:glj.materialType,
  676. materialCoe:glj.materialCoe,
  677. materialIndexType:glj.materialIndexType,
  678. materialIndexUnit:glj.materialIndexUnit,
  679. materialIndexCoe:glj.materialIndexCoe,
  680. repositoryId: glj.repositoryId
  681. };
  682. if (glj.hasOwnProperty("compilationId")) {
  683. ration_glj.from = "cpt";
  684. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改名称、规格、型号等保存到补充工料机库的
  685. ration_glj.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  686. }
  687. }
  688. return ration_glj;
  689. };
  690. ration_glj.prototype.addGLJByLib = function (GLJSelection, ration, callback) {
  691. const me = this,
  692. gljList = [],
  693. allGLJ = gljOprObj.AllRecode;
  694. GLJSelection.sort();
  695. GLJSelection.forEach(selKey => {
  696. const glj = allGLJ.find(item => gljOprObj.getIndex(item, gljLibKeyArray) === selKey);
  697. if (glj) {
  698. const rationGLJ = me.getAddDataByStd(glj, ration.ID, ration.billsItemID, ration.projectID);
  699. gljList.push(rationGLJ);
  700. }
  701. });
  702. $.bootstrapLoading.start();
  703. CommonAjax.post('/rationGlj/addGLJ', gljList, callback, function () {
  704. $.bootstrapLoading.end();
  705. });
  706. };
  707. ration_glj.prototype.updateRationGLJByChangeCode = function (recode, updateField, newval) {
  708. let me = this;
  709. let priceMap = projectObj.project.projectGLJ.datas.unitPriceMap;
  710. let priceObj = priceMap[newval];
  711. if(priceObj){
  712. if (recode.createType===undefined || recode.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  713. recode.rcode = recode.code;
  714. recode.createType = 'replace';
  715. }
  716. recode.code = priceObj.code;
  717. recode.name = priceObj.name;
  718. recode.type = priceObj.type;
  719. recode.unit = priceObj.unit;
  720. recode.shortName = priceObj.short_name;
  721. recode.specs = priceObj.specs;
  722. recode.GLJID=priceObj.glj_id;
  723. recode.original_code = priceObj.original_code;
  724. recode.basePrice = priceObj.base_price;
  725. recode.marketPrice = priceObj.market_price;
  726. }
  727. $.bootstrapLoading.start();
  728. CommonAjax.post("/rationGlj/replaceGLJ", recode, function (result) {
  729. if (result) {
  730. //result.adjustState;
  731. let glj_list = me.datas;
  732. let data = result.data;
  733. let list_index = _.findIndex(glj_list, {'ID': data.ID});
  734. let rationNode = projectObj.project.mainTree.findNode(data.rationID);
  735. let nodes = [rationNode];
  736. glj_list[list_index] = data;
  737. project.projectGLJ.loadData(function () {//加载完项目工料机再计算
  738. gljOprObj.refreshView();
  739. if (project.ration_glj.needShowToTree(data)) {//当替换的是主材或设备时,刷新对应的树节点
  740. let node = project.ration_glj.findGLJNodeByID(data.ID);
  741. if (node) {
  742. project.ration_glj.transferToNodeData(data);
  743. node.source = data;
  744. node.data = data;
  745. }
  746. node ? nodes.push(node) : "";
  747. }
  748. rationNode.data.adjustState = result.adjustState;
  749. rationNode.data.name = result.name;
  750. projectObj.mainController.refreshTreeNode(nodes);
  751. project.calcProgram.calcAndSave(rationNode);
  752. $.bootstrapLoading.end();
  753. });
  754. }
  755. }, function () {
  756. $.bootstrapLoading.end();
  757. });
  758. };
  759. ration_glj.prototype.getReplaceDataByStd = function (oldData,glj) {
  760. if (oldData.createType===undefined || oldData.createType == 'normal') {// createTypel 默认是normal 只有是定额下带的工料机才需把类型改成替换,其它的保持不变
  761. oldData.rcode = oldData.code;
  762. oldData.createType = 'replace';
  763. }
  764. if(oldData.createType == 'replace' && oldData.rcode == glj.code){//如果原数据已经是替换过的,这次替换又恢复成原数据,则把类型改回来
  765. oldData.createType = 'normal'
  766. }
  767. oldData.GLJID = glj.ID;
  768. oldData.name = glj.name;
  769. oldData.code = glj.code;
  770. oldData.original_code = glj.code;
  771. oldData.unit = glj.unit;
  772. oldData.specs = glj.specs;
  773. oldData.model = glj.model;
  774. oldData.basePrice = glj.basePrice;
  775. oldData.marketPrice = glj.basePrice;
  776. oldData.repositoryId = glj.repositoryId;
  777. oldData.materialType = glj.materialType;
  778. oldData. materialCoe = glj.materialCoe;
  779. oldData. materialIndexType = glj.materialIndexType;
  780. oldData. materialIndexUnit = glj.materialIndexUnit;
  781. oldData. materialIndexCoe = glj.materialIndexCoe;
  782. if (glj.hasOwnProperty("compilationId")) {
  783. oldData.from = "cpt";
  784. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  785. oldData.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  786. }
  787. } else {
  788. oldData.from = "std";
  789. }
  790. return oldData;
  791. };
  792. ration_glj.prototype.replaceGLJ = function (selectCode, oldData, callback) {
  793. let allGLJ = gljOprObj.AllRecode;
  794. let glj = _.find(allGLJ, function (item) {
  795. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  796. return i_key == selectCode;
  797. });
  798. if (selectCode == gljOprObj.getIndex(oldData, gljKeyArray)) {
  799. return callback(null);
  800. }
  801. oldData = this.getReplaceDataByStd(oldData,glj);
  802. $.bootstrapLoading.start();
  803. CommonAjax.post("/rationGlj/replaceGLJ", oldData, callback, function () {
  804. $.bootstrapLoading.end();
  805. });
  806. };
  807. ration_glj.prototype.mReplaceGLJ = function (selectCode, oldData, callback) {
  808. let allGLJ = gljOprObj.AllRecode,tasks = [],updateMap={};
  809. let oldIndex = gljOprObj.getIndex(oldData, gljKeyArray);
  810. let glj = _.find(allGLJ, function (item) {
  811. let i_key = gljOprObj.getIndex(item, gljLibKeyArray);
  812. return i_key == selectCode;
  813. });
  814. if (selectCode == oldIndex) {
  815. return callback(null);
  816. }
  817. let query = {
  818. projectID: oldData.projectID,
  819. code: oldData.code,
  820. name: oldData.name,
  821. unit: oldData.unit,
  822. type: oldData.type
  823. }
  824. if (oldData.specs && oldData.specs != '') {
  825. query.specs = oldData.specs;
  826. }
  827. let doc = {
  828. GLJID: glj.ID,
  829. createType: 'replace',
  830. rationItemQuantity: 0,
  831. name: glj.name,
  832. code: glj.code,
  833. original_code: glj.code,
  834. unit: glj.unit,
  835. specs: glj.specs,
  836. type: glj.gljType,
  837. model:glj.model,
  838. basePrice: glj.basePrice,
  839. marketPrice:glj.basePrice,
  840. repositoryId: glj.repositoryId,
  841. materialType: glj.materialType, //三材类别
  842. materialCoe: glj.materialCoe,
  843. materialIndexType: glj.materialIndexType,
  844. materialIndexUnit: glj.materialIndexUnit,
  845. materialIndexCoe: glj.materialIndexCoe,
  846. projectID: oldData.projectID
  847. };
  848. if (glj.hasOwnProperty("compilationId")) {
  849. doc.from = "cpt";
  850. if (glj.code.indexOf('-') != -1) {//这条工料机是用户通过修改包称、规格、型号等保存到补充工料机库的
  851. doc.original_code = glj.code.split('-')[0];//取-前的编号作为原始编号
  852. }
  853. } else {
  854. doc.from = "std";
  855. }
  856. for(let d of this.datas){//查询出所有需替换的工料机
  857. if(!gljOprObj.scopeSelectedIDMap[d.billsItemID]) continue; //如果不在选中范围的,跳过
  858. let tem_index = gljOprObj.getIndex(d, gljKeyArray);
  859. if(tem_index == oldIndex){
  860. let tem_doc = _.cloneDeep(doc);
  861. if(d.createType == 'replace'){
  862. tem_doc.rcode = d.rcode;
  863. }else if(d.createType == 'add'){//对于添加的类型,替换后还是添加类型
  864. tem_doc.createType = 'add';
  865. }else {
  866. tem_doc.rcode = d.code
  867. }
  868. let task = {
  869. updateOne:{
  870. filter : {ID:d.ID},
  871. update : tem_doc
  872. }
  873. };
  874. tasks.push(task);
  875. updateMap[d.ID] = tem_doc;
  876. }
  877. }
  878. $.bootstrapLoading.start();
  879. CommonAjax.post("/rationGlj/mReplaceGLJ", {query: query, doc: doc,tasks:tasks}, function (result) {
  880. callback(result,updateMap);
  881. }, function () {
  882. $.bootstrapLoading.end();
  883. });
  884. };
  885. ration_glj.prototype.getMainAndEquGLJ = function (rationID) {
  886. let gljList = _.filter(this.datas, function (n) {
  887. return n.rationID == rationID && (n.type == gljType.MAIN_MATERIAL || n.type == gljType.EQUIPMENT)
  888. });
  889. gljList = gljUtil.sortRationGLJ(gljList);
  890. return gljOprObj.combineWithProjectGlj(gljList);
  891. };
  892. ration_glj.prototype.transferToNodeData = function (data) {
  893. data.contain=scMathUtil.roundForObj(data.quantity,getDecimal('glj.quantity'));
  894. data.subType = data.type;
  895. };
  896. ration_glj.prototype.combineRationAndGLJ = function (ration) {
  897. if (ration) {
  898. let projectGLJData = projectObj.project.projectGLJ.datas;
  899. let projectGljs = projectGLJData.gljList;
  900. let mixRatioMap = projectGLJData.mixRatioMap;
  901. let glj = _.find(projectGljs, {'id': ration.projectGLJID});
  902. if (glj) {
  903. if(projectObj.project.projectGLJ.isEstimateType(glj.type)){
  904. ration.isEstimate = glj.is_evaluate;
  905. }
  906. ration = gljOprObj.setGLJPrice(ration,glj);
  907. ration.isAdd = glj.unit_price.is_add;
  908. let connect_index = gljOprObj.getIndex(glj, gljKeyArray);
  909. if (mixRatioMap.hasOwnProperty(connect_index)) {
  910. let mixRatios = gljOprObj.getMixRationShowDatas(mixRatioMap[connect_index], projectGljs);
  911. ration.subList = mixRatios;
  912. }
  913. }
  914. }
  915. return ration;
  916. };
  917. ration_glj.prototype.updateFromMainSpread = function (value, node, fieldName) {
  918. if (node.data[fieldName] !== value) {
  919. if (fieldName == "marketUnitFee") {
  920. let decimal = getDecimal("glj.unitPrice");
  921. let newval = number_util.checkNumberValue(value, decimal);
  922. if (newval) {
  923. fieldName = "marketPrice";
  924. projectObj.project.projectGLJ.updatePriceFromRG(node.data, fieldName, newval);
  925. return;
  926. }
  927. } else {
  928. if(fieldName == "contain"){
  929. if(value==null){
  930. value="";
  931. }else {
  932. let decimal = getDecimal("glj.quantity");
  933. value = number_util.checkNumberValue(value, decimal);
  934. fieldName="customQuantity";//填入自定义消耗
  935. }
  936. }
  937. if (value !== undefined && value !== null) {
  938. if (fieldName == "subType") {
  939. node.data.subType = value;
  940. fieldName = "type";//转换成更新工料机类型
  941. }
  942. this.updateRationGLJByEdit(node.data, fieldName, value, node);
  943. return;
  944. }
  945. }
  946. }
  947. // node.data.subType = value;
  948. projectObj.mainController.refreshTreeNode([node]);
  949. };
  950. ration_glj.prototype.refreshTreeNodeIfNeeded = function (data) {
  951. if (this.needShowToTree(data)) {
  952. this.transferToNodeData(data);
  953. gljOprObj.refreshTreeNode({"type": ModuleNames.ration_glj, "ID": data.ID});
  954. }
  955. };
  956. ration_glj.prototype.needShowToTree = function (data) {
  957. if ((data.type == gljType.MAIN_MATERIAL || data.type == gljType.EQUIPMENT) && projectObj.project.projectInfo.property.displaySetting.disPlayMainMaterial == true) {
  958. return true
  959. }
  960. return false
  961. };
  962. ration_glj.prototype.findGLJNodeByID = function (ID) {
  963. return projectObj.project.mainTree.findNode(ID);
  964. };
  965. ration_glj.prototype.findRationNodeByID = function (ID) {
  966. return projectObj.project.mainTree.findNode(ID);
  967. };
  968. ration_glj.prototype.reCalcWhenGLJChange = function (ration_glj) {//当改变定额工料机时,重新计算定额以及其父节点
  969. let node = this.findRationNodeByID(ration_glj.rationID);
  970. if (node) {
  971. node.changed = true;
  972. project.calcProgram.calcAndSave(node, function () {
  973. OVER_HEIGHT.reCalcOverHeightFee();
  974. });
  975. }
  976. };
  977. return new ration_glj(project);
  978. }
  979. };