ration.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. /**
  2. * Created by Mai on 2017/4/1.
  3. */
  4. var Ration = {
  5. createNew: function (project) {
  6. // 用户定义private方法
  7. var tools = {
  8. formatRationUpdateData: function (data) {
  9. let uData = JSON.parse(JSON.stringify(data));
  10. delete uData.feesIndex;
  11. delete uData.flagsIndex;
  12. // if (uData.fees) {
  13. // for (let fee of uData.fees) {
  14. // fee.unitFee = fee.unitFee.toFixed(2);
  15. // fee.totalFee = fee.totalFee.toFixed(2);
  16. // fee.tenderUnitFee = fee.tenderUnitFee.toFixed(2);
  17. // fee.tenderTotalFee = fee.tenderTotalFee.toFixed(2);
  18. // }
  19. // }
  20. return uData;
  21. }
  22. };
  23. // 所有通过this访问的属性,都不应在此单元外部进行写入操作
  24. var ration = function (proj) {
  25. this.project = proj;
  26. this.datas = null;
  27. var sourceType = ModuleNames.ration;
  28. this.getSourceType = function () {
  29. return sourceType;
  30. }
  31. proj.registerModule(ModuleNames.ration, this);
  32. var maxRationID = 0;
  33. this.getNewRationID = function () {
  34. return uuid.v1();
  35. //return maxRationID += 1;
  36. };
  37. this.maxRationID = function (maxID) {
  38. if (arguments.length === 0) {
  39. return maxRationID;
  40. } else {
  41. maxRationID = Math.max(maxID, maxRationID);
  42. }
  43. };
  44. };
  45. // prototype用于定义public方法
  46. ration.prototype.loadData = function (datas) {
  47. var that = this;
  48. this.datas = datas;
  49. // generate Fees & Flags Index,For View & Calculate
  50. this.datas.forEach(function (data) {
  51. data.feesIndex = {};
  52. data.fees.forEach(function (fee) {
  53. data.feesIndex[fee.fieldName] = fee;
  54. });
  55. data.flagsIndex = {};
  56. data.flags.forEach(function (flag) {
  57. data.flagsIndex[flag.fieldName] = flag;
  58. });
  59. that.maxRationID(data.ID);
  60. });
  61. };
  62. ration.prototype.setMaxID = function (ID) {
  63. this.maxRationID(ID);
  64. }
  65. ration.prototype.addDatasToList = function (new_datas) {
  66. let me = this;
  67. if(me.datas && Array.isArray(me.datas)){
  68. for(let d of new_datas){
  69. me.datas.push(d);
  70. }
  71. }else {
  72. me.datas = new_datas;
  73. }
  74. };
  75. // refresh after update
  76. ration.prototype.doAfterUpdate = function(err, data){
  77. if(data.stateRefresh){
  78. this.refreshAdjustState(data);
  79. }
  80. if(data.quantityRefresh){
  81. this.refreshQuantity(data);
  82. }
  83. };
  84. ration.prototype.refreshAdjustState = function(data){
  85. this.refreshDatas(data,'adjustState');
  86. if(data.hasOwnProperty('name')){
  87. this.refreshDatas(data,'name')
  88. }
  89. };
  90. ration.prototype.refreshQuantity = function(data){
  91. this.refreshDatas(data,'quantity');
  92. };
  93. ration.prototype.refreshDatas = function(data,fieldName){
  94. var dataIndex = _.findIndex(this.datas,function(item) {
  95. return item.ID ==data.rationID;
  96. });
  97. this.datas[dataIndex][fieldName] = data[fieldName];
  98. if(fieldName=='quantity'){
  99. this.datas[dataIndex]['isFromDetail']=1
  100. }
  101. var controller = projectObj.mainController;
  102. var selected = controller.sheet.getSelections();
  103. var col = _.findIndex(project.projSetting.main_tree_col.cols,function (col) {
  104. return col.data.field ==fieldName;
  105. });
  106. controller.sheet.getCell(selected[0].row,col).value(data[fieldName]);
  107. };
  108. ration.prototype.getTempRationData = function (id, billsID, serialNo, rType) {
  109. var newData = {'ID': id, 'serialNo': serialNo, projectID: this.project.ID()};
  110. newData[project.masterField.ration] = billsID;
  111. newData['type'] = rType;
  112. if (rType == rationType.volumePrice){
  113. newData['subType'] = gljType.GENERAL_MATERIAL; // 默认的量价类型为材料
  114. newData['programID'] = projectInfoObj.projectInfo.property.engineering;
  115. };
  116. if(rType == rationType.install){//是安装增加费生成的定额
  117. newData['programID'] = projectInfoObj.projectInfo.property.engineering;
  118. }
  119. return newData;
  120. };
  121. ration.prototype.getBillsSortRation = function (billsID) { // 该方法只适用于叶子清单
  122. var rations = this.datas.filter(function (data) {
  123. return data[project.masterField.ration] === billsID;
  124. });
  125. rations.sort(function (x, y) {
  126. return x.serialNo - y.serialNo;
  127. });
  128. return rations;
  129. };
  130. // CSL, 2017-11-13 取任何清单(父清单、叶子清单)下的所有定额
  131. ration.prototype.getRationNodes = function (billNode) {
  132. if (billNode.sourceType != ModuleNames.bills) return [];
  133. let rations = [], IDs = [];
  134. function getSubBillsIDs(node) {
  135. if (!node) return;
  136. if (node.sourceType != ModuleNames.bills) return;
  137. if (!node.children || node.children.length == 0 || node.children[0].sourceType != ModuleNames.bills)
  138. IDs.push(node.data.ID)
  139. else
  140. getSubBillsIDs(node.children[0]);
  141. getSubBillsIDs(node.nextSibling);
  142. };
  143. if (billNode.source.children.length == 0)
  144. IDs.push(billNode.data.ID)
  145. else
  146. getSubBillsIDs(billNode.children[0]);
  147. for (let id of IDs){
  148. let subRations = this.datas.filter(function (data) {
  149. return data[project.masterField.ration] === id;
  150. });
  151. rations.push(...subRations);
  152. };
  153. rations.sort(function (x, y) {
  154. return x.serialNo - y.serialNo;
  155. });
  156. let rationNodes = [];
  157. for (let ration of rations){
  158. rationNodes.push(projectObj.project.mainTree.nodes['id_' + ration.ID]);
  159. }
  160. return rationNodes;
  161. };
  162. ration.prototype.getInsertRationData = function (billsID, preRation, rationType) {
  163. var br = this.getBillsSortRation(billsID);
  164. var updateData = [];
  165. if (preRation) {
  166. var preIndex = br.indexOf(preRation), i;
  167. updateData.push({updateType: 'ut_create', updateData: this.getTempRationData(this.getNewRationID(), billsID, preIndex < br.length - 1 ? br[preIndex + 1].serialNo : br[preIndex].serialNo + 1, rationType)});
  168. for (i = preIndex + 1; i < br.length; i++) {
  169. updateData.push({updateType: 'ut_update', updateData: this.getTempRationData(br[i].ID, billsID, i < br.length - 1 ? br[i+1].serialNo : br[i].serialNo + 1, br[i].type)});
  170. }
  171. } else {
  172. updateData.push({updateType: 'ut_create', updateData: this.getTempRationData(this.getNewRationID(), billsID, br.length > 0 ? br[br.length - 1].serialNo + 1 : 1, rationType)});
  173. }
  174. return updateData;
  175. };
  176. ration.prototype.getCounterData = function (count) {
  177. var updateData = {'projectID': this.project.ID()};
  178. if (count) {
  179. updateData[this.getSourceType()] = this.maxRationID() + count;
  180. } else {
  181. updateData[this.getSourceType()] = this.maxRationID() + 1;
  182. }
  183. return updateData;
  184. };
  185. ration.prototype.insertRation = function (billsID, preRation, rationType) {
  186. var br = this.getBillsSortRation(billsID);
  187. let insertData = this.getInsertRationData(billsID, preRation, rationType);
  188. this.project.pushNow('insertRation', [this.getSourceType(), this.project.projCounter()],
  189. [insertData, this.getCounterData()]);
  190. var newRation = null;
  191. let newID = -1;
  192. for(let data of insertData){
  193. if(data.updateType === 'ut_create'){
  194. newID = data.updateData.ID;
  195. }
  196. }
  197. if (preRation) {
  198. var preIndex = br.indexOf(preRation), i;
  199. newRation = this.getTempRationData(newID, billsID, preIndex < br.length - 1 ? br[preIndex + 1].serialNo : br[preIndex].serialNo + 1, rationType);
  200. this.datas.push(newRation);
  201. for (i = preIndex + 1; i < br.length; i++) {
  202. br[i].serialNo = i < br.length - 1 ? br [i + 1].serialNo : br[i].serialNo + 1;
  203. }
  204. } else {
  205. newRation = this.getTempRationData(newID, billsID, br.length > 0 ? br[br.length - 1].serialNo + 1 : 1, rationType);
  206. this.datas.push(newRation);
  207. }
  208. return newRation;
  209. };
  210. ration.prototype.insertStdRation = function (billsID, preRation, std) {
  211. var br = this.getBillsSortRation(billsID), updateData = this.getInsertRationData(billsID, preRation, rationType.ration), newRation = null, that = this;
  212. updateData.forEach(function (data) {
  213. if (data.updateType === 'ut_create') {
  214. data.updateData.code = std.code;
  215. data.updateData.name = std.name;
  216. data.updateData.caption = std.caption;
  217. data.updateData.unit = std.unit;
  218. data.updateData.libID = std.rationRepId;
  219. data.updateData.content = std.jobContent;
  220. if (std.chapter) {
  221. data.updateData.comments = std.chapter.explanation;
  222. data.updateData.ruleText = std.chapter.ruleText;
  223. }
  224. data.updateData.from = std.type === 'complementary' ? 'cpt' : 'std';
  225. data.updateData.programID = std.feeType;
  226. data.updateData.rationAssList = projectObj.project.ration_ass.CreateNewAss(std);
  227. // calculate ration Quantity
  228. that.CalculateQuantity(data.updateData);
  229. newRation = data.updateData;
  230. }
  231. });
  232. this.project.pushNow('insertRation', [this.getSourceType(), this.project.projCounter()], [updateData, this.getCounterData()]);
  233. //newRation.ID = this.getNewRationID();
  234. if (preRation) {
  235. var preIndex = br.indexOf(preRation), i;
  236. this.datas.push(newRation);
  237. for (i = preIndex + 1; i < br.length; i++) {
  238. br[i].serialNo = i < br.length - 1 ? br [i + 1].serialNo : br[i].serialNo + 1;
  239. }
  240. } else {
  241. this.datas.push(newRation);
  242. }
  243. return newRation;
  244. };
  245. ration.prototype.getDeleteData = function (rationData) {
  246. var updateData = [];
  247. updateData.push({'updateType': 'ut_delete', 'updateData': {'ID': rationData.ID, 'projectID': this.project.ID()}});
  248. return updateData;
  249. };
  250. ration.prototype.delete = function (ration) {
  251. var ration_glj =projectObj.project.ration_glj;
  252. this.project.pushNow('deleteRation', [this.getSourceType(),ration_glj.getSourceType()], [this.getDeleteData(ration),ration_glj.getDeleteDataByRation(ration)]);
  253. project.ration_glj.deleteByRation(ration);
  254. project.ration_coe.deleteByRation(ration);
  255. project.quantity_detail.deleteByRation(ration);
  256. project.ration_installation.deleteByRation(ration);
  257. this.datas.splice(this.datas.indexOf(ration), 1);
  258. };
  259. ration.prototype.removeByID = function(ID){
  260. _.remove(this.datas,{'ID':ID});
  261. };
  262. ration.prototype.getDeleteDataByBill = function (nodes) {
  263. let updateData = [];
  264. for (let node of nodes) {
  265. if (node.children.length > 0) {
  266. updateData = updateData.concat(this.getDeleteDataByBill(node.children));
  267. } else {
  268. let rations = this.getBillsSortRation(node.getID());
  269. for (let r of rations) {
  270. updateData.push({'updateType': 'ut_delete', 'updateData': {'ID': r.ID, 'projectID': this.project.ID()}});
  271. }
  272. }
  273. }
  274. return updateData;
  275. };
  276. ration.prototype.deleteByBills = function (nodes) {
  277. for (let node of nodes) {
  278. if (node.children.length > 0) {
  279. this.deleteByBills(node.children);
  280. } else {
  281. let rations = this.getBillsSortRation(node.getID());
  282. for (let r of rations) {
  283. this.datas.splice(this.datas.indexOf(r), 1);
  284. }
  285. }
  286. }
  287. }
  288. ration.prototype.getChangePosUpdateData = function (ration1, ration2) {
  289. var updateData = [];
  290. updateData.push({updateType: 'ut_update', updateData: this.getTempRationData(ration1.ID, ration1.billsItemID, ration2.serialNo)});
  291. updateData.push({updateType: 'ut_update', updateData: this.getTempRationData(ration2.ID, ration2.billsItemID, ration1.serialNo)});
  292. return updateData;
  293. };
  294. ration.prototype.changePos = function (ration1, ration2) {
  295. var updateData = this.getChangePosUpdateData(ration1, ration2);
  296. this.project.pushNow('insertRation', [this.getSourceType()], [updateData]);
  297. var preSerialNo = ration1.serialNo;
  298. ration1.serialNo = ration2.serialNo;
  299. ration2.serialNo = preSerialNo;
  300. };
  301. ration.prototype.updateField = function (ration, field, newValue) {
  302. calcFees.setFee(ration, field, newValue);
  303. let updateData = [];
  304. let data = {'ID': ration.ID, 'projectID': this.project.ID()};
  305. if (field === 'quantity') {
  306. data[field] = newValue;
  307. data.isFromDetail=0;
  308. // to do Calculate
  309. if (ration.fees) {
  310. data.fees = ration.fees;
  311. }
  312. } else if (field === 'feesIndex.common.unitFee') {
  313. // to do Calculate
  314. if (ration.fees) {
  315. data.fees = ration.fees;
  316. }
  317. } else {
  318. data[field] = newValue;
  319. }
  320. updateData.push({'updateType': 'ut_update', 'updateData': data});
  321. this.project.pushNow('updateBills', this.getSourceType(), updateData);
  322. };
  323. ration.prototype.updateRation = function (ration, updateNow) {
  324. let updateData = [];
  325. updateData.push({'updateType': 'ut_update', 'updateData': tools.formatRationUpdateData(ration)});
  326. if (updateNow) {
  327. this.project.pushNow('updateRations', this.getSourceType(), updateData);
  328. } else {
  329. this.project.push(this.getSourceType(), updateData);
  330. }
  331. };
  332. ration.prototype.FilterNumberFromUnit = function (unit) {
  333. let reg = new RegExp('^[0-9]+');
  334. if (reg.test(unit)) {
  335. return parseInt(unit.match(reg)[0]);
  336. } else {
  337. return 1;
  338. }
  339. };
  340. ration.prototype.CalculateQuantity = function (ration) {
  341. // calculate ration Quantity
  342. let quantity_decimal = getDecimal("ration.quantity");
  343. let process_decimal = getDecimal("process");
  344. if (optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')) {
  345. let billsNode = this.project.Bills.tree.findNode(ration[this.project.masterField.ration]);
  346. let billsQuantity = billsNode.data.quantity ? billsNode.data.quantity : 0;
  347. billsQuantity=scMathUtil.roundForObj(billsQuantity,quantity_decimal);
  348. ration.quantityEXP="QDL";
  349. /* if (optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToRationUnit')) {
  350. ration.quantity = (billsQuantity / this.FilterNumberFromUnit(ration.unit)).toDecimal(quantity_decimal);
  351. } else {
  352. ration.quantity = billsQuantity.toDecimal(quantity_decimal);
  353. }*/
  354. ration.quantity = (billsQuantity / this.FilterNumberFromUnit(ration.unit)).toDecimal(quantity_decimal);//改成不管是否打勾都做转换
  355. ration.contain = scMathUtil.roundForObj(ration.quantity/billsQuantity,process_decimal);
  356. }
  357. };
  358. ration.prototype.updateRationCodes = function (recodes) {
  359. let libID = rationLibObj.getCurrentStdRationLibID();
  360. let libIDs = rationLibObj.getStdRationLibIDs();
  361. let firstLibID = rationLibObj.getFirstStdRationLibID();
  362. let engineering = projectInfoObj.projectInfo.property.engineering;
  363. let projectID = projectInfoObj.projectInfo.ID;
  364. let project = projectObj.project;
  365. let mainTree = project.mainTree;
  366. let nodeInfo =[];
  367. let refershNodes = [];
  368. if(libIDs == null){
  369. return;
  370. }
  371. for(let r of recodes){
  372. let needInstall = false;
  373. if(engineering==engineeringType.BUILD_IN) {//如果是安装工程,要看需不需要生成安装增加费
  374. needInstall = project.Bills.isFBFX(r.node);
  375. }
  376. r.value===null||r.value===undefined?"":r.value = r.value.replace(/[\s\r\n]/g, "");//去掉空格回车换行等字符
  377. nodeInfo.push({ID:r.node.data.ID,billsItemID:r.node.data.billsItemID,newCode:r.value,needInstall:needInstall});
  378. refershNodes.push(r.node);
  379. }
  380. let calQuantity = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
  381. $.bootstrapLoading.start();
  382. CommonAjax.post("/ration/replaceRations",{nodeInfo:nodeInfo,libIDs:libIDs,firstLibID: firstLibID,projectID:projectID,calQuantity:calQuantity},function (data) {
  383. for(let recode of data){
  384. let node = mainTree.getNodeByID(recode.ration.ID);
  385. if(node) {
  386. for(let temkey in recode.ration){//更新缓存
  387. node.data[temkey] = recode.ration[temkey];
  388. }
  389. node.data.feesIndex = {};
  390. //删除定额节点下的主材和设备节点
  391. project.ration_glj.removeNodeByRation(recode.ration,projectObj.mainController);
  392. project.Ration.deleteSubListOfRation(recode.ration);//删除旧定额下的相关记录
  393. //添加新的记录
  394. project.ration_glj.addDatasToList(recode.ration_gljs);
  395. project.ration_coe.addDatasToList(recode.ration_coes);
  396. project.ration_installation.addDatasToList(recode.ration_installs);
  397. project.ration_glj.addToMainTree(recode.ration_gljs);
  398. }
  399. }
  400. project.projectGLJ.loadData(function () {
  401. gljOprObj.showDataIfRationSelect(projectObj.project.mainTree.selected,"-111111111");//这里第二个参数是为了使改前和改后selectedID不一样,删除了的话下方的定额工料机不会刷新
  402. project.calcProgram.calcRationsAndSave(refershNodes);
  403. projectObj.mainController.refreshTreeNode(refershNodes, true);
  404. $.bootstrapLoading.end();
  405. });
  406. if(data.length<recodes.length&&recodes[data.length].value!=null){//说明有部分定额编号没找到记录
  407. alert('当前库中找不到定额"' + recodes[data.length].value + '"');
  408. }
  409. })
  410. };
  411. ration.prototype.addNewRation = function (itemQuery,rationType) {
  412. let me = this;
  413. let project = projectObj.project, sheetController = projectObj.mainController;
  414. let engineering = projectInfoObj.projectInfo.property.engineering;
  415. let selected = project.mainTree.selected, newSource = null, newNode = null,pre=null,br=null;
  416. let billItemID = null,serialNo=1,nextID=null;
  417. let needInstall = false;
  418. if (selected === null) { return; }
  419. if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
  420. if (selected.source.children.length > 0) {
  421. alert('当前清单已有清单子项,不能套用定额。');
  422. } else if (selected.data.calcBase&&selected.data.calcBase!="") {
  423. alert('当前有基数计算不能插入定额/量价/工料机。');
  424. } else {
  425. if(selected.data.type === billType.FB){
  426. return;
  427. }
  428. billItemID = selected.source.getID();
  429. nextID = selected.tree.rootID();
  430. br = this.getBillsSortRation(billItemID);
  431. serialNo = br.length > 0 ? br[br.length - 1].serialNo + 1 : 1
  432. }
  433. } else if (selected.sourceType === project.Ration.getSourceType()) {
  434. billItemID = selected.getParentID();
  435. br = this.getBillsSortRation(billItemID);
  436. serialNo = selected.data.serialNo+1;
  437. nextID = selected.getNextSiblingID();
  438. pre = selected.source;
  439. };
  440. if(billItemID){
  441. let newData = me.getTempRationData(me.getNewRationID(), billItemID, serialNo, rationType);
  442. let calQuantity = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
  443. let brUpdate = [];
  444. //更新兄弟节点的序列号
  445. if (pre) {
  446. let preIndex = br.indexOf(pre), i;
  447. for (i = preIndex + 1; i < br.length; i++) {
  448. br[i].serialNo = i < br.length - 1 ? br [i + 1].serialNo : br[i].serialNo + 1;
  449. brUpdate.push({projectID:newData.projectID,ID:br[i].ID,serialNo:br[i].serialNo});
  450. }
  451. }
  452. if(engineering==engineeringType.BUILD_IN) {//如果是安装工程,要看需不需要生成安装增加费
  453. let billsNode = project.mainTree.getNodeByID(billItemID);
  454. needInstall = project.Bills.isFBFX(billsNode);//在分部分项插入的定额才需要定额安装增加费
  455. }
  456. $.bootstrapLoading.start();
  457. CommonAjax.post("/ration/addNewRation",{itemQuery:itemQuery,newData:newData,firstLibID: rationLibObj.getFirstStdRationLibID(),calQuantity:calQuantity,brUpdate:brUpdate,needInstall:needInstall},function (data) {
  458. //更新缓存
  459. me.datas.push(data.ration);
  460. project.ration_glj.addDatasToList(data.ration_gljs);
  461. project.ration_coe.addDatasToList(data.ration_coes);
  462. project.ration_installation.addDatasToList(data.ration_installs);
  463. //插入树节点
  464. newSource = data.ration;
  465. newNode = project.mainTree.insert(billItemID, nextID, newSource.ID);
  466. newNode.source = newSource;
  467. newNode.sourceType = project.Ration.getSourceType();
  468. newNode.data = newSource;
  469. ProjectController.syncDisplayNewNode(sheetController, newNode);
  470. project.projectGLJ.loadData(function () {
  471. project.ration_glj.addToMainTree(data.ration_gljs);
  472. projectObj.mainController.refreshTreeNode([newNode], false);
  473. if(project.Bills.isFBFX(newNode)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
  474. // let changeNodes = project.calcProgram.calculate(newNode);//先计算不保存,如果计算安装增加费后不用自动计算,则单独调用保存的方法
  475. project.installation_fee.calcInstallationFee(function (isChange,rations) {
  476. if(isChange){
  477. rations.push(newNode);
  478. project.calcProgram.calcRationsAndSave(rations);
  479. }else {
  480. project.calcProgram.calcRationsAndSave([newNode]);
  481. }
  482. });
  483. }else {
  484. project.calcProgram.calcAndSave(newNode);
  485. }
  486. /* project.calcProgram.calcAndSave(newNode,function () {
  487. if(project.Bills.isFBFX(newNode)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
  488. project.installation_fee.calcInstallationFee(function (isChange) {
  489. if(isChange){
  490. project.calcProgram.calcAllNodesAndSave();
  491. }
  492. });
  493. }
  494. });*/
  495. $.bootstrapLoading.end();
  496. });
  497. })
  498. }
  499. };
  500. ration.prototype.deleteSubListOfRation = function(ration){
  501. projectObj.project.ration_glj.deleteByRation(ration);
  502. projectObj.project.ration_coe.deleteByRation(ration);
  503. projectObj.project.quantity_detail.deleteByRation(ration);
  504. projectObj.project.ration_installation.deleteByRation(ration);
  505. };
  506. ration.prototype.replaceRation = function (ration, std) {
  507. this.project.beginUpdate('replaceRation');
  508. // delete
  509. let ration_glj =projectObj.project.ration_glj;
  510. this.project.push(this.project.ration_glj.getSourceType(), this.project.ration_glj.getDeleteDataByRation(ration));
  511. this.deleteSubListOfRation(ration);
  512. // insertNewRation
  513. let updateData = [];
  514. ration.code = std.code;
  515. ration.name = std.name;
  516. ration.caption = std.caption;
  517. ration.unit = std.unit;
  518. ration.libID = std.rationRepId;
  519. ration.content = std.jobContent;
  520. ration.adjustState = '';
  521. if (std.chapter) {
  522. ration.comments = std.chapter.explanation;
  523. ration.ruleText = std.chapter.ruleText;
  524. }
  525. ration.from = std.type === 'complementary' ? 'cpt' : 'std';
  526. ration.programID = std.feeType;
  527. ration.rationAssList = projectObj.project.ration_ass.CreateNewAss(std);
  528. // calculate ration Quantity
  529. this.CalculateQuantity(ration);
  530. updateData.push({updateType: 'ut_update', updateData: ration});
  531. this.project.push(this.getSourceType(), updateData);
  532. this.project.endUpdate();
  533. };
  534. ration.prototype.updateContain=function (value,node) {
  535. if(isNaN(value)){
  536. alert("当前输入的数据类型不正确,请重新输入");
  537. projectObj.mainController.refreshTreeNode([node]);
  538. return;
  539. }
  540. let billNode = node.parent;
  541. let contain = scMathUtil.roundForObj(value,getDecimal("process"));
  542. if(node.data.quantityEXP=="GCLMXHJ"){//如果定额工程量是来自工程量明细
  543. var c = confirm('已有工程量明细,是否清空明细表,采用手工输入的表达式?');
  544. if(c){
  545. node.data.isFromDetail=0;
  546. project.quantity_detail.cleanQuantityDetail(node,true);
  547. }else {
  548. projectObj.mainController.refreshTreeNode([node]);
  549. return;
  550. }
  551. }
  552. let billQuantity = billNode.data.quantity||billNode.data.quantity!=""?billNode.data.quantity:0;
  553. billQuantity = parseFloat(billQuantity);
  554. node.data.contain = contain;
  555. node.data.quantityEXP="QDL*"+contain;
  556. node.data.quantity=scMathUtil.roundForObj(billQuantity*contain,getDecimal("quantity",node));
  557. let times = parseInt(node.data.unit)
  558. if (!isNaN(times)) {
  559. node.data.quantityEXP+='*'+times;
  560. }
  561. // node.data.quantity = projectObj.project.quantity_detail.autoTransformQuantity(node.data.quantity,node);//按单位做转换
  562. node.changed = true;
  563. project.calcProgram.calcAndSave(node, function () {
  564. project.projectGLJ.calcQuantity();
  565. });
  566. projectObj.mainController.refreshTreeNode(node.children);//刷新子工料机树节点总消耗量
  567. };
  568. ration.prototype.addRationChecking=function(selected){
  569. if (selected) {// Vincent, 2018-01-02
  570. if(selected.sourceType === project.Ration.getSourceType()){ // 焦点行是定额/量价/工料机,有效显示。
  571. return false;
  572. }else if(selected.sourceType === project.Bills.getSourceType()){
  573. if(selected.data.type == billType.FX||selected.data.type == billType.BX){//焦点行是分项,有效显示。
  574. return false
  575. }
  576. if(selected.data.type == billType.BILL && selected.source.children.length === 0){//焦点行是清单,且没有子项,有效显示。
  577. return false
  578. }
  579. }
  580. }
  581. return true;
  582. };
  583. ration.prototype.getAllInstallTypeRation = function () {//取所有计取安装增加费生成的定额
  584. return _.filter(this.datas,{'type':rationType.install});
  585. };
  586. ration.prototype.getLabourTotalFee=function(ration){//feesIndex.labour.totalFee 取定额的人工费合价
  587. if(ration.feesIndex&&ration.feesIndex.labour&&ration.feesIndex.labour.totalFee){
  588. return ration.feesIndex.labour.totalFee;
  589. }else {
  590. return 0;
  591. }
  592. };
  593. ration.prototype.getMaterialTotalFee=function(ration){//feesIndex.material.totalFee 取定额的材料费合价
  594. if(ration.feesIndex&&ration.feesIndex.material&&ration.feesIndex.material.totalFee){
  595. return ration.feesIndex.material.totalFee;
  596. }else {
  597. return 0;
  598. }
  599. } ;
  600. ration.prototype.getMachineTotalFee=function(ration){//feesIndex.machine.totalFee 取定额的机械费合价
  601. if(ration.feesIndex&&ration.feesIndex.machine&&ration.feesIndex.machine.totalFee){
  602. return ration.feesIndex.machine.totalFee;
  603. }else {
  604. return 0;
  605. }
  606. } ;
  607. //获取定额前缀
  608. ration.prototype.getRationPrefix = function(firstLibID, ration){
  609. if(firstLibID !== ration.libID){
  610. return rationPrefix.borrow;
  611. }
  612. if(ration.from && ration.from === rationFrom.cpt){
  613. return rationPrefix.complementary;
  614. }
  615. return rationPrefix.none;
  616. };
  617. return new ration(project);
  618. }
  619. };
  620. function FilterNumberFromUnit (unit) {
  621. let reg = new RegExp('^[0-9]+');
  622. if (reg.test(unit)) {
  623. return parseInt(unit.match(reg)[0]);
  624. } else {
  625. return 1;
  626. }
  627. };