ration.js 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  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 = getFeeIndex(data.fees);
  52. data.flagsIndex = {};
  53. data.flags.forEach(function (flag) {
  54. data.flagsIndex[flag.fieldName] = flag;
  55. });
  56. that.maxRationID(data.ID);
  57. });
  58. };
  59. ration.prototype.setMaxID = function (ID) {
  60. this.maxRationID(ID);
  61. }
  62. ration.prototype.addDatasToList = function (new_datas) {
  63. let me = this;
  64. if(me.datas && Array.isArray(me.datas)){
  65. for(let d of new_datas){
  66. me.datas.push(d);
  67. }
  68. }else {
  69. me.datas = new_datas;
  70. }
  71. };
  72. // refresh after update
  73. ration.prototype.doAfterUpdate = function(err, data){
  74. if(data.stateRefresh){
  75. this.refreshAdjustState(data);
  76. }
  77. if(data.quantityRefresh){
  78. this.refreshQuantity(data);
  79. }
  80. };
  81. ration.prototype.refreshAdjustState = function(data){
  82. this.refreshDatas(data,'adjustState');
  83. if(data.hasOwnProperty('name')){
  84. this.refreshDatas(data,'name')
  85. }
  86. };
  87. ration.prototype.refreshQuantity = function(data){
  88. this.refreshDatas(data,'quantity');
  89. };
  90. ration.prototype.refreshDatas = function(data,fieldName){
  91. var dataIndex = _.findIndex(this.datas,function(item) {
  92. return item.ID ==data.rationID;
  93. });
  94. this.datas[dataIndex][fieldName] = data[fieldName];
  95. if(fieldName=='quantity'){
  96. this.datas[dataIndex]['isFromDetail']=1
  97. }
  98. var controller = projectObj.mainController;
  99. var selected = controller.sheet.getSelections();
  100. var col = _.findIndex(project.projSetting.main_tree_col.cols,function (col) {
  101. return col.data.field ==fieldName;
  102. });
  103. controller.sheet.getCell(selected[0].row,col).value(data[fieldName]);
  104. };
  105. ration.prototype.getContain = function (billNode,quantity) {
  106. if(billNode && billNode.data.quantity&&billNode.data.quantity!=0&&billNode.data.quantity!=""){
  107. let billQuantity = scMathUtil.roundForObj(billNode.data.quantity,getDecimal("quantity",billNode));
  108. return scMathUtil.roundForObj(parseFloat(quantity)/billQuantity,getDecimal("process"));
  109. }
  110. return 0
  111. };
  112. ration.prototype.getTempRationData = function (id, billsID, serialNo, rType,priceType) {
  113. let newData = {'ID': id, 'serialNo': serialNo, projectID: this.project.ID()};
  114. let pEngineer = projectInfoObj.projectInfo.property.projectEngineering;//量价默认使用后台设置的单位工程取费专业
  115. newData[project.masterField.ration] = billsID;
  116. newData['type'] = rType;
  117. if (rType == rationType.volumePrice){
  118. newData['subType'] = priceType?priceType:gljType.GENERAL_MATERIAL; // 如果priceType 没传,默认的量价类型为材料
  119. };
  120. if(rType == rationType.ration){//空定额暂时不输入取费专业
  121. // newData['programID'] = projectInfoObj.projectInfo.property.engineering;
  122. }else {
  123. if(pEngineer) newData['programID'] = pEngineer;
  124. }
  125. return newData;
  126. };
  127. ration.prototype.getBillsSortRation = function (billsID) { // 该方法只适用于叶子清单
  128. var rations = this.datas.filter(function (data) {
  129. return data[project.masterField.ration] === billsID;
  130. });
  131. rations.sort(function (x, y) {
  132. return x.serialNo - y.serialNo;
  133. });
  134. return rations;
  135. };
  136. // CSL, 2017-11-13 取任何清单(父清单、叶子清单)下的所有定额
  137. ration.prototype.getRationNodes = function (billNode) {
  138. if (billNode.sourceType != ModuleNames.bills) return [];
  139. let rations = [], IDs = [];
  140. function getSubBillsIDs(node) {
  141. if (!node) return;
  142. if (node.sourceType != ModuleNames.bills) return;
  143. if (!node.children || node.children.length == 0 || node.children[0].sourceType != ModuleNames.bills)
  144. IDs.push(node.data.ID)
  145. else
  146. getSubBillsIDs(node.children[0]);
  147. getSubBillsIDs(node.nextSibling);
  148. };
  149. if (billNode.source.children.length == 0)
  150. IDs.push(billNode.data.ID)
  151. else
  152. getSubBillsIDs(billNode.children[0]);
  153. for (let id of IDs){
  154. let subRations = this.datas.filter(function (data) {
  155. return data[project.masterField.ration] === id;
  156. });
  157. rations.push(...subRations);
  158. };
  159. rations.sort(function (x, y) {
  160. return x.serialNo - y.serialNo;
  161. });
  162. let rationNodes = [];
  163. for (let ration of rations){
  164. rationNodes.push(projectObj.project.mainTree.nodes['id_' + ration.ID]);
  165. }
  166. return rationNodes;
  167. };
  168. ration.prototype.getInsertRationData = function (billsID, preRation, rationType) {
  169. var br = this.getBillsSortRation(billsID);
  170. var updateData = [];
  171. if (preRation) {
  172. var preIndex = br.indexOf(preRation), i;
  173. updateData.push({updateType: 'ut_create', updateData: this.getTempRationData(this.getNewRationID(), billsID, preIndex < br.length - 1 ? br[preIndex + 1].serialNo : br[preIndex].serialNo + 1, rationType)});
  174. for (i = preIndex + 1; i < br.length; i++) {
  175. 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)});
  176. }
  177. } else {
  178. updateData.push({updateType: 'ut_create', updateData: this.getTempRationData(this.getNewRationID(), billsID, br.length > 0 ? br[br.length - 1].serialNo + 1 : 1, rationType)});
  179. }
  180. return updateData;
  181. };
  182. ration.prototype.getCounterData = function (count) {
  183. var updateData = {'projectID': this.project.ID()};
  184. if (count) {
  185. updateData[this.getSourceType()] = this.maxRationID() + count;
  186. } else {
  187. updateData[this.getSourceType()] = this.maxRationID() + 1;
  188. }
  189. return updateData;
  190. };
  191. ration.prototype.insertRation = function (billsID, preRation, rationType) {
  192. var br = this.getBillsSortRation(billsID);
  193. let insertData = this.getInsertRationData(billsID, preRation, rationType);
  194. this.project.pushNow('insertRation', [this.getSourceType(), this.project.projCounter()],
  195. [insertData, this.getCounterData()]);
  196. var newRation = null;
  197. let newID = -1;
  198. for(let data of insertData){
  199. if(data.updateType === 'ut_create'){
  200. newID = data.updateData.ID;
  201. }
  202. }
  203. if (preRation) {
  204. var preIndex = br.indexOf(preRation), i;
  205. newRation = this.getTempRationData(newID, billsID, preIndex < br.length - 1 ? br[preIndex + 1].serialNo : br[preIndex].serialNo + 1, rationType);
  206. this.datas.push(newRation);
  207. for (i = preIndex + 1; i < br.length; i++) {
  208. br[i].serialNo = i < br.length - 1 ? br [i + 1].serialNo : br[i].serialNo + 1;
  209. }
  210. } else {
  211. newRation = this.getTempRationData(newID, billsID, br.length > 0 ? br[br.length - 1].serialNo + 1 : 1, rationType);
  212. this.datas.push(newRation);
  213. }
  214. return newRation;
  215. };
  216. ration.prototype.insertStdRation = function (billsID, preRation, std) {
  217. var br = this.getBillsSortRation(billsID), updateData = this.getInsertRationData(billsID, preRation, rationType.ration), newRation = null, that = this;
  218. updateData.forEach(function (data) {
  219. if (data.updateType === 'ut_create') {
  220. data.updateData.code = std.code;
  221. data.updateData.name = std.name;
  222. data.updateData.caption = std.caption;
  223. data.updateData.unit = std.unit;
  224. data.updateData.libID = std.rationRepId;
  225. data.updateData.content = std.jobContent;
  226. if (std.chapter) {
  227. data.updateData.comments = std.chapter.explanation;
  228. data.updateData.ruleText = std.chapter.ruleText;
  229. }
  230. data.updateData.from = std.type === 'complementary' ? 'cpt' : 'std';
  231. data.updateData.programID = std.feeType;
  232. data.updateData.rationAssList = projectObj.project.ration_ass.CreateNewAss(std);
  233. // calculate ration Quantity
  234. that.CalculateQuantity(data.updateData);
  235. newRation = data.updateData;
  236. }
  237. });
  238. this.project.pushNow('insertRation', [this.getSourceType(), this.project.projCounter()], [updateData, this.getCounterData()]);
  239. //newRation.ID = this.getNewRationID();
  240. if (preRation) {
  241. var preIndex = br.indexOf(preRation), i;
  242. this.datas.push(newRation);
  243. for (i = preIndex + 1; i < br.length; i++) {
  244. br[i].serialNo = i < br.length - 1 ? br [i + 1].serialNo : br[i].serialNo + 1;
  245. }
  246. } else {
  247. this.datas.push(newRation);
  248. }
  249. return newRation;
  250. };
  251. ration.prototype.getDeleteData = function (rationData) {
  252. var updateData = [];
  253. updateData.push({'updateType': 'ut_delete', 'updateData': {'ID': rationData.ID, 'projectID': this.project.ID()}});
  254. return updateData;
  255. };
  256. ration.prototype.delete = function (ration) {
  257. var ration_glj =projectObj.project.ration_glj;
  258. this.project.pushNow('deleteRation', [this.getSourceType(),ration_glj.getSourceType()], [this.getDeleteData(ration),ration_glj.getDeleteDataByRation(ration)]);
  259. this.deleteSubListOfRation(ration);
  260. this.datas.splice(this.datas.indexOf(ration), 1);
  261. };
  262. ration.prototype.removeByID = function(ID){
  263. _.remove(this.datas,{'ID':ID});
  264. };
  265. ration.prototype.getDeleteDataByBill = function (nodes) {
  266. let updateData = [];
  267. for (let node of nodes) {
  268. if (node.children.length > 0) {
  269. updateData = updateData.concat(this.getDeleteDataByBill(node.children));
  270. } else {
  271. let rations = this.getBillsSortRation(node.getID());
  272. for (let r of rations) {
  273. updateData.push({'updateType': 'ut_delete', 'updateData': {'ID': r.ID, 'projectID': this.project.ID()}});
  274. }
  275. }
  276. }
  277. return updateData;
  278. };
  279. ration.prototype.deleteByBills = function (nodes) {
  280. for (let node of nodes) {
  281. if (node.children.length > 0) {
  282. this.deleteByBills(node.children);
  283. } else {
  284. let rations = this.getBillsSortRation(node.getID());
  285. for (let r of rations) {
  286. this.datas.splice(this.datas.indexOf(r), 1);
  287. }
  288. }
  289. }
  290. }
  291. ration.prototype.getChangePosUpdateData = function (ration1, ration2) {
  292. var updateData = [];
  293. updateData.push({updateType: 'ut_update', updateData: this.getTempRationData(ration1.ID, ration1.billsItemID, ration2.serialNo)});
  294. updateData.push({updateType: 'ut_update', updateData: this.getTempRationData(ration2.ID, ration2.billsItemID, ration1.serialNo)});
  295. return updateData;
  296. };
  297. ration.prototype.changePos = function (ration1, ration2) {
  298. var updateData = this.getChangePosUpdateData(ration1, ration2);
  299. this.project.pushNow('insertRation', [this.getSourceType()], [updateData]);
  300. var preSerialNo = ration1.serialNo;
  301. ration1.serialNo = ration2.serialNo;
  302. ration2.serialNo = preSerialNo;
  303. };
  304. ration.prototype.updateField = function (ration, field, newValue) {
  305. calcFees.setFee(ration, field, newValue);
  306. let updateData = [];
  307. let data = {'ID': ration.ID, 'projectID': this.project.ID()};
  308. if (field === 'quantity') {
  309. data[field] = newValue;
  310. data.isFromDetail=0;
  311. // to do Calculate
  312. if (ration.fees) {
  313. data.fees = ration.fees;
  314. }
  315. } else if (field === 'feesIndex.common.unitFee') {
  316. // to do Calculate
  317. if (ration.fees) {
  318. data.fees = ration.fees;
  319. }
  320. } else {
  321. data[field] = newValue;
  322. }
  323. updateBillsOprRation();
  324. updateData.push({'updateType': 'ut_update', 'updateData': data});
  325. this.project.pushNow('updateBills', this.getSourceType(), updateData);
  326. };
  327. ration.prototype.updateRation = function (ration, updateNow) {
  328. let updateData = [];
  329. updateData.push({'updateType': 'ut_update', 'updateData': tools.formatRationUpdateData(ration)});
  330. if (updateNow) {
  331. this.project.pushNow('updateRations', this.getSourceType(), updateData);
  332. } else {
  333. this.project.push(this.getSourceType(), updateData);
  334. }
  335. };
  336. ration.prototype.FilterNumberFromUnit = function (unit) {
  337. let reg = new RegExp('^[0-9]+');
  338. if (reg.test(unit)) {
  339. return parseInt(unit.match(reg)[0]);
  340. } else {
  341. return 1;
  342. }
  343. };
  344. ration.prototype.CalculateQuantity = function (ration) {
  345. // calculate ration Quantity
  346. let quantity_decimal = getDecimal("ration.quantity");
  347. let process_decimal = getDecimal("process");
  348. if (optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan')) {
  349. let billsNode = this.project.Bills.tree.findNode(ration[this.project.masterField.ration]);
  350. let billsQuantity = billsNode.data.quantity ? billsNode.data.quantity : 0;
  351. billsQuantity=scMathUtil.roundForObj(billsQuantity,quantity_decimal);
  352. ration.quantityEXP="QDL";
  353. /* if (optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToRationUnit')) {
  354. ration.quantity = (billsQuantity / this.FilterNumberFromUnit(ration.unit)).toDecimal(quantity_decimal);
  355. } else {
  356. ration.quantity = billsQuantity.toDecimal(quantity_decimal);
  357. }*/
  358. ration.quantity = (billsQuantity / this.FilterNumberFromUnit(ration.unit)).toDecimal(quantity_decimal);//改成不管是否打勾都做转换
  359. ration.contain = scMathUtil.roundForObj(ration.quantity/billsQuantity,process_decimal);
  360. }
  361. };
  362. ration.prototype.updateRationCodes = function (recodes,cleanzmhs = false) {
  363. let libID = rationLibObj.getCurrentStdRationLibID();
  364. let libIDs = rationLibObj.getStdRationLibIDs();
  365. let defaultLibID = rationLibObj.getDefaultStdRationLibID();
  366. let engineering = projectInfoObj.projectInfo.property.engineering;
  367. let projectID = projectInfoObj.projectInfo.ID;
  368. let project = projectObj.project;
  369. let mainTree = project.mainTree;
  370. let nodeInfo =[];
  371. let refershNodes = [];
  372. if(libIDs == null){
  373. return;
  374. }
  375. for(let r of recodes){
  376. let needInstall = false;
  377. if(projectObj.project.isInstall()) {//如果是安装工程,要看需不需要生成安装增加费
  378. needInstall = project.Bills.isFBFX(r.node);
  379. }
  380. r.value===null||r.value===undefined?"":r.value = r.value.replace(/[\s\r\n]/g, "");//去掉空格回车换行等字符
  381. if(cleanzmhs == true||r.value != r.node.data.code){
  382. nodeInfo.push({ID:r.node.data.ID,billsItemID:r.node.data.billsItemID,newCode:r.value,needInstall:needInstall});
  383. refershNodes.push(r.node);
  384. }
  385. }
  386. let calQuantity = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
  387. $.bootstrapLoading.start();
  388. CommonAjax.post("/ration/replaceRations",{nodeInfo:nodeInfo,libIDs:libIDs,defaultLibID: defaultLibID,projectID:projectID,calQuantity:calQuantity,cleanzmhs:cleanzmhs},function (data) {
  389. for(let recode of data){
  390. let node = mainTree.getNodeByID(recode.ration.ID);
  391. if(node) {
  392. for(let temkey in recode.ration){//更新缓存
  393. node.data[temkey] = recode.ration[temkey];
  394. }
  395. node.data.feesIndex = {};
  396. //删除定额节点下的主材和设备节点
  397. project.ration_glj.removeNodeByRation(recode.ration,projectObj.mainController);
  398. project.Ration.deleteSubListOfRation(recode.ration);//删除旧定额下的相关记录
  399. //添加新的记录
  400. project.Ration.addSubListOfRation(recode);
  401. project.ration_glj.addToMainTree(recode.ration_gljs);
  402. }
  403. }
  404. project.projectGLJ.loadData(function () {
  405. mbzm_obj.nodeChanged = true;//子目模板关联刷新
  406. gljOprObj.showDataIfRationSelect(projectObj.project.mainTree.selected,"-111111111");//这里第二个参数是为了使改前和改后selectedID不一样,删除了的话下方的定额工料机不会刷新
  407. project.calcProgram.calcNodesAndSave(refershNodes);
  408. projectObj.mainController.refreshTreeNode(refershNodes, true);
  409. $.bootstrapLoading.end();
  410. });
  411. if(data.length < nodeInfo.length && nodeInfo[data.length].newCode!=null){//说明有部分定额编号没找到记录
  412. alert('当前库中找不到定额"' + nodeInfo[data.length].newCode + '"');
  413. }
  414. updateBillsOprRation();
  415. })
  416. };
  417. ration.prototype.addMultiRation = function (items, callback) {
  418. let me = this;
  419. let project = projectObj.project, sheetController = projectObj.mainController;
  420. let engineering = projectInfoObj.projectInfo.property.engineering;
  421. let selected = project.mainTree.selected, newSource = null, newNode = null,pre = null,br = null;
  422. let billItemID = null,serialNo=1,nextID=null;
  423. let needInstall = false;
  424. let newDatas = [];
  425. if (selected === null) { return; }
  426. if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
  427. if (selected.source.children.length > 0) {
  428. alert('当前清单已有清单子项,不能套用定额。');
  429. } else if (selected.data.calcBase&&selected.data.calcBase!="") {
  430. alert('当前有基数计算,不能插入定额/量价/人材机。');
  431. } else {
  432. if(selected.data.type === billType.FB){
  433. return;
  434. }
  435. billItemID = selected.source.getID();
  436. nextID = selected.tree.rootID();
  437. br = this.getBillsSortRation(billItemID);
  438. serialNo = br.length > 0 ? br[br.length - 1].serialNo + 1 : 1
  439. }
  440. } else if (selected.sourceType === project.Ration.getSourceType()) {
  441. billItemID = selected.getParentID();
  442. br = this.getBillsSortRation(billItemID);
  443. serialNo = selected.data.serialNo+1;
  444. nextID = selected.getNextSiblingID();
  445. pre = selected.source;
  446. };
  447. if(billItemID){
  448. let calQuantity = optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
  449. if(projectObj.project.isInstall()) {//如果是安装工程,要看需不需要生成安装增加费
  450. let billsNode = project.mainTree.getNodeByID(billItemID);
  451. needInstall = project.Bills.isFBFX(billsNode);//在分部分项插入的定额才需要定额安装增加费
  452. }
  453. for(let i = 0; i < items.length; i++){
  454. let newData = me.getTempRationData(me.getNewRationID(), billItemID, serialNo, items[i].rationType);
  455. serialNo++;
  456. let brUpdate = [];
  457. //更新兄弟节点的序列号
  458. if (i ===0 && pre) {
  459. let preIndex = br.indexOf(pre), i;
  460. for (i = preIndex + 1; i < br.length; i++) {
  461. br[i].serialNo = i < br.length - 1 ? br [i + 1].serialNo + items.length - 1 : br[i].serialNo + items.length;
  462. brUpdate.push({projectID:newData.projectID,ID:br[i].ID,serialNo:br[i].serialNo});
  463. }
  464. }
  465. newDatas.push({itemQuery: items[i].itemQuery, newData: newData, defaultLibID: rationLibObj.getDefaultStdRationLibID(), calQuantity: calQuantity, brUpdate: brUpdate, needInstall: needInstall})
  466. }
  467. let showLoding = true;
  468. $.bootstrapLoading.start();
  469. //保证由于异步的关系loading界面被隐藏,比如清单指引插入清单定额时,endUpdate中提前隐藏了loading
  470. let interval =setInterval(function () {
  471. if(!$.bootstrapLoading.isLoading()&& showLoding){
  472. $.bootstrapLoading.start();
  473. clearInterval(interval);
  474. }
  475. else{
  476. clearInterval(interval);
  477. }
  478. }, 100);
  479. CommonAjax.post("/ration/addMultiRation",{newDatas: newDatas},function (rstData) {
  480. let newNodes = [];
  481. //更新缓存
  482. for(let data of rstData){
  483. me.datas.push(data.ration);
  484. me.addSubListOfRation(data);
  485. //插入树节点
  486. newSource = data.ration;
  487. newNode = project.mainTree.insert(billItemID, nextID, newSource.ID);
  488. newNodes.push(newNode);
  489. nextID = project.mainTree.selected.getNextSiblingID();
  490. newNode.source = newSource;
  491. newNode.sourceType = project.Ration.getSourceType();
  492. newNode.data = newSource;
  493. ProjectController.syncDisplayNewNode(sheetController, newNode);
  494. }
  495. project.projectGLJ.loadData(function () {
  496. for(let data of rstData){
  497. project.ration_glj.addToMainTree(data.ration_gljs);
  498. }
  499. projectObj.mainController.refreshTreeNode(newNodes, false);
  500. if(project.Bills.isFBFX(newNodes[0])) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
  501. project.installation_fee.calcInstallationFee(function (isChange,rations) {
  502. if(isChange){
  503. rations = rations.concat(newNodes);
  504. project.calcProgram.calcNodesAndSave(rations);
  505. }else {
  506. project.calcProgram.calcNodesAndSave(newNodes);
  507. }
  508. });
  509. }else {
  510. project.calcProgram.calcNodesAndSave(newNodes);
  511. }
  512. updateBillsOprRation();
  513. if(callback){
  514. callback();
  515. }
  516. showLoding = false;
  517. $.bootstrapLoading.end();
  518. });
  519. })
  520. }
  521. };
  522. ration.prototype.insertVolumePrice = function(type){
  523. this.addNewRation(null,rationType.volumePrice,function (newNode) {//插入人工不需要自动定位到编号列
  524. projectObj.selectColAndFocus(newNode,null);
  525. },true,type);
  526. };
  527. ration.prototype.addNewRation = function (itemQuery,rationType,callback=null,isEmpty=false,priceType) {//priceType 是量价类型
  528. let me = this;
  529. let project = projectObj.project, sheetController = projectObj.mainController;
  530. let engineering = projectInfoObj.projectInfo.property.engineering;
  531. let selected = project.mainTree.selected, newSource = null, newNode = null,pre=null,br=null;
  532. let billItemID = null,serialNo=1,nextID=null;
  533. let needInstall = false;
  534. if (selected === null) { return null; }
  535. if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
  536. if(selected.data.type === billType.FB){
  537. return null;
  538. }
  539. else if (selected.source.children.length > 0) {
  540. alert('当前清单已有清单子项,不能套用定额。');
  541. } else if (selected.data.calcBase&&selected.data.calcBase!="") {
  542. alert('当前有基数计算,不能插入定额/量价/人材机。');
  543. } else {
  544. billItemID = selected.source.getID();
  545. nextID = selected.tree.rootID();
  546. br = this.getBillsSortRation(billItemID);
  547. serialNo = br.length > 0 ? br[br.length - 1].serialNo + 1 : 1
  548. }
  549. } else if (selected.sourceType === project.Ration.getSourceType()) {
  550. billItemID = selected.getParentID();
  551. br = this.getBillsSortRation(billItemID);
  552. serialNo = selected.data.serialNo+1;
  553. nextID = selected.getNextSiblingID();
  554. pre = selected.source;
  555. };
  556. if(billItemID){
  557. let newID = me.getNewRationID();
  558. let newData = me.getTempRationData(newID, billItemID, serialNo, rationType,priceType);
  559. let calQuantity = isEmpty===true?false:optionsOprObj.getOption(optionsOprObj.optionsTypes.GENERALOPTS, 'rationQuanACToBillsQuan');
  560. let brUpdate = [];
  561. //更新兄弟节点的序列号
  562. if (pre) {
  563. let preIndex = br.indexOf(pre), i;
  564. for (i = preIndex + 1; i < br.length; i++) {
  565. br[i].serialNo = i < br.length - 1 ? br [i + 1].serialNo : br[i].serialNo + 1;
  566. brUpdate.push({projectID:newData.projectID,ID:br[i].ID,serialNo:br[i].serialNo});
  567. }
  568. }
  569. if(projectObj.project.isInstall()) {//如果是安装工程,要看需不需要生成安装增加费
  570. let billsNode = project.mainTree.getNodeByID(billItemID);
  571. needInstall = project.Bills.isFBFX(billsNode);//在分部分项插入的定额才需要定额安装增加费
  572. }
  573. $.bootstrapLoading.start();
  574. CommonAjax.post("/ration/addNewRation",{itemQuery:itemQuery,newData:newData,defaultLibID: rationLibObj.getDefaultStdRationLibID(),calQuantity:calQuantity,brUpdate:brUpdate,needInstall:needInstall},function (data) {
  575. //更新缓存
  576. me.datas.push(data.ration);
  577. me.addSubListOfRation(data);
  578. //插入树节点
  579. newSource = data.ration;
  580. newNode = project.mainTree.insert(billItemID, nextID, newSource.ID);
  581. newNode.source = newSource;
  582. newNode.sourceType = project.Ration.getSourceType();
  583. newNode.data = newSource;
  584. project.projectGLJ.loadData(function () {
  585. ProjectController.syncDisplayNewNode(sheetController, newNode);
  586. project.ration_glj.addToMainTree(data.ration_gljs);
  587. projectObj.mainController.refreshTreeNode([newNode], false);
  588. project.calcProgram.calcAndSave(newNode,function () {
  589. if(project.Bills.isFBFX(newNode)) { //判断是否属于分部分项工程 ,是的话才需要做计取安装费计算
  590. installationFeeObj.calcInstallationFee();
  591. }
  592. });
  593. //如果添加规则中,添加内容为定额子目,则更新相关清单
  594. updateBillsOprRation();
  595. if(callback){
  596. callback(newNode);
  597. }
  598. $.bootstrapLoading.end();
  599. });
  600. })
  601. return newNode;
  602. }
  603. else return null;
  604. };
  605. ration.prototype.addNewRationFast = function (rationType,callback) {
  606. let me = this;
  607. let project = projectObj.project, sheetController = projectObj.mainController;
  608. let engineering = projectInfoObj.projectInfo.property.engineering;
  609. let selected = project.mainTree.selected, newSource = null, newNode = null,pre=null,br=null;
  610. let billItemID = null,serialNo=1,nextID=null;
  611. if (selected === null) { return null; }
  612. if (selected.sourceType === project.Bills.getSourceType() && selected.depth() > 0) {
  613. if(selected.data.type === billType.FB){
  614. return null;
  615. }
  616. else if (selected.source.children.length > 0) {
  617. alert('当前清单已有清单子项,不能套用定额。');
  618. } else if (selected.data.calcBase&&selected.data.calcBase!="") {
  619. alert('当前有基数计算,不能插入定额/量价/人材机。');
  620. } else {
  621. billItemID = selected.source.getID();
  622. nextID = selected.tree.rootID();
  623. br = this.getBillsSortRation(billItemID);
  624. serialNo = br.length > 0 ? br[br.length - 1].serialNo + 1 : 1
  625. }
  626. } else if (selected.sourceType === project.Ration.getSourceType()) {
  627. billItemID = selected.getParentID();
  628. br = this.getBillsSortRation(billItemID);
  629. serialNo = selected.data.serialNo+1;
  630. nextID = selected.getNextSiblingID();
  631. pre = selected.source;
  632. };
  633. if(billItemID){
  634. let newID = me.getNewRationID();
  635. let newData = me.getTempRationData(newID, billItemID, serialNo, rationType);
  636. let brUpdate = [];
  637. //更新兄弟节点的序列号
  638. if (pre) {
  639. let preIndex = br.indexOf(pre), i;
  640. for (i = preIndex + 1; i < br.length; i++) {
  641. br[i].serialNo = i < br.length - 1 ? br [i + 1].serialNo : br[i].serialNo + 1;
  642. brUpdate.push({projectID:newData.projectID,ID:br[i].ID,serialNo:br[i].serialNo});
  643. }
  644. }
  645. if(projectObj.project.isInstall()) {//如果是安装工程,要看需不需要生成安装增加费
  646. let billsNode = project.mainTree.getNodeByID(billItemID);
  647. }
  648. $.bootstrapLoading.start();
  649. newNode = project.mainTree.insert(billItemID, nextID, newID);
  650. newNode.sourceType = project.Ration.getSourceType();
  651. newNode.data = newData;
  652. CommonAjax.post("/ration/addNewRation",{itemQuery:null,newData:newData,defaultLibID: rationLibObj.getDefaultStdRationLibID(),calQuantity:false,brUpdate:brUpdate,needInstall:false},function (data) {
  653. //更新缓存
  654. me.datas.push(data.ration);
  655. me.addSubListOfRation(data);
  656. //插入树节点
  657. newSource = data.ration;
  658. newNode.source = newSource;
  659. newNode.data = newSource;
  660. })
  661. ProjectController.syncDisplayNewNode(sheetController, newNode);
  662. if(callback){
  663. callback(newNode);
  664. }
  665. $.bootstrapLoading.end();
  666. return newNode;
  667. }
  668. else return null;
  669. };
  670. ration.prototype.deleteSubListOfRation = function(ration){
  671. projectObj.project.ration_glj.deleteByRation(ration);
  672. projectObj.project.ration_coe.deleteByRation(ration);
  673. projectObj.project.quantity_detail.deleteByRation(ration);
  674. projectObj.project.ration_installation.deleteByRation(ration);
  675. projectObj.project.ration_template.deleteByRation(ration);
  676. };
  677. ration.prototype.addSubListOfRation = function (data) {
  678. project.ration_glj.addDatasToList(data.ration_gljs);
  679. project.ration_coe.addDatasToList(data.ration_coes);
  680. project.ration_installation.addDatasToList(data.ration_installations);
  681. project.ration_template.addDatasToList(data.ration_templates);
  682. project.quantity_detail.addDatasToList(data.quantity_details);
  683. };
  684. ration.prototype.replaceRation = function (ration, std) {
  685. this.project.beginUpdate('replaceRation');
  686. // delete
  687. let ration_glj =projectObj.project.ration_glj;
  688. this.project.push(this.project.ration_glj.getSourceType(), this.project.ration_glj.getDeleteDataByRation(ration));
  689. this.deleteSubListOfRation(ration);
  690. // insertNewRation
  691. let updateData = [];
  692. ration.code = std.code;
  693. ration.name = std.name;
  694. ration.caption = std.caption;
  695. ration.unit = std.unit;
  696. ration.libID = std.rationRepId;
  697. ration.content = std.jobContent;
  698. ration.adjustState = '';
  699. if (std.chapter) {
  700. ration.comments = std.chapter.explanation;
  701. ration.ruleText = std.chapter.ruleText;
  702. }
  703. ration.from = std.type === 'complementary' ? 'cpt' : 'std';
  704. ration.programID = std.feeType;
  705. ration.rationAssList = projectObj.project.ration_ass.CreateNewAss(std);
  706. // calculate ration Quantity
  707. this.CalculateQuantity(ration);
  708. updateData.push({updateType: 'ut_update', updateData: ration});
  709. this.project.push(this.getSourceType(), updateData);
  710. this.project.endUpdate();
  711. };
  712. ration.prototype.updateContain=function (value,node) {
  713. let me = this;
  714. if(isNaN(value)){
  715. alert("当前输入的数据类型不正确,请重新输入");
  716. projectObj.mainController.refreshTreeNode([node]);
  717. return;
  718. }
  719. if(node.data.quantityEXP=="GCLMXHJ"){//如果定额工程量是来自工程量明细
  720. hintBox.infoBox('操作确认', '已有工程量明细,是否清空明细表?', 2, function () {
  721. node.data.isFromDetail=0;
  722. project.quantity_detail.cleanQuantityDetail(node,true);
  723. me.doContainUpdate(value,node);
  724. }, function () {
  725. projectObj.mainController.refreshTreeNode([node]);
  726. },['确定','取消'],false);
  727. }else {
  728. me.doContainUpdate(value,node);
  729. }
  730. };
  731. ration.prototype.getNearRations = function (ration,callback) {
  732. if(ration&&ration.code && ration.code !=""){
  733. CommonAjax.post("/ration/getSameSectionRations",{from:ration.from,code:ration.code,libID:ration.libID},function(rations){
  734. callback(rations);
  735. })
  736. }else {
  737. callback([]);
  738. }
  739. };
  740. ration.prototype.doContainUpdate = function (value,node) {
  741. let billNode = node.parent;
  742. let contain = scMathUtil.roundForObj(value,getDecimal("process"));
  743. let billQuantity = billNode.data.quantity||billNode.data.quantity!=""?billNode.data.quantity:0;
  744. billQuantity = parseFloat(billQuantity);
  745. node.data.contain = contain;
  746. node.data.quantityEXP="QDL*"+contain;
  747. node.data.quantity=scMathUtil.roundForObj(billQuantity*contain,getDecimal("quantity",node));
  748. let times = parseInt(node.data.unit);
  749. if (!isNaN(times)) {
  750. node.data.quantityEXP+='*'+times;
  751. }
  752. // node.data.quantity = projectObj.project.quantity_detail.autoTransformQuantity(node.data.quantity,node);//按单位做转换
  753. node.changed = true;
  754. project.calcProgram.calcAndSave(node, function () {
  755. project.projectGLJ.calcQuantity();
  756. });
  757. projectObj.mainController.refreshTreeNode(node.children);//刷新子工料机树节点总消耗量
  758. };
  759. ration.prototype.addRationChecking=function(selected){
  760. if (selected) {// Vincent, 2018-01-02
  761. if(selected.sourceType === project.Ration.getSourceType()){ // 焦点行是定额/量价/工料机,有效显示。
  762. return false;
  763. }else if(selected.sourceType === project.Bills.getSourceType()){
  764. if(selected.data.type == billType.FX||selected.data.type == billType.BX){//焦点行是分项,有效显示。
  765. return false
  766. }
  767. if(selected.data.type == billType.BILL && selected.source.children.length === 0){//焦点行是清单,且没有子项,有效显示。
  768. return false
  769. }
  770. }
  771. }
  772. return true;
  773. };
  774. ration.prototype.canAdd = function (node) { // CSL.2018.07.23
  775. if (!node) return false;
  776. if (calcTools.isRationCategory(node)) return true;
  777. if (calcTools.isBill(node)){
  778. if (node.data.type == billType.FX || node.data.type == billType.BX) return true; // 分项、补项
  779. if (calcTools.isLeafBill(node)
  780. && (node.data.type != billType.DXFY)
  781. && (node.data.type != billType.FB)
  782. && project.Bills.isMeasure(node)) return true; // 叶子清单项
  783. };
  784. return false;
  785. }
  786. ration.prototype.getAllInstallTypeRation = function () {//取所有计取安装增加费生成的定额
  787. return _.filter(this.datas,{'type':rationType.install});
  788. };
  789. ration.prototype.getLabourTotalFee=function(ration){//feesIndex.labour.totalFee 取定额的人工费合价
  790. if(ration.feesIndex&&ration.feesIndex.labour&&ration.feesIndex.labour.totalFee){
  791. return ration.feesIndex.labour.totalFee;
  792. }else {
  793. return 0;
  794. }
  795. };
  796. ration.prototype.getMaterialTotalFee=function(ration){//feesIndex.material.totalFee 取定额的材料费合价
  797. if(ration.feesIndex&&ration.feesIndex.material&&ration.feesIndex.material.totalFee){
  798. return ration.feesIndex.material.totalFee;
  799. }else {
  800. return 0;
  801. }
  802. } ;
  803. ration.prototype.getMachineTotalFee=function(ration){//feesIndex.machine.totalFee 取定额的机械费合价
  804. if(ration.feesIndex&&ration.feesIndex.machine&&ration.feesIndex.machine.totalFee){
  805. return ration.feesIndex.machine.totalFee;
  806. }else {
  807. return 0;
  808. }
  809. } ;
  810. //获取定额前缀
  811. ration.prototype.getRationPrefix = function(defaultLibID, ration){
  812. if(defaultLibID !== ration.libID){
  813. return rationPrefix.borrow;
  814. }
  815. if(ration.from && ration.from === rationFrom.cpt){
  816. return rationPrefix.complementary;
  817. }
  818. return rationPrefix.none;
  819. };
  820. return new ration(project);
  821. }
  822. };
  823. function FilterNumberFromUnit (unit) {
  824. let reg = new RegExp('^[0-9]+');
  825. if (reg.test(unit)) {
  826. return parseInt(unit.match(reg)[0]);
  827. } else {
  828. return 1;
  829. }
  830. };