calc_program.js 118 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312
  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 (
  24. this.isBill(treeNode) &&
  25. treeNode.source.children &&
  26. treeNode.source.children.length > 0
  27. );
  28. },
  29. isLeafBill: function (treeNode) {
  30. // 下面挂有定额的清单也是叶子清单
  31. return (
  32. this.isBill(treeNode) &&
  33. treeNode.source.children &&
  34. treeNode.source.children.length === 0
  35. );
  36. },
  37. isLeafNode: function (treeNode) {
  38. // 最底层结点,如定额等。
  39. return treeNode.children.length === 0;
  40. },
  41. isBill_DXFY: function (treeNode) {
  42. return this.isBill(treeNode) && treeNode.data.type == billType.DXFY;
  43. },
  44. isBill_FB: function (treeNode) {
  45. return this.isBill(treeNode) && treeNode.data.type == billType.FB;
  46. },
  47. isBill_FX: function (treeNode) {
  48. return this.isBill(treeNode) && treeNode.data.type == billType.FX;
  49. },
  50. isBill_BILL: function (treeNode) {
  51. return this.isBill(treeNode) && treeNode.data.type == billType.BILL;
  52. },
  53. isBill_BX: function (treeNode) {
  54. return this.isBill(treeNode) && treeNode.data.type == billType.BX;
  55. },
  56. // 用户手工输入单价或金额的清单。叶子清单(且无定额无公式 或 有锁定单价)
  57. isCustomBill: function (treeNode) {
  58. return this.isLeafBill(treeNode) && ((treeNode.children.length === 0 && !treeNode.data.calcBase) || treeNode.data.lockUnitPrice);
  59. },
  60. isInvalidNode: function (treeNode) {
  61. // 无效的、影响正常计算的行(无意义的空行、没有金额的行等)
  62. return !(
  63. treeNode.data &&
  64. treeNode.data.feesIndex &&
  65. treeNode.data.feesIndex.common &&
  66. treeNode.data.feesIndex.common.totalFee
  67. );
  68. },
  69. isCalcBaseBill: function (treeNode) {
  70. return (
  71. this.isLeafBill(treeNode) &&
  72. treeNode.children.length === 0 &&
  73. treeNode.data.calcBase
  74. );
  75. },
  76. isTotalCostBill: function (treeNode) {
  77. return (
  78. treeNode.data.flagsIndex &&
  79. treeNode.data.flagsIndex.fixed &&
  80. treeNode.data.flagsIndex.fixed.flag &&
  81. treeNode.data.flagsIndex.fixed.flag == fixedFlag.ENGINEERINGCOST
  82. );
  83. },
  84. isRationCategory: function (treeNode) {
  85. return treeNode.sourceType === ModuleNames.ration;
  86. },
  87. isRationItem: function (treeNode) {
  88. return (
  89. this.isRationCategory(treeNode) &&
  90. treeNode.data.type === rationType.ration
  91. );
  92. },
  93. isCalcManageRation: function (treeNode) {
  94. return (
  95. this.isRationCategory(treeNode) &&
  96. (treeNode.data.type === rationType.ration ||
  97. treeNode.data.type === rationType.install ||
  98. treeNode.data.type === rationType.itemIncrease)
  99. );
  100. },
  101. isVolumePrice: function (treeNode) {
  102. return (
  103. this.isRationCategory(treeNode) &&
  104. treeNode.data.type === rationType.volumePrice
  105. );
  106. },
  107. isGljRation: function (treeNode) {
  108. return (
  109. this.isRationCategory(treeNode) &&
  110. treeNode.data.type === rationType.gljRation
  111. );
  112. },
  113. isVP_or_GLJR: function (treeNode) {
  114. // 是量价或工料机类型的定额
  115. return (
  116. this.isRationCategory(treeNode) &&
  117. (treeNode.data.type == rationType.volumePrice ||
  118. treeNode.data.type == rationType.gljRation)
  119. );
  120. },
  121. isSameTypeNode: function (node1, node2) {
  122. if (
  123. node1.parent &&
  124. node2.parent &&
  125. node1.parent === node2.parent &&
  126. node1.sourceType === node1.sourceType &&
  127. node1.data &&
  128. node2.data &&
  129. node1.data.type === node2.data.type
  130. ) {
  131. return true;
  132. }
  133. return false;
  134. },
  135. isInheritFrom: function (treeNode, flagsArr) {
  136. let cur = treeNode;
  137. while (cur.parent) {
  138. cur = cur.parent;
  139. }
  140. let flag = -1;
  141. if (
  142. cur.data.flagsIndex &&
  143. cur.data.flagsIndex.fixed &&
  144. cur.data.flagsIndex.fixed.flag
  145. )
  146. flag = cur.data.flagsIndex.fixed.flag;
  147. return flagsArr.includes(flag);
  148. },
  149. isFBFX: function (treeNode) {
  150. return projectObj.project.Bills.isFBFX(treeNode);
  151. },
  152. isTechMeasure: function (treeNode) {
  153. return projectObj.project.Bills.isTechMeasure(treeNode);
  154. },
  155. canCalcToTalFeeByOwn: function (treeNode) {
  156. return !projectObj.project.Bills.cantCalcToTalFeeByOwn(treeNode);
  157. },
  158. getChildrenFormulaNodes: function (self, allFormulaNodesArr, parentNodes) {
  159. // 获取结点parentNodes下有公式的子结点
  160. let nodes = [];
  161. for (let pn of parentNodes) {
  162. for (let node of allFormulaNodesArr) {
  163. let cur = node;
  164. while (cur) {
  165. if (cur == pn && node != self) {
  166. nodes.push(node);
  167. break;
  168. }
  169. cur = cur.parent;
  170. }
  171. }
  172. }
  173. return nodes;
  174. },
  175. /* 重要说明:
  176. 此时得到的GLJList,每条glj都有tenderQuantity = glj的quantity * 定额的quantity * glj的消耗量调整系数coe。
  177. 与定额的tenderQuantity无关,与定额的子目工程量调整系数coe无关。例如:
  178. 例:定额AB0003,工程量5,下含工料机“建筑综合工”,消耗量0.202。调价:人材机单价系数4,人工系数3,子目工程量系数2。
  179. 则GLJList中的建筑综合工:quantity 1.01, tenderQuantity 3.03。marketPrice 115, tenderPrice 460。
  180. */
  181. getGLJList: function (treeNode, needOneBill) {
  182. delete treeNode.data.gljList;
  183. if (this.isRationCategory(treeNode)) {
  184. if (!calcTools.isVP_or_GLJR(treeNode)) {
  185. treeNode.data.gljList =
  186. projectObj.project.calcProgram.getGljArrByRation(treeNode.data);
  187. }
  188. } else if (this.isBill(treeNode)) {
  189. treeNode.data.gljList = projectObj.project.ration_glj.getGljArrByBill(
  190. treeNode,
  191. needOneBill
  192. );
  193. }
  194. },
  195. getLeafBills: function (treeNode) {
  196. let leafBills = [];
  197. function getBill(node) {
  198. if (!node) return;
  199. if (calcTools.isLeafBill(node)) leafBills.push(node);
  200. if (node.firstChild()) getBill(node.firstChild());
  201. if (node.nextSibling) getBill(node.nextSibling);
  202. }
  203. let fc = treeNode.firstChild();
  204. if (fc) getBill(fc);
  205. return leafBills;
  206. },
  207. forceSelect: function (treeNode, rowsCount = 1, colsCount = 2) {
  208. projectObj.mainController.tree.selected = treeNode;
  209. let idx = projectObj.project.mainTree.items.indexOf(treeNode);
  210. let sheet = projectObj.mainSpread.getActiveSheet();
  211. sheet.setSelection(idx, 0, rowsCount, colsCount);
  212. sheet.showRow(idx, GC.Spread.Sheets.VerticalPosition.center);
  213. },
  214. initFees: function (treeNode) {
  215. if (!treeNode.data.fees) {
  216. treeNode.data.fees = [];
  217. treeNode.data.feesIndex = {};
  218. treeNode.changed = true;
  219. } else if (!treeNode.data.feesIndex) {
  220. treeNode.data.feesIndex = {};
  221. for (let fee of treeNode.data.fees) {
  222. treeNode.data.feesIndex[fee.fieldName] = fee;
  223. }
  224. treeNode.changed = true;
  225. }
  226. },
  227. initFeeField: function (treeNode, fieldName) {
  228. this.initFees(treeNode);
  229. if (!treeNode.data.feesIndex[fieldName]) {
  230. let fee = {
  231. fieldName: fieldName,
  232. unitFee: 0,
  233. totalFee: 0,
  234. tenderUnitFee: 0,
  235. tenderTotalFee: 0,
  236. };
  237. treeNode.data.fees.push(fee);
  238. treeNode.data.feesIndex[fieldName] = fee;
  239. treeNode.changed = true;
  240. }
  241. },
  242. checkFeeField: function (treeNode, feeObj) {
  243. if (!feeObj) return;
  244. if (feeObj.fieldName == "") return;
  245. // 初始化前,先拦截属性未定义、又要给该属性赋0的情况
  246. if (
  247. !treeNode.data.feesIndex ||
  248. !treeNode.data.feesIndex[feeObj.fieldName]
  249. ) {
  250. if (
  251. feeObj.unitFee == 0 &&
  252. feeObj.totalFee == 0 &&
  253. feeObj.tenderUnitFee == 0 &&
  254. feeObj.tenderTotalFee == 0
  255. )
  256. return;
  257. }
  258. this.initFeeField(treeNode, feeObj.fieldName);
  259. if (treeNode.data.feesIndex[feeObj.fieldName].unitFee != feeObj.unitFee) {
  260. treeNode.data.feesIndex[feeObj.fieldName].unitFee = feeObj.unitFee;
  261. treeNode.changed = true;
  262. }
  263. if (treeNode.data.feesIndex[feeObj.fieldName].totalFee != feeObj.totalFee) {
  264. treeNode.data.feesIndex[feeObj.fieldName].totalFee = feeObj.totalFee;
  265. treeNode.changed = true;
  266. }
  267. // 不知在何种情况下,tenderUnitFee、tenderTotalFee的值会变成NaN,这里提前处理一下
  268. if (isNaN(treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee))
  269. treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee = undefined;
  270. if (isNaN(treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee))
  271. treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee = undefined;
  272. if (
  273. treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee !=
  274. feeObj.tenderUnitFee
  275. ) {
  276. treeNode.data.feesIndex[feeObj.fieldName].tenderUnitFee =
  277. feeObj.tenderUnitFee;
  278. treeNode.changed = true;
  279. }
  280. if (
  281. treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee !=
  282. feeObj.tenderTotalFee
  283. ) {
  284. treeNode.data.feesIndex[feeObj.fieldName].tenderTotalFee =
  285. feeObj.tenderTotalFee;
  286. treeNode.changed = true;
  287. }
  288. },
  289. setFieldValue: function (treeNode, fieldName, value) {
  290. if (fieldName.includes("feesIndex")) {
  291. let arr = fieldName.split(".");
  292. this.initFeeField(treeNode, arr[1]);
  293. treeNode.data.feesIndex[arr[1]][arr[2]] = value;
  294. if (fieldName == "feesIndex.common.unitFee") {
  295. let fee = _.find(treeNode.data.fees, { fieldName: arr[1] });
  296. if (fee) fee[arr[2]] = value;
  297. }
  298. } else {
  299. treeNode.data[fieldName] = value;
  300. }
  301. treeNode.changed = true;
  302. },
  303. initSummaryFee: function (treeNode) {
  304. if (!treeNode.data.summaryFees) {
  305. treeNode.data.summaryFees = {
  306. totalFee: 0,
  307. estimateFee: 0,
  308. safetyFee: 0,
  309. chargeFee: 0,
  310. };
  311. treeNode.changed = true;
  312. }
  313. },
  314. hasAdjustPrice: function () {
  315. // 编办是否有材料的调整价发文
  316. if (
  317. projectObj.project.projSetting.glj_col &&
  318. projectObj.project.projSetting.glj_col.showAdjustPrice == true
  319. )
  320. return true;
  321. else return false;
  322. },
  323. // 参数fieldName值: 'common.totalFee'、'equipment.unitFee'
  324. getFee: function (treeNode, fieldName) {
  325. if (!treeNode) return 0;
  326. let ns = fieldName.split(".");
  327. if (ns.length != 2) return 0;
  328. else if (
  329. treeNode.data.feesIndex &&
  330. treeNode.data.feesIndex[ns[0]] &&
  331. treeNode.data.feesIndex[ns[0]][ns[1]]
  332. )
  333. return parseFloat(treeNode.data.feesIndex[ns[0]][ns[1]]);
  334. else return 0;
  335. },
  336. rationBaseFee: function (treeNode, gljTypes, priceType, isTender) {
  337. if (!treeNode.data.gljList) return 0;
  338. let me = this,
  339. result = 0;
  340. let price = 0,
  341. temp = 0,
  342. temp2 = 0;
  343. // 机械组成物价差: 机上人工、动力燃料
  344. if (
  345. priceType == priceTypes.ptDiffPrice &&
  346. (gljTypes.includes(gljType.MACHINE_LABOUR) ||
  347. gljTypes.includes(gljType.FUEL_POWER_FEE))
  348. ) {
  349. for (let glj of treeNode.data.gljList) {
  350. if ([gljType.GENERAL_MACHINE, gljType.INSTRUMENT].includes(glj.type)) {
  351. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  352. if (!mds) mds = [];
  353. for (let md of mds) {
  354. if (gljTypes.includes(md.type)) {
  355. let gljQ = isTender
  356. ? me.uiGLJQty(glj["tenderQuantity"])
  357. : me.uiGLJQty(glj["quantity"]);
  358. let mdMP = isTender ? md["tenderPrice"] : md["marketPrice"];
  359. let mdQ = me.uiGLJQty(md.consumption);
  360. let mdAP = calcTools.hasAdjustPrice()
  361. ? md["adjustPrice"]
  362. : md["basePrice"];
  363. // if (aprice != mprice){
  364. temp = (
  365. temp + (gljQ * mdQ * mdMP).toDecimal(decimalObj.process)
  366. ).toDecimal(decimalObj.process);
  367. temp2 = (
  368. temp2 + (gljQ * mdQ * mdAP).toDecimal(decimalObj.process)
  369. ).toDecimal(decimalObj.process);
  370. // }
  371. }
  372. }
  373. }
  374. }
  375. }
  376. // 普通基数计算(包括普通价差)
  377. else {
  378. for (let glj of treeNode.data.gljList) {
  379. if (gljTypes.indexOf(glj.type) >= 0) {
  380. let qty = isTender
  381. ? me.uiGLJQty(glj["tenderQuantity"])
  382. : me.uiGLJQty(glj["quantity"]);
  383. // let mprice = isTender ? me.uiGLJPrice(glj["tenderPrice"], glj) : me.uiGLJPrice(glj["marketPrice"], glj);
  384. // let aprice = calcTools.hasAdjustPrice() ? me.uiGLJPrice(glj["adjustPrice"], glj) : me.uiGLJPrice(glj["basePrice"], glj);
  385. let mprice = isTender ? glj["tenderPrice"] : glj["marketPrice"];
  386. let aprice = calcTools.hasAdjustPrice()
  387. ? glj["adjustPrice"]
  388. : glj["basePrice"];
  389. if (priceType == priceTypes.ptDiffPrice) {
  390. // if (aprice != mprice){
  391. temp = (
  392. temp + (qty * mprice).toDecimal(decimalObj.process)
  393. ).toDecimal(decimalObj.process);
  394. temp2 = (
  395. temp2 + (qty * aprice).toDecimal(decimalObj.process)
  396. ).toDecimal(decimalObj.process);
  397. // }
  398. } else {
  399. // if (priceType == priceTypes.ptBasePrice){ price = me.uiGLJPrice(glj["basePrice"], glj);}
  400. if (priceType == priceTypes.ptBasePrice) {
  401. price = glj["basePrice"];
  402. } else if (priceType == priceTypes.ptAdjustPrice) {
  403. price = aprice;
  404. } else if (priceType == priceTypes.ptMarketPrice) {
  405. price = mprice;
  406. }
  407. /*if (projectObj.project.property.areaSetting && treeNode.data.areaIncreaseFee){
  408. let p;
  409. if ([gljType.LABOUR].includes(glj.type))
  410. p = projectObj.project.property.areaSetting.labour
  411. else if (baseMaterialTypes.includes(glj.type))
  412. p = projectObj.project.property.areaSetting.material
  413. else if ([gljType.GENERAL_MACHINE].includes(glj.type))
  414. p = projectObj.project.property.areaSetting.machine;
  415. qty = qty * (1 + p * 0.01).toDecimal(decimalObj.process);
  416. }*/
  417. temp = (qty * price).toDecimal(decimalObj.process);
  418. result = (result + temp).toDecimal(decimalObj.process);
  419. }
  420. }
  421. }
  422. }
  423. if (priceType == priceTypes.ptDiffPrice) {
  424. if (typeof isCQ2018 != "undefined") {
  425. // 如下这一句十分重要!JS计算误差导致379.08-331.695=47.38499999999999。如果直接取2位会变成47.38。所以先取6位47.385,再取2位47.39。
  426. result = (temp - temp2).toDecimal(decimalObj.process);
  427. result = result.toDecimal(decimalObj.ration.unitPrice); // 重庆2018所有都是先汇总相减后再取舍
  428. } else {
  429. if (gljTypes == baseMaterialTypes)
  430. result = (temp - temp2).toDecimal(decimalObj.ration.unitPrice);
  431. else
  432. result = (
  433. temp.toDecimal(decimalObj.ration.unitPrice) -
  434. temp2.toDecimal(decimalObj.ration.unitPrice)
  435. ).toDecimal(decimalObj.ration.unitPrice);
  436. }
  437. } else {
  438. result = result.toDecimal(decimalObj.ration.unitPrice);
  439. }
  440. return result;
  441. },
  442. // masterTypeFilter 过滤机械机型:[]全部, [1,2]特大机械 [3,4]中小机械。 detailType 如机上人工费、机械折旧费等
  443. machineDetailFee: function (
  444. treeNode,
  445. gljArr,
  446. masterTypeFilter,
  447. detailType,
  448. isTender
  449. ) {
  450. if (!gljArr) return 0;
  451. let result = 0;
  452. for (let glj of gljArr) {
  453. if (baseMachineMasterTypes.includes(glj.type)) {
  454. // 机型不符
  455. if (
  456. masterTypeFilter.length > 0 &&
  457. glj.model &&
  458. !masterTypeFilter.includes(glj.model)
  459. )
  460. continue;
  461. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  462. // 获取机械组成物(调价不深入到组成物)
  463. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  464. if (!mds) mds = [];
  465. let mdSum = 0;
  466. for (let md of mds) {
  467. if (md.type == detailType) {
  468. let q = md["consumption"] ? md["consumption"] : 0;
  469. // 下面这句从养护来,建筑暂时用不上,以后可能会用上
  470. // let p = isTender ? (md["tenderPrice"] ? md["tenderPrice"] : 0) : (md["marketPrice"] ? md["marketPrice"] : 0);
  471. let p = md["basePrice"] ? md["basePrice"] : 0;
  472. mdSum = mdSum + (q * p).toDecimal(decimalObj.glj.unitPriceHasMix);
  473. mdSum = mdSum.toDecimal(decimalObj.glj.unitPriceHasMix);
  474. }
  475. }
  476. if (typeof isCQ2018 != "undefined")
  477. result = (
  478. result + (gljQ * mdSum).toDecimal(decimalObj.process)
  479. ).toDecimal(decimalObj.process);
  480. else
  481. result = (
  482. result + (gljQ * mdSum).toDecimal(decimalObj.ration.unitPrice)
  483. ).toDecimal(decimalObj.ration.unitPrice);
  484. }
  485. }
  486. result = result.toDecimal(decimalObj.ration.unitPrice);
  487. return result;
  488. },
  489. // 叶子清单、定额、总造价清单的暂估费。(父级清单是汇总子清单的暂估费,走计算程序逻辑,不在这里)
  490. estimateFee: function (treeNode, isBase, isTender) {
  491. // isBase, isTender 这两个参数用于基数计算
  492. let me = this,
  493. sumU = 0,
  494. sumT = 0,
  495. sumTU = 0,
  496. sumTT = 0;
  497. let nodeQ = me.uiNodeQty(treeNode);
  498. let nodeTQ = me.uiNodeTenderQty(treeNode);
  499. let isGather =
  500. projectObj.project.property.zanguCalcMode == zanguCalcType.gatherMaterial;
  501. // 先汇总数量,再乘市场价。如果是叶子清单,进入这里的gljList中的材料,已经是同类材料跨定额汇总过的了。
  502. function eTFee() {
  503. let rst = { eT: 0, eTT: 0 };
  504. if (!treeNode.data.gljList) return rst;
  505. let GLJObjs = [];
  506. for (let glj of treeNode.data.gljList) {
  507. if (!allMaterialTypes.includes(glj.type)) continue;
  508. if (glj.isEstimate) {
  509. let q = me.uiGLJQty(glj.totalQuantity).toDecimal(decimalObj.process);
  510. GLJObjs.push({
  511. code: glj.code,
  512. name: glj.name,
  513. specs: glj.specs,
  514. unit: glj.unit,
  515. type: glj.type,
  516. quantity: q,
  517. marketPrice: glj.marketPrice,
  518. tenderQuantity: glj.tenderQuantity,
  519. tenderPrice: glj.tenderPrice,
  520. });
  521. } else {
  522. // 组成物
  523. if (!compositionTypes.includes(glj.type)) continue;
  524. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  525. if (!mds) mds = [];
  526. for (let md of mds) {
  527. if (!md.isEstimate) continue;
  528. let isExist = false;
  529. // let glj_totalQ = (nodeQ * me.uiGLJQty(glj.quantity)).toDecimal(decimalObj.glj.quantity);
  530. let glj_totalQ = me
  531. .uiGLJQty(glj.totalQuantity)
  532. .toDecimal(decimalObj.glj.quantity);
  533. let glj_tender_totalQ = (
  534. nodeTQ * me.uiGLJQty(glj.tenderQuantity)
  535. ).toDecimal(decimalObj.glj.quantity);
  536. let mdQ = (glj_totalQ * me.uiGLJQty(md.consumption)).toDecimal(
  537. decimalObj.process
  538. );
  539. let mdTQ = (
  540. glj_tender_totalQ * me.uiGLJQty(md.consumption)
  541. ).toDecimal(decimalObj.process);
  542. for (let obj of GLJObjs) {
  543. if (
  544. gljOprObj.getIndex(md, gljKeyArray) ==
  545. gljOprObj.getIndex(obj, gljKeyArray)
  546. ) {
  547. isExist = true;
  548. obj.quantity = (obj.quantity + mdQ).toDecimal(
  549. decimalObj.glj.quantity
  550. );
  551. obj.tenderQuantity = (obj.tenderQuantity + mdTQ).toDecimal(
  552. decimalObj.glj.quantity
  553. );
  554. break;
  555. }
  556. }
  557. if (!isExist)
  558. GLJObjs.push({
  559. code: md.code,
  560. name: md.name,
  561. specs: md.specs,
  562. unit: md.unit,
  563. type: md.type,
  564. quantity: mdQ,
  565. marketPrice: md.marketPrice,
  566. tenderQuantity: mdTQ,
  567. tenderPrice: md.tenderPrice,
  568. });
  569. }
  570. }
  571. }
  572. for (let obj of GLJObjs) {
  573. let t = (
  574. me.uiGLJQty(obj.quantity) * me.uiGLJPrice(obj.marketPrice, obj)
  575. ).toDecimal(decimalObj.bills.totalPrice);
  576. rst.eT = (rst.eT + t).toDecimal(decimalObj.bills.totalPrice);
  577. let tt = (
  578. me.uiGLJQty(obj.tenderQuantity) * me.uiGLJPrice(obj.tenderPrice, obj)
  579. ).toDecimal(decimalObj.bills.totalPrice);
  580. rst.eTT = (rst.eTT + tt).toDecimal(decimalObj.bills.totalPrice);
  581. }
  582. return rst;
  583. }
  584. // 汇总子结点的暂估合价
  585. function eTFeeByChildren() {
  586. let rst = { eT: 0, eTT: 0 };
  587. for (let node of treeNode.children) {
  588. if (node.data.feesIndex && node.data.feesIndex["estimate"]) {
  589. rst.eT = (
  590. rst.eT + parseFloatPlus(node.data.feesIndex["estimate"].totalFee)
  591. ).toDecimal(decimalObj.process);
  592. rst.eTT = (
  593. rst.eTT +
  594. parseFloatPlus(node.data.feesIndex["estimate"].tenderTotalFee)
  595. ).toDecimal(decimalObj.process);
  596. }
  597. }
  598. rst.eT = rst.eT.toDecimal(decimalObj.bills.totalPrice);
  599. rst.eTT = rst.eTT.toDecimal(decimalObj.bills.totalPrice);
  600. return rst;
  601. }
  602. // 先数量乘市场价,再汇总
  603. function eUFee() {
  604. if (!treeNode.data.gljList) return 0;
  605. let rst = { eU: 0, eTU: 0 };
  606. for (let glj of treeNode.data.gljList) {
  607. if (!allMaterialTypes.includes(glj.type)) continue;
  608. if (glj.isEstimate) {
  609. rst.eU =
  610. rst.eU +
  611. (
  612. me.uiGLJQty(glj.quantity) * me.uiGLJPrice(glj.marketPrice, glj)
  613. ).toDecimal(decimalObj.process);
  614. rst.eU = rst.eU.toDecimal(decimalObj.process);
  615. // 不能直接用glj.tenderPrice,这个值不可靠。当调价界面删除单价系数后,tenderPrice没有实时计算,取得的值为0
  616. rst.eTU =
  617. rst.eTU +
  618. (me.uiGLJQty(glj.tenderQuantity) * glj.tenderPrice).toDecimal(
  619. decimalObj.process
  620. );
  621. rst.eTU = rst.eTU.toDecimal(decimalObj.process);
  622. } else {
  623. // 组成物。
  624. if (!compositionTypes.includes(glj.type)) continue;
  625. let mds = projectObj.project.composition.getCompositionByGLJ(glj);
  626. if (!mds) mds = [];
  627. for (let md of mds) {
  628. if (!md.isEstimate) continue;
  629. let mdU = (
  630. me.uiGLJQty(md.consumption) * me.uiGLJPrice(md.marketPrice)
  631. ).toDecimal(decimalObj.glj.unitPrice);
  632. rst.eU =
  633. rst.eU +
  634. (mdU * me.uiGLJQty(glj.quantity)).toDecimal(decimalObj.process);
  635. rst.eU = rst.eU.toDecimal(decimalObj.process);
  636. // 数量只调到工料机级别,工料机下的组成物不调量(如机械、混凝土)。调价调的是工料机下的组成物的价。
  637. let mdTU = (me.uiGLJQty(md.consumption) * md.tenderPrice).toDecimal(
  638. decimalObj.glj.unitPrice
  639. );
  640. rst.eTU =
  641. rst.eTU +
  642. (mdTU * glj.tenderQuantity).toDecimal(decimalObj.process);
  643. rst.eTU = rst.eTU.toDecimal(decimalObj.process);
  644. }
  645. }
  646. }
  647. rst.eU = rst.eU.toDecimal(decimalObj.bills.unitPrice);
  648. rst.eTU = rst.eTU.toDecimal(decimalObj.bills.unitPrice);
  649. return rst;
  650. }
  651. // 总造价暂估费
  652. if (me.isTotalCostBill(treeNode)) {
  653. let nodes = projectObj.project.mainTree.roots;
  654. for (let node of nodes) {
  655. if (me.isTotalCostBill(node)) break;
  656. let eU = 0,
  657. eT = 0,
  658. eTU = 0,
  659. eTT = 0;
  660. if (node.data.feesIndex && node.data.feesIndex.estimate) {
  661. eU = node.data.feesIndex.estimate.unitFee;
  662. eT = node.data.feesIndex.estimate.totalFee;
  663. eTU = node.data.feesIndex.estimate.tenderUnitFee;
  664. eTT = node.data.feesIndex.estimate.tenderTotalFee;
  665. } else {
  666. (eU = 0), (eT = 0), (eTU = 0), (eTT = 0);
  667. }
  668. sumU = (sumU + parseFloatPlus(eU)).toDecimal(decimalObj.process);
  669. sumT = (sumT + parseFloatPlus(eT)).toDecimal(decimalObj.process);
  670. sumTU = (sumTU + parseFloatPlus(eTU)).toDecimal(decimalObj.process);
  671. sumTT = (sumTT + parseFloatPlus(eTT)).toDecimal(decimalObj.process);
  672. }
  673. sumU = sumU.toDecimal(decimalObj.bills.unitPrice);
  674. sumT = sumT.toDecimal(decimalObj.bills.totalPrice);
  675. sumTU = sumTU.toDecimal(decimalObj.bills.unitPrice);
  676. sumTT = sumTT.toDecimal(decimalObj.bills.totalPrice);
  677. } else if (me.isParentBill(treeNode)) {
  678. // 父清单不要汇总单价。
  679. let eTFBC = eTFeeByChildren();
  680. sumT = eTFBC.eT;
  681. sumTT = eTFBC.eTT;
  682. sumU = undefined;
  683. sumTU = undefined;
  684. } else if (me.isLeafBill(treeNode)) {
  685. if (projectObj.project.Bills.isEngineerEst(treeNode)) {
  686. if (treeNode.data.feesIndex["common"] != undefined) {
  687. sumT = treeNode.data.feesIndex["common"].totalFee;
  688. sumU = treeNode.data.feesIndex["common"].unitFee;
  689. sumTT = treeNode.data.feesIndex["common"].tenderTotalFee;
  690. sumTU = treeNode.data.feesIndex["common"].tenderUnitFee;
  691. }
  692. } else {
  693. if (isGather) {
  694. me.getGLJList(treeNode, false);
  695. let eTF = eTFee();
  696. sumT = eTF.eT;
  697. sumTT = eTF.eTT;
  698. } else {
  699. let eTFBC = eTFeeByChildren();
  700. sumT = eTFBC.eT;
  701. sumTT = eTFBC.eTT;
  702. }
  703. let q = nodeQ ? nodeQ : 1;
  704. sumU = (sumT / q).toDecimal(decimalObj.bills.totalPrice);
  705. let tq = nodeTQ ? nodeTQ : 1;
  706. sumTU = (sumTT / tq).toDecimal(decimalObj.bills.totalPrice);
  707. }
  708. } else if (me.isRationCategory(treeNode)) {
  709. me.getGLJList(treeNode, false);
  710. let eUF = eUFee();
  711. sumU = eUF.eU;
  712. sumTU = eUF.eTU;
  713. if (isBase) {
  714. if (isTender) return sumTU;
  715. else return sumU;
  716. }
  717. if (isGather) {
  718. let eTF = eTFee();
  719. sumT = eTF.eT;
  720. sumTT = eTF.eTT;
  721. } else {
  722. sumT = (nodeQ * sumU).toDecimal(decimalObj.ration.totalPrice);
  723. sumTT = (nodeTQ * sumTU).toDecimal(decimalObj.ration.totalPrice);
  724. }
  725. }
  726. me.checkFeeField(treeNode, {
  727. fieldName: "estimate",
  728. unitFee: sumU,
  729. totalFee: sumT,
  730. tenderUnitFee: sumTU,
  731. tenderTotalFee: sumTT,
  732. });
  733. },
  734. marketPriceToBase: function (treeNode, baseName, isTender) {
  735. if (!calcTools.isVP_or_GLJR(treeNode)) return;
  736. let result = 0,
  737. me = this;
  738. function isRCJZC(treeNode, baseName) {
  739. // 基数名称中是否包含人材机主设,且树结点类型要匹配一致
  740. let rst =
  741. (treeNode.data.subType === gljType.LABOUR &&
  742. baseName.includes("人工")) || // 人工费、市场人工费
  743. (baseMaterialTypes.includes(treeNode.data.subType) &&
  744. baseName.includes("材料")) ||
  745. // (treeNode.data.subType === gljType.GENERAL_MACHINE && (baseName.includes('机械') || baseName.includes('机具'))) ||
  746. (baseMachineTypes.includes(treeNode.data.subType) &&
  747. (baseName.includes("机械") || baseName.includes("机具"))) ||
  748. (treeNode.data.subType === gljType.MAIN_MATERIAL &&
  749. baseName.includes("主材")) ||
  750. (treeNode.data.subType === gljType.EQUIPMENT &&
  751. baseName.includes("设备"));
  752. return rst;
  753. }
  754. if (
  755. baseName.includes("甲供") ||
  756. baseName.includes("甲定") ||
  757. baseName.includes("分包")
  758. ) {
  759. result = 0;
  760. } else if (baseName.includes("价差")) {
  761. if (treeNode.data.type == rationType.gljRation) {
  762. if (isRCJZC(treeNode, baseName)) {
  763. let aprice = me.uiGLJPrice(treeNode.data.basePrice); // 量价虚拟的工料机不可能有发文,这里直接取定额价。
  764. let mprice = me.uiGLJPrice(treeNode.data.marketUnitFee);
  765. result = (mprice - aprice).toDecimal(decimalObj.ration.unitPrice);
  766. }
  767. }
  768. } else if (baseName.includes("机上人工")) {
  769. if (treeNode.data.subType === gljType.GENERAL_MACHINE) {
  770. let glj = {
  771. code: treeNode.data.code,
  772. name: treeNode.data.name,
  773. specs: treeNode.data.specs,
  774. unit: treeNode.data.unit,
  775. quantity: 1,
  776. type: treeNode.data.subType, // 注意:这里要取subType
  777. };
  778. result = me.machineDetailFee(
  779. treeNode,
  780. [glj],
  781. [],
  782. gljType.MACHINE_LABOUR,
  783. isTender
  784. );
  785. }
  786. } else {
  787. if (isRCJZC(treeNode, baseName)) {
  788. if (calcTools.isVolumePrice(treeNode)) {
  789. if (isTender) {
  790. let coe = this.tenderCoe_GLJPrice();
  791. if (treeNode.data.marketUnitFee)
  792. result = (
  793. parseFloat(treeNode.data.marketUnitFee) * coe
  794. ).toDecimal(decimalObj.ration.unitPrice);
  795. else result = 0;
  796. } else
  797. result = treeNode.data.marketUnitFee
  798. ? parseFloat(treeNode.data.marketUnitFee).toDecimal(
  799. decimalObj.ration.unitPrice
  800. )
  801. : 0;
  802. } else if (calcTools.isGljRation(treeNode)) {
  803. // result = treeNode.data.basePrice ? parseFloat(treeNode.data.basePrice).toDecimal(decimalObj.ration.unitPrice) : 0;
  804. // 这里要取基价或市场价,但不能直接取basePrice,受限于项目属性的三个选项。
  805. if (baseName.includes("定额"))
  806. result = gljOprObj.getBasePrice(treeNode);
  807. else
  808. result = treeNode.data.marketUnitFee
  809. ? parseFloat(treeNode.data.marketUnitFee).toDecimal(
  810. decimalObj.ration.unitPrice
  811. )
  812. : gljOprObj.getBasePrice(treeNode);
  813. }
  814. }
  815. }
  816. return result;
  817. },
  818. partASupplyFee: function (
  819. treeNode,
  820. baseName,
  821. isTender,
  822. isRationPirce = true
  823. ) {
  824. // isRationPirce 为true时表示取定额价。如:甲供定额材料费
  825. if (!treeNode.data.gljList) return 0;
  826. let projectGLJ = projectObj.project.projectGLJ;
  827. let supplyT = [];
  828. if (baseName.includes("甲供")) supplyT = [supplyType.BFJG, supplyType.WQJG];
  829. // 字段中存储的是汉字、数字混杂!
  830. else if (baseName.includes("甲定")) supplyT = [supplyType.JDYG];
  831. let gljT = [],
  832. compT = [];
  833. if (baseName.includes("人工")) gljT = [gljType.LABOUR];
  834. // 含人工的:如甲供人工、甲定人工
  835. else if (baseName.includes("材料")) {
  836. gljT = baseMaterialTypes;
  837. compT = compositionTypes;
  838. } else if (baseName.includes("机械") || baseName.includes("机具")) {
  839. gljT = baseMachineTypes;
  840. compT = [
  841. gljType.GENERAL_MACHINE,
  842. gljType.INSTRUMENT,
  843. gljType.OTHER_MACHINE_USED,
  844. ]; // 取并集,兼容重庆2018新定额
  845. } else if (baseName.includes("主材")) {
  846. gljT = [gljType.MAIN_MATERIAL];
  847. compT = [gljType.MAIN_MATERIAL];
  848. } else if (baseName.includes("设备")) {
  849. gljT = [gljType.EQUIPMENT];
  850. }
  851. // alert(JSON.stringify(projectGLJ.testGLJs()));
  852. let supplyGLJs = projectGLJ.getGLJsBySupply(supplyT, gljT);
  853. if (supplyGLJs.length == 0) return 0;
  854. let supplyGLJsIdx = {};
  855. for (let sglj of supplyGLJs) {
  856. supplyGLJsIdx[sglj.id] = sglj;
  857. }
  858. function isSupply(composition, supplies) {
  859. for (let supply of supplies) {
  860. if (
  861. supply.code == composition.code &&
  862. supply.name == composition.name &&
  863. supply.unit == composition.unit &&
  864. supply.specs == composition.specs &&
  865. supply.type == composition.type
  866. ) {
  867. composition.basePrice = supply.unit_price.base_price;
  868. composition.marketPrice = supply.unit_price.market_price;
  869. composition.supply = supply.supply;
  870. composition.supplyX = 1;
  871. if (composition.supply == supplyType.BFJG) {
  872. let Q = supply.quantity ? supply.quantity : 1;
  873. composition.supplyX = supply.supply_quantity / Q;
  874. }
  875. return true;
  876. }
  877. }
  878. return false;
  879. }
  880. let sum = 0;
  881. for (let glj of treeNode.data.gljList) {
  882. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  883. let X = 1; // 部分甲供系数(默认1,即完全甲供)
  884. let tempSGLJ = supplyGLJsIdx[glj.projectGLJID];
  885. // 当前材料是甲供材料:①普通 ②商品硂等不计组成物的母体材料
  886. if (tempSGLJ) {
  887. // 处理部分甲供
  888. if (baseName.includes("甲供") && tempSGLJ.supply == supplyType.BFJG) {
  889. let Q = isTender ? tempSGLJ.tenderQuantity : tempSGLJ.quantity;
  890. // let Q = tempSGLJ.quantity;
  891. Q = Q ? Q : 1;
  892. X = tempSGLJ.supply_quantity / Q;
  893. }
  894. let gljP = isRationPirce
  895. ? glj.basePrice
  896. : isTender
  897. ? projectGLJ.getTenderMarketPrice(calcTools.getProjectGLJ(glj))
  898. : glj.marketPrice;
  899. sum = (sum + gljP * gljQ * X).toDecimal(decimalObj.process);
  900. } else {
  901. // 当前材料不是甲供材料
  902. // 混凝土等。组成物的母体,母体如果有组成物,则母体无法作为甲供材料,无法设置,此时要看其组成物是否是甲供材料;母体如果没有组成物,则母体有可能成为甲供材料。
  903. if (compT.includes(glj.type)) {
  904. let pGLJ = projectGLJ.getDataByID(glj.projectGLJID);
  905. let compositions = pGLJ.ratio_data; // 组成物明细
  906. if (compositions.length > 0) {
  907. for (let c of compositions) {
  908. if (isSupply(c, supplyGLJs)) {
  909. X = 1;
  910. if (baseName.includes("甲供") && c.supply == supplyType.BFJG) {
  911. X = c.supplyX;
  912. }
  913. let cP = isRationPirce
  914. ? c.basePrice
  915. : isTender
  916. ? projectGLJ.getTenderMarketPrice(calcTools.getProjectGLJ(c))
  917. : c.marketPrice;
  918. sum = (sum + cP * c.consumption * gljQ * X).toDecimal(
  919. decimalObj.process
  920. );
  921. }
  922. }
  923. }
  924. }
  925. }
  926. }
  927. sum = sum.toDecimal(decimalObj.ration.unitPrice);
  928. return sum;
  929. },
  930. getCalcType: function (treeNode) {
  931. if (this.isRationCategory(treeNode)) {
  932. return treeNodeCalcType.ctRationCalcProgram;
  933. } else if (this.isCustomBill(treeNode)) {
  934. return treeNodeCalcType.ctCustom;
  935. } else if (this.isLeafBill(treeNode)) {
  936. if (treeNode.data.lockUnitPrice) // 叶子清单锁定单价(有定额或无定额)
  937. return treeNodeCalcType.ctLockUnitPrice
  938. else if (treeNode.children && treeNode.children.length > 0) { // 叶子清单有定额
  939. // 清单单价计算模式下的叶子清单:取自己的计算程序ID,找到自己的计算程序计算。(汇总清单所有定额的工料机)
  940. if (projectObj.project.property.billsCalcMode === leafBillGetFeeType.billsPrice)
  941. return treeNodeCalcType.ctBillCalcProgram;
  942. // 前三种计算模式下的叶子清单:汇总定额的计算程序的费用类别
  943. else return treeNodeCalcType.ctGatherRationsFees;
  944. }
  945. else { // 叶子清单无锁定单价、无定额:公式计算
  946. return treeNodeCalcType.ctCalcBaseValue;
  947. }
  948. } else if (this.isBill(treeNode)) {
  949. // 父清单:汇总子清单的费用类别
  950. return treeNodeCalcType.ctGatherBillsFees;
  951. } else {
  952. return treeNodeCalcType.ctRationCalcProgram;
  953. }
  954. },
  955. cutNodeForSave(treeNode) {
  956. let me = this;
  957. /* subType、quantity、calcBase、programID、marketUnitFee等等字段较为特殊,它们的改变一定会触发计算并导致计算
  958. 结果的变化,从而引发保存动作。将这些字段放在该位置跟计算结果一起保存,可减少前端跟后端的通讯频率。 */
  959. let data = {
  960. projectID: projectObj.project.ID(),
  961. ID: treeNode.data.ID,
  962. unit: treeNode.data.unit, //对清单来说,改变单位,工程量精度会跟着改变从而影响计算。
  963. subType: treeNode.data.subType,
  964. quantity: treeNode.data.quantity,
  965. calcBase: treeNode.data.calcBase,
  966. calcBaseValue: treeNode.data.calcBaseValue,
  967. tenderCalcBaseValue: treeNode.data.tenderCalcBaseValue,
  968. programID: treeNode.data.programID,
  969. marketUnitFee: treeNode.data.marketUnitFee,
  970. marketTotalFee: treeNode.data.marketTotalFee,
  971. fees: treeNode.data.fees,
  972. isFromDetail: treeNode.data.isFromDetail,
  973. feeRate: treeNode.data.feeRate,
  974. feeRateID: treeNode.data.feeRateID,
  975. contain: treeNode.data.contain,
  976. quantityEXP: treeNode.data.quantityEXP,
  977. summaryFees: treeNode.data.summaryFees,
  978. name: treeNode.data.name,
  979. rationQuantityCoe: treeNode.data.rationQuantityCoe,
  980. quantityCoe:
  981. treeNode.data.quantityCoe == null ? {} : treeNode.data.quantityCoe,
  982. targetUnitFee: treeNode.data.targetUnitFee,
  983. targetTotalFee: treeNode.data.targetTotalFee,
  984. };
  985. // 定额大类
  986. if (me.isRationCategory(treeNode)) {
  987. data.isSubcontract = treeNode.data.isSubcontract;
  988. data.evaluationProject = treeNode.data.evaluationProject;
  989. //定额类型的工料机做特殊处理
  990. if (me.isGljRation(treeNode)) {
  991. data.code = treeNode.data.code;
  992. data.projectGLJID = treeNode.data.projectGLJID;
  993. delete data.marketUnitFee;
  994. }
  995. }
  996. // 优化掉 undefined 属性
  997. data = JSON.parse(JSON.stringify(data));
  998. return data;
  999. },
  1000. uiNodeQty: function (treeNode) {
  1001. return parseFloatPlus(treeNode.data.quantity).toDecimal(
  1002. decimalObj.decimal("quantity", treeNode)
  1003. );
  1004. },
  1005. // 在项目工料机里检查该工料机是否参与调价
  1006. isTenderProjectGLJ: function (glj) {
  1007. let projGLJ = this.getProjectGLJ(glj);
  1008. return !(projGLJ && projGLJ.is_adjust_price == 1);
  1009. },
  1010. // 取单价调价系数
  1011. tenderCoe_GLJPrice: function () {
  1012. let coe = 1;
  1013. if (
  1014. projectObj.project.property.tenderSetting &&
  1015. projectObj.project.property.tenderSetting.gljPriceTenderCoe
  1016. ) {
  1017. coe = projectObj.project.property.tenderSetting.gljPriceTenderCoe;
  1018. if (coe == "0") coe = 1; // 这里加个保护
  1019. }
  1020. return coe;
  1021. },
  1022. tenderCoe_NodeQty: function (treeNode) {
  1023. let coe = 1;
  1024. if (treeNode.data.rationQuantityCoe) {
  1025. coe = treeNode.data.rationQuantityCoe;
  1026. if (coe == "0") coe = 1; // 这里加个保护
  1027. }
  1028. return coe;
  1029. },
  1030. tenderCoe_GLJQty: function (treeNode, glj) {
  1031. let coe = 1;
  1032. if (!treeNode.data.quantityCoe) return coe;
  1033. if (!calcTools.isTenderProjectGLJ(glj)) return coe;
  1034. if (gljType.LABOUR == glj.type) {
  1035. if (treeNode.data.quantityCoe.labour)
  1036. coe = treeNode.data.quantityCoe.labour;
  1037. } else if (baseMaterialTypes.indexOf(glj.type)) {
  1038. if (treeNode.data.quantityCoe.material)
  1039. coe = treeNode.data.quantityCoe.material;
  1040. } else if (baseMachineTypes.indexOf(glj.type)) {
  1041. if (treeNode.data.quantityCoe.machine)
  1042. coe = treeNode.data.quantityCoe.machine;
  1043. } else if (gljType.MAIN_MATERIAL == glj.type) {
  1044. if (treeNode.data.quantityCoe.main) coe = treeNode.data.quantityCoe.main;
  1045. } else if (gljType.EQUIPMENT == glj.type) {
  1046. if (treeNode.data.quantityCoe.equipment)
  1047. coe = treeNode.data.quantityCoe.equipment;
  1048. }
  1049. if (coe == "0") coe = 1; // 这里加个保护
  1050. return coe;
  1051. },
  1052. uiNodeTenderQty: function (treeNode) {
  1053. return this.calcNodeTenderQty(treeNode);
  1054. },
  1055. calcNodeTenderQty: function (treeNode) {
  1056. if (this.isBill(treeNode))
  1057. // 清单只有一个工程量,没有调整后工程量。
  1058. return this.uiNodeQty(treeNode);
  1059. else {
  1060. let qCoe = 1;
  1061. /* 量价、工料机类型的定额,在反向调价之调整人材机消耗量系数时,因为他们没有工料机可调,调价结果没变,影响汇总后的父结点金额。
  1062. 所以要特殊处理:此种情况下仍然要调量价的消耗量,即还是要像"子目工程量调整系数"方式那样调,但系数又不能在"子目工程量调整系数"
  1063. 中显示出来(明明是调工料机,你却调到树结点上,这比较搞笑啊),所以可以改变tenderQuantity达到同样的效果以瞒天过海。所以在取系数时,
  1064. 无论什么系数,只要能取到就算正确。
  1065. 2020-04-05 注: 以上是老黄历。新思路是量价只作为定额调整,不作为工料机调整。两种反调模式下,统一都只调子目消耗量系数。
  1066. 为避免歧义,量价的工料机调整系数不允许输入。
  1067. */
  1068. // if (calcTools.isVP_or_GLJR(treeNode)){
  1069. // if (treeNode.data.rationQuantityCoe)
  1070. // qCoe = treeNode.data.rationQuantityCoe
  1071. // else if (treeNode.data.quantityCoe && treeNode.data.quantityCoe.labour)
  1072. // qCoe = treeNode.data.quantityCoe.labour;
  1073. // }
  1074. // else {
  1075. if (treeNode.data.rationQuantityCoe)
  1076. qCoe = treeNode.data.rationQuantityCoe;
  1077. // };
  1078. if (qCoe == "0" || qCoe == 0) qCoe = 1;
  1079. treeNode.data.tenderQuantity = (
  1080. this.uiNodeQty(treeNode) * qCoe
  1081. ).toDecimal(decimalObj.decimal("quantity", treeNode));
  1082. return treeNode.data.tenderQuantity;
  1083. }
  1084. },
  1085. calcGLJTenderQty: function (treeNode, glj) {
  1086. if (treeNode.data.quantityCoe == undefined) {
  1087. glj.tenderQuantity = glj.quantity;
  1088. } else {
  1089. let coe = 1;
  1090. if (this.isTenderProjectGLJ(glj))
  1091. coe = this.tenderCoe_GLJQty(treeNode, glj);
  1092. glj.tenderQuantity = (glj.quantity * coe).toDecimal(
  1093. decimalObj.glj.quantity
  1094. );
  1095. }
  1096. return glj.tenderQuantity;
  1097. },
  1098. calcGLJTenderPrice: function (glj) {
  1099. let projGLJ = calcTools.getProjectGLJ(glj);
  1100. if (projGLJ == null) {
  1101. // 量价定额虚拟出来的工料机,在项目工料机中查不到。
  1102. glj.tenderPrice =
  1103. projectObj.project.projectGLJ.getTenderMarketPrice(projGLJ);
  1104. } else {
  1105. let pCoe = 1;
  1106. // 先从项目工料机里检查该工料机是否参与调价
  1107. if (projGLJ.is_adjust_price != 1) pCoe = this.tenderCoe_GLJPrice();
  1108. glj.tenderPrice = (glj.marketPrice * pCoe).toDecimal(
  1109. decimalObj.glj.unitPrice
  1110. );
  1111. }
  1112. return glj.tenderPrice;
  1113. },
  1114. // 界面显示的工料机价格,包括定额价、市场价等。参数 price 传入一个普通的价格数值即可。
  1115. uiGLJPrice: function (price, glj) {
  1116. if (price) {
  1117. let projGLJ = glj ? calcTools.getProjectGLJ(glj) : null;
  1118. let d =
  1119. projGLJ && projGLJ.ratio_data.length > 0
  1120. ? decimalObj.glj.unitPriceHasMix
  1121. : decimalObj.glj.unitPrice;
  1122. return parseFloat(price).toDecimal(d);
  1123. } else return 0;
  1124. },
  1125. // 界面显示的工料机数量。参数 quantity 传入一个普通的数量数值即可。
  1126. uiGLJQty: function (quantity) {
  1127. if (quantity)
  1128. return parseFloat(quantity).toDecimal(decimalObj.glj.quantity);
  1129. else return 0;
  1130. },
  1131. hasTargetTotalFee: function (treeNode) {
  1132. // targetTotalFee 有时为字符串“0”,此种情况会执行if 条件引起逻辑错误。所以这里封闭成方法直接调用。
  1133. return (
  1134. treeNode.data.targetTotalFee && parseFloat(treeNode.data.targetTotalFee)
  1135. );
  1136. },
  1137. hasQuantity: function (treeNode) {
  1138. return treeNode.data.quantity && parseFloat(treeNode.data.quantity);
  1139. },
  1140. getRationsByProjectGLJ(PGLJID) {
  1141. let rationIDs = [];
  1142. let RGs = projectObj.project.ration_glj.datas;
  1143. let PGLJIDs = [];
  1144. if (Array.isArray(PGLJID)) {
  1145. //为了提高效率,改成支持传入数组
  1146. PGLJIDs = PGLJID;
  1147. } else {
  1148. PGLJIDs = [PGLJID];
  1149. }
  1150. for (let rg of RGs) {
  1151. if (PGLJIDs.indexOf(rg.projectGLJID) !== -1) {
  1152. rationIDs.push(rg.rationID);
  1153. }
  1154. }
  1155. let rationNodes = [];
  1156. let nodes = projectObj.project.mainTree.nodes;
  1157. for (let rID of rationIDs) {
  1158. rationNodes.push(nodes["id_" + rID]);
  1159. }
  1160. // 工料机形式的定额
  1161. let items = projectObj.project.mainTree.items;
  1162. for (let item of items) {
  1163. if (PGLJIDs.indexOf(item.data.projectGLJID) !== -1)
  1164. rationNodes.push(item);
  1165. }
  1166. return rationNodes;
  1167. },
  1168. getNodesByProgramID(programID) {
  1169. let discreteNodes = [];
  1170. let nodes = projectObj.project.mainTree.items;
  1171. for (let node of nodes) {
  1172. if (node.data.programID == programID) discreteNodes.push(node);
  1173. }
  1174. return discreteNodes;
  1175. },
  1176. getProjectGLJ(glj) {
  1177. if (glj.projectGLJID) {
  1178. return projectObj.project.projectGLJ.getDataByID(glj.projectGLJID);
  1179. } else return null;
  1180. },
  1181. labourDays(node, isTender) {
  1182. if (!node.data.gljList) return 0;
  1183. let rst = 0;
  1184. calcTools.uiNodeQty(node);
  1185. for (let glj of node.data.gljList) {
  1186. if (glj.type == gljType.LABOUR) {
  1187. let gljQ = isTender ? glj.tenderQuantity : glj.quantity;
  1188. gljQ = gljQ.toDecimal(decimalObj.glj.quantity);
  1189. rst = (rst + gljQ).toDecimal(decimalObj.process);
  1190. }
  1191. }
  1192. return rst.toDecimal(decimalObj.glj.quantity);
  1193. },
  1194. getProjectFeatureProperty(propertyKey) {
  1195. for (let o of projectObj.project.property.projectFeature) {
  1196. if (o.key == propertyKey) {
  1197. return o.value;
  1198. }
  1199. }
  1200. },
  1201. getFeeRateByNode(node) {
  1202. let decimal = getDecimal("feeRate");
  1203. if (node.data.feeRateID) {
  1204. let r = projectObj.project.FeeRate.getFeeRateByID(node.data.feeRateID);
  1205. if (r) return scMathUtil.roundForObj(r.rate, decimal);
  1206. }
  1207. if (node.data.feeRate || node.data.feeRate == 0)
  1208. return scMathUtil.roundForObj(node.data.feeRate, decimal);
  1209. return 100;
  1210. },
  1211. isEmptyObject(obj) {
  1212. let arr = Object.keys(obj);
  1213. return arr.length == 0;
  1214. },
  1215. // 清单价格是否大于最高限价
  1216. unitFeeGTMaxPrice: function (node, feeField) {
  1217. if (!this.isBill(node)) {
  1218. return false;
  1219. }
  1220. const totalFee = this.getFee(node, feeField);
  1221. const maxPrice = node.data.maxPrice;
  1222. // 最高限价有值才对比
  1223. if (!commonUtil.isNumber(maxPrice)) {
  1224. return false;
  1225. }
  1226. return totalFee > +maxPrice;
  1227. },
  1228. // 清单价格是否小于最低限价
  1229. unitFeeLTMinPrice: function (node, feeField) {
  1230. if (!this.isBill(node)) {
  1231. return false;
  1232. }
  1233. const totalFee = this.getFee(node, feeField);
  1234. const minPrice = node.data.minPrice;
  1235. // 最低限价有值才对比
  1236. if (!commonUtil.isNumber(minPrice)) {
  1237. return false;
  1238. }
  1239. return totalFee < +minPrice;
  1240. },
  1241. getTenderTypeStr: function () {
  1242. let tenderSetting = projectObj.project.property.tenderSetting;
  1243. let ct =
  1244. tenderSetting && tenderSetting.calcPriceOption
  1245. ? tenderSetting.calcPriceOption
  1246. : "priceBase_RCJ";
  1247. if (ct == "priceBase") ct = "priceBase_RCJ"; // 兼容旧项目
  1248. return ct;
  1249. },
  1250. getTenderType: function () {
  1251. let rst;
  1252. let sOption = calcTools.getTenderTypeStr();
  1253. if (sOption == "coeBase") rst = tenderTypes.ttCalc;
  1254. else if (sOption == "priceBase_RCJ") rst = tenderTypes.ttReverseGLJ;
  1255. else if (sOption == "priceBase_ZM") rst = tenderTypes.ttReverseRation;
  1256. return rst;
  1257. },
  1258. // 取树结点的调价系数。
  1259. getCoe: function (node, tender) {
  1260. if (tender == tenderTypes.ttReverseGLJ)
  1261. return calcTools.isVP_or_GLJR(node)
  1262. ? node.data.rationQuantityCoe
  1263. : node.data.quantityCoe
  1264. ? node.data.quantityCoe.labour
  1265. : 0;
  1266. else if (tender == tenderTypes.ttReverseRation)
  1267. return node.data.rationQuantityCoe;
  1268. },
  1269. };
  1270. let rationCalcBases = {
  1271. 定额基价人工费: function (node, isTender) {
  1272. return calcTools.rationBaseFee(
  1273. node,
  1274. [gljType.LABOUR],
  1275. priceTypes.ptBasePrice,
  1276. isTender
  1277. );
  1278. },
  1279. 定额基价材料费: function (node, isTender) {
  1280. return calcTools.rationBaseFee(
  1281. node,
  1282. baseMaterialTypes,
  1283. priceTypes.ptBasePrice,
  1284. isTender
  1285. );
  1286. },
  1287. 定额基价机械费: function (node, isTender) {
  1288. return calcTools.rationBaseFee(
  1289. node,
  1290. [gljType.GENERAL_MACHINE],
  1291. priceTypes.ptBasePrice,
  1292. isTender
  1293. );
  1294. },
  1295. 定额基价机上人工费: function (node, isTender) {
  1296. return calcTools.machineDetailFee(
  1297. node,
  1298. node.data.gljList,
  1299. [],
  1300. gljType.MACHINE_LABOUR,
  1301. isTender
  1302. );
  1303. },
  1304. 人工费价差: function (node, isTender) {
  1305. return calcTools.rationBaseFee(
  1306. node,
  1307. [gljType.LABOUR],
  1308. priceTypes.ptDiffPrice,
  1309. isTender
  1310. );
  1311. },
  1312. 材料费价差: function (node, isTender) {
  1313. return calcTools.rationBaseFee(
  1314. node,
  1315. baseMaterialTypes,
  1316. priceTypes.ptDiffPrice,
  1317. isTender
  1318. );
  1319. },
  1320. 机械费价差: function (node, isTender) {
  1321. return calcTools.rationBaseFee(
  1322. node,
  1323. [gljType.GENERAL_MACHINE],
  1324. priceTypes.ptDiffPrice,
  1325. isTender
  1326. );
  1327. },
  1328. 主材费价差: function (node, isTender) {
  1329. return calcTools.rationBaseFee(
  1330. node,
  1331. [gljType.MAIN_MATERIAL],
  1332. priceTypes.ptDiffPrice,
  1333. isTender
  1334. );
  1335. },
  1336. 设备费价差: function (node, isTender) {
  1337. return calcTools.rationBaseFee(
  1338. node,
  1339. [gljType.EQUIPMENT],
  1340. priceTypes.ptDiffPrice,
  1341. isTender
  1342. );
  1343. },
  1344. 主材费: function (node, isTender) {
  1345. return calcTools.rationBaseFee(
  1346. node,
  1347. [gljType.MAIN_MATERIAL],
  1348. priceTypes.ptBasePrice,
  1349. isTender
  1350. );
  1351. },
  1352. 设备费: function (node, isTender) {
  1353. return calcTools.rationBaseFee(
  1354. node,
  1355. [gljType.EQUIPMENT],
  1356. priceTypes.ptBasePrice,
  1357. isTender
  1358. );
  1359. },
  1360. 人工工日: function (node, isTender) {
  1361. return calcTools.labourDays(node, isTender);
  1362. },
  1363. 甲供定额基价人工费: function (node, isTender) {
  1364. return calcTools.partASupplyFee(node, "甲供定额基价人工费", isTender, true);
  1365. },
  1366. 甲供定额基价材料费: function (node, isTender) {
  1367. return calcTools.partASupplyFee(node, "甲供定额基价材料费", isTender, true);
  1368. },
  1369. 甲供定额基价机械费: function (node, isTender) {
  1370. return calcTools.partASupplyFee(node, "甲供定额基价机械费", isTender, true);
  1371. },
  1372. 甲供主材费: function (node, isTender) {
  1373. return calcTools.partASupplyFee(node, "甲供主材费", isTender, false);
  1374. },
  1375. 甲供设备费: function (node, isTender) {
  1376. return calcTools.partASupplyFee(node, "甲供设备费", isTender, false);
  1377. },
  1378. 甲定定额基价人工费: function (node, isTender) {
  1379. return calcTools.partASupplyFee(node, "甲定定额基价人工费", isTender, true);
  1380. },
  1381. 甲定定额基价材料费: function (node, isTender) {
  1382. return calcTools.partASupplyFee(node, "甲定定额基价材料费", isTender, true);
  1383. },
  1384. 甲定定额基价机械费: function (node, isTender) {
  1385. return calcTools.partASupplyFee(node, "甲定定额基价机械费", isTender, true);
  1386. },
  1387. 甲定主材费: function (node, isTender) {
  1388. return calcTools.partASupplyFee(node, "甲定主材费", isTender, false);
  1389. },
  1390. 甲定设备费: function (node, isTender) {
  1391. return calcTools.partASupplyFee(node, "甲定设备费", isTender, false);
  1392. },
  1393. 暂估材料费: function (node, isTender) {
  1394. return calcTools.estimateFee(node, true, isTender);
  1395. },
  1396. 分包定额基价人工费: function (node, isTender) {
  1397. if (node.data.isSubcontract)
  1398. return calcTools.rationBaseFee(
  1399. node,
  1400. [gljType.LABOUR],
  1401. priceTypes.ptBasePrice,
  1402. isTender
  1403. );
  1404. else return 0;
  1405. },
  1406. 分包定额基价材料费: function (node, isTender) {
  1407. if (node.data.isSubcontract)
  1408. return calcTools.rationBaseFee(
  1409. node,
  1410. baseMaterialTypes,
  1411. priceTypes.ptBasePrice,
  1412. isTender
  1413. );
  1414. else return 0;
  1415. },
  1416. 分包定额基价机械费: function (node, isTender) {
  1417. if (node.data.isSubcontract)
  1418. return calcTools.rationBaseFee(
  1419. node,
  1420. [gljType.GENERAL_MACHINE],
  1421. priceTypes.ptBasePrice,
  1422. isTender
  1423. );
  1424. else return 0;
  1425. },
  1426. 分包主材费: function (node, isTender) {
  1427. if (node.data.isSubcontract)
  1428. return calcTools.rationBaseFee(
  1429. node,
  1430. [gljType.MAIN_MATERIAL],
  1431. priceTypes.ptBasePrice,
  1432. isTender
  1433. );
  1434. else return 0;
  1435. },
  1436. 分包设备费: function (node, isTender) {
  1437. if (node.data.isSubcontract)
  1438. return calcTools.rationBaseFee(
  1439. node,
  1440. [gljType.EQUIPMENT],
  1441. priceTypes.ptBasePrice,
  1442. isTender
  1443. );
  1444. else return 0;
  1445. },
  1446. 分包人工工日: function (node, isTender) {
  1447. if (node.data.isSubcontract) return calcTools.labourDays(node, isTender);
  1448. else return 0;
  1449. },
  1450. };
  1451. let analyzer = {
  1452. error: "",
  1453. standard: function (expr) {
  1454. let str = expr;
  1455. str = str.replace(/\s/g, ""); // 去空格、去中文空格
  1456. str = str.replace(/(/g, "("); // 中文括号"("换成英文括号"("
  1457. str = str.replace(/)/g, ")"); // 中文括号")"换成英文括号")"
  1458. str = str.replace(/f/g, "F"); // f换成F
  1459. str = str.replace(/l/g, "L"); // l换成L
  1460. return str;
  1461. },
  1462. getFArr: function (expr) {
  1463. let pattF = new RegExp(/F\d+/gi);
  1464. let arrF = expr.match(pattF);
  1465. return arrF ? arrF : [];
  1466. },
  1467. getAtIDArr: function (expr) {
  1468. // ['@1','@2']
  1469. let patt = new RegExp(/@\d+/gi);
  1470. let arr = expr.match(patt);
  1471. return arr ? arr : [];
  1472. },
  1473. getBaseArr: function (expr) {
  1474. let pattBase = new RegExp(/\[[\u4E00-\u9FA5]+\]/gi);
  1475. let arrBase = expr.match(pattBase);
  1476. return arrBase ? arrBase : [];
  1477. },
  1478. getID: function (FName, template) {
  1479. // F13 → 4
  1480. let idx = FName.slice(1) - 1;
  1481. let id = template.calcItems[idx] ? template.calcItems[idx].ID : null;
  1482. return id;
  1483. },
  1484. getFName: function (atID, template) {
  1485. // @3 → F7
  1486. for (var i = 0; i < template.calcItems.length; i++) {
  1487. if (template.calcItems[i].ID == atID.slice(1)) {
  1488. return "F" + (i + 1);
  1489. }
  1490. }
  1491. return null;
  1492. },
  1493. getItem: function (FName, template) {
  1494. // F3 → calcItems[2] → {Object}
  1495. let idx = FName.slice(1) - 1;
  1496. return template.calcItems[idx];
  1497. },
  1498. isCycleCalc: function (expression, ID, template) {
  1499. // 这里判断expression,是ID引用: @5+@6
  1500. let atID = `@${ID}`;
  1501. // 避免部分匹配,如:@10匹配@1
  1502. let idx = expression.indexOf(atID);
  1503. if (idx >= 0) {
  1504. let nextPos = idx + atID.length;
  1505. if (nextPos >= expression.length) return true;
  1506. let char = expression.charAt(nextPos);
  1507. if (!char.isNumberStr()) return true;
  1508. }
  1509. let atIDs = analyzer.getAtIDArr(expression);
  1510. for (let atID of atIDs) {
  1511. let item = template.compiledCalcItems[atID.slice(1)];
  1512. if (analyzer.isCycleCalc(item.expression, ID, template)) return true;
  1513. }
  1514. return false;
  1515. },
  1516. isLegal: function (dispExpr, itemID, template) {
  1517. // 检测包括:无效字符、基数是否中括号、基数是否定义、行引用、循环计算
  1518. function testValue(expr) {
  1519. try {
  1520. expr = expr.replace(/\[[\u4E00-\u9FA5]+\]/gi, "0");
  1521. expr = expr.replace(/@\d+/gi, "0");
  1522. expr = expr.replace(/L/gi, "0");
  1523. expr = expr.replace(/%/gi, "*0.01");
  1524. if (expr.includes("00")) return false;
  1525. eval(expr);
  1526. return true;
  1527. } catch (err) {
  1528. return false;
  1529. }
  1530. }
  1531. let me = analyzer;
  1532. let expr = me.standard(dispExpr);
  1533. let invalidChars = /[^0-9\u4e00-\u9fa5\+\-\*\/\(\)\.\[\]FL%]/g;
  1534. if (invalidChars.test(expr)) {
  1535. analyzer.error = `表达式中含有${hintBox.font("无效字符")}!`;
  1536. // hintBox.infoBox('错误提示',`表达式中含有${hintBox.font('无效字符')}!`,1);
  1537. return false;
  1538. }
  1539. let i = expr.search(/\df/gi); // 4F3
  1540. let j = expr.search(/\d\[/gi); // 4[定额基价人工费]
  1541. if (i > -1 || j > -1) {
  1542. analyzer.error = `表达式中${hintBox.font("缺少运算符")}!`;
  1543. // hintBox.infoBox('错误提示', `表达式中${hintBox.font('缺少运算符')}!`, 1);
  1544. return false;
  1545. }
  1546. let pattCn = new RegExp(/[\u4E00-\u9FA5]+/gi);
  1547. let arrCn = expr.match(pattCn);
  1548. let pattBase = new RegExp(/\[[\u4E00-\u9FA5]+\]/gi);
  1549. let arrBase = expr.match(pattBase);
  1550. if (arrCn && !arrBase) {
  1551. analyzer.error = `定额基数必须用中括号${hintBox.font("[]")}括起来!`;
  1552. // hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
  1553. return false;
  1554. }
  1555. if (arrCn && arrBase && arrCn.length != arrBase.length) {
  1556. for (let cn of arrCn) {
  1557. let tempBase = `[${cn}]`;
  1558. if (!arrBase.includes(tempBase)) {
  1559. analyzer.error = `定额基数“${hintBox.font(
  1560. cn
  1561. )}”必须用中括号${hintBox.font("[]")}括起来!`;
  1562. // hintBox.infoBox('错误提示', `定额基数“${hintBox.font(cn)}”必须用中括号${hintBox.font('[]')}括起来!`, 1);
  1563. return false;
  1564. }
  1565. }
  1566. // 这里要加一个保险。因为上面的 for 循环在“主材费 + [主材费]” 情况下有Bug
  1567. analyzer.error = `定额基数必须用中括号${hintBox.font("[]")}括起来!`;
  1568. // hintBox.infoBox('错误提示', `定额基数必须用中括号${hintBox.font('[]')}括起来!`, 1);
  1569. return false;
  1570. }
  1571. if (arrBase) {
  1572. for (let base of arrBase) {
  1573. let baseName = base.slice(1, -1);
  1574. if (!rationCalcBases[baseName]) {
  1575. analyzer.error = `定额基数${hintBox.font(
  1576. "[" + baseName + "]"
  1577. )}未定义!`;
  1578. // hintBox.infoBox('错误提示', `定额基数${hintBox.font('[' +baseName + ']')}未定义!`, 1);
  1579. return false;
  1580. }
  1581. }
  1582. }
  1583. let arrF = me.getFArr(expr);
  1584. for (let F of arrF) {
  1585. let num = F.slice(1);
  1586. if (num > template.calcItems.length) {
  1587. let s = hintBox.font("F" + num);
  1588. analyzer.error = `表达式中 “${hintBox.font(s)}” 行号引用错误!`;
  1589. // hintBox.infoBox('错误提示', `表达式中 “${hintBox.font(s)}” 行号引用错误!`, 1);
  1590. return false;
  1591. }
  1592. }
  1593. let expression = me.getExpression(expr, template);
  1594. if (me.isCycleCalc(expression, itemID, template)) {
  1595. analyzer.error = `表达式中有${hintBox.font("循环计算")}!`;
  1596. // hintBox.infoBox('错误提示', `表达式中有${hintBox.font('循环计算')}!`, 1);
  1597. return false;
  1598. }
  1599. if (!testValue(expression)) {
  1600. analyzer.error = `表达式中有${hintBox.font("语法错误")}!`;
  1601. // hintBox.infoBox('错误提示', `表达式中有${hintBox.font('语法错误')}!`, 1);
  1602. return false;
  1603. }
  1604. return true; // 表达式合法
  1605. },
  1606. refIDToLines: function (expression, template) {
  1607. // @2、@3 → F7、F8
  1608. let rst = expression;
  1609. let atIDArr = analyzer.getAtIDArr(rst);
  1610. let fArr = [];
  1611. for (let atID of atIDArr) {
  1612. let FN = analyzer.getFName(atID, template);
  1613. fArr.push(FN);
  1614. }
  1615. for (let i = 0; i < atIDArr.length; i++) {
  1616. let patt = new RegExp(atIDArr[i]);
  1617. let val = fArr[i];
  1618. rst = rst.replace(patt, val);
  1619. }
  1620. return rst;
  1621. },
  1622. refLineToIDs: function (dispExpr, template) {
  1623. // F7、F8 → @2、@3
  1624. let rst = analyzer.standard(dispExpr);
  1625. let fArr = analyzer.getFArr(rst);
  1626. let IDArr = [];
  1627. for (let F of fArr) {
  1628. let ID = analyzer.getID(F, template);
  1629. IDArr.push(ID);
  1630. }
  1631. for (let i = 0; i < fArr.length; i++) {
  1632. let patt = new RegExp(fArr[i]);
  1633. let val = `@${IDArr[i]}`;
  1634. rst = rst.replace(patt, val);
  1635. }
  1636. return rst;
  1637. },
  1638. getDispExpr: function (expression, template) {
  1639. return analyzer.refIDToLines(expression, template);
  1640. },
  1641. getExpression: function (dispExpr, template) {
  1642. return analyzer.refLineToIDs(dispExpr, template);
  1643. },
  1644. getDispExprUser: function (dispExpr, labourCoe) {
  1645. // labourCoe 是 str 类型
  1646. let rst = analyzer.standard(dispExpr);
  1647. rst = rst.replace(/L/g, labourCoe);
  1648. return rst;
  1649. },
  1650. getCompiledExpr: function (expression, labourCoe) {
  1651. // labourCoe 是 str 类型
  1652. let rst = expression;
  1653. let atIDArr = analyzer.getAtIDArr(rst);
  1654. let IDArr = atIDArr.map(function (atID) {
  1655. return atID.slice(1);
  1656. });
  1657. for (var i = 0; i < atIDArr.length; i++) {
  1658. let patt = new RegExp(atIDArr[i]);
  1659. let val = `$CE.at(${IDArr[i]},false)`;
  1660. rst = rst.replace(patt, val);
  1661. }
  1662. rst = rst.replace(/%/g, "*0.01");
  1663. rst = rst.replace(/\[/g, "$CE.base('");
  1664. rst = rst.replace(/\]/g, "',false)");
  1665. rst = rst.replace(/L/g, labourCoe);
  1666. return rst;
  1667. },
  1668. getCompiledTenderExpr: function (compiledExpr) {
  1669. let rst = compiledExpr.replace(/false/g, "true");
  1670. return rst;
  1671. },
  1672. getStatement: function (expression, template) {
  1673. let rst = expression;
  1674. let atIDArr = analyzer.getAtIDArr(rst);
  1675. let IDArr = atIDArr.map(function (atID) {
  1676. return atID.slice(1);
  1677. });
  1678. for (var i = 0; i < atIDArr.length; i++) {
  1679. let patt = new RegExp(atIDArr[i]);
  1680. let val =
  1681. projectObj.project.calcProgram.compiledTemplates[template.ID]
  1682. .compiledCalcItems[IDArr[i]].name;
  1683. rst = rst.replace(patt, val);
  1684. }
  1685. rst = rst.replace(/\[/g, "");
  1686. rst = rst.replace(/\]/g, "");
  1687. rst = rst.replace(/L/g, "人工系数");
  1688. return rst;
  1689. },
  1690. calcItemMaxID: function (template) {
  1691. let MaxID = 0;
  1692. for (let item of template.calcItems) {
  1693. if (item.ID > MaxID) MaxID = item.ID;
  1694. }
  1695. return MaxID;
  1696. },
  1697. calcItemIsUsed: function (template, calcItem) {
  1698. let atID = "@" + calcItem.ID;
  1699. for (var i = 0; i < template.calcItems.length; i++) {
  1700. let item = template.calcItems[i];
  1701. let atIDArr = analyzer.getAtIDArr(item.expression);
  1702. if (atIDArr.indexOf(atID) >= 0) {
  1703. calcItem.tempUsed = i;
  1704. return true;
  1705. }
  1706. }
  1707. return false;
  1708. },
  1709. refreshUsedCalcItemsStatement: function (template, calcItem) {
  1710. let atID = "@" + calcItem.ID;
  1711. for (var i = 0; i < template.calcItems.length; i++) {
  1712. let item = template.calcItems[i];
  1713. let atIDArr = analyzer.getAtIDArr(item.expression);
  1714. if (atIDArr.indexOf(atID) >= 0) {
  1715. item.statement = analyzer.getStatement(item.expression, template);
  1716. }
  1717. }
  1718. },
  1719. calcItemLabourCoe: function (calcItem) {
  1720. let lc = 0;
  1721. if (calcItem.labourCoeID)
  1722. lc =
  1723. projectObj.project.calcProgram.compiledLabourCoes[
  1724. calcItem.labourCoeID
  1725. ].coe.toString();
  1726. return lc;
  1727. },
  1728. templateRefresh: function (template) {
  1729. for (let item of template) {
  1730. item.dispExpr = analyzer.getDispExpr(item.expression, template);
  1731. item.dispExprUser = analyzer.getDispExprUser(
  1732. item.dispExpr,
  1733. me.calcItemLabourCoe(item)
  1734. );
  1735. }
  1736. },
  1737. templateMaxID: function () {
  1738. let ts = projectObj.project.calcProgram.templates;
  1739. let MaxID = 0;
  1740. for (let t of ts) {
  1741. if (t.ID > MaxID) MaxID = t.ID;
  1742. }
  1743. return MaxID;
  1744. },
  1745. templateNewName: function (name) {
  1746. let i = 1;
  1747. while (projectObj.project.calcProgram.compiledTemplateMaps[name + i]) {
  1748. i++;
  1749. }
  1750. return name + i;
  1751. },
  1752. templateNameIsExist: function (name) {
  1753. if (projectObj.project.calcProgram.compiledTemplateMaps[name]) return true;
  1754. else return false;
  1755. },
  1756. templateIsUsed: function (ID) {
  1757. let nodes = projectObj.project.mainTree.items;
  1758. for (let node of nodes) {
  1759. if (node.data && node.data.programID && node.data.programID == ID) {
  1760. return true;
  1761. }
  1762. }
  1763. return false;
  1764. },
  1765. fieldNameIsUsed: function (template, fieldName) {
  1766. let fieldNameEn =
  1767. projectObj.project.calcProgram.compiledFeeTypeMaps[fieldName];
  1768. for (var i = 0; i < template.calcItems.length; i++) {
  1769. if (template.calcItems[i].fieldName == fieldNameEn) {
  1770. template.fieldNameTempUsed = i;
  1771. return true;
  1772. }
  1773. }
  1774. return false;
  1775. },
  1776. };
  1777. let executeObj = {
  1778. treeNode: null,
  1779. template: null,
  1780. tempCalcItem: null,
  1781. at: function (ID, isTender) {
  1782. let item = executeObj.template.compiledCalcItems[ID];
  1783. let rst = isTender ? item.tenderUnitFee : item.unitFee;
  1784. rst = parseFloat(rst);
  1785. return rst;
  1786. },
  1787. base: function (baseName, isTender) {
  1788. let me = executeObj;
  1789. // 量价、工料机形式的定额, 要把自己的市场单价用于计算程序中的基数。
  1790. if (calcTools.isVP_or_GLJR(me.treeNode))
  1791. return calcTools.marketPriceToBase(me.treeNode, baseName, isTender);
  1792. else {
  1793. if (!rationCalcBases[baseName]) {
  1794. hintBox.infoBox(
  1795. "系统提示",
  1796. "定额基数“" +
  1797. baseName +
  1798. "”未定义,计算错误。 (模板 " +
  1799. me.template.ID +
  1800. ",规则 " +
  1801. me.tempCalcItem.ID +
  1802. ")",
  1803. 1
  1804. );
  1805. return 0;
  1806. } else return rationCalcBases[baseName](me.treeNode, isTender);
  1807. }
  1808. },
  1809. HJ: function () {
  1810. let me = this;
  1811. let p = me.treeNode.data.calcBaseValue ? me.treeNode.data.calcBaseValue : 0;
  1812. let q = calcTools.uiNodeQty(me.treeNode)
  1813. ? calcTools.uiNodeQty(me.treeNode)
  1814. : 1;
  1815. let u = (p / q).toDecimal(decimalObj.decimal("unitPrice", me.treeNode));
  1816. return u;
  1817. },
  1818. };
  1819. class CalcProgram {
  1820. constructor(project) {
  1821. let me = this;
  1822. me.project = project;
  1823. me.datas = [];
  1824. me.rationMap = null; //定额 - 工料机映射临时变量
  1825. me.pgljMap = null;
  1826. project.registerModule(ModuleNames.calc_program, me);
  1827. }
  1828. // 兼容Project框架方法
  1829. getSourceType() {
  1830. return ModuleNames.calc_program;
  1831. }
  1832. // 兼容Project框架方法
  1833. // isInit:是否初始化,进入单位工程为true,导出接口为false,不需要存储费率临时数据
  1834. loadData(datas, isInit) {
  1835. this.datas = datas;
  1836. this.compileAllTemps(isInit);
  1837. }
  1838. // 兼容Project框架方法
  1839. doAfterUpdate(err, data) {
  1840. if (!err) {
  1841. $.bootstrapLoading.end();
  1842. }
  1843. }
  1844. // 经测试,全部编译一次耗时0.003~0.004秒。耗时基本忽略不计。
  1845. compileAllTemps(isInit = false) {
  1846. let me = this;
  1847. me.compiledFeeRates = {};
  1848. me.compiledLabourCoes = {};
  1849. me.compiledTemplates = {};
  1850. me.compiledTemplateMaps = {};
  1851. me.compiledTemplateNames = [];
  1852. me.compiledFeeTypeMaps = {};
  1853. me.compiledFeeTypeNames = [];
  1854. me.compiledCalcBases = {};
  1855. me.feeRates = this.project.FeeRate.datas.rates;
  1856. me.labourCoes = this.project.labourCoe.datas.coes;
  1857. me.feeTypes = cpFeeTypes;
  1858. // me.calcBases = rationCalcBase;
  1859. me.templates = this.project.calcProgram.datas.templates;
  1860. // me.templates.push(defaultBillTemplate);
  1861. // 先编译公用的基础数据
  1862. me.compilePublics();
  1863. me.compileTemplateMaps();
  1864. for (let t of me.templates) {
  1865. me.compileTemplate(t);
  1866. }
  1867. }
  1868. compilePublics() {
  1869. let me = this;
  1870. for (let rate of me.feeRates) {
  1871. me.compiledFeeRates[rate.ID] = rate;
  1872. }
  1873. for (let coe of me.labourCoes) {
  1874. me.compiledLabourCoes[coe.ID] = coe;
  1875. }
  1876. for (let ft of me.feeTypes) {
  1877. me.compiledFeeTypeMaps[ft.type] = ft.name;
  1878. me.compiledFeeTypeMaps[ft.name] = ft.type; // 中文预编译,可靠性有待验证
  1879. me.compiledFeeTypeNames.push(ft.name);
  1880. }
  1881. /* for (let cb of me.calcBases) {
  1882. me.compiledCalcBases[cb.dispName] = cb; // 中文预编译,可靠性有待验证
  1883. }*/
  1884. }
  1885. compileTemplateMaps() {
  1886. let me = this;
  1887. function clearObj(obj) {
  1888. for (let key in obj) {
  1889. delete obj[key];
  1890. }
  1891. }
  1892. clearObj(me.compiledTemplates);
  1893. clearObj(me.compiledTemplateMaps);
  1894. me.compiledTemplateNames.splice(0, me.compiledTemplateNames.length);
  1895. for (let t of me.templates) {
  1896. me.compiledTemplates[t.ID] = t;
  1897. me.compiledTemplateMaps[t.ID] = t.name;
  1898. me.compiledTemplateMaps[t.name] = t.ID;
  1899. me.compiledTemplateNames.push(t.name);
  1900. }
  1901. }
  1902. compileTemplate(template) {
  1903. let me = this;
  1904. // me.compiledTemplates[template.ID] = template;
  1905. // me.compiledTemplateMaps[template.ID] = template.name;
  1906. // me.compiledTemplateMaps[template.name] = template.ID;
  1907. // me.compiledTemplateNames.push(template.name);
  1908. template.hasCompiled = false;
  1909. template.errs = [];
  1910. let private_extract_ID = function (str, idx) {
  1911. let subStr = str.slice(idx);
  1912. let patt = new RegExp(/@\d+/);
  1913. let atID = subStr.match(patt);
  1914. let ID = atID ? atID[0].slice(1) : null;
  1915. return ID;
  1916. };
  1917. let private_parse_ref = function (item, itemIdx) {
  1918. let idx = item.expression.indexOf("@", 0);
  1919. while (idx >= 0) {
  1920. let ID = private_extract_ID(item.expression, idx);
  1921. let len = ID ? ID.toString().length : 0;
  1922. if (len) {
  1923. let subItem = template.compiledCalcItems[ID];
  1924. if (subItem) {
  1925. if (subItem.ID !== item.ID) {
  1926. private_parse_ref(
  1927. subItem,
  1928. template.compiledCalcItems[ID + "_idx"]
  1929. );
  1930. } else {
  1931. template.errs.push("循环引用ID: " + ID);
  1932. }
  1933. } else {
  1934. template.errs.push("找不到ID: " + ID);
  1935. console.log("找不到ID: " + ID);
  1936. }
  1937. }
  1938. idx = item.expression.indexOf("@", idx + len + 1);
  1939. }
  1940. if (template.compiledSeq.indexOf(itemIdx) < 0) {
  1941. template.compiledSeq.push(itemIdx);
  1942. }
  1943. };
  1944. let private_compile_items = function () {
  1945. for (let idx of template.compiledSeq) {
  1946. let item = template.calcItems[idx];
  1947. let lc = analyzer.calcItemLabourCoe(item);
  1948. // 用于界面显示。disExpr是公式模板,不允许修改:人工系数占位符被修改后变成数值,第二次无法正确替换。
  1949. item.dispExprUser = analyzer.getDispExprUser(item.dispExpr, lc);
  1950. if (item.expression == "HJ") item.compiledExpr = "$CE.HJ()";
  1951. else item.compiledExpr = analyzer.getCompiledExpr(item.expression, lc);
  1952. if (item.feeRateID) {
  1953. let orgFeeRate = item.feeRate;
  1954. let cfr = me.compiledFeeRates[item.feeRateID];
  1955. item.feeRate = cfr ? cfr.rate : 100;
  1956. // if (!orgFeeRate || (orgFeeRate && orgFeeRate != item.feeRate)){
  1957. // me.saveForReports.push({templatesID: template.ID, calcItem: item});
  1958. // }
  1959. }
  1960. // 字段名映射
  1961. item.displayFieldName = me.compiledFeeTypeMaps[item.fieldName];
  1962. }
  1963. };
  1964. if (template && template.calcItems && template.calcItems.length > 0) {
  1965. template.compiledSeq = [];
  1966. template.compiledCalcItems = {};
  1967. for (let i = 0; i < template.calcItems.length; i++) {
  1968. let item = template.calcItems[i];
  1969. item.dispExpr = analyzer.getDispExpr(item.expression, template);
  1970. template.compiledCalcItems[item.ID] = item;
  1971. template.compiledCalcItems[item.ID + "_idx"] = i;
  1972. }
  1973. for (let i = 0; i < template.calcItems.length; i++) {
  1974. let item = template.calcItems[i];
  1975. if (template.compiledSeq.indexOf(i) < 0) {
  1976. private_parse_ref(item, i);
  1977. }
  1978. }
  1979. if (template.errs.length == 0) {
  1980. private_compile_items();
  1981. template.hasCompiled = true;
  1982. } else {
  1983. console.log("errors: " + template.errs.toString());
  1984. }
  1985. }
  1986. }
  1987. // 删掉多余的费用。例如:①切换取费类别 ②从其它计算方式(有很多费)切换到公式计算方式(只需要common费),多出来的费要删除。
  1988. // 如果指定了保留字段,则按用户指定的来。如果没指定保留字段,则按默认的来:总造价清单只留common, estimate两个费用类别。其它公式清单只留common。
  1989. deleteUselessFees(treeNode, fieldNameArr) {
  1990. if (!(treeNode.data.fees && treeNode.data.fees.length > 0)) return;
  1991. let keeps = fieldNameArr ? fieldNameArr : [];
  1992. // 这两个默认是要保留的
  1993. if (!keeps.includes("common")) keeps.push("common");
  1994. if (!keeps.includes("estimate")) keeps.push("estimate");
  1995. for (let i = 0; i < treeNode.data.fees.length; i++) {
  1996. if (!keeps.includes(treeNode.data.fees[i].fieldName)) {
  1997. delete treeNode.data.feesIndex[treeNode.data.fees[i].fieldName];
  1998. treeNode.data.fees.splice(i, 1);
  1999. treeNode.changed = true;
  2000. }
  2001. }
  2002. }
  2003. // 不能直接删除该属性,否则无法冲掉库中已存储的值。下同。
  2004. deleteProperties(treeNode, propNamesArr) {
  2005. for (let pn of propNamesArr) {
  2006. if (treeNode.data[pn]) {
  2007. treeNode.data[pn] = null;
  2008. treeNode.changed = true;
  2009. }
  2010. }
  2011. }
  2012. // 只计算treeNode自身。changedArr: 外部传来的一个数组,专门存储发生变动的节点。
  2013. innerCalc(treeNode, changedArr, tenderType) {
  2014. if (treeNode.sourceType === ModuleNames.ration_glj) return; // 仅用作树节点显示的工料机不能参与计算。
  2015. let me = this;
  2016. //设置定额工料机映射表
  2017. me.setRationMap();
  2018. treeNode.calcType = calcTools.getCalcType(treeNode);
  2019. // 父清单汇总子清单的费用类别
  2020. if (treeNode.calcType == treeNodeCalcType.ctGatherBillsFees)
  2021. me.innerCalcBill(treeNode, 2)
  2022. // 叶子清单:汇总定额的费用类别
  2023. else if (treeNode.calcType == treeNodeCalcType.ctGatherRationsFees)
  2024. me.innerCalcBill(treeNode, 1)
  2025. // 叶子清单:锁定单价
  2026. else if (treeNode.calcType == treeNodeCalcType.ctLockUnitPrice)
  2027. me.innerCalcBill(treeNode, 4)
  2028. // 叶子清单:公式计算
  2029. else if (treeNode.calcType == treeNodeCalcType.ctCalcBaseValue)
  2030. me.innerCalcBillExpr(treeNode)
  2031. // 叶子清单:手工修改单价或金额。
  2032. else if (treeNode.calcType == treeNodeCalcType.ctCustom)
  2033. me.innerCalcBillCustom(treeNode);
  2034. // 定额:计算程序
  2035. else me.innerCalcRation(treeNode, tenderType);
  2036. if (!calcTools.isTotalCostBill(treeNode))
  2037. // 已在上面的分支中计算过
  2038. calcTools.estimateFee(treeNode);
  2039. if (treeNode.changed && !changedArr.includes(treeNode))
  2040. changedArr.push(treeNode);
  2041. }
  2042. // 清单部分抽取出来,供分摊清单公用。
  2043. // commonCalcType:1 叶子清单汇总定额的费用类别; 2 父清单汇总子清单的费用类别。
  2044. // 3: 分摊:叶子清单汇总定额的费用类别。4: 清单单价锁定。
  2045. innerCalcBill(treeNode, commonCalcType, tender = tenderTypes.ttCalc) {
  2046. let me = this;
  2047. treeNode.data.programID = null;
  2048. calcTools.initFees(treeNode);
  2049. let nodes = [];
  2050. if (commonCalcType == 1) {
  2051. calcTools.getGLJList(treeNode, true);
  2052. nodes = me.project.Ration.getRationNodes(treeNode);
  2053. } else if (commonCalcType == 2) {
  2054. // 固定清单 "材料(工程设备)暂估价" 比较特殊,不进行父项汇总(需求是这么要求的)
  2055. // nodes = treeNode.children
  2056. nodes = me.project.Bills.getGatherNodes(treeNode);
  2057. } else if (commonCalcType == 3) nodes = treeNode.children;
  2058. function isBaseFeeType(type) {
  2059. return (
  2060. ["labour", "material", "machine", "mainMaterial", "equipment", "labourInc"].indexOf(
  2061. type
  2062. ) > -1
  2063. );
  2064. }
  2065. let nQ = calcTools.uiNodeQty(treeNode);
  2066. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  2067. let bq = nQ ? nQ : 1;
  2068. let btq = nTQ ? nTQ : 1;
  2069. let rst = [];
  2070. for (let ft of cpFeeTypes) {
  2071. let ftObj = {};
  2072. ftObj.fieldName = ft.type;
  2073. ftObj.name = ft.name;
  2074. let buf = 0,
  2075. btf = 0,
  2076. btuf = 0,
  2077. bttf = 0;
  2078. if (commonCalcType == 2) {
  2079. for (let node of nodes) {
  2080. if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
  2081. btf = (
  2082. btf + parseFloatPlus(node.data.feesIndex[ft.type].totalFee)
  2083. ).toDecimal(decimalObj.process);
  2084. bttf = (
  2085. bttf + parseFloatPlus(node.data.feesIndex[ft.type].tenderTotalFee)
  2086. ).toDecimal(decimalObj.process);
  2087. }
  2088. }
  2089. }
  2090. else if (commonCalcType == 1 || commonCalcType == 3) {
  2091. let sum_rtf = 0,
  2092. sum_rttf = 0;
  2093. for (let node of nodes) {
  2094. let ruf = 0,
  2095. rtuf = 0,
  2096. rtf = 0,
  2097. rttf = 0;
  2098. if (node.data.feesIndex && node.data.feesIndex[ft.type]) {
  2099. ruf = parseFloatPlus(
  2100. node.data.feesIndex[ft.type].unitFee
  2101. ).toDecimal(decimalObj.bills.unitPrice);
  2102. rtuf = parseFloatPlus(
  2103. node.data.feesIndex[ft.type].tenderUnitFee
  2104. ).toDecimal(decimalObj.bills.unitPrice);
  2105. rtf = parseFloatPlus(
  2106. node.data.feesIndex[ft.type].totalFee
  2107. ).toDecimal(decimalObj.bills.totalPrice);
  2108. rttf = parseFloatPlus(
  2109. node.data.feesIndex[ft.type].tenderTotalFee
  2110. ).toDecimal(decimalObj.bills.totalPrice);
  2111. }
  2112. // 取费方式为子目含量,清单行/列的XX单价应 =ROUND( ∑ROUND(定额XX单价*含量,清单单价精度),清单单价精度)
  2113. if (
  2114. me.project.property.billsCalcMode ===
  2115. leafBillGetFeeType.rationContent
  2116. ) {
  2117. buf = (
  2118. buf +
  2119. (ruf * parseFloatPlus(node.data.contain)).toDecimal(
  2120. decimalObj.bills.unitPrice
  2121. )
  2122. ).toDecimal(decimalObj.process);
  2123. if (node.data.tenderQuantity)
  2124. node.data.tenderContaion = (
  2125. node.data.tenderQuantity / bq
  2126. ).toDecimal(decimalObj.process);
  2127. else node.data.tenderContaion = node.data.contain;
  2128. btuf = (
  2129. btuf +
  2130. (rtuf * parseFloatPlus(node.data.tenderContaion)).toDecimal(
  2131. decimalObj.bills.unitPrice
  2132. )
  2133. ).toDecimal(decimalObj.process);
  2134. }
  2135. sum_rtf = (sum_rtf + rtf).toDecimal(decimalObj.process);
  2136. sum_rttf = (sum_rttf + rttf).toDecimal(decimalObj.process);
  2137. }
  2138. if (me.project.property.billsCalcMode == leafBillGetFeeType.rationPriceConverse || me.project.property.billsCalcMode == leafBillGetFeeType.rationPrice) {
  2139. buf = (sum_rtf / bq).toDecimal(decimalObj.process);
  2140. btuf = (sum_rttf / btq).toDecimal(decimalObj.process);
  2141. }
  2142. if (isBaseFeeType(ft.type) || (me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice && ft.type == "common")) {
  2143. btf = sum_rtf;
  2144. bttf = sum_rttf;
  2145. } else {
  2146. btf = (buf.toDecimal(decimalObj.bills.unitPrice) * bq).toDecimal(decimalObj.process);
  2147. bttf = (btuf.toDecimal(decimalObj.bills.unitPrice) * btq).toDecimal(decimalObj.process);
  2148. }
  2149. }
  2150. else if (commonCalcType == 4){ // 清单单价锁定
  2151. if (treeNode.data.feesIndex && treeNode.data.feesIndex[ft.type]) {
  2152. buf = parseFloatPlus(treeNode.data.feesIndex[ft.type].unitFee).toDecimal(decimalObj.bills.unitPrice);
  2153. btuf = parseFloatPlus(treeNode.data.feesIndex[ft.type].tenderUnitFee).toDecimal(decimalObj.bills.unitPrice);
  2154. btf = (bq * buf).toDecimal(decimalObj.bills.totalPrice);
  2155. bttf = (btq * btuf).toDecimal(decimalObj.bills.totalPrice);
  2156. }
  2157. }
  2158. ftObj.totalFee = btf.toDecimal(decimalObj.bills.totalPrice);
  2159. ftObj.tenderTotalFee = bttf.toDecimal(decimalObj.bills.totalPrice);
  2160. ftObj.unitFee = buf.toDecimal(decimalObj.bills.unitPrice);
  2161. ftObj.tenderUnitFee = btuf.toDecimal(decimalObj.bills.unitPrice);
  2162. calcTools.checkFeeField(treeNode, ftObj);
  2163. rst.push(ftObj);
  2164. }
  2165. treeNode.data.calcTemplate = { calcItems: rst };
  2166. }
  2167. innerCalcBillExpr(treeNode) {
  2168. delete treeNode.data.gljList;
  2169. let me = this;
  2170. me.deleteProperties(treeNode, ["programID"]);
  2171. me.deleteUselessFees(treeNode, ["common", "rationCommon"]);
  2172. let nQ = calcTools.uiNodeQty(treeNode);
  2173. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  2174. let f = calcTools.getFeeRateByNode(treeNode);
  2175. let b = treeNode.data.calcBaseValue ? treeNode.data.calcBaseValue : 0;
  2176. let tb = treeNode.data.tenderCalcBaseValue
  2177. ? treeNode.data.tenderCalcBaseValue
  2178. : 0;
  2179. let q = nQ ? nQ : 1;
  2180. let tq = nTQ ? nTQ : 1;
  2181. let uf = ((b * f * 0.01) / q).toDecimal(decimalObj.bills.unitPrice);
  2182. let tuf = ((tb * f * 0.01) / tq).toDecimal(decimalObj.bills.unitPrice);
  2183. let tf =
  2184. me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice
  2185. ? (b * f) / 100
  2186. : uf * q;
  2187. tf = tf.toDecimal(decimalObj.bills.totalPrice);
  2188. let ttf =
  2189. me.project.property.billsCalcMode === leafBillGetFeeType.rationPrice
  2190. ? (tb * f) / 100
  2191. : tuf * tq;
  2192. ttf = ttf.toDecimal(decimalObj.bills.totalPrice);
  2193. calcTools.checkFeeField(treeNode, {
  2194. fieldName: "common",
  2195. unitFee: uf,
  2196. totalFee: tf,
  2197. tenderUnitFee: tuf,
  2198. tenderTotalFee: ttf,
  2199. });
  2200. // 总造价清单还要做单项工程、建设项目的四大项金额汇总
  2201. if (calcTools.isTotalCostBill(treeNode)) {
  2202. // 公式叶子清单没有暂估费,但总造价清单除外。
  2203. calcTools.estimateFee(treeNode);
  2204. calcTools.initSummaryFee(treeNode);
  2205. treeNode.data.summaryFees.totalFee = tf;
  2206. treeNode.data.summaryFees.estimateFee = calcTools.getFee(
  2207. treeNode,
  2208. "estimate.totalFee"
  2209. );
  2210. treeNode.data.summaryFees.safetyFee = calcTools.getFee(
  2211. calcTools.getNodeByFlag(fixedFlag.SAFETY_CONSTRUCTION),
  2212. "common.totalFee"
  2213. );
  2214. treeNode.data.summaryFees.chargeFee = calcTools.getFee(
  2215. calcTools.getNodeByFlag(fixedFlag.CHARGE),
  2216. "common.totalFee"
  2217. );
  2218. }
  2219. treeNode.data.calcTemplate = { calcItems: [] };
  2220. }
  2221. innerCalcBillCustom(treeNode) {
  2222. let me = this;
  2223. delete treeNode.data.gljList;
  2224. me.deleteProperties(treeNode, [
  2225. "calcBase",
  2226. "calcBaseValue",
  2227. "tenderCalcBaseValue",
  2228. "programID",
  2229. ]);
  2230. me.deleteUselessFees(treeNode, ["rationCommon"]);
  2231. // 2017-09-27 需求改了,除了第 1 、 2.2部分以外,都可以手工修改综合单价、综合合价并参与计算
  2232. // 2021-09-14 增加强制修改综合单价功能,所以“除了第 1 、 2.2部分以外,...” 这里的业务取消。
  2233. // if (calcTools.canCalcToTalFeeByOwn(treeNode)) {
  2234. if (treeNode.data.feesIndex && treeNode.data.feesIndex.common) {
  2235. let ftObj = { fieldName: "common" };
  2236. let nQ = calcTools.uiNodeQty(treeNode);
  2237. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  2238. ftObj.unitFee = parseFloatPlus(treeNode.data.feesIndex.common.unitFee); // 以单价为基础数据。金额从单价计算获得。
  2239. ftObj.totalFee = (ftObj.unitFee * nQ).toDecimal(decimalObj.bills.totalPrice);
  2240. ftObj.tenderUnitFee = ftObj.unitFee;
  2241. ftObj.tenderTotalFee = (ftObj.tenderUnitFee * nTQ).toDecimal(decimalObj.bills.totalPrice);
  2242. calcTools.checkFeeField(treeNode, ftObj);
  2243. } else {
  2244. if (treeNode.data.fees && treeNode.data.fees.length > 0) {
  2245. treeNode.data.fees = null;
  2246. treeNode.data.feesIndex = null;
  2247. treeNode.changed = true;
  2248. }
  2249. }
  2250. treeNode.data.calcTemplate = { calcItems: [] };
  2251. }
  2252. // 定额部分抽取出来,供分摊定额公用。
  2253. innerCalcRation(treeNode, tenderType = tenderTypes.ttCalc) {
  2254. let me = this;
  2255. let fnArr = [];
  2256. // 如果是反算工料机,这里要先保证coe有值。
  2257. if (tenderType == tenderTypes.ttReverseGLJ) {
  2258. let coe = (
  2259. treeNode.data.tender_activeTarget / treeNode.data.tender_activeTotal
  2260. ).toDecimal(decimalObj.process);
  2261. treeNode.data.quantityCoe = {
  2262. labour: coe,
  2263. material: coe,
  2264. machine: coe,
  2265. main: coe,
  2266. equipment: coe,
  2267. };
  2268. }
  2269. calcTools.getGLJList(treeNode, true);
  2270. let nQ = calcTools.uiNodeQty(treeNode);
  2271. let nTQ = calcTools.uiNodeTenderQty(treeNode);
  2272. if (treeNode.calcType == treeNodeCalcType.ctRationCalcProgram) {
  2273. // 量价、工料机类型的定额要求"市场合价"
  2274. if (calcTools.isVP_or_GLJR(treeNode)) {
  2275. let u = treeNode.data.marketUnitFee ? treeNode.data.marketUnitFee : 0;
  2276. let t = (u * nQ).toDecimal(decimalObj.ration.totalPrice);
  2277. if (treeNode.data.marketTotalFee != t) {
  2278. treeNode.data.marketTotalFee = t;
  2279. treeNode.changed = true;
  2280. }
  2281. }
  2282. }
  2283. let template = me.compiledTemplates[treeNode.data.programID];
  2284. treeNode.data.calcTemplate = template;
  2285. if (treeNode && template && template.hasCompiled) {
  2286. //2018-08-27 空行的时候,取费专业为空,template也为空,加入template非空判断
  2287. let $CE = executeObj;
  2288. $CE.treeNode = treeNode;
  2289. $CE.template = template;
  2290. calcTools.initFees(treeNode);
  2291. for (let idx of template.compiledSeq) {
  2292. let calcItem = template.calcItems[idx];
  2293. $CE.tempCalcItem = calcItem;
  2294. let feeRate = 100; // 100%
  2295. if (calcItem.feeRate != undefined)
  2296. feeRate = parseFloat(calcItem.feeRate).toDecimal(decimalObj.feeRate);
  2297. calcItem.unitFee = (
  2298. eval(calcItem.compiledExpr) *
  2299. feeRate *
  2300. 0.01
  2301. ).toDecimal(decimalObj.decimal("unitPrice", treeNode));
  2302. calcItem.totalFee = (calcItem.unitFee * nQ).toDecimal(
  2303. decimalObj.decimal("totalPrice", treeNode)
  2304. );
  2305. let tExpr = analyzer.getCompiledTenderExpr(calcItem.compiledExpr);
  2306. calcItem.tenderUnitFee = (eval(tExpr) * feeRate * 0.01).toDecimal(
  2307. decimalObj.decimal("unitPrice", treeNode)
  2308. );
  2309. calcItem.tenderTotalFee = (calcItem.tenderUnitFee * nTQ).toDecimal(
  2310. decimalObj.decimal("totalPrice", treeNode)
  2311. );
  2312. if (calcItem.fieldName) {
  2313. fnArr.push(calcItem.fieldName);
  2314. calcTools.checkFeeField(treeNode, calcItem);
  2315. }
  2316. }
  2317. if (
  2318. tenderType == tenderTypes.ttReverseRation ||
  2319. tenderType == tenderTypes.ttReverseGLJ
  2320. )
  2321. this.reverseTenderCalc(treeNode, tenderType);
  2322. me.deleteUselessFees(treeNode, fnArr);
  2323. }
  2324. }
  2325. // 存储、刷新零散的多个结点。
  2326. saveNodes(treeNodes, callback) {
  2327. if (treeNodes.length < 1) {
  2328. $.bootstrapLoading.end();
  2329. this.rationMap = null;
  2330. this.pgljMap = null;
  2331. return;
  2332. }
  2333. let me = this;
  2334. let dataArr = [];
  2335. for (let node of treeNodes) {
  2336. if (node.changed) {
  2337. // console.log(node.data.name);
  2338. let data = calcTools.cutNodeForSave(node);
  2339. let newData = { type: node.sourceType, data: data };
  2340. dataArr.push(newData);
  2341. }
  2342. }
  2343. if (dataArr.length < 1) {
  2344. $.bootstrapLoading.end();
  2345. return;
  2346. }
  2347. if (projectObj.project.projectInfo.lastFileVer != VERSION) {
  2348. let data = {
  2349. ID: projectObj.project.ID(),
  2350. lastFileVer: VERSION,
  2351. };
  2352. let newData = { type: "project", data: data };
  2353. dataArr.push(newData);
  2354. }
  2355. $.bootstrapLoading.start();
  2356. let startTime = +new Date();
  2357. me.project.updateNodes(dataArr, function (data) {
  2358. me.rationMap = null;
  2359. me.pgljMap = null;
  2360. if (callback) {
  2361. callback(data);
  2362. }
  2363. for (let node of treeNodes) {
  2364. delete node.changed;
  2365. }
  2366. projectObj.mainController.refreshTreeNode(treeNodes, false, false);
  2367. projectObj.project.projectInfo.lastFileVer = VERSION;
  2368. // 批量树结点计算后,计算程序早已物是人非,所以这里要重新计算一下。警告:第二个参数千万不能改成3,否则死循环!
  2369. if (activeSubSheetIsCalcProgram())
  2370. calcProgramObj.refreshCalcProgram(
  2371. projectObj.project.mainTree.selected,
  2372. 2
  2373. );
  2374. $.bootstrapLoading.end();
  2375. });
  2376. }
  2377. // 计算本节点及所有会被影响到的节点,如:所有父节点(默认,可选)、公式引用节点(默认,可选)。
  2378. // 修改一个树节点,实际上要计算和保存的是一批树结点:层层父结点、被其它结点(的公式)引用的公式结点。
  2379. calculate(treeNode, calcParents = true, calcFormulas = true, tender) {
  2380. let me = this;
  2381. let changedNodes = [];
  2382. me.innerCalc(treeNode, changedNodes, tender);
  2383. if (treeNode.changed) {
  2384. // 计算父结点
  2385. if (calcParents) {
  2386. let curNode = treeNode.parent;
  2387. while (curNode) {
  2388. me.innerCalc(curNode, changedNodes, tender);
  2389. curNode = curNode.parent;
  2390. }
  2391. }
  2392. // 父结点算完,再计算所有的公式结点(必须先算完父结点,再算公式结点)
  2393. if (calcFormulas) {
  2394. me.calcFormulaNodes(changedNodes, tender);
  2395. }
  2396. }
  2397. return changedNodes;
  2398. }
  2399. // 计算并保存一个树节点。(修改一个树节点,实际上要计算和保存的是一批树结点:层层父结点、被其它结点(的公式)引用的公式结点)
  2400. calcAndSave(treeNode, callback, tender) {
  2401. this.calcNodesAndSave([treeNode], callback, tender);
  2402. /* let changedNodes = this.calculate(treeNode, true, true, tender); 统一调用相同的方法
  2403. this.saveNodes(changedNodes, callback);*/
  2404. }
  2405. /* 计算所有树结点(分3种情况),并返回发生变动的零散的多个树结点。参数取值如下:
  2406. calcAllType.catAll 计算所有树结点 (默认值)
  2407. calcAllType.catBills 计算所有清单 (改变项目属性中清单取费算法时会用到)
  2408. calcAllType.catRations 计算所有定额、工料机形式的定额、量价,因为它们都走自己的计算程序 (改变人工系数、费率值、工料机单价时会用到)
  2409. (calcAllType.catRations时程序中做了特殊处理,实际上是计算所有树结点!)
  2410. 调价相关参数:
  2411. tender: null:不调价(普通计算)。 1: 正向调价 2:反向调价-调子目 3: 反向调价-调工料机
  2412. */
  2413. calcAllNodes(calcType = calcAllType.catAll, tender) {
  2414. let me = this;
  2415. let changedNodes = [];
  2416. function calcNodes(nodes) {
  2417. for (let node of nodes) {
  2418. if (node.children.length > 0) {
  2419. calcNodes(node.children);
  2420. }
  2421. if (calcType == calcAllType.catAll || calcType == node.sourceType) {
  2422. node.calcType = calcTools.getCalcType(node);
  2423. if (node.calcType != treeNodeCalcType.ctCalcBaseValue)
  2424. me.innerCalc(node, changedNodes, tender);
  2425. }
  2426. }
  2427. }
  2428. // calcAllType.catRations 参数情况不会计算父结点(因为父结点是清单),所以这里进行特殊处理。
  2429. if (calcType == calcAllType.catRations) calcType == calcAllType.catAll;
  2430. calcNodes(me.project.mainTree.roots);
  2431. me.calcFormulaNodes(changedNodes, tender);
  2432. if (tender) {
  2433. for (let node of projectObj.project.mainTree.items) {
  2434. this.clearTenderCache(node);
  2435. }
  2436. }
  2437. return changedNodes;
  2438. }
  2439. // tender: null:不调价(普通计算)。 1: 正向调价 2:反向调价-调子目 3: 反向调价-调工料机
  2440. calcAllNodesAndSave(calcType = calcAllType.catAll, callback, tender) {
  2441. let changedNodes = this.calcAllNodes(calcType, tender);
  2442. this.saveNodes(changedNodes, callback);
  2443. }
  2444. // 计算零散的、混杂的树节点:清单、定额混合等(如:用到某一计算程序的定额和清单)。
  2445. // 计算多条零散的定额,并计算他们所属的清单、父清单、引用清单。如:批量替换工料机后受影响的定额。
  2446. // 计算多条零散的清单,并计算他们的父清单、引用清单。如:花选删除树结点(如花选清单、定额等,不区分树结点类型)。
  2447. calcNodesAndSave(nodes, callback, tender) {
  2448. let me = this,
  2449. rationNodes = [],
  2450. billNodes = [],
  2451. leafBills = [],
  2452. allChangedNodes = [];
  2453. for (let node of nodes) {
  2454. if (node.sourceType == ModuleNames.ration) rationNodes.push(node);
  2455. else billNodes.push(node);
  2456. }
  2457. // 多条定额同属一条叶子清单时,避免叶子清单重复计算
  2458. for (let ration of rationNodes) {
  2459. me.innerCalc(ration, allChangedNodes, tender);
  2460. let leafBill = ration.parent;
  2461. if (leafBill && leafBills.indexOf(leafBill) < 0) leafBills.push(leafBill);
  2462. }
  2463. billNodes.merge(leafBills);
  2464. for (let bill of billNodes) {
  2465. let changeBills = me.calculate(bill, true, false, tender);
  2466. allChangedNodes.merge(changeBills);
  2467. }
  2468. me.calcFormulaNodes(allChangedNodes, tender);
  2469. me.saveNodes(allChangedNodes, callback);
  2470. }
  2471. // 计算全部公式项。 (changedArr:将通过本方法后发生改变的节点存入changedArr中)
  2472. calcFormulaNodes(changedArr, tender) {
  2473. let me = this;
  2474. let formulaNodes = cbTools.getFormulaNodes(true);
  2475. if (formulaNodes.length == 0) return;
  2476. for (let formulaNode of formulaNodes) {
  2477. formulaNode.data.userCalcBase = formulaNode.data.calcBase; // 这句不该出现,projectObj.project.calcBase中要改进。
  2478. projectObj.project.calcBase.calculate(formulaNode, true);
  2479. if (projectObj.project.calcBase.success) {
  2480. // 计算公式结点
  2481. me.innerCalc(formulaNode, changedArr, tender);
  2482. // 计算父结点
  2483. if (formulaNode.changed) {
  2484. let curNode = formulaNode.parent;
  2485. while (curNode) {
  2486. me.innerCalc(curNode, changedArr, tender);
  2487. curNode = curNode.parent;
  2488. }
  2489. }
  2490. }
  2491. }
  2492. }
  2493. // 计算叶子清单下的所有子结点、自身、所有父结点、公式引用结点(即跟该叶子清单相关的所有结点)。最后打包存储。
  2494. calcLeafAndSave(treeNode, tender) {
  2495. let me = this;
  2496. if (!calcTools.isLeafBill(treeNode)) return;
  2497. if (treeNode.children && treeNode.children.length > 0) {
  2498. let changedNodes = [];
  2499. for (let child of treeNode.children) {
  2500. me.innerCalc(child, changedNodes);
  2501. }
  2502. let curChangeds = me.calculate(treeNode, true, true, tender);
  2503. changedNodes.merge(curChangeds);
  2504. me.saveNodes(changedNodes);
  2505. }
  2506. }
  2507. // 排除指定项的综合合价计算(用于带循环计算的情况。这里的汇总只到清单级别即可:清单单价取费时,汇总到清单和汇总到定额两个值不一样)
  2508. getTotalFee(baseNodes, excludeNodes, tender) {
  2509. let rst = 0;
  2510. const totalFeeType = tender ? "common.tenderTotalFee" : "common.totalFee";
  2511. function calcNodes(nodes) {
  2512. for (let node of nodes) {
  2513. if (!node) {
  2514. continue;
  2515. }
  2516. if (!excludeNodes.includes(node)) {
  2517. if (
  2518. node.source &&
  2519. node.source.children &&
  2520. node.source.children.length > 0
  2521. ) {
  2522. calcNodes(node.children);
  2523. } else {
  2524. if (node.sourceType == ModuleNames.bills) {
  2525. rst = (rst + calcTools.getFee(node, totalFeeType)).toDecimal(
  2526. decimalObj.decimal("totalPrice", node)
  2527. );
  2528. }
  2529. }
  2530. }
  2531. }
  2532. }
  2533. calcNodes(baseNodes);
  2534. return rst;
  2535. }
  2536. // 税前工程造价 ,adj调价
  2537. getBeforeTaxTotalFee(excludeNodes, tender) {
  2538. let baseNodes = [],
  2539. me = this;
  2540. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.SUB_ENGINERRING));
  2541. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.MEASURE));
  2542. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.OTHER));
  2543. baseNodes.push(calcTools.getNodeByFlag(fixedFlag.CHARGE));
  2544. return me.getTotalFee(baseNodes, excludeNodes, tender);
  2545. }
  2546. // 清理调价缓存数据
  2547. clearTenderCache(treeNode) {
  2548. // 这些属性值为什么不定义在一个对象里?因为每次要判断对象是否存在,十分麻烦。不如直接写简单。分散书写,统一处理也很好用。
  2549. if (treeNode.data.tender_activeTotal)
  2550. delete treeNode.data.tender_activeTotal;
  2551. if (treeNode.data.tender_activeTarget)
  2552. delete treeNode.data.tender_activeTarget;
  2553. if (treeNode.data.tender_fullLoad) delete treeNode.data.tender_fullLoad;
  2554. if (treeNode.data.tender_distribute) {
  2555. delete treeNode.data.targetTotalFee;
  2556. delete treeNode.data.targetUnitFee;
  2557. delete treeNode.data.tender_distribute;
  2558. }
  2559. }
  2560. initGljPriceTenderCoe() {
  2561. if (
  2562. projectObj.project.property.tenderSetting &&
  2563. projectObj.project.property.tenderSetting.gljPriceTenderCoe &&
  2564. projectObj.project.property.tenderSetting.gljPriceTenderCoe != 1
  2565. ) {
  2566. projectObj.project.property.tenderSetting.gljPriceTenderCoe = 1; // 修改缓存值,用于计算
  2567. projectObj.project.property.needRestoreGgljPriceTenderCoe = true; // 做个标记,告诉回调函数
  2568. }
  2569. }
  2570. // 反向调价-初始化调价树、清理缓存数据等
  2571. reverseTenderInitDatas() {
  2572. for (let node of tender_obj.tenderTree.items) {
  2573. if (node.data.rationQuantityCoe) node.data.rationQuantityCoe = null;
  2574. let qcObj = node.data.quantityCoe;
  2575. if (qcObj) {
  2576. for (let pn in qcObj) {
  2577. qcObj[pn] = null;
  2578. }
  2579. }
  2580. this.clearTenderCache(node);
  2581. }
  2582. // 反向调价时人材机单价调整系数要归1:因为既可以调量又可以调价,以哪个为基准进行反调?过于复杂,仅以通用的调量逻辑为基准即可满足需求。
  2583. this.initGljPriceTenderCoe();
  2584. }
  2585. // 反向调价简单计算:只计算当前单一结点,由目标金额计算定额量系数或工料机量系数coe,再根据此coe计算定额的调后量、调后合价。
  2586. // ⑴只计算参数指定的一个单一的结点,连父结点、引用结点都不计算。此结点只会是定额、量价、工料机款定额,不会是清单。
  2587. // ⑵执行此方法的前提:已在其它地方把总的目标金额分摊好了,此结点已获取目标金额。
  2588. reverseTenderCalc(treeNode, tender) {
  2589. if (tender == tenderTypes.ttReverseRation) {
  2590. if (
  2591. treeNode.data.feesIndex.common &&
  2592. treeNode.data.feesIndex.common.tenderUnitFee !=
  2593. treeNode.data.feesIndex.common.unitFee
  2594. ) {
  2595. treeNode.data.feesIndex.common.tenderUnitFee =
  2596. treeNode.data.feesIndex.common.unitFee;
  2597. treeNode.changed = true;
  2598. }
  2599. }
  2600. if (!treeNode.data.targetTotalFee) {
  2601. // 没有目标金额、但有输入目标单价的:根据目标单价算出目标金额。
  2602. if (treeNode.data.targetUnitFee) {
  2603. treeNode.data.targetTotalFee = (
  2604. treeNode.data.targetUnitFee * treeNode.data.quantity
  2605. ).toDecimal(decimalObj.decimal("totalPrice", treeNode));
  2606. treeNode.changed = true;
  2607. } else {
  2608. // 既没有目标金额也没有目标单价,此时要初始化使调价合价=原始综合合价,调价单价=原始综合单价。
  2609. if (
  2610. treeNode.data.feesIndex.common &&
  2611. treeNode.data.feesIndex.common.tenderUnitFee !=
  2612. treeNode.data.feesIndex.common.unitFee
  2613. ) {
  2614. treeNode.data.feesIndex.common.tenderUnitFee =
  2615. treeNode.data.feesIndex.common.unitFee;
  2616. treeNode.changed = true;
  2617. }
  2618. if (
  2619. treeNode.data.feesIndex.common &&
  2620. treeNode.data.feesIndex.common.tenderTotalFee !=
  2621. treeNode.data.feesIndex.common.totalFee
  2622. ) {
  2623. treeNode.data.feesIndex.common.tenderTotalFee =
  2624. treeNode.data.feesIndex.common.totalFee;
  2625. treeNode.changed = true;
  2626. }
  2627. return;
  2628. }
  2629. }
  2630. // 经过前面的一通折腾还是没有目标单价的话,那么就要通过目标金额算出来。
  2631. if (
  2632. !treeNode.data.targetUnitFee ||
  2633. parseFloat(treeNode.data.targetUnitFee) == 0
  2634. ) {
  2635. if (calcTools.hasQuantity(treeNode))
  2636. treeNode.data.targetUnitFee = (
  2637. treeNode.data.targetTotalFee / treeNode.data.quantity
  2638. ).toDecimal(decimalObj.decimal("unitPrice", treeNode));
  2639. }
  2640. // 系数=调后单价/调前单价
  2641. let coe = 1;
  2642. if (treeNode.data.feesIndex.common.totalFee != 0)
  2643. coe = (
  2644. treeNode.data.targetUnitFee / treeNode.data.feesIndex.common.unitFee
  2645. ).toDecimal(decimalObj.process);
  2646. // 量价、工料机款式的定额:它们无下挂工料机可调,直接调树结点的消耗量。
  2647. let isVP_RevGLJ =
  2648. tender == tenderTypes.ttReverseGLJ && calcTools.isVP_or_GLJR(treeNode);
  2649. if (tender == tenderTypes.ttReverseRation || isVP_RevGLJ) {
  2650. treeNode.data.tenderQuantity = (treeNode.data.quantity * coe).toDecimal(
  2651. decimalObj.decimal("quantity", treeNode)
  2652. );
  2653. if (treeNode.data.rationQuantityCoe != coe) {
  2654. treeNode.data.rationQuantityCoe = coe;
  2655. treeNode.changed = true;
  2656. }
  2657. if (isVP_RevGLJ) {
  2658. treeNode.data.quantityCoe = {
  2659. labour: 0,
  2660. material: 0,
  2661. machine: 0,
  2662. main: 0,
  2663. equipment: 0,
  2664. };
  2665. treeNode.changed = true;
  2666. }
  2667. let ttf = (
  2668. treeNode.data.tenderQuantity *
  2669. treeNode.data.feesIndex.common.tenderUnitFee
  2670. ).toDecimal(decimalObj.decimal("totalPrice", treeNode));
  2671. if (treeNode.data.feesIndex.common.tenderTotalFee != ttf) {
  2672. treeNode.data.feesIndex.common.tenderTotalFee = ttf;
  2673. treeNode.changed = true;
  2674. }
  2675. } else if (tender == tenderTypes.ttReverseGLJ) {
  2676. let qcObj = treeNode.data.quantityCoe;
  2677. if (!qcObj || calcTools.isEmptyObject(qcObj)) {
  2678. treeNode.data.quantityCoe = {
  2679. labour: coe,
  2680. material: coe,
  2681. machine: coe,
  2682. main: coe,
  2683. equipment: coe,
  2684. };
  2685. treeNode.changed = true;
  2686. } else {
  2687. // 这种写法会漏掉属性,导致界面显示不统一。
  2688. /* for (let pn in qcObj){
  2689. if (qcObj[pn] != coe){
  2690. qcObj[pn] = coe;
  2691. treeNode.changed = true;
  2692. }
  2693. };*/
  2694. if (qcObj.labour != coe) {
  2695. qcObj.labour = coe;
  2696. treeNode.changed = true;
  2697. }
  2698. if (qcObj.material != coe) {
  2699. qcObj.material = coe;
  2700. treeNode.changed = true;
  2701. }
  2702. if (qcObj.machine != coe) {
  2703. qcObj.machine = coe;
  2704. treeNode.changed = true;
  2705. }
  2706. if (qcObj.main != coe) {
  2707. qcObj.main = coe;
  2708. treeNode.changed = true;
  2709. }
  2710. if (qcObj.equipment != coe) {
  2711. qcObj.equipment = coe;
  2712. treeNode.changed = true;
  2713. }
  2714. }
  2715. projectObj.project.calcProgram.calculate(
  2716. treeNode,
  2717. false,
  2718. false,
  2719. tenderTypes.ttCalc
  2720. ); // 再正向算
  2721. }
  2722. }
  2723. // 反向调价-分摊前的准备工作。包括:
  2724. // ⑴结点是否满载
  2725. // ⑵若是满载,汇总孩子的金额、目标金额给它
  2726. // ⑶标记此结点的目标金额来自孩子,未来它不往下分摊(汇上来再摊下去无用功)
  2727. prepareForDistribute(treeNode) {
  2728. if (!treeNode) return;
  2729. if (treeNode.firstChild()) this.prepareForDistribute(treeNode.firstChild());
  2730. if (treeNode.children.length == 0) {
  2731. } else {
  2732. let full = true;
  2733. for (let i = 0; i < treeNode.children.length; i++) {
  2734. let child = treeNode.children[i];
  2735. if (
  2736. !child.data.tender_fullLoad &&
  2737. !calcTools.hasTargetTotalFee(child)
  2738. ) {
  2739. full = false;
  2740. break;
  2741. }
  2742. }
  2743. if (full) {
  2744. let total = 0,
  2745. target = 0;
  2746. for (let i = 0; i < treeNode.children.length; i++) {
  2747. let child = treeNode.children[i];
  2748. total = total + parseFloat(child.data.feesIndex["common"].totalFee);
  2749. target = target + parseFloat(child.data.targetTotalFee);
  2750. }
  2751. treeNode.data.tender_activeTotal = total;
  2752. treeNode.data.tender_activeTarget = target;
  2753. treeNode.data.targetTotalFee = target;
  2754. treeNode.data.tender_distribute = 2;
  2755. }
  2756. treeNode.data.tender_fullLoad = full;
  2757. }
  2758. if (treeNode.nextSibling) this.prepareForDistribute(treeNode.nextSibling);
  2759. }
  2760. // 反向调价-分摊目标合价:从父到子往下分摊。
  2761. distributeTargetTotalFee(treeNode) {
  2762. if (!treeNode) return;
  2763. if (treeNode.data.feesIndex && treeNode.data.feesIndex["common"]) {
  2764. // 空清单忽略
  2765. // 默认能够执行到这里时每个节点已经被初始化,缓存已删除
  2766. treeNode.data.tender_activeTotal =
  2767. treeNode.data.feesIndex["common"].totalFee;
  2768. // 开始分摊:只分摊自有目标金额、从父结点分摊到的金额(不分摊子结点汇总上来的金额)
  2769. if (
  2770. calcTools.hasTargetTotalFee(treeNode) &&
  2771. !(
  2772. treeNode.data.tender_distribute &&
  2773. treeNode.data.tender_distribute == 2
  2774. )
  2775. ) {
  2776. treeNode.data.tender_activeTarget = treeNode.data.targetTotalFee;
  2777. // 先把会破坏金额比例关系的孩子排除:1.有目标金额的 2.满载的(孙子全满,没有分摊空间,所以实质上该孩子的金额已被锁死无法分摊)
  2778. for (let i = 0; i < treeNode.children.length; i++) {
  2779. let child = treeNode.children[i];
  2780. if (!child.data.feesIndex || !child.data.feesIndex["common"])
  2781. continue; // 空白行清单、定额
  2782. child.data.tender_activeTotal =
  2783. child.data.feesIndex["common"].totalFee;
  2784. if (calcTools.hasTargetTotalFee(child)) {
  2785. child.data.tender_activeTarget = child.data.targetTotalFee;
  2786. console.log(treeNode.data.tender_activeTotal);
  2787. console.log(child.data.tender_activeTotal);
  2788. treeNode.data.tender_activeTotal =
  2789. treeNode.data.tender_activeTotal - child.data.tender_activeTotal;
  2790. treeNode.data.tender_activeTarget =
  2791. treeNode.data.tender_activeTarget -
  2792. child.data.tender_activeTarget;
  2793. }
  2794. }
  2795. if (treeNode.data.tender_activeTotal != 0) {
  2796. let coe = (
  2797. treeNode.data.tender_activeTarget / treeNode.data.tender_activeTotal
  2798. ).toDecimal(decimalObj.process);
  2799. for (let i = 0; i < treeNode.children.length; i++) {
  2800. let child = treeNode.children[i];
  2801. if (!child.data.feesIndex || !child.data.feesIndex["common"])
  2802. continue; // 空白行清单、定额
  2803. if (!calcTools.hasTargetTotalFee(child)) {
  2804. child.data.tender_activeTarget = (
  2805. coe * child.data.tender_activeTotal
  2806. ).toDecimal(decimalObj.decimal("totalPrice", treeNode));
  2807. child.data.targetTotalFee = child.data.tender_activeTarget;
  2808. child.data.tender_distribute = 1; // 1表示分摊金额来自父结点。2表示分摊金额来自孩子结点。
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. if (treeNode.firstChild())
  2815. this.distributeTargetTotalFee(treeNode.firstChild());
  2816. if (treeNode.nextSibling)
  2817. this.distributeTargetTotalFee(treeNode.nextSibling);
  2818. }
  2819. // 反向调价逼近
  2820. reverseTenderApproach(callback, tender) {
  2821. let me = this;
  2822. function root0() {
  2823. return tender_obj.tenderTree.roots[0];
  2824. }
  2825. if (!root0().data.targetTotalFee) return; // 根结点没有指定目标金额时,逼近会带来莫名其妙的结果
  2826. let G_DIGIT = 0.01; // 系数调整步距(0.1最终结果误差大。0.001目标金额与逼前金额差距大时无法有效逼近)
  2827. let MaxDiffValue = 0.1; // 可接受的最大差值。(如果实际差值比这个大:说明列表结点耗尽,无法达到指定精度。公路设为1,建筑设为0.1)
  2828. let times = 300; // 逼近计算的极限次数。正常情况下“单位系数金额”列表中的结点耗尽即退出,这里指定轮数是最后保险阀,防止无限死循环。
  2829. let calcModel = 1; // 计算模式:1 精度优先(差值不接近0不停,直到结点用完或极限次数用完。时间长精度高)2 速度优先(达到指定差值范围即熔断逼近。时间短差值大)
  2830. let diffProp = 0.0001; // 计算模式=2(速度优先)时有效。 通过这个金额比例值计算可接受的最大差值D。差值D = 根结点金额 * diffProp
  2831. let isTest = true; // 测试
  2832. // 按指定的比例获取可接受的差值:如目标金额的万分之一。
  2833. function getPropV(node) {
  2834. let v = parseFloat((node.data.targetTotalFee * diffProp).toFixed(0)); // node.data.feesIndex.common.totalFee
  2835. return Math.max(v, MaxDiffValue);
  2836. }
  2837. // 取根结点的:调后金额跟目标金额差值,看还有多少误差需要处理。
  2838. function getRootDiff() {
  2839. return (
  2840. root0().data.feesIndex.common.tenderTotalFee -
  2841. root0().data.targetTotalFee
  2842. ).toDecimal(3);
  2843. }
  2844. // 生成每单位差值的定额结点列表。
  2845. function getNodeDiffs() {
  2846. let arr = [];
  2847. for (let i = 0; i < tender_obj.tenderTree.items.length; i++) {
  2848. let node = tender_obj.tenderTree.items[i];
  2849. if (calcTools.isInvalidNode(node)) continue;
  2850. // 量价还是要参与,因为它贡献了金额,如果它的金额比重很大,它退出了,会导致其它结点过调。
  2851. // if (calcTools.isRationCategory(node) && (!calcTools.isVP_or_GLJR(node))){
  2852. if (calcTools.isRationCategory(node)) {
  2853. let coe = calcTools.getCoe(node, tender);
  2854. if (coe != 0) {
  2855. let diff = Math.abs(
  2856. node.data.feesIndex.common.tenderTotalFee -
  2857. node.data.feesIndex.common.totalFee
  2858. );
  2859. node.data.tender_diffValuePerCoe = (
  2860. (diff * G_DIGIT) /
  2861. coe
  2862. ).toDecimal(decimalObj.process);
  2863. node.data.tender_rowNo = i + 1; // node在UI上显示的行号
  2864. arr.push(node);
  2865. }
  2866. }
  2867. }
  2868. arr.sort(function sortArr(a, b) {
  2869. return a.data.tender_diffValuePerCoe - b.data.tender_diffValuePerCoe;
  2870. });
  2871. if (isTest) {
  2872. let arr2 = [];
  2873. for (let i = 0; i < arr.length; i++) {
  2874. arr2.push({
  2875. row: arr[i].data.tender_rowNo,
  2876. code: arr[i].data.code + " " + arr[i].data.name,
  2877. diff: arr[i].data.tender_diffValuePerCoe,
  2878. });
  2879. }
  2880. console.log(arr2);
  2881. }
  2882. return arr;
  2883. }
  2884. // 每单位差值的定额结点列表中,取离给定值最近的定额结点。
  2885. function getCloseNode(arr, value) {
  2886. let index = 0;
  2887. let d_value = Number.MAX_VALUE;
  2888. for (let i = 0; i < arr.length; i++) {
  2889. let new_d_value = Math.abs(arr[i].data.tender_diffValuePerCoe - value);
  2890. if (new_d_value <= d_value) {
  2891. if (
  2892. new_d_value === d_value &&
  2893. arr[i].data.tender_diffValuePerCoe <
  2894. arr[index].data.tender_diffValuePerCoe
  2895. ) {
  2896. continue;
  2897. }
  2898. index = i;
  2899. d_value = new_d_value;
  2900. }
  2901. }
  2902. return { idx: index, node: arr[index] };
  2903. }
  2904. // 逼近(单轮)。arr 参考取值列表。返回{type, node, nodeIdx}。
  2905. // type:1正常,2无结点,3结点过调。node:结点。nodeIdx:结点在列表中的索引位置。node.data.tender_rowNo 在UI上的行号。
  2906. function approach(arr) {
  2907. let v = getRootDiff();
  2908. let obj = getCloseNode(arr, Math.abs(v)); // {idx, node} 极端:{0, undefind}
  2909. let closeNode = obj.node;
  2910. if (!closeNode) return { type: 2, node: undefined, nodeIdx: -1 }; // arr 被清空了
  2911. let d = v > 0 ? -G_DIGIT : G_DIGIT;
  2912. let coe = calcTools.getCoe(closeNode, tender);
  2913. if (coe + d < 0) return { type: 3, node: obj.node, nodeIdx: obj.idx }; // 再调的话,系数就变负数了,过调
  2914. if (tender == tenderTypes.ttReverseRation) {
  2915. closeNode.data.tender_previousCoe = closeNode.data.rationQuantityCoe; // tender_previousCoe: 上一次的调整系数,用于撤回
  2916. closeNode.data.rationQuantityCoe = (
  2917. closeNode.data.rationQuantityCoe + d
  2918. ).toDecimal(decimalObj.process);
  2919. } else if (tender == tenderTypes.ttReverseGLJ) {
  2920. if (calcTools.isVP_or_GLJR(closeNode)) {
  2921. closeNode.data.tender_previousCoe = closeNode.data.rationQuantityCoe;
  2922. closeNode.data.rationQuantityCoe = (
  2923. closeNode.data.rationQuantityCoe + d
  2924. ).toDecimal(decimalObj.process);
  2925. } else {
  2926. closeNode.data.tender_previousCoe = closeNode.data.quantityCoe.labour;
  2927. closeNode.data.quantityCoe.labour = (
  2928. closeNode.data.quantityCoe.labour + d
  2929. ).toDecimal(decimalObj.process);
  2930. closeNode.data.quantityCoe.material = (
  2931. closeNode.data.quantityCoe.material + d
  2932. ).toDecimal(decimalObj.process);
  2933. closeNode.data.quantityCoe.machine = (
  2934. closeNode.data.quantityCoe.machine + d
  2935. ).toDecimal(decimalObj.process);
  2936. closeNode.data.quantityCoe.main = (
  2937. closeNode.data.quantityCoe.main + d
  2938. ).toDecimal(decimalObj.process);
  2939. closeNode.data.quantityCoe.equipment = (
  2940. closeNode.data.quantityCoe.equipment + d
  2941. ).toDecimal(decimalObj.process);
  2942. }
  2943. }
  2944. me.calculate(closeNode, true, true, tenderTypes.ttCalc);
  2945. return { type: 1, node: obj.node, nodeIdx: obj.idx };
  2946. }
  2947. // 撤消最后一轮逼近(调过头了,回退一步)
  2948. function undoLastApproach(obj) {
  2949. let closeNode = obj.node;
  2950. let coe = closeNode.data.tender_previousCoe;
  2951. if (tender == tenderTypes.ttReverseRation) {
  2952. closeNode.data.rationQuantityCoe = coe;
  2953. } else if (tender == tenderTypes.ttReverseGLJ) {
  2954. if (calcTools.isVP_or_GLJR(closeNode)) {
  2955. closeNode.data.rationQuantityCoe = coe;
  2956. } else {
  2957. closeNode.data.quantityCoe.labour = coe;
  2958. closeNode.data.quantityCoe.material = coe;
  2959. closeNode.data.quantityCoe.machine = coe;
  2960. closeNode.data.quantityCoe.main = coe;
  2961. closeNode.data.quantityCoe.equipment = coe;
  2962. }
  2963. }
  2964. me.calculate(closeNode, true, true, tenderTypes.ttCalc);
  2965. if (isTest) {
  2966. let _sp = `        `; // 保留空格,打印对齐
  2967. let _node = `[行${obj.node.data.tender_rowNo} 索引${obj.nodeIdx}]`;
  2968. console.log(`${_sp} ${_node} 过调,已回退`);
  2969. }
  2970. }
  2971. let root = tender_obj.tenderTree.roots[0];
  2972. let propV = getPropV(root);
  2973. let vArr = getNodeDiffs();
  2974. let d1 = getRootDiff();
  2975. if (isTest) {
  2976. let _tq = `调前${root.data.feesIndex.common.totalFee}`;
  2977. let _mb = `目标${root.data.targetTotalFee}`;
  2978. let _wbj = `调后无逼近${root.data.feesIndex.common.tenderTotalFee}`;
  2979. let _cz = `差值${d1}`;
  2980. let _js = `轮${times} 系数步距${G_DIGIT}`;
  2981. let _yx =
  2982. calcModel == 2
  2983. ? `速度优先(差比${diffProp} 差域0~${propV})`
  2984. : "精度优先";
  2985. console.log(`${_tq}|${_mb}|${_wbj}|${_cz}|${_yx}|${_js}`);
  2986. }
  2987. // 多轮逼进
  2988. for (let i = 1; i <= times; i++) {
  2989. // 与目标金额差值在1以内,整数部分已相同,结果很棒。很多时候能达到完美的差值0,但不能用0判断,因为金额取小数时有问题。
  2990. if (Math.abs(d1) < MaxDiffValue) break;
  2991. // 速度优先模式下,结果到达差值范围内,即熔断逼近。
  2992. if (calcModel == 2) {
  2993. if (Math.abs(d1) < propV) break;
  2994. }
  2995. let obj = approach(vArr);
  2996. if (obj.type == 2) break; // 结点耗完,列表已清空,无结点可调。
  2997. if (obj.type == 3) {
  2998. // 结点过调,该结点任务已完成,不再参与调节,从列表中清除
  2999. vArr.splice(obj.nodeIdx, 1);
  3000. continue;
  3001. }
  3002. let d2 = getRootDiff();
  3003. if (isTest) {
  3004. let _time = `【第 ${i} 轮】调整`;
  3005. let _node = `[行${obj.node.data.tender_rowNo} 索引${obj.nodeIdx}]`;
  3006. let _coe = `${obj.node.data.tender_previousCoe} → ${calcTools.getCoe(
  3007. obj.node,
  3008. tender
  3009. )}`;
  3010. let _d = `差值${d1} → ${d2}`;
  3011. console.log(`${_time}${_node} ${_coe},${_d}`);
  3012. }
  3013. if (Math.abs(d2) > Math.abs(d1)) {
  3014. // 逼近后差值反而变大,证明此轮调节不合适,回退一步,并将结点从列表清除
  3015. undoLastApproach(obj);
  3016. vArr.splice(obj.nodeIdx, 1);
  3017. } else if (Math.abs(d2) == Math.abs(d1)) {
  3018. // 调前调后差距相同时,会死循环,也从列表中清除
  3019. vArr.splice(obj.nodeIdx, 1);
  3020. } else {
  3021. d1 = d2;
  3022. }
  3023. }
  3024. // 重要注释:到这里,所有系数已处理就绪,最后直接全局正算即可。
  3025. // 到这一步,被处理的定额、及其受影响的父结点、引用结点等均已正算完成(approach方法、undoLastApproach方法),但都未保存。
  3026. // 最后全局正算目的:⑴计算除第一部以外的其它部分 ⑵保存。正算在调用外面完成。
  3027. // this.calcAllNodesAndSave(calcAllType.catAll, callback, tenderTypes.ttCalc);
  3028. }
  3029. setRationMap() {
  3030. if (this.rationMap == null) {
  3031. this.rationMap = {};
  3032. for (let glj of projectObj.project.ration_glj.datas) {
  3033. if (this.rationMap[glj.rationID]) {
  3034. this.rationMap[glj.rationID].push(glj);
  3035. } else {
  3036. this.rationMap[glj.rationID] = [glj];
  3037. }
  3038. }
  3039. }
  3040. if (this.pgljMap == null) {
  3041. this.pgljMap = _.indexBy(
  3042. projectObj.project.projectGLJ.datas.gljList,
  3043. "id"
  3044. );
  3045. }
  3046. }
  3047. getGljArrByRation(ration) {
  3048. if (ration.type == rationType.gljRation) {
  3049. let glj = JSON.parse(JSON.stringify(ration));
  3050. glj.type = glj.subType;
  3051. glj.quantity = 1;
  3052. glj.totalQuantity = parseFloatPlus(ration.quantity);
  3053. return [glj];
  3054. } else {
  3055. if (!this.rationMap) return [];
  3056. let result = this.rationMap[ration.ID];
  3057. if (!result) return [];
  3058. result = gljOprObj.combineWithProjectGlj(
  3059. result,
  3060. false,
  3061. ration,
  3062. this.pgljMap
  3063. );
  3064. return result;
  3065. }
  3066. }
  3067. doTenderCalc(callback) {
  3068. $.bootstrapLoading.start();
  3069. setTimeout(() => {
  3070. let tender = calcTools.getTenderType();
  3071. if (
  3072. tender == tenderTypes.ttReverseGLJ ||
  3073. tender == tenderTypes.ttReverseRation
  3074. ) {
  3075. // 调价计算必须依赖调价树。
  3076. if (!tender_obj.tenderTree) {
  3077. tender_obj.createTree();
  3078. tender_obj.createTreeNodes();
  3079. }
  3080. // 反向调价+逼近原理:
  3081. // 清理调价缓存 → 分摊目标金额(从子往父处理满载、从父往子分摊) → 全局反算 → 逼近 → 全局正算、存储
  3082. this.reverseTenderInitDatas();
  3083. this.prepareForDistribute(tender_obj.tenderTree.roots[0]);
  3084. this.distributeTargetTotalFee(tender_obj.tenderTree.roots[0]);
  3085. this.calcAllNodes(calcAllType.catAll, tender); // 先全局反算:得到每定额的coe、基础调后金额(误差大,需逼近)
  3086. this.reverseTenderApproach(callback, tender); // 逼近上述基础调后金额
  3087. }
  3088. // 全局正算(用的是主树,无需调价树)
  3089. this.calcAllNodesAndSave(
  3090. calcAllType.catAll,
  3091. callback,
  3092. tenderTypes.ttCalc
  3093. );
  3094. });
  3095. }
  3096. }
  3097. // export default analyzer;