calc_program.js 112 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528
  1. /**
  2. * Created by CSL on 2017-07-19.
  3. * 计算程序。所有定额、清单、父清单的计算都从此入。
  4. */
  5. let calcTools = {
  6. getNodeByFlag: function (flag) {
  7. let bill = cbTools.findBill(flag);
  8. if (bill) return this.getNodeByID(bill.ID)
  9. else return null;
  10. },
  11. getNodeByID: function (ID){
  12. return cbTools.getNodeByID(ID);
  13. },
  14. // 是否是标题清单
  15. /*isTitleBills: function (node) {
  16. let flag = node.getFlag();
  17. return titleFlags.includes(flag);
  18. },*/
  19. isBill: function(treeNode){
  20. return treeNode.sourceType === ModuleNames.bills;
  21. },
  22. isParentBill: function (treeNode) {
  23. return this.isBill(treeNode) &&
  24. treeNode.source.children &&
  25. treeNode.source.children.length > 0;
  26. },
  27. isLeafBill: function(treeNode){ // 下面挂有定额的清单也是叶子清单
  28. return this.isBill(treeNode) &&
  29. treeNode.source.children &&
  30. treeNode.source.children.length === 0;
  31. },
  32. isLeafNode: function(treeNode){ // 最底层结点,如定额等。
  33. return treeNode.children.length === 0;
  34. },
  35. isBill_DXFY: function(treeNode){
  36. return this.isBill(treeNode) && treeNode.data.type == billType.DXFY;
  37. },
  38. isBill_FB: function(treeNode){
  39. return this.isBill(treeNode) && treeNode.data.type == billType.FB;
  40. },
  41. isBill_FX: function(treeNode){
  42. return this.isBill(treeNode) && treeNode.data.type == billType.FX;
  43. },
  44. isBill_BILL: function(treeNode){
  45. return this.isBill(treeNode) && treeNode.data.type == billType.BILL;
  46. },
  47. isBill_BX: function(treeNode){
  48. return this.isBill(treeNode) && treeNode.data.type == billType.BX;
  49. },
  50. isNullBill: function (treeNode) {
  51. return this.isLeafBill(treeNode) && (treeNode.children.length === 0) && (!treeNode.data.calcBase);
  52. },
  53. isCalcBaseBill: function(treeNode){
  54. return this.isLeafBill(treeNode) && (treeNode.children.length === 0) && (treeNode.data.calcBase);
  55. },
  56. isTotalCostBill: function (treeNode) {
  57. return treeNode.data.flagsIndex && treeNode.data.flagsIndex.fixed && treeNode.data.flagsIndex.fixed.flag &&
  58. treeNode.data.flagsIndex.fixed.flag == fixedFlag.TOTAL_COST;
  59. },
  60. isRationCategory: function(treeNode){
  61. return treeNode.sourceType === ModuleNames.ration;
  62. },
  63. isRationItem: function(treeNode){
  64. return this.isRationCategory(treeNode) && treeNode.data.type === rationType.ration;
  65. },
  66. isCalcManageRation:function(treeNode){
  67. return this.isRationCategory(treeNode) && (treeNode.data.type === rationType.ration || treeNode.data.type === rationType.install|| treeNode.data.type === rationType.itemIncrease);
  68. },
  69. isVolumePrice: function (treeNode) {
  70. return this.isRationCategory(treeNode) && treeNode.data.type === rationType.volumePrice;
  71. },
  72. isGljRation: function (treeNode) {
  73. return this.isRationCategory(treeNode) && treeNode.data.type === rationType.gljRation;
  74. },
  75. isVP_or_GLJR: function (treeNode) { // 是量价或工料机类型的定额
  76. return this.isRationCategory(treeNode) &&
  77. (treeNode.data.type == rationType.volumePrice || treeNode.data.type == rationType.gljRation);
  78. },
  79. isSameTypeNode: function (node1, node2) {
  80. if (node1.parent && node2.parent && (node1.parent === node2.parent) && (node1.sourceType === node1.sourceType)
  81. && (node1.data && node2.data && node1.data.type === node2.data.type)){
  82. return true;
  83. }
  84. return false;
  85. },
  86. isInheritFrom: function (treeNode, flagsArr){
  87. let cur = treeNode;
  88. while (cur.parent) {
  89. cur = cur.parent;
  90. };
  91. let flag = -1;
  92. if (cur.data.flagsIndex && cur.data.flagsIndex.fixed && cur.data.flagsIndex.fixed.flag)
  93. flag = cur.data.flagsIndex.fixed.flag;
  94. return flagsArr.includes(flag);
  95. },
  96. isFBFX:function (treeNode) {
  97. return projectObj.project.Bills.isFBFX(treeNode);
  98. },
  99. isTechMeasure:function(treeNode){
  100. return projectObj.project.Bills.isTechMeasure(treeNode)
  101. },
  102. isInheritFrom:function(treeNode, flag){
  103. let rst = false;
  104. let curNode = treeNode;
  105. while (curNode){
  106. if (curNode.data && curNode.data.flagsIndex && curNode.data.flagsIndex.fixed &&
  107. curNode.data.flagsIndex.fixed.flag == flag){
  108. rst = true;
  109. break;
  110. }
  111. curNode = curNode.parent;
  112. };
  113. return rst;
  114. },
  115. getChildrenFormulaNodes: function (self, allFormulaNodesArr, parentNodes){ // 获取结点parentNodes下有公式的子结点
  116. let nodes = [];
  117. for (let pn of parentNodes){
  118. for (let node of allFormulaNodesArr){
  119. let cur = node;
  120. while (cur) {
  121. if (cur == pn && node != self){
  122. nodes.push(node);
  123. break;
  124. }
  125. cur = cur.parent;
  126. };
  127. };
  128. };
  129. return nodes;
  130. },
  131. /* 重要说明:
  132. 此时得到的GLJList,每条glj都有tenderQuantity = glj的quantity * 定额的quantity * glj的消耗量调整系数coe。
  133. 与定额的tenderQuantity无关,与定额的子目工程量调整系数coe无关。例如:
  134. 例:定额AB0003,工程量5,下含工料机“建筑综合工”,消耗量0.202。调价:人材机单价系数4,人工系数3,子目工程量系数2。
  135. 则GLJList中的建筑综合工:quantity 1.01, tenderQuantity 3.03。marketPrice 115, tenderPrice 460。
  136. */
  137. /*getGLJList: function (treeNode, needOneBill) {
  138. delete treeNode.data.gljList;
  139. if (this.isRationCategory(treeNode)) {
  140. if (!calcTools.isVP_or_GLJR(treeNode)){
  141. treeNode.data.gljList = projectObj.project.calcProgram.getGljArrByRation(treeNode.data);
  142. }
  143. }
  144. else if (this.isBill(treeNode)){
  145. treeNode.data.gljList = projectObj.project.ration_glj.getGljArrByBill(treeNode, needOneBill);
  146. };
  147. },*/
  148. getGLJList: function (treeNode, needOneBill) {
  149. delete treeNode.data.gljList;
  150. if (this.isRationCategory(treeNode)) {
  151. if (treeNode.data.type != rationType.volumePrice) {
  152. treeNode.data.gljList = projectObj.project.calcProgram.getGljArrByRation(treeNode.data);
  153. }
  154. }
  155. else if (this.isBill(treeNode)){
  156. let nodeQ = this.uiNodeQty(treeNode);
  157. let q = nodeQ ? nodeQ : 1;
  158. let rNodes = projectObj.project.Ration.getRationNodes(treeNode);
  159. let rations = rNodes.map(function (node) {return node.data});
  160. treeNode.data.gljList = projectObj.project.ration_glj.getGatherGljArrByRations(rations, needOneBill, q);
  161. };
  162. },
  163. getLeafBills: function (treeNode){
  164. let leafBills = [];
  165. function getBill(node){
  166. if (!node) return;
  167. if (calcTools.isLeafBill(node))
  168. leafBills.push(node);
  169. if (node.firstChild()) getBill(node.firstChild());
  170. if (node.nextSibling) getBill(node.nextSibling);
  171. };
  172. let fc = treeNode.firstChild();
  173. if (fc) getBill(fc);
  174. return leafBills;
  175. },
  176. forceSelect: function (treeNode, rowsCount = 1, colsCount = 2){
  177. projectObj.mainController.tree.selected = treeNode;
  178. let idx = projectObj.project.mainTree.items.indexOf(treeNode);
  179. let sheet = projectObj.mainSpread.getActiveSheet();
  180. sheet.setSelection(idx, 0, rowsCount, colsCount);
  181. sheet.showRow(idx, GC.Spread.Sheets.VerticalPosition.center);
  182. },
  183. clearFees: function (treeNode) {
  184. if (!treeNode || !treeNode.data.feesIndex) {
  185. return;
  186. }
  187. let clearFeeField = ['unitFee', 'totalFee', 'tenderUnitFee', 'tenderTotalFee'];
  188. for (let feeField in treeNode.data.feesIndex) {
  189. for (let subFee of clearFeeField) {
  190. treeNode.data.feesIndex[feeField][subFee] = 0;
  191. }
  192. }
  193. },
  194. initFees: function (treeNode){
  195. if (!treeNode.data.fees) {
  196. treeNode.data.fees = [];
  197. treeNode.data.feesIndex = {};
  198. treeNode.updateData.fees = []; // 在某种未知情况下,treeNode.data.fees有值,导致这句无法执行。下同
  199. treeNode.updateData.feesIndex = {};
  200. treeNode.changed = true;
  201. }
  202. else if (!treeNode.data.feesIndex){
  203. treeNode.data.feesIndex = {};
  204. treeNode.updateData.feesIndex = {};
  205. for (let fee of treeNode.data.fees){
  206. treeNode.data.feesIndex[fee.fieldName] = fee;
  207. treeNode.updateData.feesIndex[fee.fieldName] = fee;
  208. };
  209. treeNode.changed = true;
  210. };
  211. },
  212. initFeeField: function (treeNode, fieldName){
  213. this.initFees(treeNode);
  214. if (!treeNode.data.feesIndex[fieldName]) {
  215. let fee = {
  216. 'fieldName': fieldName,
  217. 'unitFee': 0,
  218. 'totalFee': 0,
  219. 'tenderUnitFee': 0,
  220. 'tenderTotalFee': 0
  221. };
  222. let newArr = treeNode.data.fees.filter(function (ele) {return ele.fieldName == fieldName});
  223. if (newArr.length > 0)
  224. fee = newArr[0]
  225. else
  226. treeNode.data.fees.push(fee);
  227. treeNode.data.feesIndex[fieldName] = fee;
  228. treeNode.updateData.fees = treeNode.data.fees;
  229. treeNode.changed = true;
  230. };
  231. },
  232. checkFeeField: function (treeNode, feeObj){
  233. if (!feeObj) return;
  234. if (feeObj.fieldName == '') return;
  235. // 初始化前,先拦截属性末定义、又要给该属性赋0的情况
  236. if (!treeNode.data.feesIndex || !treeNode.data.feesIndex[feeObj.fieldName]){
  237. if (feeObj.unitFee == 0 && feeObj.totalFee == 0 && feeObj.tenderUnitFee == 0 && feeObj.tenderTotalFee == 0) return;
  238. }
  239. this.initFeeField(treeNode, feeObj.fieldName);
  240. if (treeNode.data.feesIndex[feeObj.fieldName].unitFee != feeObj.unitFee){
  241. treeNode.data.feesIndex[feeObj.fieldName].unitFee = feeObj.unitFee;
  242. treeNode.changed = true;
  243. };
  244. if (treeNode.data.feesIndex[feeObj.fieldName].totalFee != feeObj.totalFee){
  245. treeNode.data.feesIndex[feeObj.fieldName].totalFee = feeObj.totalFee;
  246. treeNode.changed = true;
  247. };
  248. // 不知在何种情况下,tenderUnitFee、tenderTotalFee的值会变成NaN,这里提前处理一下
  249. if (isNaN(treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee))
  250. treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee = undefined;
  251. if (isNaN(treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee))
  252. treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee = undefined;
  253. if (treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee != feeObj.tenderUnitFee){
  254. treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee = feeObj.tenderUnitFee;
  255. treeNode.changed = true;
  256. };
  257. if (treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee != feeObj.tenderTotalFee){
  258. treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee = feeObj.tenderTotalFee;
  259. treeNode.changed = true;
  260. };
  261. },
  262. setFieldValue: function (treeNode, fieldName, value){
  263. if (value == null) value = 0;
  264. if (fieldName.includes('feesIndex')){
  265. let arr = fieldName.split('.');
  266. this.initFeeField(treeNode, arr[1]);
  267. if (treeNode.data.feesIndex[arr[1]][arr[2]] != value) {
  268. treeNode.data.feesIndex[arr[1]][arr[2]] = value;
  269. treeNode.updateData.feesIndex = treeNode.data.feesIndex;
  270. if(fieldName == 'feesIndex.common.unitFee'){
  271. let fee = _.find(treeNode.updateData.fees,{'fieldName':arr[1]});
  272. if(fee) fee[arr[2]] = value;
  273. }
  274. treeNode.changed = true;
  275. }
  276. }
  277. else{
  278. if (treeNode.data[fieldName] != value){
  279. treeNode.updateData[fieldName] = value;
  280. treeNode.changed = true;
  281. }
  282. };
  283. },
  284. initSummaryFee: function (treeNode){
  285. if (!treeNode.data.summaryFees){
  286. treeNode.data.summaryFees = {
  287. totalFee: 0,
  288. estimateFee: 0,
  289. safetyFee: 0,
  290. chargeFee: 0
  291. };
  292. treeNode.updateData.summaryFees = {
  293. totalFee: 0,
  294. estimateFee: 0,
  295. safetyFee: 0,
  296. chargeFee: 0
  297. };
  298. treeNode.changed = true;
  299. };
  300. },
  301. hasAdjustPrice: function(){ // 编办是否有材料的调整价发文
  302. if (projectObj.project.projSetting.glj_col && projectObj.project.projSetting.glj_col.showAdjustPrice == true)
  303. return true
  304. else
  305. return false;
  306. },
  307. // 参数fieldName值: 'common.totalFee'、'equipment.unitFee'
  308. getFee: function (treeNode, fieldName) {
  309. if (!treeNode) return 0;
  310. let ns = fieldName.split(".");
  311. if (ns.length != 2)
  312. return 0
  313. else if (treeNode.data.feesIndex && treeNode.data.feesIndex[ns[0]] && treeNode.data.feesIndex[ns[0]][ns[1]])
  314. return parseFloat(treeNode.data.feesIndex[ns[0]][ns[1]])
  315. else
  316. return 0;
  317. },
  318. // 该方法已精简,不支持价差基数的计算。
  319. rationBaseFee: function (treeNode, gljTypes, priceType, isTender){
  320. if (!treeNode.data.gljList) return 0;
  321. let me = this, result = 0;
  322. let price = 0, temp = 0, temp2 = 0;
  323. for (let glj of treeNode.data.gljList) {
  324. if (gljTypes.indexOf(glj.type) >= 0) {
  325. if (isTender){
  326. calcTools.calcGLJTenderPrice(glj);
  327. calcTools.calcGLJTenderQty(treeNode, glj);
  328. };
  329. let gljQ = isTender ? me.uiGLJQty(glj["tenderQuantity"]) : me.uiGLJQty(glj["quantity"]);
  330. let mprice = isTender ? me.uiGLJPrice(glj["tenderPrice"], glj) : me.uiGLJPrice(glj["marketPrice"], glj);
  331. let aprice = calcTools.hasAdjustPrice() ? me.uiGLJPrice(glj["adjustPrice"], glj) : me.uiGLJPrice(glj["basePrice"], glj);
  332. // if (priceType == priceTypes.ptBasePrice){ price = me.uiGLJPrice(glj["basePrice"], glj);}
  333. if (priceType == priceTypes.ptBasePrice){ price = glj["basePrice"];}
  334. else if (priceType == priceTypes.ptAdjustPrice){price = aprice;}
  335. else if (priceType == priceTypes.ptMarketPrice){price = mprice;}
  336. let nodeQ = calcTools.uiNodeQty(treeNode);
  337. temp = (price * gljQ * nodeQ).toDecimal(decimalObj.process);
  338. result = (result + temp).toDecimal(decimalObj.process);
  339. };
  340. };
  341. result = result.toDecimal(decimalObj.ration.totalPrice);
  342. return result;
  343. },
  344. // masterTypeFilter 过滤机械机型:[]全部, [1,2]特大机械 [3,4]中小机械。 detailType 如机上人工费、机械折旧费等
  345. machineDetailFee: function (treeNode, gljArr, masterTypeFilter, detailType, isTender) {
  346. if (!gljArr) return 0;
  347. let result = 0;
  348. let nodeQ = calcTools.uiNodeQty(treeNode) ? calcTools.uiNodeQty(treeNode) : 0;
  349. for (let glj of gljArr) {
  350. if (baseMachineMasterTypes.includes(glj.type)){
  351. // 机型不符
  352. if ((masterTypeFilter.length > 0) && (glj.model && !masterTypeFilter.includes(glj.model))) continue;
  353. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  354. // 获取机械组成物(调价不深入到组成物)
  355. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  356. if (!mds) mds = [];
  357. let mdSum = 0;
  358. for (let md of mds) {
  359. if (md.type == detailType) {
  360. let q = md["consumption"] ? md["consumption"] : 0;
  361. let p = md["basePrice"] ? md["basePrice"] : 0;
  362. mdSum = mdSum + (q * p).toDecimal(decimalObj.glj.unitPriceHasMix);
  363. mdSum = (mdSum).toDecimal(decimalObj.glj.unitPriceHasMix);
  364. }
  365. }
  366. result = (result + (nodeQ * gljQ * mdSum).toDecimal(decimalObj.process)).toDecimal(decimalObj.process)
  367. }
  368. }
  369. result = (result).toDecimal(decimalObj.ration.totalPrice);
  370. return result;
  371. },
  372. // 叶子清单、定额、总造价清单的暂估费。(父级清单是汇总子清单的暂估费,走计算程序逻辑,不在这里)
  373. estimateFee: function (treeNode, isBase, isTender){ // isBase, isTender 这两个参数用于基数计算
  374. let me = this, sumU = 0, sumT = 0, sumTU = 0, sumTT = 0;
  375. let nodeQ = me.uiNodeQty(treeNode);
  376. let nodeTQ = me.uiNodeTenderQty(treeNode);
  377. let isGather = (projectObj.project.property.zanguCalcMode == zanguCalcType.gatherMaterial);
  378. // 先汇总数量,再乘市场价。如果是叶子清单,进入这里的gljList中的材料,已经是同类材料跨定额汇总过的了。
  379. function eTFee(){
  380. let rst = {eT: 0, eTT: 0};
  381. if (!treeNode.data.gljList) return rst;
  382. let GLJObjs = [];
  383. for (let glj of treeNode.data.gljList) {
  384. if (!allMaterialTypes.includes(glj.type)) continue;
  385. if (glj.isEstimate){
  386. let q = me.uiGLJQty((glj.totalQuantity)).toDecimal(decimalObj.process);
  387. GLJObjs.push({code: glj.code, name: glj.name, specs: glj.specs, unit: glj.unit, type: glj.type, quantity: q,
  388. marketPrice: glj.marketPrice, tenderQuantity: glj.tenderQuantity, tenderPrice: glj.tenderPrice});
  389. }
  390. else{ // 组成物
  391. if (!compositionTypes.includes(glj.type)) continue;
  392. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  393. if (!mds) mds = [];
  394. for (let md of mds){
  395. if (!md.isEstimate) continue;
  396. let isExist = false;
  397. // let glj_totalQ = (nodeQ * me.uiGLJQty(glj.quantity)).toDecimal(decimalObj.glj.quantity);
  398. let glj_totalQ = me.uiGLJQty((glj.totalQuantity)).toDecimal(decimalObj.glj.quantity);
  399. let glj_tender_totalQ = (nodeTQ * me.uiGLJQty(glj.tenderQuantity)).toDecimal(decimalObj.glj.quantity);
  400. let mdQ = (glj_totalQ * me.uiGLJQty(md.consumption)).toDecimal(decimalObj.process);
  401. let mdTQ = (glj_tender_totalQ * me.uiGLJQty(md.consumption)).toDecimal(decimalObj.process);
  402. for (let obj of GLJObjs){
  403. if (gljOprObj.getIndex(md, gljKeyArray) == gljOprObj.getIndex(obj, gljKeyArray)){
  404. isExist = true;
  405. obj.quantity = (obj.quantity + mdQ).toDecimal(decimalObj.glj.quantity);
  406. obj.tenderQuantity = (obj.tenderQuantity + mdTQ).toDecimal(decimalObj.glj.quantity);
  407. break;
  408. }
  409. };
  410. if (!isExist)
  411. GLJObjs.push({code: md.code, name: md.name, specs: md.specs, unit: md.unit, type: md.type, quantity: mdQ,
  412. marketPrice: md.marketPrice, tenderQuantity: mdTQ, tenderPrice: md.tenderPrice});
  413. }
  414. }
  415. };
  416. for (let obj of GLJObjs){
  417. let t = (me.uiGLJQty(obj.quantity) * me.uiGLJPrice(obj.marketPrice, obj)).toDecimal(decimalObj.bills.totalPrice);
  418. rst.eT = (rst.eT + t).toDecimal(decimalObj.bills.totalPrice);
  419. let tt = (me.uiGLJQty(obj.tenderQuantity) * me.uiGLJPrice(obj.tenderPrice, obj)).toDecimal(decimalObj.bills.totalPrice);
  420. rst.eTT = (rst.eTT + tt).toDecimal(decimalObj.bills.totalPrice);
  421. };
  422. return rst;
  423. };
  424. // 汇总子结点的暂估合价
  425. function eTFeeByChildren(){
  426. let rst = {eT: 0, eTT: 0};
  427. for (let node of treeNode.children){
  428. if (node.data.feesIndex && node.data.feesIndex['estimate']) {
  429. rst.eT = (rst.eT + parseFloatPlus(node.data.feesIndex['estimate'].totalFee)).toDecimal(decimalObj.process);
  430. rst.eTT = (rst.eTT + parseFloatPlus(node.data.feesIndex['estimate'].tenderTotalFee)).toDecimal(decimalObj.process);
  431. };
  432. };
  433. rst.eT = (rst.eT).toDecimal(decimalObj.bills.totalPrice);
  434. rst.eTT = (rst.eTT).toDecimal(decimalObj.bills.totalPrice);
  435. return rst;
  436. };
  437. // 先数量乘市场价,再汇总
  438. function eUFee(){
  439. if (!treeNode.data.gljList) return 0;
  440. let rst = {eU: 0, eTU: 0};
  441. for (let glj of treeNode.data.gljList) {
  442. if (!allMaterialTypes.includes(glj.type)) continue;
  443. if (glj.isEstimate){
  444. rst.eU = rst.eU + (me.uiGLJQty(glj.quantity) * me.uiGLJPrice(glj.marketPrice, glj)).toDecimal(decimalObj.process);
  445. rst.eU = rst.eU.toDecimal(decimalObj.process);
  446. // 不能直接用glj.tenderPrice,这个值不可靠。当调价界面删除单价系数后,tenderPrice没有实时计算,取得的值为0
  447. rst.eTU = rst.eTU + (me.uiGLJQty(glj.tenderQuantity) * glj.tenderPrice).toDecimal(decimalObj.process);
  448. rst.eTU = rst.eTU.toDecimal(decimalObj.process);
  449. }
  450. else{ // 组成物。
  451. if (!compositionTypes.includes(glj.type)) continue;
  452. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  453. if (!mds) mds = [];
  454. for (let md of mds){
  455. if (!md.isEstimate) continue;
  456. let mdU = (me.uiGLJQty(md.consumption) * me.uiGLJPrice(md.marketPrice)).toDecimal(decimalObj.glj.unitPrice);
  457. rst.eU = rst.eU + (mdU * me.uiGLJQty(glj.quantity)).toDecimal(decimalObj.process);
  458. rst.eU = rst.eU.toDecimal(decimalObj.process);
  459. // 数量只调到工料机级别,工料机下的组成物不调量(如机械、混凝土)。调价调的是工料机下的组成物的价。
  460. let mdTU = (me.uiGLJQty(md.consumption) * md.tenderPrice).toDecimal(decimalObj.glj.unitPrice);
  461. rst.eTU = rst.eTU + (mdTU * glj.tenderQuantity).toDecimal(decimalObj.process);
  462. rst.eTU = rst.eTU.toDecimal(decimalObj.process);
  463. }
  464. }
  465. };
  466. rst.eU = rst.eU.toDecimal(decimalObj.bills.unitPrice);
  467. rst.eTU = rst.eTU.toDecimal(decimalObj.bills.unitPrice);
  468. return rst;
  469. };
  470. // 总造价暂估费
  471. if (me.isTotalCostBill(treeNode)){
  472. let nodes = projectObj.project.mainTree.roots;
  473. for (let node of nodes){
  474. if (me.isTotalCostBill(node)) break;
  475. let eU = 0, eT = 0, eTU = 0, eTT = 0;
  476. if (node.data.feesIndex && node.data.feesIndex.estimate){
  477. eU = node.data.feesIndex.estimate.unitFee;
  478. eT = node.data.feesIndex.estimate.totalFee;
  479. eTU = node.data.feesIndex.estimate.tenderUnitFee;
  480. eTT = node.data.feesIndex.estimate.tenderTotalFee;
  481. }
  482. else {
  483. eU = 0, eT = 0, eTU = 0, eTT = 0;
  484. };
  485. sumU = (sumU + parseFloatPlus(eU)).toDecimal(decimalObj.process);
  486. sumT = (sumT + parseFloatPlus(eT)).toDecimal(decimalObj.process);
  487. sumTU = (sumTU + parseFloatPlus(eTU)).toDecimal(decimalObj.process);
  488. sumTT = (sumTT + parseFloatPlus(eTT)).toDecimal(decimalObj.process);
  489. };
  490. sumU = (sumU).toDecimal(decimalObj.bills.unitPrice);
  491. sumT = (sumT).toDecimal(decimalObj.bills.totalPrice);
  492. sumTU = (sumTU).toDecimal(decimalObj.bills.unitPrice);
  493. sumTT = (sumTT).toDecimal(decimalObj.bills.totalPrice);
  494. }
  495. else if (me.isParentBill(treeNode)){ // 父清单不要汇总单价。
  496. let eTFBC = eTFeeByChildren();
  497. sumT = eTFBC.eT;
  498. sumTT = eTFBC.eTT;
  499. sumU = undefined;
  500. sumTU = undefined;
  501. }
  502. else if (me.isLeafBill(treeNode)){
  503. if (projectObj.project.Bills.isEngineerEst(treeNode)){
  504. if (treeNode.data.feesIndex['common'] != undefined){
  505. sumT = treeNode.data.feesIndex['common'].totalFee;
  506. sumU = treeNode.data.feesIndex['common'].unitFee;
  507. sumTT = treeNode.data.feesIndex['common'].tenderTotalFee;
  508. sumTU = treeNode.data.feesIndex['common'].tenderUnitFee;
  509. }
  510. }
  511. else{
  512. if (isGather){
  513. me.getGLJList(treeNode, false);
  514. let eTF = eTFee();
  515. sumT = eTF.eT;
  516. sumTT = eTF.eTT;
  517. }
  518. else{
  519. let eTFBC = eTFeeByChildren();
  520. sumT = eTFBC.eT;
  521. sumTT = eTFBC.eTT;
  522. };
  523. let q = nodeQ ? nodeQ : 1;
  524. sumU = (sumT / q).toDecimal(decimalObj.bills.totalPrice);
  525. let tq = nodeTQ ? nodeTQ : 1;
  526. sumTU = (sumTT / tq).toDecimal(decimalObj.bills.totalPrice);
  527. }
  528. }
  529. else if (me.isRationCategory(treeNode)){
  530. me.getGLJList(treeNode, false);
  531. let eUF = eUFee();
  532. sumU = eUF.eU;
  533. sumTU = eUF.eTU;
  534. if (isBase) {
  535. if (isTender)
  536. return sumTU
  537. else
  538. return sumU;
  539. };
  540. if (isGather){
  541. let eTF = eTFee();
  542. sumT = eTF.eT;
  543. sumTT = eTF.eTT;
  544. }
  545. else{
  546. sumT = (nodeQ * sumU).toDecimal(decimalObj.ration.totalPrice);
  547. sumTT = (nodeTQ * sumTU).toDecimal(decimalObj.ration.totalPrice);
  548. }
  549. };
  550. me.checkFeeField(treeNode, {'fieldName': 'estimate', 'unitFee': sumU, 'totalFee': sumT,
  551. 'tenderUnitFee': sumTU, 'tenderTotalFee': sumTT});
  552. },
  553. marketPriceToBase: function (treeNode, baseName, isTender) {
  554. if (!calcTools.isVP_or_GLJR(treeNode)) return;
  555. let result = 0, me = this;
  556. function isRCJZC(treeNode, baseName) { // 基数名称中是否包含人材机主设,且树结点类型要匹配一致
  557. let rst = (treeNode.data.subType === gljType.LABOUR && baseName.includes('人工')) || // 人工费、市场人工费
  558. (baseMaterialTypes.includes(treeNode.data.subType) && baseName.includes('材料')) ||
  559. // (treeNode.data.subType === gljType.GENERAL_MACHINE && (baseName.includes('机械') || baseName.includes('机具'))) ||
  560. (baseMachineTypes.includes(treeNode.data.subType) && (baseName.includes('机械') || baseName.includes('机具'))) ||
  561. (treeNode.data.subType === gljType.MAIN_MATERIAL && baseName.includes('主材')) ||
  562. (treeNode.data.subType === gljType.EQUIPMENT && baseName.includes('设备'));
  563. return rst;
  564. }
  565. if (baseName.includes('甲供') || baseName.includes('甲定') || baseName.includes('分包')) {
  566. result = 0;
  567. }
  568. else if (baseName.includes('价差')) {
  569. if (treeNode.data.type == rationType.gljRation) {
  570. if (isRCJZC(treeNode, baseName)) {
  571. let aprice = me.uiGLJPrice(treeNode.data.basePrice); // 量价虚拟的工料机不可能有发文,这里直接取定额价。
  572. let mprice = me.uiGLJPrice(treeNode.data.marketUnitFee);
  573. result = (mprice - aprice).toDecimal(decimalObj.ration.unitPrice);
  574. }
  575. }
  576. }
  577. else if (baseName.includes('机上人工')) {
  578. if (treeNode.data.subType === gljType.GENERAL_MACHINE) {
  579. let glj = {
  580. 'code': treeNode.data.code,
  581. 'name': treeNode.data.name,
  582. 'specs': treeNode.data.specs,
  583. 'unit': treeNode.data.unit,
  584. 'quantity': 1,
  585. 'type': treeNode.data.subType // 注意:这里要取subType
  586. };
  587. result = me.machineDetailFee(treeNode, [glj], [], gljType.MACHINE_LABOUR, isTender);
  588. }
  589. }
  590. else {
  591. if (isRCJZC(treeNode, baseName)) {
  592. if (calcTools.isVolumePrice(treeNode)){
  593. if (isTender){
  594. let coe = this.tenderCoe_GLJPrice();
  595. if (treeNode.data.marketUnitFee)
  596. result = (parseFloat(treeNode.data.marketUnitFee) * coe).toDecimal(decimalObj.ration.unitPrice)
  597. else
  598. result = 0;
  599. }
  600. else
  601. result = treeNode.data.marketUnitFee ? parseFloat(treeNode.data.marketUnitFee).toDecimal(decimalObj.ration.unitPrice) : 0
  602. }
  603. else if (calcTools.isGljRation(treeNode)) {
  604. // result = treeNode.data.basePrice ? parseFloat(treeNode.data.basePrice).toDecimal(decimalObj.ration.unitPrice) : 0;
  605. // 这里要取基价或市场价,但不能直接取basePrice,受限于项目属性的三个选项。
  606. if (baseName.includes('定额'))
  607. result = gljOprObj.getBasePrice(treeNode)
  608. else
  609. result = treeNode.data.marketUnitFee ? parseFloat(treeNode.data.marketUnitFee).toDecimal(decimalObj.ration.unitPrice) : gljOprObj.getBasePrice(treeNode);
  610. };
  611. }
  612. };
  613. return result;
  614. },
  615. partASupplyFee: function (treeNode, baseName, isTender, isRationPirce = true) { // isRationPirce 为true时表示取定额价。如:甲供定额材料费
  616. if (!treeNode.data.gljList) return 0;
  617. let projectGLJ = projectObj.project.projectGLJ;
  618. let supplyT = [];
  619. if (baseName.includes('甲供'))
  620. supplyT = [supplyType.BFJG, supplyType.WQJG] // 字段中存储的是汉字、数字混杂!
  621. else if (baseName.includes('甲定'))
  622. supplyT = [supplyType.JDYG];
  623. let gljT = [], compT = [];
  624. if (baseName.includes('人工')) gljT = [gljType.LABOUR]; // 含人工的:如甲供人工、甲定人工
  625. else if (baseName.includes('材料')){
  626. gljT = baseMaterialTypes;
  627. compT = compositionTypes;
  628. }
  629. else if (baseName.includes('机械') || baseName.includes('机具')) {
  630. gljT = baseMachineTypes;
  631. compT = [gljType.GENERAL_MACHINE, gljType.INSTRUMENT, gljType.OTHER_MACHINE_USED]; // 取并集,兼容重庆2018新定额
  632. }
  633. else if (baseName.includes('主材')) {
  634. gljT = [gljType.MAIN_MATERIAL];
  635. compT = [gljType.MAIN_MATERIAL];
  636. }
  637. else if (baseName.includes('设备')) {
  638. gljT = [gljType.EQUIPMENT];
  639. };
  640. // alert(JSON.stringify(projectGLJ.testGLJs()));
  641. let supplyGLJs = projectGLJ.getGLJsBySupply(supplyT, gljT);
  642. if (supplyGLJs.length == 0) return 0;
  643. let supplyGLJsIdx = {};
  644. for (let sglj of supplyGLJs){supplyGLJsIdx[sglj.id] = sglj};
  645. function isSupply(composition, supplies) {
  646. for (let supply of supplies){
  647. if(supply.code == composition.code && supply.name == composition.name && supply.unit == composition.unit &&
  648. supply.specs == composition.specs && supply.type == composition.type ){
  649. composition.basePrice = supply.unit_price.base_price;
  650. composition.marketPrice = supply.unit_price.market_price;
  651. composition.supply = supply.supply;
  652. composition.supplyX = 1;
  653. if (composition.supply == supplyType.BFJG){
  654. let Q = supply.quantity ? supply.quantity : 1;
  655. composition.supplyX = supply.supply_quantity / Q;
  656. }
  657. return true;
  658. }
  659. };
  660. return false;
  661. };
  662. let sum = 0;
  663. for (let glj of treeNode.data.gljList){
  664. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  665. let X = 1; // 部分甲供系数(默认1,即完全甲供)
  666. let tempSGLJ = supplyGLJsIdx[glj.projectGLJID];
  667. // 当前材料是甲供材料:①普通 ②商品硂等不计组成物的母体材料
  668. if (tempSGLJ) {
  669. // 处理部分甲供
  670. if (baseName.includes('甲供') && (tempSGLJ.supply == supplyType.BFJG)){
  671. let Q = isTender ? tempSGLJ.tenderQuantity : tempSGLJ.quantity;
  672. // let Q = tempSGLJ.quantity;
  673. Q = Q ? Q : 1;
  674. X = tempSGLJ.supply_quantity / Q;
  675. };
  676. let gljP = isRationPirce ? glj.basePrice : (isTender ? projectGLJ.getTenderMarketPrice(calcTools.getProjectGLJ(glj)) : glj.marketPrice);
  677. sum = (sum + gljP * gljQ * X).toDecimal(decimalObj.process);
  678. }
  679. else{ // 当前材料不是甲供材料
  680. // 混凝土等。组成物的母体,母体如果有组成物,则母体无法作为甲供材料,无法设置,此时要看其组成物是否是甲供材料;母体如果没有组成物,则母体有可能成为甲供材料。
  681. if (compT.includes(glj.type)) {
  682. let pGLJ = projectGLJ.getDataByID(glj.projectGLJID);
  683. let compositions = pGLJ.ratio_data; // 组成物明细
  684. if (compositions.length > 0){
  685. for (let c of compositions){
  686. if (isSupply(c, supplyGLJs)) {
  687. X = 1;
  688. if (baseName.includes('甲供') && (c.supply == supplyType.BFJG)){
  689. X = c.supplyX;
  690. };
  691. let cP = isRationPirce ? c.basePrice : (isTender ? projectGLJ.getTenderMarketPrice(calcTools.getProjectGLJ(c)) : c.marketPrice);
  692. sum = (sum + cP * c.consumption * gljQ * X).toDecimal(decimalObj.process);
  693. }
  694. }
  695. };
  696. }
  697. };
  698. };
  699. sum = sum.toDecimal(decimalObj.ration.unitPrice);
  700. return sum;
  701. },
  702. getCalcType: function (treeNode) {
  703. if (this.isRationCategory(treeNode)){
  704. return treeNodeCalcType.ctRationCalcProgram;
  705. }
  706. else if (this.isNullBill(treeNode)){
  707. return treeNodeCalcType.ctNull;
  708. }
  709. else if (this.isLeafBill(treeNode)) {
  710. if (treeNode.children && treeNode.children.length > 0){
  711. // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算。(汇总清单所有定额的工料机)
  712. // if (projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  713. // return treeNodeCalcType.ctBillCalcProgram;
  714. // else // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
  715. return treeNodeCalcType.ctGatherRationsFees;
  716. }
  717. else{ // 公式计算
  718. return treeNodeCalcType.ctCalcBaseValue;
  719. };
  720. }
  721. else if (this.isBill(treeNode)) { // 父清单:汇总子清单的费用类别
  722. return treeNodeCalcType.ctGatherBillsFees;
  723. }
  724. else {
  725. return treeNodeCalcType.ctRationCalcProgram;
  726. };
  727. },
  728. cutNodeForSave(treeNode){
  729. let me = this;
  730. /* subType、quantity、calcBase、programID、marketUnitFee等等字段较为特殊,它们的改变一定会触发计算并导致计算
  731. 结果的变化,从而引发保存动作。将这些字段放在该位置跟计算结果一起保存,可减少前端跟后端的通讯频率。 */
  732. let data = treeNode.updateData;
  733. data.projectID = projectObj.project.ID();
  734. data.ID = treeNode.data.ID;
  735. //对比计算结果与原数据的值,有改变的才提交保存
  736. if(treeNode.temData){
  737. for(let key in treeNode.data){
  738. if(key == "feesIndex" || key =="flagsIndex" || key =="gljList" || key =="calcTemplate") continue;// 这两个字段不用保存到后台;
  739. if(treeNode.data[key]&& typeof treeNode.data[key] == "object"){//对象类型转换成字符串比较
  740. if(Array.isArray(treeNode.data[key])) treeNode.data[key].sort();
  741. if(Array.isArray(treeNode.temData[key])) treeNode.temData[key].sort();
  742. if(JSON.stringify(treeNode.temData[key])!== JSON.stringify(treeNode.data[key]) ){
  743. data[key] = treeNode.data[key];
  744. }
  745. }else if(treeNode.temData[key]!==treeNode.data[key]){
  746. data[key] = treeNode.data[key];
  747. }
  748. }
  749. }
  750. // 定额大类
  751. if (me.isRationCategory(treeNode)) {
  752. // 这4个位置要分别找到更新的地方按新的来更新
  753. // data.isSubcontract = treeNode.data.isSubcontract;
  754. // data.evaluationProject = treeNode.data.evaluationProject;
  755. //定额类型的工料机做特殊处理
  756. if(me.isGljRation(treeNode)){
  757. // data.code = treeNode.data.code;
  758. // data.projectGLJID = treeNode.data.projectGLJID;
  759. delete data.marketUnitFee;
  760. };
  761. };
  762. // 优化掉 undefined 属性
  763. data = JSON.parse(JSON.stringify(data));
  764. delete data.feesIndex;
  765. return data;
  766. },
  767. uiNodeQty: function (treeNode){
  768. return parseFloatPlus(treeNode.data.quantity).toDecimal(decimalObj.decimal("quantity", treeNode));
  769. },
  770. // 在项目工料机里检查该工料机是否参与调价
  771. isTenderProjectGLJ: function (glj){
  772. let projGLJ = this.getProjectGLJ(glj);
  773. return !(projGLJ && projGLJ.is_adjust_price == 1);
  774. },
  775. // 取单价调价系数
  776. tenderCoe_GLJPrice: function (){
  777. let coe = 1;
  778. if (projectObj.project.property.tenderSetting && projectObj.project.property.tenderSetting.gljPriceTenderCoe){
  779. coe = projectObj.project.property.tenderSetting.gljPriceTenderCoe;
  780. if (coe == '0') coe = 1; // 这里加个保护
  781. };
  782. return coe;
  783. },
  784. tenderCoe_NodeQty: function (treeNode){
  785. let coe = 1;
  786. if (treeNode.data.rationQuantityCoe){
  787. coe = treeNode.data.rationQuantityCoe;
  788. if (coe == '0') coe = 1; // 这里加个保护
  789. };
  790. return coe;
  791. },
  792. tenderCoe_GLJQty: function (treeNode, glj){
  793. let coe = 1;
  794. if (!treeNode.data.quantityCoe) return coe;
  795. if (!calcTools.isTenderProjectGLJ(glj)) return coe;
  796. if (gljType.LABOUR == glj.type){
  797. if (treeNode.data.quantityCoe.labour)
  798. coe = treeNode.data.quantityCoe.labour;
  799. }
  800. else if (baseMaterialTypes.indexOf(glj.type)){
  801. if (treeNode.data.quantityCoe.material)
  802. coe = treeNode.data.quantityCoe.material;
  803. }
  804. else if (baseMachineTypes.indexOf(glj.type)){
  805. if (treeNode.data.quantityCoe.machine)
  806. coe = treeNode.data.quantityCoe.machine;
  807. }
  808. else if (gljType.MAIN_MATERIAL == glj.type){
  809. if (treeNode.data.quantityCoe.main)
  810. coe = treeNode.data.quantityCoe.main;
  811. }
  812. else if (gljType.EQUIPMENT == glj.type){
  813. if (treeNode.data.quantityCoe.equipment)
  814. coe = treeNode.data.quantityCoe.equipment;
  815. };
  816. if (coe == '0') coe = 1; // 这里加个保护
  817. return coe;
  818. },
  819. uiNodeTenderQty: function (treeNode){
  820. return this.calcNodeTenderQty(treeNode);
  821. },
  822. calcNodeTenderQty: function (treeNode){
  823. if (this.isBill(treeNode)) // 清单只有一个工程量,没有调整后工程量。
  824. return this.uiNodeQty(treeNode)
  825. else{
  826. let qCoe = 1;
  827. /* 量价、工料机类型的定额,在反向调价之调整人材机消耗量系数时,因为他们没有工料机可调,调价结果没变,影响汇总后的父结点金额。
  828. 所以要特殊处理:此种情况下仍然要调量价的消耗量,即还是要像"子目工程量调整系数"方式那样调,但系数又不能在"子目工程量调整系数"
  829. 中显示出来(明明是调工料机,你却调到树结点上,这比较搞笑啊),所以可以改变tenderQuantity达到同样的效果以瞒天过海。所以在取系数时,
  830. 无论什么系数,只要能取到就算正确。
  831. 2020-04-05 注: 以上是老黄历。新思路是量价只作为定额调整,不作为工料机调整。两种反调模式下,统一都只调子目消耗量系数。
  832. 为避免歧义,量价的工料机调整系数不允许输入。
  833. */
  834. // if (calcTools.isVP_or_GLJR(treeNode)){
  835. // if (treeNode.data.rationQuantityCoe)
  836. // qCoe = treeNode.data.rationQuantityCoe
  837. // else if (treeNode.data.quantityCoe && treeNode.data.quantityCoe.labour)
  838. // qCoe = treeNode.data.quantityCoe.labour;
  839. // }
  840. // else {
  841. if (treeNode.data.rationQuantityCoe)
  842. qCoe = treeNode.data.rationQuantityCoe;
  843. // };
  844. if (qCoe == '0' || qCoe == 0) qCoe = 1;
  845. treeNode.data.tenderQuantity = (this.uiNodeQty(treeNode) * qCoe).toDecimal(decimalObj.decimal("quantity", treeNode));
  846. return treeNode.data.tenderQuantity;
  847. }
  848. },
  849. calcGLJTenderQty: function (treeNode, glj){
  850. if (treeNode.data.quantityCoe == undefined){
  851. glj.tenderQuantity = glj.quantity;
  852. }
  853. else{
  854. let coe = 1;
  855. if (this.isTenderProjectGLJ(glj))
  856. coe = this.tenderCoe_GLJQty(treeNode, glj);
  857. glj.tenderQuantity = (glj.quantity * coe).toDecimal(decimalObj.glj.quantity);
  858. }
  859. return glj.tenderQuantity;
  860. },
  861. calcGLJTenderPrice: function (glj) {
  862. let projGLJ = calcTools.getProjectGLJ(glj);
  863. if (projGLJ == null){ // 量价定额虚拟出来的工料机,在项目工料机中查不到。
  864. glj.tenderPrice = projectObj.project.projectGLJ.getTenderMarketPrice(projGLJ);
  865. }else{
  866. let pCoe = 1;
  867. // 先从项目工料机里检查该工料机是否参与调价
  868. if (projGLJ.is_adjust_price != 1) pCoe = this.tenderCoe_GLJPrice();
  869. glj.tenderPrice = (glj.marketPrice * pCoe).toDecimal(decimalObj.glj.unitPrice);
  870. };
  871. return glj.tenderPrice;
  872. },
  873. // 界面显示的工料机价格,包括定额价、市场价等。参数 price 传入一个普通的价格数值即可。
  874. uiGLJPrice: function (price, glj){
  875. if (price){
  876. let projGLJ = glj ? calcTools.getProjectGLJ(glj) : null;
  877. let d = (projGLJ && projGLJ.ratio_data.length > 0) ? decimalObj.glj.unitPriceHasMix : decimalObj.glj.unitPrice;
  878. return parseFloat(price).toDecimal(d);
  879. }
  880. else return 0;
  881. },
  882. // 界面显示的工料机数量。参数 quantity 传入一个普通的数量数值即可。
  883. uiGLJQty: function (quantity){
  884. if (quantity)
  885. return parseFloat(quantity).toDecimal(decimalObj.glj.quantity)
  886. else return 0;
  887. },
  888. hasTargetTotalFee: function (treeNode){ // targetTotalFee 有时为字符串“0”,此种情况会执行if 条件引起逻辑错误。所以这里封闭成方法直接调用。
  889. return (treeNode.data.targetTotalFee && parseFloat(treeNode.data.targetTotalFee));
  890. },
  891. hasQuantity: function (treeNode){
  892. return (treeNode.data.quantity && parseFloat(treeNode.data.quantity));
  893. },
  894. getRationsByProjectGLJ(PGLJID){
  895. let rationIDs = [];
  896. let RGs = projectObj.project.ration_glj.datas;
  897. let PGLJIDs = [];
  898. if(Array.isArray(PGLJID)){//为了提高效率,改成支持传入数组
  899. PGLJIDs = PGLJID
  900. }else {
  901. PGLJIDs = [PGLJID];
  902. }
  903. for (let rg of RGs){
  904. if (PGLJIDs.indexOf(rg.projectGLJID) !== -1){
  905. rationIDs.push(rg.rationID);
  906. }
  907. };
  908. let rationNodes = [];
  909. let nodes = projectObj.project.mainTree.nodes;
  910. for (let rID of rationIDs){
  911. rationNodes.push(nodes['id_' + rID]);
  912. };
  913. // 工料机形式的定额
  914. let items = projectObj.project.mainTree.items;
  915. for (let item of items){
  916. if (PGLJIDs.indexOf(item.data.projectGLJID) !== -1)
  917. rationNodes.push(item);
  918. };
  919. return rationNodes;
  920. },
  921. getNodesByProgramID(programID){
  922. let discreteNodes = [];
  923. let nodes = projectObj.project.mainTree.items;
  924. for (let node of nodes){
  925. if (node.data.programID == programID)
  926. discreteNodes.push(node);
  927. };
  928. return discreteNodes;
  929. },
  930. getProjectGLJ(glj){
  931. if (glj.projectGLJID){
  932. return projectObj.project.projectGLJ.getDataByID(glj.projectGLJID);
  933. }
  934. else return null;
  935. },
  936. labourDays(node, isTender){
  937. if (!node.data.gljList) return 0;
  938. let rst = 0;
  939. calcTools.uiNodeQty(node);
  940. for (let glj of node.data.gljList) {
  941. if (glj.type == gljType.LABOUR) {
  942. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  943. gljQ = gljQ.toDecimal(decimalObj.glj.quantity);
  944. rst = (rst + gljQ).toDecimal(decimalObj.process);
  945. }
  946. };
  947. return rst.toDecimal(decimalObj.glj.quantity);
  948. },
  949. getProjectFeatureProperty(propertyKey){
  950. for (let o of projectObj.project.property.projectFeature){
  951. if (o.key == propertyKey){
  952. return o.value;
  953. }
  954. };
  955. },
  956. getFeeRateByNode(node){
  957. let decimal = getDecimal("feeRate");
  958. if(node.data.feeRateID) {
  959. let r = projectObj.project.FeeRate.getFeeRateByID(node.data.feeRateID);
  960. if (r) return scMathUtil.roundForObj(r.rate, decimal);
  961. };
  962. if (node.data.feeRate || node.data.feeRate == 0)
  963. return scMathUtil.roundForObj(node.data.feeRate,decimal);
  964. return 100;
  965. },
  966. isEmptyObject(obj){
  967. let arr = Object.keys(obj);
  968. return arr.length == 0;
  969. },
  970. isBudgetProject(){
  971. return projectObj.project.property.valuationType == 'bill';
  972. },
  973. isBillProject(){
  974. return projectObj.project.property.valuationType == 'ration';
  975. },
  976. getTenderCalcType: function () {
  977. let tenderSetting = projectObj.project.property.tenderSetting;
  978. let ct = tenderSetting && tenderSetting.calcPriceOption? tenderSetting.calcPriceOption : "coeBase";
  979. if (ct == 'priceBase') ct = 'priceBase_RCJ'; // 兼容旧项目
  980. return ct;
  981. }
  982. };
  983. let rationCalcBases = {
  984. '人工费': function (node, isTender) {
  985. return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptMarketPrice, isTender);
  986. },
  987. '材料费': function (node, isTender) {
  988. return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptMarketPrice, isTender);
  989. },
  990. '施工机械使用费': function (node, isTender) {
  991. return calcTools.rationBaseFee(node, [gljType.GENERAL_MACHINE], priceTypes.ptMarketPrice, isTender);
  992. },
  993. '施工机械人工费': function (node, isTender) {
  994. return calcTools.machineDetailFee(node, node.data.gljList, [], gljType.MACHINE_LABOUR, isTender);
  995. },
  996. '定额商品砼费': function (node, isTender) {
  997. return calcTools.rationBaseFee(node, [gljType.COMMERCIAL_CONCRETE, gljType.COMMERCIAL_MORTAR], priceTypes.ptBasePrice, isTender);
  998. },
  999. '定额外购砼构件费': function (node, isTender) {
  1000. return calcTools.rationBaseFee(node, [gljType.PURCHASE_COMPONENT], priceTypes.ptBasePrice, isTender);
  1001. },
  1002. '定额绿化苗木费': function (node, isTender) {
  1003. return calcTools.rationBaseFee(node, [gljType.GREEN_SEEDLING], priceTypes.ptBasePrice, isTender);
  1004. },
  1005. '设备购置费': function (node, isTender) {
  1006. return calcTools.rationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptMarketPrice, isTender);
  1007. },
  1008. '定额人工费': function (node, isTender) {
  1009. return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptBasePrice, isTender);
  1010. },
  1011. '定额材料费': function (node, isTender) {
  1012. return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptBasePrice, isTender);
  1013. },
  1014. '定额施工机械使用费': function (node, isTender) {
  1015. return calcTools.rationBaseFee(node, [gljType.GENERAL_MACHINE], priceTypes.ptBasePrice, isTender);
  1016. },
  1017. '定额设备费': function (node, isTender) {
  1018. return calcTools.rationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptBasePrice, isTender);
  1019. }
  1020. /*
  1021. '人工费价差': function (node, isTender) {
  1022. return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptDiffPrice, isTender);
  1023. },
  1024. '材料费价差': function (node, isTender) {
  1025. return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptDiffPrice, isTender);
  1026. },
  1027. '机械费价差': function (node, isTender) {
  1028. return calcTools.rationBaseFee(node, [gljType.GENERAL_MACHINE], priceTypes.ptDiffPrice, isTender);
  1029. },
  1030. '主材费价差': function (node, isTender) {
  1031. return calcTools.rationBaseFee(node, [gljType.MAIN_MATERIAL], priceTypes.ptDiffPrice, isTender);
  1032. },
  1033. '设备费价差': function (node, isTender) {
  1034. return calcTools.rationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptDiffPrice, isTender);
  1035. },
  1036. '主材费': function (node, isTender) {
  1037. return calcTools.rationBaseFee(node, [gljType.MAIN_MATERIAL], priceTypes.ptBasePrice, isTender);
  1038. },
  1039. '设备费': function (node, isTender) {
  1040. return calcTools.rationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptBasePrice, isTender);
  1041. },
  1042. '人工工日': function (node, isTender) {
  1043. return calcTools.labourDays(node, isTender);
  1044. },
  1045. '甲供定额基价人工费': function (node, isTender) {
  1046. return calcTools.partASupplyFee(node, '甲供定额基价人工费', isTender, true);
  1047. },
  1048. '甲供定额基价材料费': function (node, isTender) {
  1049. return calcTools.partASupplyFee(node, '甲供定额基价材料费', isTender, true);
  1050. },
  1051. '甲供定额基价机械费': function (node, isTender) {
  1052. return calcTools.partASupplyFee(node, '甲供定额基价机械费', isTender, true);
  1053. },
  1054. '甲供主材费': function (node, isTender) {
  1055. return calcTools.partASupplyFee(node, '甲供主材费', isTender, false);
  1056. },
  1057. '甲供设备费': function (node, isTender) {
  1058. return calcTools.partASupplyFee(node, '甲供设备费', isTender, false);
  1059. },
  1060. '甲定定额基价人工费': function (node, isTender) {
  1061. return calcTools.partASupplyFee(node, '甲定定额基价人工费', isTender, true);
  1062. },
  1063. '甲定定额基价材料费': function (node, isTender) {
  1064. return calcTools.partASupplyFee(node, '甲定定额基价材料费', isTender, true);
  1065. },
  1066. '甲定定额基价机械费': function (node, isTender) {
  1067. return calcTools.partASupplyFee(node, '甲定定额基价机械费', isTender, true);
  1068. },
  1069. '甲定主材费': function (node, isTender) {
  1070. return calcTools.partASupplyFee(node, '甲定主材费', isTender, false);
  1071. },
  1072. '甲定设备费': function (node, isTender) {
  1073. return calcTools.partASupplyFee(node, '甲定设备费', isTender, false);
  1074. },
  1075. '暂估材料费': function (node, isTender) {
  1076. return calcTools.estimateFee(node, true, isTender);
  1077. },
  1078. '分包定额基价人工费': function (node, isTender) {
  1079. if (node.data.isSubcontract)
  1080. return calcTools.rationBaseFee(node, [gljType.LABOUR], priceTypes.ptBasePrice, isTender)
  1081. else
  1082. return 0;
  1083. },
  1084. '分包定额基价材料费': function (node, isTender) {
  1085. if (node.data.isSubcontract)
  1086. return calcTools.rationBaseFee(node, baseMaterialTypes, priceTypes.ptBasePrice, isTender)
  1087. else
  1088. return 0;
  1089. },
  1090. '分包定额基价机械费': function (node, isTender) {
  1091. if (node.data.isSubcontract)
  1092. return calcTools.rationBaseFee(node, [gljType.GENERAL_MACHINE], priceTypes.ptBasePrice, isTender)
  1093. else
  1094. return 0;
  1095. },
  1096. '分包主材费': function (node, isTender) {
  1097. if (node.data.isSubcontract)
  1098. return calcTools.rationBaseFee(node, [gljType.MAIN_MATERIAL], priceTypes.ptBasePrice, isTender)
  1099. else
  1100. return 0;
  1101. },
  1102. '分包设备费': function (node, isTender) {
  1103. if (node.data.isSubcontract)
  1104. return calcTools.rationBaseFee(node, [gljType.EQUIPMENT], priceTypes.ptBasePrice, isTender)
  1105. else
  1106. return 0;
  1107. },
  1108. '分包人工工日': function (node, isTender) {
  1109. if (node.data.isSubcontract)
  1110. return calcTools.labourDays(node, isTender)
  1111. else
  1112. return 0;
  1113. }*/
  1114. };
  1115. let analyzer = {
  1116. error: '',
  1117. standard: function(expr){
  1118. let str = expr;
  1119. str = str.replace(/\s/g, ""); // 去空格、去中文空格
  1120. str = str.replace(/(/g, "("); // 中文括号"("换成英文括号"("
  1121. str = str.replace(/)/g, ")"); // 中文括号")"换成英文括号")"
  1122. str = str.replace(/f/g, "F"); // f换成F
  1123. str = str.replace(/l/g, "L"); // l换成L
  1124. return str;
  1125. },
  1126. getFArr: function (expr) {
  1127. let pattF = new RegExp(/F\d+/gi);
  1128. let arrF = expr.match(pattF);
  1129. return arrF ? arrF : [];
  1130. },
  1131. getAtIDArr: function (expr) { // ['@1','@2']
  1132. let patt = new RegExp(/@\d+/gi);
  1133. let arr = expr.match(patt);
  1134. return arr ? arr : [];
  1135. },
  1136. getBaseArr: function (expr) {
  1137. let pattBase = new RegExp(/\[[\u4E00-\u9FA5]+\]/gi);
  1138. let arrBase = expr.match(pattBase);
  1139. return arrBase ? arrBase : [];
  1140. },
  1141. getID: function (FName, template) { // F13 → 4
  1142. let idx = FName.slice(1) - 1;
  1143. let id = template.calcItems[idx] ? template.calcItems[idx].ID : null;
  1144. return id;
  1145. },
  1146. getFName: function (atID, template) { // @3 → F7
  1147. for (var i = 0; i < template.calcItems.length; i++) {
  1148. if (template.calcItems[i].ID == atID.slice(1)) {
  1149. return 'F'+ (i + 1);
  1150. }
  1151. }
  1152. return null;
  1153. },
  1154. getItem: function (FName, template){ // F3 → calcItems[2] → {Object}
  1155. let idx = FName.slice(1) - 1;
  1156. return template.calcItems[idx];
  1157. },
  1158. isCycleCalc: function (expression, ID, template) { // 这里判断expression,是ID引用: @5+@6
  1159. let atID = `@${ID}`;
  1160. // 避免部分匹配,如:@10匹配@1
  1161. let idx = expression.indexOf(atID);
  1162. if (idx >= 0){
  1163. let nextPos = idx + atID.length;
  1164. if (nextPos >= expression.length)
  1165. return true;
  1166. let char = expression.charAt(nextPos);
  1167. if (!char.isNumberStr())
  1168. return true;
  1169. };
  1170. let atIDs = analyzer.getAtIDArr(expression);
  1171. for (let atID of atIDs) {
  1172. let item = template.compiledCalcItems[atID.slice(1)];
  1173. if (analyzer.isCycleCalc(item.expression, ID, template))
  1174. return true;
  1175. }
  1176. return false;
  1177. },
  1178. isLegal: function (dispExpr, itemID, template) { // 检测包括:无效字符、基数是否中括号、基数是否定义、行引用、循环计算
  1179. function testValue(expr){
  1180. try {
  1181. expr = expr.replace(/\[[\u4E00-\u9FA5]+\]/gi, '0');
  1182. expr = expr.replace(/@\d+/gi, '0');
  1183. expr = expr.replace(/L/gi, '0');
  1184. expr = expr.replace(/%/gi, '*0.01');
  1185. if (expr.includes('00'))
  1186. return false;
  1187. eval(expr);
  1188. return true;
  1189. }
  1190. catch (err) {
  1191. return false;
  1192. }
  1193. };
  1194. let me = analyzer;
  1195. let expr = me.standard(dispExpr);
  1196. let invalidChars = /[^0-9\u4e00-\u9fa5\+\-\*\/\(\)\.\[\]FL%]/g;
  1197. if (invalidChars.test(expr)){
  1198. analyzer.error = `表达式中含有${hintBox.font('无效字符')}!`;
  1199. // hintBox.infoBox('错误提示',`表达式中含有${hintBox.font('无效字符')}!`,1);
  1200. return false;
  1201. };
  1202. let i = expr.search(/\df/ig); // 4F3
  1203. let j = expr.search(/\d\[/ig); // 4[定额基价人工费]
  1204. if (i > -1 || j > -1){
  1205. analyzer.error = `表达式中${hintBox.font('缺少运算符')}!`;
  1206. // hintBox.infoBox('错误提示', `表达式中${hintBox.font('缺少运算符')}!`, 1);
  1207. return false;
  1208. }
  1209. let pattCn = new RegExp(/[\u4E00-\u9FA5]+/gi);
  1210. let arrCn = expr.match(pattCn);
  1211. let pattBase = new RegExp(/\[[\u4E00-\u9FA5]+\]/gi);
  1212. let arrBase = expr.match(pattBase);
  1213. if (arrCn && !arrBase){
  1214. analyzer.error = `定额基数必须用中括号${hintBox.font('[]')}括起来!`;
  1215. // hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
  1216. return false;
  1217. };
  1218. if (arrCn && arrBase && (arrCn.length != arrBase.length)){
  1219. for (let cn of arrCn){
  1220. let tempBase = `[${cn}]`;
  1221. if (!arrBase.includes(tempBase)){
  1222. analyzer.error = `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`;
  1223. // hintBox.infoBox('错误提示', `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`, 1);
  1224. return false;
  1225. }
  1226. };
  1227. // 这里要加一个保险。因为上面的 for 循环在“主材费 + [主材费]” 情况下有Bug
  1228. analyzer.error =`定额基数必须用中括号${hintBox.font('[]')}括起来!`;
  1229. // hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
  1230. return false;
  1231. };
  1232. if (arrBase){
  1233. for (let base of arrBase){
  1234. let baseName = base.slice(1, -1);
  1235. if (!rationCalcBases[baseName]){
  1236. analyzer.error = `定额基数${hintBox.font('[' +baseName + ']')}未定义!`;
  1237. // hintBox.infoBox('错误提示', `定额基数${hintBox.font('[' +baseName + ']')}未定义!`, 1);
  1238. return false;
  1239. }
  1240. };
  1241. };
  1242. let arrF = me.getFArr(expr);
  1243. for (let F of arrF){
  1244. let num = F.slice(1);
  1245. if (num > template.calcItems.length){
  1246. let s = hintBox.font('F'+num);
  1247. analyzer.error = `表达式中 “${hintBox.font(s)}” 行号引用错误!`;
  1248. // hintBox.infoBox('错误提示', `表达式中 “${hintBox.font(s)}” 行号引用错误!`, 1);
  1249. return false;
  1250. };
  1251. };
  1252. let expression = me.getExpression(expr, template);
  1253. if (me.isCycleCalc(expression, itemID, template)){
  1254. analyzer.error = `表达式中有${hintBox.font('循环计算')}!`;
  1255. // hintBox.infoBox('错误提示', `表达式中有${hintBox.font('循环计算')}!`, 1);
  1256. return false;
  1257. };
  1258. if (!testValue(expression)){
  1259. analyzer.error = `表达式中有${hintBox.font('语法错误')}!`;
  1260. // hintBox.infoBox('错误提示', `表达式中有${hintBox.font('语法错误')}!`, 1);
  1261. return false;
  1262. };
  1263. return true; // 表达式合法
  1264. },
  1265. refIDToLines: function (expression, template) { // @2、@3 → F7、F8
  1266. let rst = expression;
  1267. let atIDArr = analyzer.getAtIDArr(rst);
  1268. let fArr = [];
  1269. for (let atID of atIDArr) {
  1270. let FN = analyzer.getFName(atID, template);
  1271. fArr.push(FN);
  1272. };
  1273. for (let i = 0; i < atIDArr.length; i++) {
  1274. let patt = new RegExp(atIDArr[i]);
  1275. let val = fArr[i];
  1276. rst = rst.replace(patt, val);
  1277. };
  1278. return rst;
  1279. },
  1280. refLineToIDs: function (dispExpr, template) { // F7、F8 → @2、@3
  1281. let rst = analyzer.standard(dispExpr);
  1282. let fArr = analyzer.getFArr(rst);
  1283. let IDArr = [];
  1284. for (let F of fArr) {
  1285. let ID = analyzer.getID(F, template);
  1286. IDArr.push(ID);
  1287. };
  1288. for (let i = 0; i < fArr.length; i++) {
  1289. let patt = new RegExp(fArr[i]);
  1290. let val = `@${IDArr[i]}`;
  1291. rst = rst.replace(patt, val);
  1292. };
  1293. return rst;
  1294. },
  1295. getDispExpr: function (expression, template) {
  1296. return analyzer.refIDToLines(expression, template);
  1297. },
  1298. getExpression: function (dispExpr, template) {
  1299. return analyzer.refLineToIDs(dispExpr, template);
  1300. },
  1301. getDispExprUser: function (dispExpr, labourCoe) { // labourCoe 是 str 类型
  1302. let rst = analyzer.standard(dispExpr);
  1303. rst = rst.replace(/L/g, labourCoe);
  1304. return rst;
  1305. },
  1306. getCompiledExpr: function (expression, labourCoe) { // labourCoe 是 str 类型
  1307. let rst = expression;
  1308. let atIDArr = analyzer.getAtIDArr(rst);
  1309. let IDArr = atIDArr.map(function (atID) {
  1310. return atID.slice(1);
  1311. });
  1312. for (var i = 0; i < atIDArr.length; i++) {
  1313. let patt = new RegExp(atIDArr[i]);
  1314. let val = `$CE.at(${IDArr[i]},false)`;
  1315. rst = rst.replace(patt, val);
  1316. };
  1317. rst = rst.replace(/%/g, "*0.01");
  1318. rst = rst.replace(/\[/g, "$CE.base('");
  1319. rst = rst.replace(/\]/g, "',false)");
  1320. rst = rst.replace(/L/g, labourCoe);
  1321. return rst;
  1322. },
  1323. getCompiledTenderExpr: function (compiledExpr) {
  1324. let rst = compiledExpr.replace(/false/g, "true");
  1325. return rst;
  1326. },
  1327. getStatement: function (expression, template) {
  1328. let rst = expression;
  1329. let atIDArr = analyzer.getAtIDArr(rst);
  1330. let IDArr = atIDArr.map(function (atID) {
  1331. return atID.slice(1);
  1332. });
  1333. for (var i = 0; i < atIDArr.length; i++) {
  1334. let patt = new RegExp(atIDArr[i]);
  1335. let val = projectObj.project.calcProgram.compiledTemplates[template.ID].compiledCalcItems[IDArr[i]].name;
  1336. rst = rst.replace(patt, val);
  1337. };
  1338. rst = rst.replace(/\[/g, "");
  1339. rst = rst.replace(/\]/g, "");
  1340. rst = rst.replace(/L/g, '人工系数');
  1341. return rst;
  1342. },
  1343. calcItemMaxID: function(template){
  1344. let MaxID = 0;
  1345. for (let item of template.calcItems){
  1346. if (item.ID > MaxID)
  1347. MaxID = item.ID;
  1348. };
  1349. return MaxID;
  1350. },
  1351. calcItemIsUsed: function(template, calcItem){
  1352. let atID = '@' + calcItem.ID;
  1353. for (var i = 0; i < template.calcItems.length; i++) {
  1354. let item = template.calcItems[i];
  1355. let atIDArr = analyzer.getAtIDArr(item.expression);
  1356. if (atIDArr.indexOf(atID) >= 0){
  1357. calcItem.tempUsed = i;
  1358. return true;
  1359. }
  1360. }
  1361. return false;
  1362. },
  1363. refreshUsedCalcItemsStatement: function(template, calcItem){
  1364. let atID = '@' + calcItem.ID;
  1365. for (var i = 0; i < template.calcItems.length; i++) {
  1366. let item = template.calcItems[i];
  1367. let atIDArr = analyzer.getAtIDArr(item.expression);
  1368. if (atIDArr.indexOf(atID) >= 0){
  1369. item.statement = analyzer.getStatement(item.expression, template);
  1370. };
  1371. }
  1372. },
  1373. calcItemLabourCoe: function(calcItem){
  1374. let lc = 0;
  1375. if (calcItem.labourCoeID)
  1376. lc = projectObj.project.calcProgram.compiledLabourCoes[calcItem.labourCoeID].coe.toString();
  1377. return lc;
  1378. },
  1379. templateRefresh: function(template){
  1380. for (let item of template){
  1381. item.dispExpr = analyzer.getDispExpr(item.expression, template);
  1382. item.dispExprUser = analyzer.getDispExprUser(item.dispExpr, me.calcItemLabourCoe(item));
  1383. };
  1384. },
  1385. templateMaxID: function(){
  1386. let ts = projectObj.project.calcProgram.templates;
  1387. let MaxID = 0;
  1388. for (let t of ts){
  1389. if (t.ID > MaxID)
  1390. MaxID = t.ID;
  1391. };
  1392. return MaxID;
  1393. },
  1394. templateNewName: function (name) {
  1395. let i = 1;
  1396. while (projectObj.project.calcProgram.compiledTemplateMaps[name + i]) {
  1397. i++;
  1398. };
  1399. return name + i;
  1400. },
  1401. templateNameIsExist: function (name) {
  1402. if (projectObj.project.calcProgram.compiledTemplateMaps[name])
  1403. return true
  1404. else return false;
  1405. },
  1406. templateIsUsed: function (ID){
  1407. let nodes = projectObj.project.mainTree.items;
  1408. for (let node of nodes){
  1409. if (node.data && node.data.programID && node.data.programID == ID) {
  1410. return true;
  1411. }
  1412. };
  1413. return false;
  1414. },
  1415. fieldNameIsUsed: function(template, fieldName){
  1416. let fieldNameEn = projectObj.project.calcProgram.compiledFeeTypeMaps[fieldName];
  1417. for (var i = 0; i < template.calcItems.length; i++) {
  1418. if (template.calcItems[i].fieldName == fieldNameEn){
  1419. template.fieldNameTempUsed = i;
  1420. return true;
  1421. }
  1422. }
  1423. return false;
  1424. }
  1425. };
  1426. let executeObj = {
  1427. treeNode: null,
  1428. template: null,
  1429. tempCalcItem: null,
  1430. at: function(ID, isTender) {
  1431. let item = executeObj.template.compiledCalcItems[ID];
  1432. let rst = isTender ? item.tenderTotalFee : item.totalFee;
  1433. rst = parseFloat(rst);
  1434. return rst;
  1435. },
  1436. base: function(baseName, isTender) {
  1437. let me = executeObj;
  1438. // 量价、工料机形式的定额, 要把自己的市场单价用于计算程序中的基数。
  1439. if (calcTools.isVP_or_GLJR(me.treeNode))
  1440. return calcTools.marketPriceToBase(me.treeNode, baseName, isTender)
  1441. else{
  1442. if (!rationCalcBases[baseName]){
  1443. hintBox.infoBox('系统提示', '定额基数“' + baseName + '”未定义,计算错误。 (模板 ' + me.template.ID + ',规则 ' + me.tempCalcItem.ID +')', 1);
  1444. return 0;
  1445. }
  1446. else
  1447. return rationCalcBases[baseName](me.treeNode, isTender);
  1448. }
  1449. },
  1450. HJ: function () {
  1451. let me = this;
  1452. let p = me.treeNode.data.calcBaseValue ? me.treeNode.data.calcBaseValue : 0;
  1453. let q = calcTools.uiNodeQty(me.treeNode) ? calcTools.uiNodeQty(me.treeNode) : 1;
  1454. let u = (p / q).toDecimal(decimalObj.decimal('unitPrice', me.treeNode));
  1455. return u;
  1456. }
  1457. };
  1458. class CalcProgram {
  1459. constructor(project){
  1460. let me = this;
  1461. me.project = project;
  1462. me.datas = [];
  1463. me.rationMap = null;//定额 - 工料机映射临时变量
  1464. me.pgljMap = null;
  1465. project.registerModule(ModuleNames.calc_program, me);
  1466. };
  1467. // 兼容Project框架方法
  1468. getSourceType () {
  1469. return ModuleNames.calc_program;
  1470. };
  1471. // 兼容Project框架方法
  1472. // isInit:是否初始化,进入单位工程为true,导出接口为false,不需要存储费率临时数据
  1473. loadData (datas, isInit) {
  1474. this.datas = datas;
  1475. this.compileAllTemps(isInit);
  1476. };
  1477. // 兼容Project框架方法
  1478. doAfterUpdate (err, data) {
  1479. if(!err){
  1480. $.bootstrapLoading.end();
  1481. }
  1482. };
  1483. // 经测试,全部编译一次耗时0.003~0.004秒。耗时基本忽略不计。
  1484. compileAllTemps(isInit = false){
  1485. let me = this;
  1486. me.compiledFeeRates = {};
  1487. me.compiledLabourCoes = {};
  1488. me.compiledTemplates = {};
  1489. me.compiledTemplateMaps = {};
  1490. me.compiledTemplateNames = [];
  1491. me.compiledFeeTypeMaps = {};
  1492. me.compiledFeeTypeNames = [];
  1493. me.compiledCalcBases = {};
  1494. me.feeRates = this.project.FeeRate.datas.rates;
  1495. me.labourCoes = this.project.labourCoe.datas.coes;
  1496. me.feeTypes = cpFeeTypes;
  1497. // me.calcBases = rationCalcBase;
  1498. me.templates = this.project.calcProgram.datas.templates;
  1499. // me.templates.push(defaultBillTemplate);
  1500. // 先编译公用的基础数据
  1501. me.compilePublics();
  1502. me.compileTemplateMaps();
  1503. for (let t of me.templates){
  1504. me.compileTemplate(t);
  1505. };
  1506. };
  1507. compilePublics(){
  1508. let me = this;
  1509. for (let rate of me.feeRates) {
  1510. me.compiledFeeRates[rate.ID] = rate;
  1511. }
  1512. for (let coe of me.labourCoes) {
  1513. me.compiledLabourCoes[coe.ID] = coe;
  1514. }
  1515. for (let ft of me.feeTypes) {
  1516. me.compiledFeeTypeMaps[ft.type] = ft.name;
  1517. me.compiledFeeTypeMaps[ft.name] = ft.type; // 中文预编译,可靠性有待验证
  1518. me.compiledFeeTypeNames.push(ft.name);
  1519. }
  1520. /* for (let cb of me.calcBases) {
  1521. me.compiledCalcBases[cb.dispName] = cb; // 中文预编译,可靠性有待验证
  1522. }*/
  1523. };
  1524. compileTemplateMaps(){
  1525. let me = this;
  1526. function clearObj(obj){
  1527. for (let key in obj) {
  1528. delete obj[key];
  1529. }
  1530. };
  1531. clearObj(me.compiledTemplates);
  1532. clearObj(me.compiledTemplateMaps);
  1533. me.compiledTemplateNames.splice(0, me.compiledTemplateNames.length);
  1534. for (let t of me.templates){
  1535. me.compiledTemplates[t.ID] = t;
  1536. me.compiledTemplateMaps[t.ID] = t.name;
  1537. me.compiledTemplateMaps[t.name] = t.ID;
  1538. me.compiledTemplateNames.push(t.name);
  1539. };
  1540. };
  1541. compileTemplate(template){
  1542. let me = this;
  1543. // me.compiledTemplates[template.ID] = template;
  1544. // me.compiledTemplateMaps[template.ID] = template.name;
  1545. // me.compiledTemplateMaps[template.name] = template.ID;
  1546. // me.compiledTemplateNames.push(template.name);
  1547. template.hasCompiled = false;
  1548. template.errs = [];
  1549. let private_extract_ID = function(str, idx){
  1550. let subStr = str.slice(idx);
  1551. let patt = new RegExp(/@\d+/);
  1552. let atID = subStr.match(patt);
  1553. let ID = atID ? atID[0].slice(1) : null;
  1554. return ID;
  1555. };
  1556. let private_parse_ref = function(item, itemIdx){
  1557. let idx = item.expression.indexOf('@', 0);
  1558. while (idx >= 0) {
  1559. let ID = private_extract_ID(item.expression, idx);
  1560. let len = ID ? ID.toString().length : 0;
  1561. if (len) {
  1562. let subItem = template.compiledCalcItems[ID];
  1563. if (subItem) {
  1564. if (subItem.ID !== item.ID) {
  1565. private_parse_ref(subItem, template.compiledCalcItems[ID + "_idx"]);
  1566. } else {
  1567. template.errs.push("循环引用ID: " + ID);
  1568. }
  1569. } else {
  1570. template.errs.push("找不到ID: " + ID);
  1571. console.log('找不到ID: ' + ID);
  1572. }
  1573. }
  1574. idx = item.expression.indexOf('@', idx + len + 1);
  1575. }
  1576. if (template.compiledSeq.indexOf(itemIdx) < 0) {
  1577. template.compiledSeq.push(itemIdx);
  1578. }
  1579. };
  1580. let private_compile_items = function() {
  1581. for (let idx of template.compiledSeq) {
  1582. let item = template.calcItems[idx];
  1583. let lc = analyzer.calcItemLabourCoe(item);
  1584. // 用于界面显示。disExpr是公式模板,不允许修改:人工系数占位符被修改后变成数值,第二次无法正确替换。
  1585. item.dispExprUser = analyzer.getDispExprUser(item.dispExpr, lc);
  1586. if (item.expression == 'HJ')
  1587. item.compiledExpr = '$CE.HJ()'
  1588. else
  1589. item.compiledExpr = analyzer.getCompiledExpr(item.expression, lc);
  1590. if (item.feeRateID) {
  1591. let orgFeeRate = item.feeRate;
  1592. let cfr = me.compiledFeeRates[item.feeRateID];
  1593. item.feeRate = cfr ? cfr.rate : 100;
  1594. // if (!orgFeeRate || (orgFeeRate && orgFeeRate != item.feeRate)){
  1595. // me.saveForReports.push({templatesID: template.ID, calcItem: item});
  1596. // }
  1597. };
  1598. // 字段名映射
  1599. item.displayFieldName = me.compiledFeeTypeMaps[item.fieldName];
  1600. }
  1601. };
  1602. if (template && template.calcItems && template.calcItems.length > 0) {
  1603. template.compiledSeq = [];
  1604. template.compiledCalcItems = {};
  1605. for (let i = 0; i < template.calcItems.length; i++) {
  1606. let item = template.calcItems[i];
  1607. item.dispExpr = analyzer.getDispExpr(item.expression, template);
  1608. template.compiledCalcItems[item.ID] = item;
  1609. template.compiledCalcItems[item.ID + "_idx"] = i;
  1610. }
  1611. for (let i = 0; i < template.calcItems.length; i++) {
  1612. let item = template.calcItems[i];
  1613. if (template.compiledSeq.indexOf(i) < 0) {
  1614. private_parse_ref(item, i);
  1615. }
  1616. }
  1617. if (template.errs.length == 0) {
  1618. private_compile_items();
  1619. template.hasCompiled = true;
  1620. } else {
  1621. console.log('errors: ' + template.errs.toString());
  1622. }
  1623. };
  1624. };
  1625. // 删掉多余的费用。例如:①切换取费类别 ②从其它计算方式(有很多费)切换到公式计算方式(只需要common费),多出来的费要删除。
  1626. // 如果指定了保留字段,则按用户指定的来。如果没指定保留字段,则按默认的来:总造价清单只留common, estimate两个费用类别。其它公式清单只留common。
  1627. deleteUselessFees(treeNode, fieldNameArr){
  1628. if (!(treeNode.data.fees && treeNode.data.fees.length > 0)) return;
  1629. let keeps = fieldNameArr ? fieldNameArr : [];
  1630. // 这两个默认是要保留的
  1631. if (!keeps.includes('common')) keeps.push('common');
  1632. if (!keeps.includes('estimate')) keeps.push('estimate');
  1633. for (let i = 0; i < treeNode.data.fees.length; i++) {
  1634. if (!keeps.includes(treeNode.data.fees[i].fieldName)) {
  1635. delete treeNode.data.feesIndex[treeNode.data.fees[i].fieldName];
  1636. treeNode.data.fees.splice(i, 1);
  1637. treeNode.changed = true;
  1638. }
  1639. };
  1640. };
  1641. // 不能直接删除该属性,否则无法冲掉库中已存储的值。下同。
  1642. deleteProperties (treeNode, propNamesArr){
  1643. for (let pn of propNamesArr){
  1644. if (treeNode.data[pn]){
  1645. treeNode.data[pn] = null;
  1646. treeNode.changed = true;
  1647. }
  1648. };
  1649. };
  1650. // 只计算treeNode自身。changedArr: 外部传来的一个数组,专门存储发生变动的节点。
  1651. innerCalc(treeNode, changedArr, tenderType){
  1652. if (treeNode.sourceType === ModuleNames.ration_glj) return; // 仅用作树节点显示的工料机不能参与计算。
  1653. let me = this;
  1654. //设置定额工料机映射表
  1655. me.setRationMap();
  1656. me.setUpdateDataToNode(treeNode); // 先更新要计算的节点信息
  1657. if(!treeNode.temData) treeNode.temData = _.cloneDeep(treeNode.data); // 有可能会有多次计算,只有第一次才保存原始数据,用来对于更新。
  1658. treeNode.calcType = calcTools.getCalcType(treeNode);
  1659. // 父清单汇总子清单的费用类别
  1660. if (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees)
  1661. me.innerCalcBill(treeNode, 2)
  1662. // 叶子清单汇总定额的费用类别
  1663. else if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees)
  1664. me.innerCalcBill(treeNode, 1)
  1665. // 叶子清单:公式计算
  1666. else if (treeNode.calcType == treeNodeCalcType.ctCalcBaseValue)
  1667. me.innerCalcBillExpr(treeNode)
  1668. // 叶子清单:手工修改单价或金额(无定额、无公式计算,什么都没有时)。
  1669. else if (treeNode.calcType == treeNodeCalcType.ctNull)
  1670. me.innerCalcBillCustom(treeNode)
  1671. // 定额:计算程序
  1672. else
  1673. me.innerCalcRation(treeNode, tenderType);
  1674. // if (!calcTools.isTotalCostBill(treeNode)) // 已在上面的分支中计算过
  1675. // calcTools.estimateFee(treeNode);
  1676. if (treeNode.changed && !changedArr.includes(treeNode)) changedArr.push(treeNode);
  1677. };
  1678. // 清单部分抽取出来,供分摊清单公用。commonCalcType:1 叶子清单汇总定额的费用类别; 2 父清单汇总子清单的费用类别。3: 分摊:叶子清单汇总定额的费用类别。
  1679. innerCalcBill(treeNode, commonCalcType, tender = tenderTypes.ttCalc){
  1680. let me = this;
  1681. treeNode.data.programID = null;
  1682. calcTools.initFees(treeNode);
  1683. let nodes = [];
  1684. if (commonCalcType == 1){
  1685. calcTools.getGLJList(treeNode, true);
  1686. nodes = me.project.Ration.getRationNodes(treeNode);
  1687. }
  1688. else if (commonCalcType == 2)
  1689. nodes = treeNode.children
  1690. else if (commonCalcType == 3)
  1691. nodes = treeNode.children;
  1692. let nQ = calcTools.uiNodeQty(treeNode);
  1693. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  1694. let bq = nQ ? nQ : 1;
  1695. let btq = nTQ ? nTQ : 1;
  1696. let rst = [];
  1697. for (let ft of cpFeeTypes) {
  1698. let ftObj = {};
  1699. ftObj.fieldName = ft.type;
  1700. ftObj.name = ft.name;
  1701. let buf = 0, btf = 0, btuf = 0, bttf = 0;
  1702. if (commonCalcType == 2){
  1703. for (let node of nodes) {
  1704. if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
  1705. btf = (btf + parseFloatPlus(node.data.feesIndex[ft.type].totalFee)).toDecimal(decimalObj.process);
  1706. bttf = (bttf + parseFloatPlus(node.data.feesIndex[ft.type].tenderTotalFee)).toDecimal(decimalObj.process);
  1707. if (calcTools.isBudgetProject()){
  1708. buf = (btf / bq).toDecimal(decimalObj.process);
  1709. btuf = (bttf / bq).toDecimal(decimalObj.process);
  1710. }
  1711. };
  1712. };
  1713. }
  1714. else if ((commonCalcType == 1) || (commonCalcType == 3)){
  1715. let sum_rtf = 0, sum_rttf = 0;
  1716. for (let node of nodes) {
  1717. let ruf = 0, rtuf = 0, rtf = 0, rttf = 0;
  1718. if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
  1719. ruf = parseFloatPlus(node.data.feesIndex[ft.type].unitFee).toDecimal(decimalObj.bills.unitPrice);
  1720. rtuf = parseFloatPlus(node.data.feesIndex[ft.type].tenderUnitFee).toDecimal(decimalObj.bills.unitPrice);
  1721. rtf = parseFloatPlus(node.data.feesIndex[ft.type].totalFee).toDecimal(decimalObj.bills.totalPrice);
  1722. rttf = parseFloatPlus(node.data.feesIndex[ft.type].tenderTotalFee).toDecimal(decimalObj.bills.totalPrice);
  1723. };
  1724. sum_rtf = (sum_rtf + rtf).toDecimal(decimalObj.process);
  1725. sum_rttf = (sum_rttf + rttf).toDecimal(decimalObj.process);
  1726. };
  1727. buf = (sum_rtf / bq).toDecimal(decimalObj.process);
  1728. btuf = (sum_rttf / btq).toDecimal(decimalObj.process);
  1729. btf = sum_rtf;
  1730. bttf = sum_rttf;
  1731. if (calcTools.isBillProject() && (ft.type == 'common' || ft.type == 'rationCommon')) { // 招投标项目, 还要反算
  1732. buf = buf.toDecimal(decimalObj.bills.unitPrice);
  1733. btuf = btuf.toDecimal(decimalObj.bills.unitPrice);
  1734. btf = (buf * nQ).toDecimal(decimalObj.bills.totalPrice);
  1735. bttf = (btuf * nQ).toDecimal(decimalObj.bills.totalPrice);
  1736. };
  1737. };
  1738. ftObj.totalFee = btf.toDecimal(decimalObj.bills.totalPrice);
  1739. ftObj.tenderTotalFee = bttf.toDecimal(decimalObj.bills.totalPrice);
  1740. ftObj.unitFee = buf.toDecimal(decimalObj.bills.unitPrice);
  1741. ftObj.tenderUnitFee = btuf.toDecimal(decimalObj.bills.unitPrice);
  1742. calcTools.checkFeeField(treeNode, ftObj);
  1743. rst.push(ftObj);
  1744. };
  1745. treeNode.data.calcTemplate = {"calcItems": rst};
  1746. };
  1747. innerCalcBillExpr(treeNode){
  1748. delete treeNode.data.gljList;
  1749. let me = this;
  1750. me.deleteProperties(treeNode, ['programID']);
  1751. me.deleteUselessFees(treeNode, ['common', 'rationCommon']);
  1752. let nQ = calcTools.uiNodeQty(treeNode);
  1753. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  1754. let tf = treeNode.data.calcBaseValue ? treeNode.data.calcBaseValue : 0;
  1755. let ttf = treeNode.data.tenderCalcBaseValue ? treeNode.data.tenderCalcBaseValue : 0;
  1756. let q = nQ ? nQ : 1;
  1757. let tq = nTQ ? nTQ : 1;
  1758. let uf = (tf / q).toDecimal(decimalObj.bills.unitPrice);
  1759. let tuf = (ttf / tq).toDecimal(decimalObj.bills.unitPrice);
  1760. if (calcTools.isBillProject()){
  1761. tf = (uf * q).toDecimal(decimalObj.bills.totalPrice);
  1762. ttf = (tuf * q).toDecimal(decimalObj.bills.totalPrice);
  1763. };
  1764. calcTools.checkFeeField(treeNode, {'fieldName': 'common', 'unitFee': uf, 'totalFee': tf, 'tenderUnitFee': tuf, 'tenderTotalFee': ttf});
  1765. //第一部分建安费下,使用基数计算的清单,定额建安费应=金额
  1766. if (cbTools.getBelongFlagList(treeNode).includes(fixedFlag.CONSTRUCTION_INSTALL_FEE))
  1767. calcTools.checkFeeField(treeNode, {'fieldName': 'rationCommon', 'unitFee': uf, 'totalFee': tf, 'tenderUnitFee': tuf, 'tenderTotalFee': ttf});
  1768. // 总造价清单还要做单项工程、建设项目的四大项金额汇总
  1769. // if (calcTools.isTotalCostBill(treeNode)){
  1770. // // 公式叶子清单没有暂估费,但总造价清单除外。
  1771. // calcTools.estimateFee(treeNode);
  1772. // calcTools.initSummaryFee(treeNode);
  1773. // treeNode.data.summaryFees.totalFee = tf;
  1774. // treeNode.data.summaryFees.estimateFee = calcTools.getFee(treeNode, 'estimate.totalFee');
  1775. // }
  1776. treeNode.data.calcTemplate = {"calcItems": []};
  1777. };
  1778. innerCalcBillCustom(treeNode){
  1779. let me = this;
  1780. delete treeNode.data.gljList;
  1781. me.deleteProperties(treeNode, ['calcBase', 'calcBaseValue', 'tenderCalcBaseValue', 'programID']);
  1782. me.deleteUselessFees(treeNode, ['common', 'rationCommon']);
  1783. if (treeNode.data.feesIndex && treeNode.data.feesIndex.common){
  1784. let ftObj = {fieldName: 'common'};
  1785. let nQ = calcTools.uiNodeQty(treeNode);
  1786. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  1787. if (treeNode.data.calcFlag == treeNodeCalcFlag.customUnitPrice){ // 修改了清单单价:以单价为准,算金额
  1788. ftObj.unitFee = parseFloatPlus(treeNode.data.feesIndex.common.unitFee);
  1789. ftObj.totalFee = (ftObj.unitFee * nQ).toDecimal(decimalObj.bills.totalPrice);
  1790. ftObj.tenderUnitFee = ftObj.unitFee;
  1791. ftObj.tenderTotalFee = (ftObj.tenderUnitFee * nTQ).toDecimal(decimalObj.bills.totalPrice);
  1792. }
  1793. else if (treeNode.data.calcFlag == treeNodeCalcFlag.customTotalPrice){ // 修改了清单金额:以金额为准,算单价。修改了清单数量也一样
  1794. ftObj.totalFee = parseFloatPlus(treeNode.data.feesIndex.common.totalFee);
  1795. ftObj.unitFee = nQ ? (ftObj.totalFee / nQ) : ftObj.totalFee; // 如果工程量为0或空,综合单价直接等于综合合价
  1796. ftObj.unitFee = ftObj.unitFee.toDecimal(decimalObj.bills.unitPrice);
  1797. ftObj.tenderTotalFee = ftObj.totalFee;
  1798. ftObj.tenderUnitFee = nTQ ? (ftObj.tenderTotalFee / nTQ) : ftObj.tenderTotalFee;
  1799. ftObj.tenderUnitFee = ftObj.tenderUnitFee.toDecimal(decimalObj.bills.unitPrice);
  1800. if (calcTools.isBillProject()) { // 招投标项目, 还要反算
  1801. ftObj.totalFee = (ftObj.unitFee * nQ).toDecimal(decimalObj.bills.totalPrice);
  1802. ftObj.tenderTotalFee = (ftObj.tenderUnitFee * nTQ).toDecimal(decimalObj.bills.totalPrice);
  1803. };
  1804. };
  1805. calcTools.checkFeeField(treeNode, ftObj);
  1806. // 数量、金额时,同步定额建安费
  1807. if (calcTools.isInheritFrom(treeNode, 1)){
  1808. let ftObj2 = {
  1809. fieldName: 'rationCommon',
  1810. unitFee: ftObj.unitFee,
  1811. totalFee: ftObj.totalFee,
  1812. tenderUnitFee: ftObj.tenderUnitFee,
  1813. tenderTotalFee: ftObj.tenderTotalFee
  1814. };
  1815. calcTools.checkFeeField(treeNode, ftObj2);
  1816. };
  1817. }
  1818. treeNode.data.calcTemplate = {"calcItems": []};
  1819. };
  1820. // 定额部分抽取出来,供分摊定额公用。
  1821. innerCalcRation(treeNode, tenderType = tenderTypes.ttCalc){
  1822. let me = this;
  1823. let fnArr = [];
  1824. calcTools.getGLJList(treeNode, true);
  1825. let nQ = calcTools.uiNodeQty(treeNode) ? calcTools.uiNodeQty(treeNode) : 1;
  1826. let nTQ = calcTools.uiNodeTenderQty(treeNode) ? calcTools.uiNodeTenderQty(treeNode) : 1;
  1827. if (treeNode.calcType == treeNodeCalcType.ctRationCalcProgram) {
  1828. // 量价、工料机类型的定额要求"市场合价"
  1829. if (calcTools.isVP_or_GLJR(treeNode)){
  1830. let u = treeNode.data.marketUnitFee ? treeNode.data.marketUnitFee : 0;
  1831. let t = (u * nQ).toDecimal(decimalObj.ration.totalPrice);
  1832. if (treeNode.data.marketTotalFee != t){
  1833. treeNode.data.marketTotalFee = t;
  1834. treeNode.changed = true;
  1835. };
  1836. };
  1837. };
  1838. let template = me.compiledTemplates[treeNode.data.programID];
  1839. treeNode.data.calcTemplate = template;
  1840. if (treeNode && template && template.hasCompiled) {//2018-08-27 空行的时候,取费专业为空,template也为空,加入template非空判断
  1841. let $CE = executeObj;
  1842. $CE.treeNode = treeNode;
  1843. $CE.template = template;
  1844. calcTools.initFees(treeNode);
  1845. for (let idx of template.compiledSeq) {
  1846. let calcItem = template.calcItems[idx];
  1847. $CE.tempCalcItem = calcItem;
  1848. let feeRate = 100; // 100%
  1849. if (calcItem.feeRate != undefined)
  1850. feeRate = parseFloat(calcItem.feeRate).toDecimal(decimalObj.feeRate);
  1851. let expr = calcItem.compiledExpr;
  1852. let tf = (eval(expr) * feeRate * 0.01).toDecimal(decimalObj.process);
  1853. calcItem.totalFee = tf.toDecimal(decimalObj.decimal('totalPrice', treeNode));
  1854. calcItem.unitFee = (tf / nQ).toDecimal(decimalObj.decimal('unitPrice', treeNode));
  1855. let tExpr = analyzer.getCompiledTenderExpr(calcItem.compiledExpr);
  1856. let ttf = (eval(tExpr) * feeRate * 0.01).toDecimal(decimalObj.process);
  1857. calcItem.tenderTotalFee = ttf.toDecimal(decimalObj.decimal('totalPrice', treeNode));
  1858. calcItem.tenderUnitFee = (ttf / nTQ).toDecimal(decimalObj.decimal('unitPrice', treeNode));
  1859. if (calcItem.fieldName) {
  1860. fnArr.push(calcItem.fieldName);
  1861. calcTools.checkFeeField(treeNode, calcItem);
  1862. };
  1863. };
  1864. if (tenderType == tenderTypes.ttReverseRation || tenderType == tenderTypes.ttReverseGLJ)
  1865. this.calcTenderReverse(treeNode, tenderType);
  1866. me.deleteUselessFees(treeNode, fnArr);
  1867. };
  1868. };
  1869. // 存储、刷新零散的多个结点。
  1870. saveNodes(treeNodes, callback){
  1871. if (treeNodes.length < 1) {
  1872. $.bootstrapLoading.end();
  1873. this.rationMap = null;
  1874. this.pgljMap = null;
  1875. return;
  1876. }
  1877. let me = this;
  1878. let dataArr = [];
  1879. let updateMap = {};
  1880. for (let node of treeNodes){
  1881. if (node.changed){
  1882. let data = calcTools.cutNodeForSave(node);
  1883. let newData = {'type': node.sourceType, 'data': data};
  1884. dataArr.push(newData);
  1885. updateMap[node.data.ID] = data;
  1886. }
  1887. };
  1888. if (dataArr.length < 1) {
  1889. $.bootstrapLoading.end();
  1890. return;
  1891. };
  1892. $.bootstrapLoading.start();
  1893. me.project.updateNodes(dataArr, function (data) {
  1894. for (let node of treeNodes){
  1895. delete node.changed;
  1896. delete node.temData;
  1897. node.updateData = {};
  1898. };
  1899. me.rationMap = null;
  1900. me.pgljMap = null;
  1901. if(callback){
  1902. callback(data);
  1903. };
  1904. projectObj.mainController.refreshTreeNode(treeNodes,false,false);
  1905. // 批量树结点计算后,计算程序早已物是人非,所以这里要重新计算一下。警告:第二个参数千万不能改成3,否则死循环!
  1906. if (activeSubSheetIsCalcProgram())
  1907. calcProgramObj.refreshCalcProgram(projectObj.project.mainTree.selected, 2);
  1908. projectInfoObj.refreshTotalPriceSpan();
  1909. $.bootstrapLoading.end();
  1910. });
  1911. };
  1912. // 计算本节点及所有会被影响到的节点,如:所有父节点(默认,可选)、公式引用节点(默认,可选)。修改一个树节点,实际上要计算和保存的是一批树结点:层层父结点、被其它结点(的公式)引用的公式结点。
  1913. calculate(treeNode, calcParents = true, calcFormulas = true, tender){
  1914. let me = this;
  1915. let changedNodes = [];
  1916. me.innerCalc(treeNode, changedNodes, tender);
  1917. if (treeNode.changed) {
  1918. // 计算父结点
  1919. if (calcParents){
  1920. let curNode = treeNode.parent;
  1921. while (curNode){
  1922. me.innerCalc(curNode, changedNodes, tender);
  1923. curNode = curNode.parent;
  1924. };
  1925. };
  1926. // 父结点算完,再计算所有的公式结点(必须先算完父结点,再算公式结点)
  1927. if (calcFormulas) {
  1928. me.calcFormulaNodes(changedNodes, tender);
  1929. };
  1930. };
  1931. return changedNodes;
  1932. };
  1933. // 计算并保存一个树节点。(修改一个树节点,实际上要计算和保存的是一批树结点:层层父结点、被其它结点(的公式)引用的公式结点)
  1934. calcAndSave(treeNode, callback, tender){
  1935. this.calcNodesAndSave([treeNode],callback,tender);
  1936. /* let changedNodes = this.calculate(treeNode, true, true, tender); 统一调用相同的方法
  1937. this.saveNodes(changedNodes, callback);*/
  1938. };
  1939. /* 计算所有树结点(分3种情况),并返回发生变动的零散的多个树结点。参数取值如下:
  1940. calcAllType.catAll 计算所有树结点 (默认值)
  1941. calcAllType.catBills 计算所有清单 (改变项目属性中清单取费算法时会用到)
  1942. calcAllType.catRations 计算所有定额、工料机形式的定额、量价,因为它们都走自己的计算程序 (改变人工系数、费率值、工料机单价时会用到)
  1943. (calcAllType.catRations时程序中做了特殊处理,实际上是计算所有树结点!)
  1944. 调价相关参数:
  1945. tender: null:不调价(普通计算)。 1: 正向调价 2:反向调价-调子目 3: 反向调价-调工料机
  1946. */
  1947. calcAllNodes(calcType = calcAllType.catAll, tender){
  1948. let me = this;
  1949. let changedNodes = [];
  1950. function calcNodes(nodes) {
  1951. for (let node of nodes) {
  1952. me.setUpdateDataToNode(node);
  1953. if (node.children.length > 0) {
  1954. calcNodes(node.children);
  1955. };
  1956. if (calcType == calcAllType.catAll || calcType == node.sourceType) {
  1957. node.calcType = calcTools.getCalcType(node);
  1958. if (node.calcType != treeNodeCalcType.ctCalcBaseValue)
  1959. me.innerCalc(node, changedNodes, tender);
  1960. };
  1961. }
  1962. };
  1963. // calcAllType.catRations 参数情况不会计算父结点(因为父结点是清单),所以这里进行特殊处理。
  1964. if (calcType == calcAllType.catRations)
  1965. calcType == calcAllType.catAll;
  1966. calcNodes(me.project.mainTree.roots);
  1967. me.calcFormulaNodes(changedNodes, tender);
  1968. if (tender){ // 普通计算不执行,只有3种调价计算才清。
  1969. for(let node of projectObj.project.mainTree.items){
  1970. this.clearTenderCache(node);
  1971. };
  1972. };
  1973. return changedNodes;
  1974. };
  1975. // tender: null:不调价(普通计算)。 1: 正向调价 2:反向调价-调子目 3: 反向调价-调工料机
  1976. calcAllNodesAndSave(calcType = calcAllType.catAll, callback, tender){
  1977. let changedNodes = this.calcAllNodes(calcType, tender);
  1978. this.saveNodes(changedNodes, callback);
  1979. };
  1980. setUpdateDataToNode(node){//将updateData里面的值设到node.data上,计算结点时才能拿到最新的值
  1981. if(!_.isEmpty(node.updateData)){
  1982. node.changed = true;
  1983. for(let key in node.updateData){
  1984. node.data[key] = node.updateData[key];
  1985. }
  1986. }
  1987. };
  1988. // 计算零散的、混杂的树节点:清单、定额混合等(如:用到某一计算程序的定额和清单)。
  1989. // 计算多条零散的定额,并计算他们所属的清单、父清单、引用清单。如:批量替换工料机后受影响的定额。
  1990. // 计算多条零散的清单,并计算他们的父清单、引用清单。如:花选删除树结点(如花选清单、定额等,不区分树结点类型)。
  1991. calcNodesAndSave(nodes, callback, tender){
  1992. let me = this, rationNodes = [], billNodes = [], leafBills = [], allChangedNodes = [];
  1993. for (let node of nodes) {
  1994. me.setUpdateDataToNode(node);//多节点更新的情况,要先更新值,因为计算过程中有可能要引用新的值
  1995. if (node.sourceType == ModuleNames.ration)
  1996. rationNodes.push(node)
  1997. else
  1998. billNodes.push(node);
  1999. };
  2000. // 多条定额同属一条叶子清单时,避免叶子清单重复计算
  2001. for (let ration of rationNodes) {
  2002. me.innerCalc(ration, allChangedNodes, tender);
  2003. let leafBill = ration.parent;
  2004. if (leafBill && leafBills.indexOf(leafBill) < 0)
  2005. leafBills.push(leafBill);
  2006. };
  2007. billNodes.merge(leafBills);
  2008. for (let bill of billNodes){
  2009. let changeBills = me.calculate(bill, true, false, tender);
  2010. allChangedNodes.merge(changeBills);
  2011. };
  2012. me.calcFormulaNodes(allChangedNodes, tender);
  2013. me.saveNodes(allChangedNodes, callback);
  2014. };
  2015. // 计算全部公式项。 (changedArr:将通过本方法后发生改变的节点存入changedArr中)
  2016. calcFormulaNodes(changedArr, tender){
  2017. let me = this;
  2018. let formulaNodes = cbTools.getFormulaNodes(true);
  2019. if (formulaNodes.length == 0) return;
  2020. for (let formulaNode of formulaNodes){
  2021. formulaNode.data.userCalcBase = formulaNode.data.calcBase; // 这句不该出现,projectObj.project.calcBase中要改进。
  2022. projectObj.project.calcBase.calculate(formulaNode, true);
  2023. if (projectObj.project.calcBase.success){
  2024. // 计算公式结点
  2025. me.innerCalc(formulaNode, changedArr, tender);
  2026. // 计算父结点
  2027. if (formulaNode.changed){
  2028. let curNode = formulaNode.parent;
  2029. while (curNode){
  2030. me.innerCalc(curNode, changedArr, tender);
  2031. curNode = curNode.parent;
  2032. };
  2033. };
  2034. };
  2035. };
  2036. };
  2037. // 计算叶子清单下的所有子结点、自身、所有父结点、公式引用结点(即跟该叶子清单相关的所有结点)。最后打包存储。
  2038. calcLeafAndSave(treeNode, tender){
  2039. let me = this;
  2040. if(!calcTools.isLeafBill(treeNode)) return;
  2041. if (treeNode.children && treeNode.children.length > 0) {
  2042. let changedNodes = [];
  2043. for (let child of treeNode.children){
  2044. me.innerCalc(child, changedNodes);
  2045. };
  2046. let curChangeds = me.calculate(treeNode, true, true, tender);
  2047. changedNodes.merge(curChangeds);
  2048. me.saveNodes(changedNodes);
  2049. };
  2050. };
  2051. // 排除指定项的综合合价计算(用于带循环计算的情况。这里的汇总只到清单级别即可:清单单价取费时,汇总到清单和汇总到定额两个值不一样)
  2052. getTotalFee(baseNodes, excludeNodes, feeField){
  2053. let rst = 0;
  2054. function calcNodes(nodes) {
  2055. for (let node of nodes) {
  2056. if(!node){
  2057. continue;
  2058. }
  2059. if (!excludeNodes.includes(node)){
  2060. if (node.source && node.source.children && node.source.children.length > 0) {
  2061. calcNodes(node.children);
  2062. }
  2063. else{
  2064. if (node.sourceType == ModuleNames.bills) {
  2065. //这里不四舍五入,保证中间过程不四舍五入
  2066. rst += calcTools.getFee(node, feeField);
  2067. };
  2068. }
  2069. }
  2070. }
  2071. };
  2072. calcNodes(baseNodes);
  2073. return rst;
  2074. };
  2075. // 税前工程造价 ,adj调价
  2076. getBeforeTaxTotalFee(excludeNodes, tender){
  2077. let baseNodes = [], me = this;
  2078. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.SUB_ENGINERRING));
  2079. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.MEASURE));
  2080. // baseNodes.push(calcTools.getNodeByFlag(fixedFlag.OTHER));
  2081. // baseNodes.push(calcTools.getNodeByFlag(fixedFlag.CHARGE));
  2082. return me.getTotalFee(baseNodes, excludeNodes, tender);
  2083. };
  2084. // 反向调价需初始化调价树、缓存数据等
  2085. initReverseTenderDatas (){
  2086. for(let node of tender_obj.tenderTree.items){
  2087. if (node.data.rationQuantityCoe) node.data.rationQuantityCoe = null;
  2088. let qcObj = node.data.quantityCoe;
  2089. if (qcObj){
  2090. for (let pn in qcObj){
  2091. qcObj[pn] = null;
  2092. };
  2093. };
  2094. this.clearTenderCache(node);
  2095. };
  2096. // 反向调价时人材机单价调整系数要归1:因为既可以调量又可以调价,以哪个为基准进行反调?过于复杂,仅以通用的调量逻辑为基准即可满足需求。
  2097. if (projectObj.project.property.tenderSetting && projectObj.project.property.tenderSetting.gljPriceTenderCoe
  2098. && (projectObj.project.property.tenderSetting.gljPriceTenderCoe != 1)){
  2099. projectObj.project.property.tenderSetting.gljPriceTenderCoe = 1; // 修改缓存值,用于计算
  2100. projectObj.project.property.needRestoreGgljPriceTenderCoe = true; // 做个标记,告诉回调函数
  2101. }
  2102. };
  2103. // 反向调价
  2104. calcTenderReverse(treeNode, tender){
  2105. if (tender == tenderTypes.ttReverseRation) {
  2106. if (treeNode.data.feesIndex.common.tenderUnitFee != treeNode.data.feesIndex.common.unitFee) {
  2107. treeNode.data.feesIndex.common.tenderUnitFee = treeNode.data.feesIndex.common.unitFee;
  2108. treeNode.changed = true;
  2109. }
  2110. };
  2111. if (!treeNode.data.targetTotalFee){
  2112. if (treeNode.data.targetUnitFee){
  2113. treeNode.data.targetTotalFee = (treeNode.data.targetUnitFee * treeNode.data.quantity).toDecimal(decimalObj.decimal('totalPrice', treeNode));
  2114. treeNode.changed = true;
  2115. }
  2116. else{ // 既没有目标金额也没有目标单价,此时要初始化使调价合价=原始综合合价,调价单价=原始综合单价。
  2117. if (treeNode.data.feesIndex.common.tenderUnitFee != treeNode.data.feesIndex.common.unitFee) {
  2118. treeNode.data.feesIndex.common.tenderUnitFee = treeNode.data.feesIndex.common.unitFee;
  2119. treeNode.changed = true;
  2120. };
  2121. if (treeNode.data.feesIndex.common.tenderTotalFee != treeNode.data.feesIndex.common.totalFee) {
  2122. treeNode.data.feesIndex.common.tenderTotalFee = treeNode.data.feesIndex.common.totalFee;
  2123. treeNode.changed = true;
  2124. };
  2125. return;
  2126. }
  2127. };
  2128. if (!treeNode.data.targetUnitFee || (parseFloat(treeNode.data.targetUnitFee) == 0)){
  2129. if (calcTools.hasQuantity(treeNode))
  2130. treeNode.data.targetUnitFee = (treeNode.data.targetTotalFee / treeNode.data.quantity).toDecimal(decimalObj.decimal('unitPrice', treeNode));
  2131. }
  2132. let coe = 1;
  2133. if (treeNode.data.feesIndex.common.totalFee != 0)
  2134. coe = (treeNode.data.targetUnitFee / treeNode.data.feesIndex.common.unitFee).toDecimal(decimalObj.process);
  2135. // 调价情况之————量价反调工料机(量价无工料机可调,还是按定额来调,即直接调树结点的消耗量)
  2136. let isVP_RevGLJ =(tender == tenderTypes.ttReverseGLJ) && calcTools.isVP_or_GLJR(treeNode);
  2137. if ((tender == tenderTypes.ttReverseRation) || isVP_RevGLJ){
  2138. treeNode.data.tenderQuantity = (treeNode.data.quantity * coe).toDecimal(decimalObj.decimal("quantity", treeNode));
  2139. if (treeNode.data.rationQuantityCoe != coe){
  2140. treeNode.data.rationQuantityCoe = coe;
  2141. treeNode.changed = true;
  2142. };
  2143. if (isVP_RevGLJ){
  2144. treeNode.data.quantityCoe = {labour: 0, material: 0, machine: 0, main: 0, equipment: 0};
  2145. treeNode.changed = true;
  2146. };
  2147. let ttf = (treeNode.data.tenderQuantity * treeNode.data.feesIndex.common.tenderUnitFee).toDecimal(decimalObj.decimal('totalPrice', treeNode));
  2148. if (treeNode.data.feesIndex.common.tenderTotalFee != ttf){
  2149. treeNode.data.feesIndex.common.tenderTotalFee = ttf;
  2150. treeNode.changed = true;
  2151. };
  2152. }else if (tender == tenderTypes.ttReverseGLJ){
  2153. let qcObj = treeNode.data.quantityCoe;
  2154. if (!qcObj || calcTools.isEmptyObject(qcObj)){
  2155. treeNode.data.quantityCoe = {labour: coe, material: coe, machine: coe, main: coe, equipment: coe};
  2156. treeNode.changed = true;
  2157. }else{
  2158. // 这种写法会漏掉属性,导致界面显示不统一。
  2159. /* for (let pn in qcObj){
  2160. if (qcObj[pn] != coe){
  2161. qcObj[pn] = coe;
  2162. treeNode.changed = true;
  2163. }
  2164. };*/
  2165. if (qcObj.labour != coe) {
  2166. qcObj.labour = coe;
  2167. treeNode.changed = true;
  2168. };
  2169. if (qcObj.material != coe) {
  2170. qcObj.material = coe;
  2171. treeNode.changed = true;
  2172. };
  2173. if (qcObj.machine != coe) {
  2174. qcObj.machine = coe;
  2175. treeNode.changed = true;
  2176. };
  2177. if (qcObj.main != coe) {
  2178. qcObj.main = coe;
  2179. treeNode.changed = true;
  2180. };
  2181. if (qcObj.equipment != coe) {
  2182. qcObj.equipment = coe;
  2183. treeNode.changed = true;
  2184. };
  2185. };
  2186. projectObj.project.calcProgram.calculate(treeNode, false, false, tenderTypes.ttCalc); // 再正向算
  2187. };
  2188. };
  2189. // 清理调价缓存数据
  2190. clearTenderCache(treeNode){
  2191. // 这些属性值为什么不定义在一个对象里?因为每次要判断对象是否存在,十分麻烦。不如直接写简单。分散书写,统一处理也很好用。
  2192. if (treeNode.data.tender_activeTotal) delete treeNode.data.tender_activeTotal;
  2193. if (treeNode.data.tender_activeTarget) delete treeNode.data.tender_activeTarget;
  2194. if (treeNode.data.tender_fullLoad) delete treeNode.data.tender_fullLoad;
  2195. if (treeNode.data.tender_distribute){
  2196. delete treeNode.data.targetTotalFee;
  2197. delete treeNode.data.targetUnitFee;
  2198. delete treeNode.data.tender_distribute;
  2199. };
  2200. };
  2201. // 调价:分摊前的准备工作。主要标记满载的结点。
  2202. prepareForDistribute(treeNode){
  2203. if (!treeNode) return;
  2204. if (treeNode.firstChild())
  2205. this.prepareForDistribute(treeNode.firstChild());
  2206. if (treeNode.children.length == 0){
  2207. // if (!treeNode.data.feesIndex['common'])
  2208. // treeNode.data.tender_fullLoad = true
  2209. // else
  2210. // treeNode.data.tender_fullLoad = false;
  2211. }
  2212. else{
  2213. let full = true;
  2214. for (let i = 0; i < treeNode.children.length; i++) {
  2215. let child = treeNode.children[i];
  2216. if (!child.data.tender_fullLoad && !calcTools.hasTargetTotalFee(child)){
  2217. full = false;
  2218. break;
  2219. };
  2220. }
  2221. if (full) {
  2222. let total = 0, target = 0;
  2223. for (let i = 0; i < treeNode.children.length; i++) {
  2224. let child = treeNode.children[i];
  2225. total = total + parseFloat(child.data.feesIndex['common'].totalFee);
  2226. target = target + parseFloat(child.data.targetTotalFee);
  2227. };
  2228. treeNode.data.tender_activeTotal = total;
  2229. treeNode.data.tender_activeTarget = target;
  2230. treeNode.data.targetTotalFee = target;
  2231. treeNode.data.tender_distribute = 2;
  2232. };
  2233. treeNode.data.tender_fullLoad = full;
  2234. };
  2235. /*if (calcTools.isBill(treeNode) && (treeNode.data.tender_fullLoad != undefined)){
  2236. console.log(treeNode.data.name + ',tender_fullLoad: ' + treeNode.data.tender_fullLoad + ', target: ' + calcTools.hasTargetTotalFee(treeNode));
  2237. };*/
  2238. /* if (calcTools.isRationItem(treeNode)){
  2239. console.log(treeNode.data);
  2240. }*/
  2241. if (treeNode.nextSibling)
  2242. this.prepareForDistribute(treeNode.nextSibling);
  2243. };
  2244. // 调价之分摊目标合价:从父到子往下分摊。
  2245. distributeTargetTotalFee(treeNode){
  2246. if (!treeNode) return;
  2247. if (treeNode.data.feesIndex && treeNode.data.feesIndex['common']){ // 空清单忽略
  2248. // 默认能够执行到这里时每个节点已经被初始化,缓存已删除
  2249. treeNode.data.tender_activeTotal = treeNode.data.feesIndex['common'].totalFee;
  2250. // 开始分摊:只分摊自有目标金额、从父结点分摊到的金额(不分摊子结点摊上来的金额)
  2251. if (calcTools.hasTargetTotalFee(treeNode) && !(treeNode.data.tender_distribute && treeNode.data.tender_distribute == 2)){
  2252. treeNode.data.tender_activeTarget = treeNode.data.targetTotalFee;
  2253. // 先把会破坏金额比例关系的孩子排除:1.有目标金额的 2.满载的(孙子全满,没有分摊空间,所以实质上该孩子的金额已被锁死无法分摊)
  2254. for (let i = 0; i < treeNode.children.length; i++) {
  2255. let child = treeNode.children[i];
  2256. if (!child.data.feesIndex || !child.data.feesIndex['common']) continue; // 空白行清单、定额
  2257. child.data.tender_activeTotal = child.data.feesIndex['common'].totalFee;
  2258. if (calcTools.hasTargetTotalFee(child)){
  2259. child.data.tender_activeTarget = child.data.targetTotalFee;
  2260. console.log(treeNode.data.tender_activeTotal);
  2261. console.log(child.data.tender_activeTotal);
  2262. treeNode.data.tender_activeTotal = treeNode.data.tender_activeTotal - child.data.tender_activeTotal;
  2263. treeNode.data.tender_activeTarget = treeNode.data.tender_activeTarget - child.data.tender_activeTarget;
  2264. };
  2265. }
  2266. if (treeNode.data.tender_activeTotal != 0){
  2267. let coe = (treeNode.data.tender_activeTarget / treeNode.data.tender_activeTotal).toDecimal(decimalObj.process);
  2268. for (let i = 0; i < treeNode.children.length; i++) {
  2269. let child = treeNode.children[i];
  2270. if (!child.data.feesIndex || !child.data.feesIndex['common']) continue; // 空白行清单、定额
  2271. if (!calcTools.hasTargetTotalFee(child)){
  2272. child.data.tender_activeTarget = (coe * child.data.tender_activeTotal).toDecimal(decimalObj.decimal('totalPrice', treeNode));
  2273. child.data.targetTotalFee = child.data.tender_activeTarget;
  2274. child.data.tender_distribute = 1; // 1表示分摊金额来自父结点。2表示分摊金额来自孩子结点。
  2275. }
  2276. }
  2277. };
  2278. };
  2279. }
  2280. if (treeNode.firstChild())
  2281. this.distributeTargetTotalFee(treeNode.firstChild());
  2282. if (treeNode.nextSibling)
  2283. this.distributeTargetTotalFee(treeNode.nextSibling);
  2284. };
  2285. setRationMap(){
  2286. if(this.rationMap == null){
  2287. this.rationMap = {};
  2288. for(let glj of projectObj.project.ration_glj.datas){
  2289. if(this.rationMap[glj.rationID]){
  2290. this.rationMap[glj.rationID].push(glj)
  2291. }else {
  2292. this.rationMap[glj.rationID] = [glj];
  2293. }
  2294. }
  2295. }
  2296. if(this.pgljMap == null ){
  2297. this.pgljMap = _.indexBy(projectObj.project.projectGLJ.datas.gljList, 'id');
  2298. }
  2299. };
  2300. getGljArrByRation(ration){
  2301. if(ration.itemType=="定额"){//分摊定额
  2302. return divideObj.getRationGLJDatas(ration);
  2303. }
  2304. if (ration.type == rationType.gljRation){
  2305. let glj = JSON.parse(JSON.stringify(ration));
  2306. glj.type = glj.subType;
  2307. glj.quantity = 1;
  2308. glj.totalQuantity = parseFloatPlus(ration.quantity);
  2309. return [glj];
  2310. } else{
  2311. if(!this.rationMap) return [];
  2312. let result = this.rationMap[ration.ID];
  2313. if(!result) return [];
  2314. result = gljOprObj.combineWithProjectGlj(result,false,ration,this.pgljMap);
  2315. return result;
  2316. }
  2317. };
  2318. doTenderCalc(callback){
  2319. let sOption = calcTools.getTenderCalcType();
  2320. let tender;
  2321. if (sOption =='coeBase')
  2322. tender = tenderTypes.ttCalc
  2323. else if (sOption =='priceBase_RCJ')
  2324. tender = tenderTypes.ttReverseGLJ
  2325. else if (sOption =='priceBase_ZM')
  2326. tender = tenderTypes.ttReverseRation;
  2327. if (tender == tenderTypes.ttReverseGLJ || tender == tenderTypes.ttReverseRation){
  2328. this.initReverseTenderDatas();
  2329. this.prepareForDistribute(tender_obj.tenderTree.roots[0]);
  2330. this.distributeTargetTotalFee(tender_obj.tenderTree.roots[0]);
  2331. };
  2332. this.calcAllNodesAndSave(calcAllType.catAll, callback, tender);
  2333. };
  2334. };
  2335. // export default analyzer;