ration.js 31 KB

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