shandong_common.js 90 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588
  1. // INTERFACE_EXPORT =,必须这么写,这样才能在导出时动态加载脚本后,覆盖前端代码
  2. // 参考广东中山导出接口
  3. INTERFACE_EXPORT = (() => {
  4. "use strict";
  5. const feeRateMap = {
  6. 冬季施工增加费: "DJSGZJFFL",
  7. 冬季施工: "DJSGZJFFL",
  8. 雨季施工增加费: "YUJSGZJFFL",
  9. 雨季施工: "YUJSGZJFFL",
  10. 夜间施工增加费: "YEJSGZJFFL",
  11. 夜间施工: "YEJSGZJFFL",
  12. 高原地区施工增加费: "GYDQSGZJFFL",
  13. 高原施工: "GYDQSGZJFFL",
  14. 风沙地区施工增加费: "FSDQSGZJFFL",
  15. 风沙施工: "FSDQSGZJFFL",
  16. 沿海地区施工增加费: "YHDQSGZJFFL",
  17. 沿海施工: "YHDQSGZJFFL",
  18. 行车干扰施工增加费: "XCGRGCSGZJFFL",
  19. 行车干扰: "XCGRGCSGZJFFL",
  20. 工地转移费: "GDZYFFL",
  21. '工地转移(km)': "GDZYFFL",
  22. 施工辅助费: "SGFZFFL",
  23. 施工辅助: "SGFZFFL",
  24. 基本费用: "JBFYFL",
  25. 主副食运费补贴: "ZFSYFBTFL",
  26. '综合里程(km)': "ZFSYFBTFL",
  27. 职工探亲路费: "ZGTQLFFL",
  28. 职工探亲: "ZGTQLFFL",
  29. 职工取暖补贴: "ZGQNBTFL",
  30. 职工取暖: "ZGQNBTFL",
  31. 财务费用: "CWFYFL",
  32. 养老保险费: "YANGLBXFFL",
  33. 失业保险费: "SYBXFFL",
  34. 医疗保险费: "YILBXFFL",
  35. 工伤保险费: "GSBXFL",
  36. 养老保险: "YANGLBXFFL",
  37. 失业保险: "SYBXFFL",
  38. 医疗保险: "YILBXFFL",
  39. 工伤保险: "GSBXFL",
  40. 住房公积金: "ZFGJJFL",
  41. 规费: "GFZHFL",
  42. 利润: "LRL",
  43. 税金: "SL",
  44. 土方: "TF",
  45. 石方: "SF",
  46. 运输: "YS",
  47. 路面: "LM",
  48. "路面(不计雨)": "LM",
  49. 隧道: "SD",
  50. 构造物I: "GZW1",
  51. "构造物I(不计冬)": "GZW1",
  52. "构造物I(不计雨)": "GZW1",
  53. 构造物II: "GZW2",
  54. "构造物III(桥梁)": "GZW3",
  55. "构造物III(除桥以外)": "GZW3",
  56. "构造物III(除桥以外不计雨夜)": "GZW3",
  57. 技术复杂大桥: "JSFZDQ",
  58. "钢材及钢结构(桥梁)": "GJG",
  59. "钢材及钢结构(除桥以外)": "GJG",
  60. "钢材及钢结构(除桥以外不计夜)": "GJG",
  61. };
  62. //计算程序有,这里没有:施工机械使用费\施工机械人工费\定额人工费\定额材料费\定额施工机械使用费
  63. const itemFeeMap = {
  64. 'marketLabour': 'RGF',
  65. 'marketMaterial': 'CLF',
  66. 'marketMachine':'JXSYF',
  67. 'marketEquipment': 'SBGZF',
  68. 'direct': 'DEZJF',
  69. 'equipment': 'DESBF',
  70. 'marketDirect': 'ZJF',
  71. 'measure': 'CSF',
  72. 'measure1': 'CSF1',
  73. 'measure2': 'CSF2',
  74. 'manage': 'QYGLF',
  75. 'force': 'GF',
  76. 'profit': 'LR',
  77. 'tax': 'SJ',
  78. 'common': 'JAF',
  79. 'rationCommon': 'DEJAF'
  80. };
  81. const feeLibNoMap = {
  82. 'eba0e7c0-cfe6-11ea-ba15-739be477d1fe': 'GYSFL-000000-2018-86',
  83. '451d3180-e02e-11ea-8056-1514dfc2f39e': 'GYSFL-340000-2019-210',
  84. '32923ff0-e912-11ea-8b20-d93bc370e960': 'GYSFL-440000-2019-544'
  85. };
  86. const FixedCostMap = {
  87. //折旧费、检修费、维护费、安拆辅助费
  88. '折旧费': 1,
  89. '检修费': 1,
  90. '维护费': 1,
  91. '安拆辅助费':1
  92. }
  93. const RoadGradeMap = {
  94. "高速公路": "0",
  95. "一级公路": "1",
  96. "二级公路": "2",
  97. "三级公路": "3",
  98. "四级公路": "4",
  99. "等外公路": "5",
  100. "独立桥梁": "6",
  101. "独立隧道": "7"
  102. }
  103. const sectionNameMap = {
  104. "清单 第100章 总则": true,
  105. "清单 第200章 路基": true,
  106. "清单 第300章 路面": true,
  107. "清单 第400章 桥梁、涵洞": true,
  108. "清单 第500章 隧道": true,
  109. "清单 第600章 安全设施及预埋管线": true,
  110. "清单 第700章 绿化及环境保护设施": true,
  111. // "清单 第800章 机电工程": true,
  112. // "清单 第900章 附属区房建工程":true
  113. }
  114. const ListCodeMap = {
  115. "第100章至700章清单":"1",
  116. "清单 第100章 总则": "一",
  117. "清单 第200章 路基": "二",
  118. "清单 第300章 路面": "三",
  119. "清单 第400章 桥梁、涵洞": "四",
  120. "清单 第500章 隧道": "五",
  121. "清单 第600章 安全设施及预埋管线": "六",
  122. "清单 第700章 绿化及环境保护设施": "七",
  123. // "清单 第800章 机电工程": "八",
  124. // "清单 第900章 附属区房建工程": "九",
  125. "已包含在清单合计中的材料、工程设备、专业工程暂估价合计": "10",
  126. "清单合计减去材料、工程设备、专业工程暂估价合计": "11",
  127. "计日工合计": "12",
  128. "劳务": "12.1",
  129. "材料": "12.2",
  130. "机械": "12.3",
  131. "暂列金额(不含计日工总额)": "13",
  132. "投标报价": "14"
  133. }
  134. const ratioCodeMap = {
  135. "01ZJF":"0",
  136. "02JXF":"1",
  137. "03WHF":"2",
  138. "04ACFZF":"3"
  139. }
  140. function getBasePrice(projectGLJID, tenderProject) {
  141. let glj = _.find(tenderProject.projectGLJ.datas.gljList, {
  142. id: projectGLJID
  143. })
  144. return glj ? gljUtil.getBasePrice(glj, null, null, null, decimalObj, false, _, scMathUtil) : 0;
  145. }
  146. function getFeeRate(programID, fieldName, tenderProject) {
  147. let rate = 0;
  148. let template = tenderProject.calcProgram.compiledTemplates;
  149. if (template[programID]) {
  150. let item = _.find(template[programID].calcItems, {
  151. fieldName: fieldName
  152. })
  153. if (item) rate = item.feeRate;
  154. }
  155. return rate
  156. }
  157. function billNameChecking(bNode,projectName,fixedFlag) {
  158. let data = bNode.data;
  159. let fail = null;
  160. let pass = true;
  161. if (data.flagsIndex && data.flagsIndex.fixed) {
  162. let flag = data.flagsIndex.fixed.flag;
  163. switch (flag) {
  164. case fixedFlag.ONE_SEVEN_BILLS:
  165. pass = data.name == "第100章至700章清单" || data.name == "第100章至700章清单合计";
  166. break;
  167. case fixedFlag.PROVISIONAL_TOTAL:
  168. pass = data.name == "已包含在清单合计中的材料、工程设备、专业工程暂估价合计";
  169. break;
  170. case fixedFlag.BILLS_TOTAL_WT_PROV:
  171. pass = data.name == "清单合计减去材料、工程设备、专业工程暂估价合计";
  172. break;
  173. case fixedFlag.DAYWORK_LABOR:
  174. pass = data.name == "计日工合计";
  175. break;
  176. /* case fixedFlag.LABOUR_SERVICE:
  177. pass = data.name == "劳务";
  178. break;
  179. case fixedFlag.MATERIAL:
  180. pass = data.name == "材料";
  181. break;
  182. case fixedFlag.CONSTRUCTION_MACHINE:
  183. pass = data.name == "机械";
  184. break; */
  185. case fixedFlag.PROVISIONAL:
  186. pass = data.name == "暂列金额(不含计日工总额)";
  187. break;
  188. case fixedFlag.TOTAL_COST:
  189. pass = data.name == "投标报价";
  190. break;
  191. case fixedFlag.ONE_HUNDRED_BILLS:
  192. pass = data.name == "清单 第100章 总则";
  193. break;
  194. }
  195. } else {
  196. if (bNode.parent) {
  197. const pdata = bNode.parent.data;
  198. if (pdata.flagsIndex && pdata.flagsIndex.fixed && pdata.flagsIndex.fixed.flag == fixedFlag.ONE_SEVEN_BILLS) {
  199. if (!sectionNameMap[data.name]) pass = false
  200. }
  201. }
  202. }
  203. if(pass == false)fail = { hint: `清单:"${data.name?data.name:""}",名字不符合规范!`, type: projectName }
  204. return fail;
  205. }
  206. /**
  207. *
  208. * @param {String} areaKey - 地区标识,如:'安徽@马鞍山',有些地区的接口只是取值上有不同,共有一个接口脚本, 需要通过地区标识确定一些特殊处理
  209. * @param {Number} exportKind - 导出类型,招标、投标、控制价
  210. * @param {Object} projectData - 项目表数据:{ 建设项目Data, children: [单位工程...] }
  211. * @param {Object} tenderDetailMap - 单位工程ID与getData接口数据(projectObj.project的结构)的映射。
  212. * @return {Promise<Array>} - 返回的数据结构必须按照规定:[{ data, exportKind, fileName }],参考web\building_saas\standard_interface\index.js中的注释说明
  213. */
  214. async function entry(areaKey, exportKind, projectData, tenderDetailMap) {
  215. const {
  216. CONFIG: {
  217. TYPE
  218. },
  219. UTIL,
  220. Element
  221. } = INTERFACE_EXPORT_BASE;
  222. const {
  223. EXPORT_KIND: {
  224. BID_INVITATION,
  225. BID_SUBMISSION,
  226. CONTROL
  227. },
  228. fixedFlag,
  229. } = window.commonConstants;
  230. let cprjType = {
  231. 1: "GCLQD", // 招标
  232. 2: "TBBJ", // 投标
  233. 3: "ZBKZJ", // 控制价
  234. };
  235. const isBidInvitation = exportKind === BID_INVITATION; // 是否是招标
  236. const isBidSubmission = exportKind === BID_SUBMISSION; // 是否是投标
  237. const isControl = exportKind === CONTROL; // 是否是控制价
  238. function emptyElement(name) {
  239. this.name = name;
  240. this.attrs = [];
  241. this.children = [];
  242. }
  243. // 建设项目根节点信息
  244. function CprjInfo(projectName) {
  245. const attrs = [{
  246. name: "CprjName",
  247. value: projectName,
  248. },
  249. {
  250. name: "CprjType",
  251. value: cprjType[exportKind],
  252. },
  253. ];
  254. Element.call(this, "CprjInfo", attrs);
  255. }
  256. // 项目基本信息
  257. function SystemInfo(projectData) {
  258. let baseInfo = _.find(projectData.property.basicInformation, {
  259. dispName: "基本信息",
  260. });
  261. //“招标工程量清单”、“招标控制价”时,输出该字段,为导出该文件的当前时间
  262. let makeData = {
  263. value : UTIL.getNowFormatTime(true)
  264. }
  265. //投标的时候取基本信息的makeData字段
  266. if(isBidSubmission) makeData = _.find(baseInfo.items, { "key": "makeDate" });
  267. // 取编制软件序列号所属单位。读取项目属性-建设项目基本信息的“投标单位”字段。该字段需要模板中新增。等确定后再修改
  268. let softwareNumHolder = _.find(baseInfo.items, { "key": "???" });
  269. let hardID = UTIL.generateHardwareId();
  270. let [cpuId, diskId, macId] = hardID.split(";");
  271. const orgScretInfoStr = `SoftwareName=纵横公路工程造价管理软件,SoftwareVer=V${VERSION},SoftwareCompany=珠海纵横创新软件有限公,SoftwareNumber=${userID},HardNumber=${diskId},MacAddress=${macId},SoftwareNumberHolder=${softwareNumHolder}`
  272. let scretInfo = sm3Digest(orgScretInfoStr);
  273. const attrs = [{
  274. name: "Name",
  275. value: "公路工程造价数据标准",
  276. },
  277. {
  278. name: "Version",
  279. value: "1.0",
  280. },
  281. {
  282. name: "SoftwareName",
  283. value: "纵横公路工程造价管理软件",
  284. },
  285. {
  286. name: "SoftwareVer",
  287. value: "V" + VERSION,
  288. },
  289. {
  290. name: "SoftwareCompany",
  291. value: "珠海纵横创新软件有限公司",
  292. },
  293. {
  294. name: "MakeDate",
  295. value: makeData?makeData.value:"",
  296. },
  297. {
  298. name: "SoftwareNumber",
  299. value: window.btoa(userID),
  300. },
  301. {
  302. name: "HardNumber",
  303. value: window.btoa(diskId),
  304. },
  305. {
  306. name: "MacAddress",
  307. value: window.btoa(macId),
  308. },
  309. {
  310. name: "SoftwareNumberHolder",
  311. value: softwareNumHolder,
  312. },
  313. {
  314. name: "SecretInfo",
  315. value: scretInfo,
  316. },
  317. ];
  318. if (isBidSubmission)
  319. attrs.splice(6, 0, {
  320. name: "BidderVer",
  321. value: UTIL.getNowFormatTime(true),
  322. });
  323. Element.call(this, "SystemInfo", attrs);
  324. }
  325. //造价依据
  326. function CostBasis() {
  327. // ItemStandardNo="GYSFX-000000-2018-86"
  328. const attrs = [{
  329. name: "MakeRuleNo",
  330. value: "GYSBB-000000-2018-86",
  331. },
  332. {
  333. name: "MakeRuleName",
  334. value: "公路工程建设项目概算预算编制办法",
  335. },
  336. {
  337. name: "ItemStandardNo",
  338. value: "GYSFX-000000-2018-86",
  339. },
  340. ];
  341. Element.call(this, "CostBasis", attrs);
  342. //定额库信息
  343. //to do 改成实际的值
  344. function NormLib() {
  345. const attrs = [{
  346. name: "NormLibNo",
  347. value: "YSDE-000000-2018-86",
  348. },
  349. {
  350. name: "NormLibName",
  351. value: "部颁公路工程预算定额(2018)",
  352. },
  353. {
  354. name: "Type",
  355. value: "ZDEK",
  356. },
  357. ];
  358. Element.call(this, "NormLib", attrs);
  359. }
  360. this.children.push(new NormLib());
  361. }
  362. function Rate(tenderProject, feeRateInfo, seirNo) {
  363. //RateNo="1" Name="纵横软件测试版本" RateLibNo="GYSFL-000000-2018-86"
  364. const attrs = [{
  365. name: "RateNo",
  366. value: seirNo,
  367. },
  368. {
  369. name: "Name",
  370. value: feeRateInfo.name,
  371. },
  372. {
  373. name: "RateLibNo",
  374. value: feeLibNoMap[feeRateInfo.libID],
  375. },
  376. ];
  377. Element.call(this, "Rate", attrs);
  378. let RateParams = new emptyElement("RateParams");
  379. let subRates = projectObj.project.FeeRate.getAllSubRates(feeRateInfo.rates);
  380. for (let s of subRates) {
  381. let sname = s.name.replace("(%)", "");
  382. sname = sname.replace("(%)", "");
  383. if (feeRateMap[sname]) {
  384. let value = "";
  385. if (s.editable) {
  386. let sel = _.find(s.optionList, {
  387. selected: true,
  388. });
  389. if (sel) {
  390. value = sel.name;
  391. } else if (gljUtil.isDef(s.value)) {
  392. value = s.value;
  393. }
  394. } else {
  395. value = _.findIndex(s.optionList, {
  396. selected: true,
  397. });
  398. if (value == -1) value = 0;
  399. }
  400. /* if (sname == '利润') tenderProject.ProfitRate = value;
  401. if (sname == '税金') tenderProject.TaxRate = value; */
  402. RateParams.children.push(new RateParam(feeRateMap[sname], value));
  403. }
  404. }
  405. this.children.push(RateParams);
  406. function RateParam(RateTypeNo, RateParamNo) {
  407. //<RateParam RateTypeNo="DJSGZJFFL" RateParamNo="0" Ratio="100"/>
  408. const attrs = [{
  409. name: "RateTypeNo",
  410. value: RateTypeNo,
  411. },
  412. {
  413. name: "RateParamNo",
  414. value: RateParamNo,
  415. },
  416. {
  417. name: "Ratio",
  418. value: "100",
  419. },
  420. ];
  421. Element.call(this, "RateParam", attrs);
  422. }
  423. let RateValues = new emptyElement("RateValues");
  424. function RateValue(CostTypeNo, RateTypeNo, value) {
  425. const attrs = [{
  426. name: "CostTypeNo",
  427. value: CostTypeNo,
  428. },
  429. {
  430. name: "RateTypeNo",
  431. value: RateTypeNo,
  432. },
  433. {
  434. name: "RateValue",
  435. value: value,
  436. },
  437. ];
  438. Element.call(this, "RateValue", attrs);
  439. }
  440. let prefix = "";
  441. for (let r of feeRateInfo.rates) {
  442. if (!r.ParentID && feeRateMap[r.name]) prefix = feeRateMap[r.name];
  443. if (feeRateMap[r.name] && r.ParentID) {
  444. RateValues.children.push(new RateValue(prefix, feeRateMap[r.name], r.rate));
  445. }
  446. }
  447. this.children.push(RateValues);
  448. }
  449. function Pract(tpdata, seriNo) {
  450. let pgljData = tpdata.projectGLJ.datas;
  451. let decimalObj = tpdata.property.decimal;
  452. const attrs = [{
  453. name: "PractNo",
  454. value: seriNo,
  455. },
  456. {
  457. name: "Name",
  458. value: pgljData.constData.usedUnitPriceInfo.name,
  459. },
  460. ];
  461. Element.call(this, "Pract", attrs);
  462. let Param = {
  463. name: "Param",
  464. attrs: [{
  465. name: "TaxLibNo",
  466. value: "CCSBZ-440000-2019-544",
  467. },
  468. {
  469. name: "AuxRate",
  470. value: pgljData.constData.assistProductionFeeRate,
  471. },
  472. ],
  473. children: [],
  474. };
  475. if (isBidSubmission || isControl) { //导出到招标文件中,不输出这一部分。
  476. let elecDatas = electrovalenceObj.getElectrovalenceDatas(null, pgljData.com_electrovalence, pgljData.gljList);
  477. electrovalenceObj.calcPertElectrovalenceMarketPrice(elecDatas);
  478. for (let e of elecDatas) {
  479. let Electro = {
  480. name: "Electro",
  481. attrs: [{
  482. name: "Code",
  483. value: e.code,
  484. },
  485. {
  486. name: "Price",
  487. value: e.electPrice,
  488. },
  489. {
  490. name: "Ratio",
  491. value: e.coe,
  492. },
  493. ],
  494. children: [],
  495. };
  496. Param.children.push(Electro);
  497. }
  498. }
  499. this.children.push(Param);
  500. function Mp(g) {
  501. const attrs = [{
  502. name: "Code",
  503. value: g.code,
  504. },
  505. {
  506. name: "PractName",
  507. value: g.name,
  508. },
  509. {
  510. name: "Spec",
  511. value: g.specs,
  512. },
  513. {
  514. name: "Unit",
  515. value: g.unit,
  516. },
  517. {
  518. name: "BudgetPrice",
  519. value: g.priceInfo.tenderPrice,
  520. },
  521. {
  522. name: "NormPrice",
  523. value: g.priceInfo.basePrice,
  524. },
  525. {
  526. name: "IsAdd",
  527. value: g.unit_price.is_add,
  528. },
  529. ];
  530. Element.call(this, "Mp", attrs);
  531. }
  532. function Material(g) {
  533. const attrs = [{
  534. name: "Code",
  535. value: g.code,
  536. },
  537. {
  538. name: "PractName",
  539. value: g.name,
  540. },
  541. {
  542. name: "Spec",
  543. value: g.specs,
  544. },
  545. {
  546. name: "Unit",
  547. value: g.unit,
  548. },
  549. {
  550. name: "BudgetPrice",
  551. value: g.priceInfo.tenderPrice,
  552. },
  553. {
  554. name: "NormPrice",
  555. value: g.priceInfo.basePrice,
  556. },
  557. {
  558. name: "IsAdd",
  559. value: g.unit_price.is_add,
  560. },
  561. {
  562. name: "OrgPrice",
  563. value: g.unit_price.originalPrice ? g.unit_price.originalPrice : 0,
  564. },
  565. {
  566. name: "TransFee",
  567. value: g.unit_price.unitFreight ? g.unit_price.unitFreight : 0,
  568. },
  569. {
  570. name: "GwRate",
  571. value: g.unit_price.grossWeightCoe_n ? g.unit_price.grossWeightCoe_n : 0,
  572. },
  573. {
  574. name: "OffSiteLf",
  575. value: g.unit_price.offSiteTransportLossRate_n ? g.unit_price.offSiteTransportLossRate_n : 0,
  576. },
  577. {
  578. name: "OnSiteLf",
  579. value: 0,
  580. },
  581. {
  582. name: "LoadLf",
  583. value: g.unit_price.handlingLossRate_n ? g.unit_price.handlingLossRate_n : 0,
  584. },
  585. {
  586. name: "StoreRate",
  587. value: g.unit_price.purchaseStorageRate_n ? g.unit_price.purchaseStorageRate_n : 0,
  588. },
  589. {
  590. name: "PackageRecycleFee",
  591. value: g.unit_price.packageRecoverValue ? g.unit_price.packageRecoverValue : 0,
  592. },
  593. ];
  594. Element.call(this, "Material", attrs);
  595. // if (g.unit_price.calcMaterial == 1) { //有材料计算
  596. // let index = gljUtil.getIndex(g);
  597. // let orList = [];
  598. // for (let o of pgljData.originalList) {
  599. // if (o.connect_key == index) orList.push(new OrgPrices(o));
  600. // }
  601. // if (orList.length > 0) this.children = orList;
  602. // }
  603. function CostStructure(r) {
  604. //待获取
  605. this.name = "CostStructure";
  606. this.attrs = [];
  607. this.children = [];
  608. }
  609. function Consume(r, o) {
  610. this.name = "Consume";
  611. this.attrs = [];
  612. this.children = [];
  613. for (let g of o.ration_gljs) {
  614. if (g.rationID == r.ID) {
  615. let r_quantity = scMathUtil.roundForObj(r.quantity, tpdata.property.decimal.ration.quantity);
  616. this.children.push(new ConsumeItem(g, r_quantity));
  617. }
  618. }
  619. }
  620. function ConsumeItem(g, ration_quantity) {
  621. const attrs = [{
  622. name: "Code", //待获取
  623. value: g.code,
  624. },
  625. {
  626. name: "Consumption",
  627. value: scMathUtil.roundForObj(ration_quantity * parseFloat(g.quantity), tpdata.property.decimal.glj.quantity),
  628. },
  629. ];
  630. Element.call(this, "ConsumeItem", attrs);
  631. }
  632. function Norm(r, o) {
  633. const attrs = [{
  634. name: "NormLibNo", //待获取
  635. value: "",
  636. },
  637. {
  638. name: "DisplayCode",
  639. value: r.code,
  640. },
  641. {
  642. name: "Name",
  643. value: r.name,
  644. },
  645. {
  646. name: "Unit",
  647. value: r.unit,
  648. },
  649. {
  650. name: "Num",
  651. value: r.quantity,
  652. },
  653. {
  654. name: "CostTypeNo",
  655. value: "", //待获取
  656. },
  657. {
  658. name: "FabricationCost", //待获取
  659. value: "",
  660. },
  661. {
  662. name: "AdjustStatus",
  663. value: "",
  664. },
  665. ];
  666. Element.call(this, "Norm", attrs);
  667. this.children.push(new CostStructure(r));
  668. this.children.push(new Consume(r, o));
  669. }
  670. function SelfCollect(o) {
  671. const attrs = [{
  672. name: "OtherCost",
  673. value: 0,
  674. }, ];
  675. Element.call(this, "SelfCollect", attrs);
  676. for (let r of o.rations) {
  677. this.children.push(new Norm(r, o));
  678. }
  679. }
  680. function OrgPrices(o) {
  681. const attrs = [{
  682. name: "OrgPricevalue",
  683. value: o.supplyPrice,
  684. },
  685. {
  686. name: "Ratio",
  687. value: o.coe,
  688. },
  689. ];
  690. Element.call(this, "OrgPrices", attrs);
  691. if (!o.rations) return;
  692. this.children.push(new SelfCollect(o));
  693. }
  694. }
  695. function Mech(g,gljKeyMap) {
  696. const attrs = [{
  697. name: "Code",
  698. value: g.code,
  699. },
  700. {
  701. name: "PractName",
  702. value: g.name,
  703. },
  704. {
  705. name: "Spec",
  706. value: g.specs,
  707. },
  708. {
  709. name: "Unit",
  710. value: g.unit,
  711. },
  712. {
  713. name: "BudgetPrice",
  714. value: g.priceInfo.tenderPrice,
  715. },
  716. {
  717. name: "NormPrice",
  718. value: g.priceInfo.basePrice,
  719. },
  720. {
  721. name: "IsAdd",
  722. value: g.unit_price.is_add,
  723. },
  724. ];
  725. Element.call(this, "Mech", attrs);
  726. let FixedCostItems = [];
  727. let fcsum = 0;
  728. let VariableCostItems = [];
  729. let vcsum = 0;
  730. if (g.ratio_data && g.ratio_data.length > 0) {
  731. for (let ratio of g.ratio_data) {
  732. let rIndex = gljUtil.getIndex(ratio);
  733. let rglj = gljKeyMap[rIndex];
  734. let ts = scMathUtil.roundForObj(parseFloat(ratio.consumption) * rglj.priceInfo.tenderPrice, decimalObj.glj.unitPrice);
  735. if (FixedCostMap[ratio.name]) {
  736. FixedCostItems.push(new FixedCostItem(ratio));
  737. fcsum = scMathUtil.roundForObj(fcsum + ts, decimalObj.glj.unitPrice);
  738. } else {
  739. VariableCostItems.push(new VariableCostItem(ratio));
  740. vcsum = scMathUtil.roundForObj(vcsum + ts, decimalObj.glj.unitPrice);
  741. }
  742. }
  743. }
  744. if (FixedCostItems.length > 0) {
  745. let fc = new FixedCost(fcsum);
  746. fc.children = FixedCostItems;
  747. this.children.push(fc);
  748. }
  749. if (VariableCostItems.length > 0) {
  750. let vc = new VariableCost(vcsum);
  751. vc.children = VariableCostItems;
  752. this.children.push(vc);
  753. }
  754. function VariableCost(sum) {
  755. const attrs = [{
  756. name: "VariableCostSum",
  757. value: sum,
  758. }];
  759. Element.call(this, "VariableCost", attrs);
  760. }
  761. function VariableCostItem(item) {
  762. const attrs = [{
  763. name: "VariableCostNo",
  764. value: item.code,
  765. },{
  766. name: "Consumption",
  767. value: item.consumption,
  768. }]
  769. Element.call(this, "VariableCostItem", attrs);
  770. }
  771. function FixedCost(sum) {
  772. const attrs = [{
  773. name: "FixedCostSum",
  774. value: sum,
  775. }, {
  776. name: "FixedRate",
  777. value: 1,
  778. }];
  779. Element.call(this, "FixedCost", attrs);
  780. }
  781. function FixedCostItem(item) {
  782. const attrs = [{
  783. name: "FixedCostNo",
  784. value: ratioCodeMap[item.code],
  785. },{
  786. name: "Sum",
  787. value: item.consumption,
  788. }]
  789. Element.call(this, "FixedCostItem", attrs);
  790. }
  791. }
  792. let Mps = new emptyElement("Mps");
  793. let Materials = new emptyElement("Materials");
  794. let Mechs = new emptyElement("Mechs");
  795. let gljKeyMap = {};
  796. let temMechs = [];
  797. if (isBidSubmission || isControl) { //导出到招标文件中,不输出这一部分。
  798. for (let g of pgljData.gljList) {
  799. if (!g.quantity) {
  800. continue;
  801. }
  802. let type = g.type + "";
  803. gljKeyMap[gljUtil.getIndex(g)] = g;
  804. type = type.charAt(0);
  805. if (type == "1") {
  806. Mps.children.push(new Mp(g));
  807. } else if (type == "2" || type == 5) {
  808. Materials.children.push(new Material(g));
  809. } else if (type == "3") {
  810. temMechs.push(g);
  811. }
  812. }
  813. for (let t of temMechs) {
  814. Mechs.children.push(new Mech(t,gljKeyMap));
  815. }
  816. }
  817. this.children.push(Mps);
  818. this.children.push(Materials);
  819. this.children.push(Mechs);
  820. }
  821. function EprjInfo(tenderProject) {
  822. let bills = tenderProject.Bills.datas;
  823. let feature = tenderProject.property.projectFeature ? tenderProject.property.projectFeature : [];
  824. let totalItem = null;
  825. let proItem = null; //暂列金额项
  826. let safeItem = null;
  827. let oneToSevenItem = null;
  828. for (let b of bills) {
  829. if (b.flagsIndex && b.flagsIndex.fixed && b.flagsIndex.fixed.flag == fixedFlag.TOTAL_COST) totalItem = b;
  830. if (b.flagsIndex && b.flagsIndex.fixed && b.flagsIndex.fixed.flag == fixedFlag.PROVISIONAL) proItem = b;
  831. if (b.flagsIndex && b.flagsIndex.fixed && b.flagsIndex.fixed.flag == fixedFlag.ONE_SEVEN_BILLS) oneToSevenItem = b;
  832. if(b.code == "102-3" && b.name=="安全生产费") safeItem = b;
  833. }
  834. const attrs = [{
  835. name: "Name",
  836. value: tenderProject.projectInfo.name,
  837. },
  838. {
  839. name: "Sums",
  840. value: totalItem.feesIndex && totalItem.feesIndex.common && totalItem.feesIndex.common.tenderTotalFee ? totalItem.feesIndex.common.tenderTotalFee : 0,
  841. },
  842. ];
  843. //输出控制价、投标文件时,取调价后的标段总造价。
  844. //输出招标文件时,取0
  845. if (isBidInvitation) attrs[1].value = 0;
  846. Element.call(this, "EprjInfo", attrs);
  847. this.children.push(new SummaryOfCost(totalItem, proItem,safeItem,oneToSevenItem,feature));
  848. this.children.push(new MakeInfo(tenderProject));
  849. this.children.push(new Params(tenderProject));
  850. this.children.push(new getBillsItems(tenderProject));
  851. this.children.push(new getIndexs(tenderProject));
  852. let bidEvaluationMainMaterials = getBidEvaluationMainMaterial(tenderProject);
  853. if(bidEvaluationMainMaterials.length > 0) this.children.push(...bidEvaluationMainMaterials);
  854. //山东接口还需要增加几个表的数据(就是把原报表的显示数据转到投标文件里)
  855. // 1. 投标报价汇总表
  856. this.children.push(new quoteSummary(tenderProject));
  857. // 2. 计日工表
  858. let spdw = sporadicWork(tenderProject);
  859. if (spdw) {
  860. this.children.push(spdw);
  861. }
  862. // 3. 材料暂估价表
  863. let estMaterialRpt = materialEstimate(tenderProject);
  864. if (estMaterialRpt) {
  865. this.children.push(estMaterialRpt);
  866. }
  867. // 4. 工程设备暂估价表
  868. let estMachineRpt = getMachineTempEst(tenderProject);
  869. if (estMachineRpt) {
  870. this.children.push(estMachineRpt);
  871. }
  872. // 5. 专业工程暂估价表
  873. let estSpecPrjRpt = getSpecPrjEst(tenderProject);
  874. if (estSpecPrjRpt) {
  875. this.children.push(estSpecPrjRpt);
  876. }
  877. // 6. 工程量清单单价分析表
  878. }
  879. function _getBidGljCode(tenderProject, orgGlj) {
  880. let rst = orgGlj.code;
  881. if (tenderProject.bid_evaluation_list && tenderProject.bid_evaluation_list.datas) {
  882. for (let bGlj of tenderProject.bid_evaluation_list.datas) {
  883. if (bGlj.projectGLJID === orgGlj.id) {
  884. rst = bGlj.seq;
  885. break;
  886. }
  887. }
  888. }
  889. return rst;
  890. }
  891. function _getFee(bill, key = 'common', valueKey = 'tenderTotalFee') {
  892. let rstSum = 0;
  893. if (bill) {
  894. let dtlB = (bill.data) ? bill.data : bill;
  895. if (dtlB.fees) {
  896. for (let fee of dtlB.fees) {
  897. if (fee.fieldName === key) {
  898. rstSum = fee[valueKey];
  899. break;
  900. }
  901. }
  902. }
  903. }
  904. return rstSum;
  905. };
  906. function quoteSummary(tenderProject) {
  907. let quoteSummaryItem = new emptyElement('QuoteSummary');
  908. // let attrs = [];
  909. //1. 取固定清单,
  910. // 1.1 100~700章总清单(flags有属性为19的那个) -> topNode100To700
  911. // 1.2 已包含在清单合计中的材料、工程设备、专业工程暂估价合计 标记:20
  912. // 1.3 清单合计减去材料、工程设备、专业工程暂估价|合计 标记:21
  913. // 1.4 计日工合计 标记:22
  914. // 1.5 暂列金额(不含计日工总额) 标记:26
  915. // 1.6 投标报价 标记:9
  916. let topNode100To700, nodeZXZDJ, nodeQDKCZXZDJ, nodeJRG, nodeZLJE, nodeTBBJ;
  917. let chapterNodes = [];
  918. tenderProject.Bills.datas.forEach((bill)=> {
  919. if (bill.flags && bill.flags.length > 0) {
  920. for (let flag of bill.flags) {
  921. switch(flag.flag) {
  922. case 19 :
  923. topNode100To700 = bill;
  924. break;
  925. case 20 :
  926. nodeZXZDJ = bill;
  927. break;
  928. case 21 :
  929. nodeQDKCZXZDJ = bill;
  930. break;
  931. case 22 :
  932. nodeJRG = bill;
  933. break;
  934. case 26 :
  935. nodeZLJE = bill;
  936. break;
  937. case 9 :
  938. nodeTBBJ = bill;
  939. break;
  940. default :
  941. break;
  942. }
  943. }
  944. }
  945. });
  946. //2. 然后获取topNode100To700下的所有次一级清单(100章...700章)
  947. if (topNode100To700) {
  948. for (let rootBill of tenderProject.Bills.tree.roots) {
  949. // 100~700章总清单在top级别(山东养护)
  950. if (rootBill.data.ID === topNode100To700.ID) {
  951. rootBill.children.forEach((subBill)=> {
  952. if (subBill.data.name.includes('00章')) {
  953. chapterNodes.push(subBill);
  954. }
  955. });
  956. break;
  957. }
  958. }
  959. }
  960. //3. 拼凑数据
  961. let nodeAttrs = [];
  962. if (topNode100To700) {
  963. let order = 1;
  964. //读取投标报价汇总表信息。1.ItemNo 序号。2.ChapterNo 章次。 3.Name 科目名称。 4.Sum 金额。
  965. chapterNodes.forEach((cnode)=> {
  966. let chapterIdx = cnode.data.name.indexOf("00章");
  967. nodeAttrs.push({ItemNo: order, ChapterNo: cnode.data.name.substr(chapterIdx - 1, 3), Name: cnode.data.name, Sum: _getFee(cnode)});
  968. order++;
  969. });
  970. nodeAttrs.push({ItemNo: order, ChapterNo: '', Name: '第100章至700章清单合计', Sum: _getFee(topNode100To700)});
  971. order++;
  972. if (nodeZXZDJ) {
  973. nodeAttrs.push({ItemNo: order, ChapterNo: '', Name: '已包含在清单合计中的材料、工程设备、专业工程暂估价合计', Sum: _getFee(nodeZXZDJ)});
  974. order++;
  975. }
  976. if (nodeQDKCZXZDJ) {
  977. nodeAttrs.push({ItemNo: order, ChapterNo: '', Name: `清单合计减去材料、工程设备、专业工程暂估价合计(即${order - 2}-${order - 1})=${order}`, Sum: _getFee(nodeQDKCZXZDJ)});
  978. order++;
  979. }
  980. if (nodeJRG) {
  981. nodeAttrs.push({ItemNo: order, ChapterNo: '', Name: `计日工合计`, Sum: _getFee(nodeJRG)});
  982. order++;
  983. }
  984. if (nodeZLJE) {
  985. nodeAttrs.push({ItemNo: order, ChapterNo: '', Name: `暂列金额(不含计日工总额)`, Sum: _getFee(nodeZLJE)});
  986. order++;
  987. }
  988. if (nodeTBBJ) {
  989. nodeAttrs.push({ItemNo: order, ChapterNo: '', Name: `投标报价(${chapterNodes.length + 1} + ${order - 2}+${order - 1})=${order}`, Sum: _getFee(nodeZLJE)});
  990. order++;
  991. }
  992. }
  993. function _Item(item) {
  994. const attrs = [
  995. { name: 'ItemNo',
  996. value: item.ItemNo
  997. },
  998. { name: 'ChapterNo',
  999. value: item.ChapterNo
  1000. },
  1001. { name: 'Name',
  1002. value: item.Name
  1003. },
  1004. { name: 'Sum',
  1005. value: item.Sum
  1006. }
  1007. ];
  1008. let rst = new emptyElement('Item');
  1009. rst.attrs.push(...attrs);
  1010. return rst;
  1011. }
  1012. for (let attr of nodeAttrs) {
  1013. quoteSummaryItem.children.push(_Item(attr));
  1014. }
  1015. return quoteSummaryItem;
  1016. }
  1017. function sporadicWork(tenderProject) {
  1018. //计日工表,含:劳务、材料、施工机械、计日工汇总
  1019. let hasSporadicWork = false;
  1020. let sporadicWorkItem = new Element('SporadicWork');
  1021. let nodeLabour, nodeMaterial, nodeMachine;
  1022. //首先收集过滤计日工相关清单
  1023. tenderProject.Bills.datas.forEach((bill)=> {
  1024. if (bill.flags && bill.flags.length > 0) {
  1025. for (let flag of bill.flags) {
  1026. switch(flag.flag) {
  1027. case 23 :
  1028. nodeLabour = bill;
  1029. break;
  1030. case 24 :
  1031. nodeMaterial = bill;
  1032. break;
  1033. case 25 :
  1034. nodeMachine = bill;
  1035. break;
  1036. default :
  1037. break;
  1038. }
  1039. }
  1040. }
  1041. });
  1042. const _buildWorkNodeItem = function(orgNode, subNodes, parentKey, childKey) {
  1043. let parentNode = new Element(parentKey);
  1044. sporadicWorkItem.children.push(parentNode);
  1045. const pSumAttrs = [
  1046. {
  1047. name: 'Sum',
  1048. value: _getFee(orgNode)
  1049. }
  1050. ];
  1051. // Element.call(this, parentKey, pSumAttrs);
  1052. parentNode.attrs.push(...pSumAttrs);
  1053. subNodes.forEach((node)=> {
  1054. let childNode = new Element(childKey);
  1055. parentNode.children.push(childNode);
  1056. const attrs = [
  1057. { name: 'ItemNo',
  1058. value: node.code
  1059. }, {
  1060. name: 'Name',
  1061. value: node.name
  1062. }, {
  1063. name: 'Unit',
  1064. value: node.unit
  1065. }, {
  1066. name: 'Num',
  1067. value: node.quantity
  1068. }, {
  1069. name: 'Price',
  1070. value: _getFee(node, 'common', 'tenderUnitFee')
  1071. }, {
  1072. name: 'Sum',
  1073. value: _getFee(node)
  1074. }
  1075. ];
  1076. childNode.attrs.push(...attrs);
  1077. });
  1078. };
  1079. //1. 判断劳务
  1080. if (nodeLabour) {
  1081. let subNodes = [];
  1082. tenderProject.Bills.datas.forEach((bill)=> {
  1083. if (bill.ParentID === nodeLabour.ID) {
  1084. subNodes.push(bill);
  1085. }
  1086. });
  1087. if (subNodes.length > 0) {
  1088. hasSporadicWork = true;
  1089. //创建劳务Mps节点及劳务Mps下Mp子节点
  1090. _buildWorkNodeItem(nodeLabour, subNodes, 'Mps', 'Mp');
  1091. }
  1092. }
  1093. //2. 判断材料
  1094. if (nodeMaterial) {
  1095. let subNodes = [];
  1096. tenderProject.Bills.datas.forEach((bill)=> {
  1097. if (bill.ParentID === nodeMaterial.ID) {
  1098. subNodes.push(bill);
  1099. }
  1100. });
  1101. if (subNodes.length > 0) {
  1102. hasSporadicWork = true;
  1103. //创建材料Materials节点及劳务Materials下Material子节点
  1104. _buildWorkNodeItem(nodeMaterial, subNodes, 'Materials', 'Material');
  1105. }
  1106. }
  1107. //3. 判断施工机械
  1108. if (nodeMachine) {
  1109. let subNodes = [];
  1110. tenderProject.Bills.datas.forEach((bill)=> {
  1111. if (bill.ParentID === nodeMachine.ID) {
  1112. subNodes.push(bill);
  1113. }
  1114. });
  1115. if (subNodes.length > 0) {
  1116. hasSporadicWork = true;
  1117. //创建施工机械Meehs节点及劳务Meehs下Meeh子节点
  1118. _buildWorkNodeItem(nodeMachine, subNodes, 'Meehs', 'Meeh');
  1119. }
  1120. }
  1121. //4. 判断计日工汇总
  1122. if (hasSporadicWork) {
  1123. let summaryNode = new Element('Summary');
  1124. sporadicWorkItem.children.push(summaryNode);
  1125. const pSumAttrs = [
  1126. {
  1127. name: 'Sum',
  1128. value: _getFee(nodeLabour) + _getFee(nodeMaterial) + _getFee(nodeMachine)
  1129. }
  1130. ];
  1131. summaryNode.attrs = pSumAttrs;
  1132. //把劳务、材料、施工机械
  1133. function _workItem(node, name, remark='') {
  1134. let childNode = new Element('Item');
  1135. summaryNode.children.push(childNode);
  1136. const attrs = [
  1137. {
  1138. name: "Name",
  1139. value: name,
  1140. },
  1141. {
  1142. name: "Sum",
  1143. value: _getFee(node),
  1144. },
  1145. {
  1146. name: "Remark",
  1147. value: remark,
  1148. }
  1149. ]
  1150. childNode.attrs.push(...attrs);
  1151. }
  1152. _workItem(nodeLabour, '劳务');
  1153. _workItem(nodeMaterial, '材料');
  1154. _workItem(nodeMachine, '机械');
  1155. }
  1156. //返回
  1157. if (hasSporadicWork) {
  1158. return sporadicWorkItem;
  1159. } else {
  1160. return null;
  1161. }
  1162. }
  1163. function materialEstimate(tenderProject) {
  1164. let mEstNode = new emptyElement('MaterialEstimate');
  1165. let items = [];
  1166. //材料暂估价明细
  1167. tenderProject.projectGLJ.datas.gljList.forEach((glj)=> {
  1168. if (glj.is_evaluate && glj.type !== 5 && glj.type !== 301) {
  1169. items.push(glj);
  1170. }
  1171. });
  1172. if (items.length > 0) {
  1173. items.forEach((glj, sno)=> {
  1174. let mEstItemNode = new emptyElement('Item');
  1175. mEstNode.children.push(mEstItemNode);
  1176. let attrs = [
  1177. {name: 'ItemNo', value: sno + 1},
  1178. {name: 'Code', value: _getBidGljCode(tenderProject, glj)},
  1179. {name: 'Number', value: glj.code},
  1180. {name: 'Name', value: glj.name},
  1181. {name: 'Unit', value: glj.unit},
  1182. {name: 'Num', value: glj.tenderQuantity},
  1183. {name: 'Price', value: glj.unit_price.market_price},
  1184. {name: 'Sum', value: glj.tenderQuantity * glj.unit_price.market_price, type:TYPE.DECIMAL},
  1185. {name: 'Remark', value: (glj.remark) ? glj.remark : ''}
  1186. ];
  1187. mEstItemNode.attrs.push(...attrs);
  1188. });
  1189. return mEstNode;
  1190. } else {
  1191. return null;
  1192. }
  1193. }
  1194. function getMachineTempEst(tenderProject) {
  1195. let mEstNode = new emptyElement('PrjDeviceEstimate');
  1196. let items = [];
  1197. //工程设备明细
  1198. tenderProject.projectGLJ.datas.gljList.forEach((glj)=> {
  1199. if (glj.is_evaluate && glj.type === 5) {
  1200. items.push(glj);
  1201. }
  1202. });
  1203. if (items.length > 0) {
  1204. items.forEach((glj, sno)=> {
  1205. let mEstItemNode = new emptyElement('Item');
  1206. mEstNode.children.push(mEstItemNode);
  1207. let attrs = [
  1208. {name: 'ItemNo', value: sno + 1},
  1209. {name: 'Code', value: _getBidGljCode(tenderProject, glj)},
  1210. {name: 'Number', value: glj.code},
  1211. {name: 'Name', value: glj.name},
  1212. {name: 'Unit', value: glj.unit},
  1213. {name: 'Num', value: glj.tenderQuantity},
  1214. {name: 'Price', value: glj.unit_price.market_price},
  1215. {name: 'Sum', value: glj.tenderQuantity * glj.unit_price.market_price, type:TYPE.DECIMAL},
  1216. {name: 'Remark', value: (glj.remark) ? glj.remark : ''}
  1217. ];
  1218. mEstItemNode.attrs.push(...attrs);
  1219. });
  1220. return mEstNode;
  1221. } else {
  1222. return null;
  1223. }
  1224. }
  1225. function getSpecPrjEst(tenderProject) {
  1226. let mEstNode = new emptyElement('SpecPrjEstimate');
  1227. let sum = 0;
  1228. let items = [];
  1229. //专业工程暂估明细
  1230. tenderProject.Bills.datas.forEach((bill)=> {
  1231. if (bill.specialProvisional === '专业工程') {
  1232. items.push(bill);
  1233. }
  1234. });
  1235. if (items.length > 0) {
  1236. items.forEach((bill, sno)=> {
  1237. let mEstItemNode = new emptyElement('Item');
  1238. mEstNode.children.push(mEstItemNode);
  1239. let ttl = _getFee(bill);
  1240. sum += ttl;
  1241. let attrs = [
  1242. {name: 'ItemNo', value: sno + 1},
  1243. {name: 'Name', value: bill.name},
  1244. {name: 'Content', value: bill.jobContent.toString()},
  1245. {name: 'Sum', value: ttl, type:TYPE.DECIMAL},
  1246. ];
  1247. mEstItemNode.attrs.push(...attrs);
  1248. });
  1249. mEstNode.attrs.push({name: 'Sum', value: sum});
  1250. return mEstNode;
  1251. } else {
  1252. return null;
  1253. }
  1254. }
  1255. function getBillsAnalyze(tenderProject) {
  1256. // 本函数是尽量复刻【5.5表】工程量清单单价分析表的‘综合’计算式脚本的相关逻辑,具体细节根据实际环境有所调整(前端环境已有不少现成的结构及数据,能少跑不少逻辑)
  1257. let djfxbNode = new emptyElement('ListUnitPriceAnalysis');
  1258. // 工程量清单单价分析(100~700章 清单下所有定额工料机的综合)
  1259. let topNode100To700;
  1260. let sno = 1;
  1261. const prefix = '_';
  1262. let filterMtlTypes = [202, 203, 204, 301];
  1263. for (let bill of tenderProject.Bills.datas) {
  1264. if (bill.flags && bill.flags.length > 0) {
  1265. for (let flag of bill.flags) {
  1266. if (flag.flag === 19) {
  1267. for (let rootBill of tenderProject.Bills.tree.roots) {
  1268. if (rootBill.ID === bill.ID) {
  1269. topNode100To700 = rootBill;
  1270. break;
  1271. }
  1272. }
  1273. break;
  1274. }
  1275. }
  1276. }
  1277. }
  1278. const cacheObj = {};
  1279. const proKeysArr = [];
  1280. const addedGljCodeCache = {};
  1281. //说明:根据实际情况,用户会直接在清单下加工料机,此工料机属于定额层次,那么算工程量的时候要加上这个(沟通后这种几率很小,暂时返回0,如有再补上)
  1282. const _getAdhocGljQty = function(billsId, rationCode, rstType = 1) {
  1283. let rst = 0;
  1284. // for (let nbidx = 0; nbidx < newRBillsIdArr.length; nbidx++) {
  1285. // if (newRBillsIdArr[nbidx] === billsId && newRCodeArr[nbidx] === rationCode) {
  1286. // rst = (rstType === 1) ? newRQtyArr[nbidx] : newTtlArr[nbidx];
  1287. // break;
  1288. // }
  1289. // }
  1290. return rst;
  1291. };
  1292. const _getCacheObjInitialedItem = function(bill = null, glj = null) {
  1293. return {
  1294. code: (bill) ? bill.code : ((glj) ? glj.code : ''),
  1295. name: (bill) ? bill.name : ((glj) ? glj.name : ''),
  1296. quantity: 0,
  1297. labourConsume: 0,
  1298. labourUnitPrice: 0,
  1299. labourTotalPrice: 0,
  1300. mainMaterialFee: 0,
  1301. auxiliaryMaterialFee: 0,
  1302. materialUnitFee: (bill) ? _getFee(bill, 'marketMaterial', 'unitFee') : 0,
  1303. machineFee: (bill) ? _getFee(bill, 'marketMachine') : 0,
  1304. otherFee: (bill) ? _getFee(bill, 'measure') : 0, //措施费
  1305. managementFee: (bill) ? (_getFee(bill, 'manage') + _getFee(bill, 'force')) : 0, //管理+规费
  1306. taxFee: (bill) ? _getFee(bill, 'tax') : 0,
  1307. profitFee: (bill) ? _getFee(bill, 'profit') : 0,
  1308. unitPrice: (bill) ? _getFee(bill, 'common', 'unitFee') : 0
  1309. };
  1310. };
  1311. const _getPrjGLJ = function(gljID) {
  1312. let rst = null;
  1313. for (let glj of tenderProject.projectGLJ.datas.gljList) {
  1314. if (glj.id === gljID) {
  1315. rst = glj;
  1316. break;
  1317. }
  1318. }
  1319. };
  1320. const _createNode = function(billIdKey, bill) {
  1321. if (cacheObj[billIdKey]) {
  1322. //1. 叶子清单,先创建清单Item
  1323. let bQtn = 1;
  1324. if (bill.hasOwnProperty('quantity')) {
  1325. bQtn = parseFloat(bill.quantity);
  1326. if (isNaN(bQtn)) bQtn = 1;
  1327. }
  1328. let billMainMaterialTtl = cacheObj[billIdKey].mainMaterialFee/bQtn;
  1329. let billAuxiliaryMaterialTtl = cacheObj[billIdKey].auxiliaryMaterialFee/bQtn;
  1330. let leafBillAttrs = [
  1331. {name: 'ItemNo', vlaue: sno},
  1332. {name: 'Code', vlaue: cacheObj[billIdKey].code},
  1333. {name: 'Name', vlaue: cacheObj[billIdKey].name},
  1334. {name: 'LaborWorkDays', vlaue: cacheObj[billIdKey].labourConsume / bQtn},
  1335. {name: 'LaborUnitPrice', vlaue: cacheObj[billIdKey].labourUnitPrice},
  1336. {name: 'LaborUnitTotal', vlaue: cacheObj[billIdKey].labourTotalPrice / bQtn},
  1337. {name: 'MainMaterialConsume', vlaue: 0},
  1338. {name: 'MainMaterialUnit', vlaue: ''},
  1339. {name: 'MainMaterialUnitPrice', vlaue: 0},
  1340. {name: 'MainMaterialTotal', vlaue: billMainMaterialTtl},
  1341. {name: 'AuxiliaryMaterialFee', vlaue: billAuxiliaryMaterialTtl},
  1342. {name: 'MaterialSum', vlaue: billMainMaterialTtl + billAuxiliaryMaterialTtl},
  1343. {name: 'MachUsageFee', vlaue: cacheObj[billIdKey].machineFee/bQtn},
  1344. {name: 'OtherFee', vlaue: cacheObj[billIdKey].otherFee/bQtn},
  1345. {name: 'ManageFee', vlaue: cacheObj[billIdKey].managementFee/bQtn},
  1346. {name: 'Tax', vlaue: cacheObj[billIdKey].taxFee/bQtn},
  1347. {name: 'Profit', vlaue: cacheObj[billIdKey].profitFee/bQtn},
  1348. {name: 'Price', vlaue: _getFee(bill)},
  1349. ];
  1350. sno++;
  1351. let itemNode = new emptyElement('Item');
  1352. itemNode.attrs.push(...leafBillAttrs);
  1353. djfxbNode.children.push(itemNode);
  1354. //2. 清单下工料机
  1355. cacheObj[billIdKey].items.forEach((gljItem)=> {
  1356. let showQty = gljItem.mainMaterialConsume/cacheObj[billIdKey].quantity;
  1357. showQty = Math.round(showQty * 1000000) / 1000000;
  1358. let gljAttrs = [
  1359. {name: 'ItemNo', vlaue: sno},
  1360. {name: 'Code', vlaue: gljItem.code},
  1361. {name: 'Name', vlaue: gljItem.name},
  1362. {name: 'LaborWorkDays', vlaue: 0},
  1363. {name: 'LaborUnitPrice', vlaue: 0},
  1364. {name: 'LaborUnitTotal', vlaue: 0},
  1365. {name: 'MainMaterialConsume', vlaue: showQty},
  1366. {name: 'MainMaterialUnit', vlaue: gljItem.mainMaterialUnit},
  1367. {name: 'MainMaterialUnitPrice', vlaue: gljItem.mainMaterialUnitPrice},
  1368. {name: 'MainMaterialTotal', vlaue: showQty * gljItem.mainMaterialUnitPrice},
  1369. {name: 'AuxiliaryMaterialFee', vlaue: 0},
  1370. {name: 'MaterialSum', vlaue: 0},
  1371. {name: 'MachUsageFee', vlaue: 0},
  1372. {name: 'OtherFee', vlaue: 0},
  1373. {name: 'ManageFee', vlaue: 0},
  1374. {name: 'Tax', vlaue: 0},
  1375. {name: 'Profit', vlaue: 0},
  1376. {name: 'Price', vlaue: _getFee(bill)},
  1377. ];
  1378. sno++;
  1379. });
  1380. }
  1381. };
  1382. const _getAllGlj = function(parentBill) {
  1383. if (parentBill.children.length > 0) {
  1384. parentBill.children.forEach((subBill)=> {
  1385. _getAllGlj(subBill);
  1386. });
  1387. } else {
  1388. let billIdKey = prefix + parentBill.ID;
  1389. if (!cacheObj.hasOwnProperty(billIdKey)) {
  1390. cacheObj[billIdKey] = _getCacheObjInitialedItem(parentBill);
  1391. addedGljCodeCache[billIdKey] = [];
  1392. proKeysArr.push(billIdKey);
  1393. }
  1394. tenderProject.ration_glj.forEach((rglj)=> {
  1395. if (rglj.billsItemID === parentBill.ID) {
  1396. let gljQty = parseFloat(rglj.quantity);
  1397. if (isNaN(gljQty)) gljQty = 0;
  1398. let gljRationQty = parseFloat(rglj.rationItemQuantity);
  1399. if (isNaN(gljRationQty)) gljRationQty = 0;
  1400. let gljCns = gljQty * gljRationQty;
  1401. let prjGlj = _getPrjGLJ(rglj.projectGLJID);
  1402. let gljUnitPrice = parseFloat(prjGlj.unit_price.market_price);
  1403. let gljTotalPrice = gljCns * gljUnitPrice;
  1404. let gljCode = rglj.code;
  1405. if (rglj.type === 1) {
  1406. //人工
  1407. cacheObj[billIdKey].labourConsume = cacheObj[billIdKey].labourConsume + gljCns;
  1408. cacheObj[billIdKey].labourUnitPrice = gljUnitPrice;
  1409. cacheObj[billIdKey].labourTotalPrice = cacheObj[billIdKey].labourTotalPrice + gljTotalPrice;
  1410. } else if (filterMtlTypes.indexOf(dtlType) < 0) {
  1411. if (!addedGljCodeCache[billIdKey].includes(gljCode)) {
  1412. addedGljCodeCache[billIdKey].push(gljCode);
  1413. }
  1414. if (prjGlj.is_main_material) {
  1415. let dtlObj = {};
  1416. dtlObj.code = gljCode;
  1417. dtlObj.name = rglj.name;
  1418. dtlObj.specs = rglj.specs;
  1419. //
  1420. let adhocGljQty = _getAdhocGljQty(parentBill.ID, dtlObj.code);
  1421. let adhocGljTtl = adhocGljQty * gljUnitPrice;
  1422. dtlObj.mainMaterialConsume = gljCns + adhocGljQty; //考虑清单单独加工料机的情况,需要补上消耗量
  1423. dtlObj.mainMaterialUnitPrice = gljUnitPrice;
  1424. dtlObj.mainMaterialTotalPrice = gljTotalPrice;
  1425. dtlObj.mainMaterialUnit = rglj.unit;
  1426. let isAdd = 0;
  1427. for (let i = 0; i < cacheObj[billIdKey].items.length; i++) {
  1428. //先比较对象中是否已存在同一条工料机,存在,则累加汇总消耗量和金额;否则添加。
  1429. if (dtlObj.code === cacheObj[billIdKey].items[i].code && dtlObj.name === cacheObj[billIdKey].items[i].name && dtlObj.mainMaterialUnit === cacheObj[billIdKey].items[i].mainMaterialUnit && dtlObj.specs === cacheObj[billIdKey].items[i].specs) {
  1430. cacheObj[billIdKey].items[i].mainMaterialConsume = cacheObj[billIdKey].items[i].mainMaterialConsume + gljCns;
  1431. cacheObj[billIdKey].items[i].mainMaterialTotalPrice = cacheObj[billIdKey].items[i].mainMaterialTotalPrice + gljTotalPrice;
  1432. isAdd = 1;
  1433. break;
  1434. }
  1435. }
  1436. if (isAdd === 0) {
  1437. cacheObj[billIdKey].items.push(dtlObj);
  1438. }
  1439. cacheObj[billIdKey].mainMaterialFee = cacheObj[billIdKey].mainMaterialFee + gljTotalPrice + adhocGljTtl;
  1440. } else {
  1441. cacheObj[billIdKey].auxiliaryMaterialFee = cacheObj[billIdKey].auxiliaryMaterialFee + gljTotalPrice;
  1442. }
  1443. }
  1444. }
  1445. });
  1446. // 整理完后,开始创建XML节点(这里与参考脚本逻辑不一样了,直接开始创建)
  1447. _createNode(billIdKey, parentBill);
  1448. }
  1449. };
  1450. if (topNode100To700) {
  1451. topNode100To700.children.forEach((topChapterBill)=> {
  1452. _getAllGlj(topChapterBill);
  1453. });
  1454. }
  1455. //...
  1456. return djfxbNode;
  1457. }
  1458. function getBidEvaluationMainMaterial(tenderProject) {
  1459. let bidMaterials = [];
  1460. let i = 1;
  1461. for (let b of tenderProject.bidMaterialData) {
  1462. bidMaterials.push(new BidEvaluationMainMaterial(b, i));
  1463. i++
  1464. }
  1465. return bidMaterials;
  1466. function BidEvaluationMainMaterial(b, index) {
  1467. const attrs = [{
  1468. name: "Code",
  1469. value: b.seq,
  1470. },
  1471. {
  1472. name: "Number",
  1473. value: b.code
  1474. },
  1475. {
  1476. name: "Name",
  1477. value: b.name
  1478. },
  1479. {
  1480. name: "Specification",
  1481. value: b.specs
  1482. },
  1483. {
  1484. name: "Unit",
  1485. value: b.unit
  1486. },
  1487. {
  1488. name: "Price",
  1489. value: b.marketPrice || '0',
  1490. type: TYPE.DECIMAL
  1491. },
  1492. {
  1493. name: "LimitedPrice",
  1494. value: b.marketPrice || '0',
  1495. type: TYPE.DECIMAL
  1496. },
  1497. {
  1498. name: "Quantity",
  1499. value: 0,//b.quantity
  1500. type: TYPE.DECIMAL
  1501. },
  1502. {
  1503. name: "Total",
  1504. value: 0//b.totalPrice
  1505. },
  1506. {
  1507. name: "Remark",
  1508. value: b.remark
  1509. }
  1510. ];
  1511. if (isBidSubmission || isControl) {
  1512. attrs[7].value = b.quantity;
  1513. attrs[8].value = b.totalPrice;
  1514. }
  1515. Element.call(this, "BidEvaluationMainMaterial", attrs);
  1516. }
  1517. }
  1518. function getIndexs(tenderProject) {
  1519. let Indexs = new emptyElement('Indexs');
  1520. let feature = tenderProject.property.projectFeature ? tenderProject.property.projectFeature : [];
  1521. for (let f of feature) {
  1522. if (f.code) Indexs.children.push(new IndexItem(f))
  1523. }
  1524. return Indexs;
  1525. function IndexItem(fea) {
  1526. const attrs = [{
  1527. name: "Code",
  1528. value: fea.code,
  1529. },
  1530. {
  1531. name: "Name",
  1532. value: fea.dispName,
  1533. },
  1534. {
  1535. name: "Unit",
  1536. value: fea.unit,
  1537. },
  1538. {
  1539. name: "Value",
  1540. value: fea.value,
  1541. },
  1542. {
  1543. name: "Remark",
  1544. value: fea.remark,
  1545. }
  1546. ]
  1547. Element.call(this, "IndexItem", attrs);
  1548. }
  1549. }
  1550. function getBillsItems(tenderProject) {
  1551. let items = new emptyElement("Items");
  1552. let rootNodes = tenderProject.mainTree.roots;
  1553. for (let r of rootNodes) {
  1554. setItem(r, -1, items.children);
  1555. }
  1556. return items;
  1557. function setItem(bNode, level, list) {
  1558. if (bNode.sourceType == ModuleNames.ration) return;
  1559. let item = new bill(bNode, level);
  1560. if (bNode.children && bNode.children.length > 0) {
  1561. level += 1;
  1562. for (let c of bNode.children) {
  1563. setItem(c, level, item.children);
  1564. }
  1565. }
  1566. list.push(item);
  1567. function getCalcType(node) {
  1568. /*
  1569. 判断是否父项:
  1570. 是父项,则取1;
  1571. 是叶子项,则判断其下有无套定额/量价/工料机:
  1572. 有则取1;
  1573. 无则判断有无基数计算:
  1574. 有则取2;
  1575. 无则取3 */
  1576. if (node.children && node.children.length > 0) {
  1577. return 1; //是父项,则取1, 有套定额/量价/工料机,也取1
  1578. } else {
  1579. return node.data.calcBase && node.data.calcBase != "" ? 2 : 3
  1580. }
  1581. }
  1582. function getItemType(node) {
  1583. let Bills = projectObj.project.Bills;
  1584. //是100~900章部分、或是计日工部分,叶子清单输出1,父项输出0;
  1585. if (Bills.isBelongOneToSeven(node)||Bills.isBelongDayWork(node)) {
  1586. if (node.children && node.children.length > 0) {
  1587. return node.children[0].sourceType == ModuleNames.ration ? 1 : 0
  1588. }
  1589. return 1 //叶子清单输出1
  1590. } else {
  1591. return 0;
  1592. /* //非100~900章部分,
  1593. // 是暂列金额,判断暂列金额的金额等于0,则输出为0;暂列金额的金额不等于0,则输出为1;
  1594. if (node.data.name && node.data.name.indexOf("暂列金额") != -1) {
  1595. let sum = node.data.feesIndex && node.data.feesIndex.common ? node.data.feesIndex.common.tenderTotalFee : "";
  1596. return gljUtil.isNotEmpty(sum) ? 1 : 0
  1597. } else { //非暂列金额,则判断清单的工程量是否等于0,等于0,则输出0;不等于0,则输出1
  1598. return gljUtil.isNotEmpty(node.data.quantity) ? 1 : 0
  1599. } */
  1600. }
  1601. }
  1602. function bill(bNode, level) {
  1603. let data = bNode.data;
  1604. let CostKind = 3;
  1605. if (data.name && data.name.indexOf("安全生产费") != -1) CostKind = 1;
  1606. if (data.name && data.name.indexOf("暂列金额") != -1) CostKind = 2;
  1607. //1 = 工程量×综合单价;2 = 计算基数×费率;3 = 工程量×单价。
  1608. let CalcType = getCalcType(bNode);
  1609. //取暂估价类型。读取造价书界面的专项暂定列。0=材料暂估价,1=工程设备暂估价,2=专业工程暂估价,没有选的输出为空。
  1610. let ProvisionalType = "";
  1611. if (data.specialProvisional == "材料") ProvisionalType = 0;
  1612. if (data.specialProvisional == "工程设备") ProvisionalType = 1;
  1613. if (data.specialProvisional == "专业工程") ProvisionalType = 2;
  1614. //MpRatio
  1615. let MpRatio = "";
  1616. let MaterialRatio = "";
  1617. let MechRatio = "";
  1618. if (data.quantityCoe) {
  1619. if (data.quantityCoe["labour"]) MpRatio = data.quantityCoe["labour"];
  1620. if (data.quantityCoe["material"]) MaterialRatio = data.quantityCoe["material"];
  1621. if (data.quantityCoe["machine"]) MechRatio = data.quantityCoe["machine"];
  1622. }
  1623. let fail = billNameChecking(bNode,tenderProject.projectInfo.name,fixedFlag)
  1624. //fail: { hint: '错误提示', type: '提示所属(基本就是单位工程名称)' }
  1625. let ListCode = "";
  1626. if (ListCodeMap[data.name]) ListCode = ListCodeMap[data.name];
  1627. if (data.code && data.code != "") ListCode = data.code;
  1628. const attrs = [{
  1629. name: "ListCode",
  1630. value: ListCode,
  1631. },
  1632. {
  1633. name: "ListName",
  1634. value: data.name,
  1635. fail:fail
  1636. },
  1637. {
  1638. name: "Unit",
  1639. value: data.unit,
  1640. },
  1641. {
  1642. name: "Num",
  1643. value: data.quantity,
  1644. type: TYPE.DECIMAL,
  1645. toFix:3
  1646. },
  1647. {
  1648. name: "QtyFormula",
  1649. value: data.feesIndex && data.feesIndex.common ? data.feesIndex.common.tenderTotalFee : "",//data.calcBase //data.calcBase ? cbParser.toFExpr(data.calcBase, tenderProject.mainTree.items) : "",
  1650. type: TYPE.DECIMAL,
  1651. toFix:2
  1652. },
  1653. {
  1654. name: "Price",
  1655. value: 0,//data.feesIndex && data.feesIndex.common ? data.feesIndex.common.tenderUnitFee : "",
  1656. type: TYPE.DECIMAL,
  1657. toFix:2
  1658. },
  1659. {
  1660. name: "Rate",
  1661. value: 100,
  1662. },
  1663. {
  1664. name: "Sum",
  1665. value: 0,//data.feesIndex && data.feesIndex.common ? data.feesIndex.common.tenderTotalFee : "",
  1666. type: TYPE.DECIMAL,
  1667. toFix:2
  1668. },
  1669. {
  1670. name: "ChapterKind",
  1671. value: level > 3 ? 3 : level,
  1672. },
  1673. {
  1674. name: "CostKind",
  1675. value: CostKind,
  1676. },
  1677. {
  1678. name: "CalcType",
  1679. value: CalcType,
  1680. },
  1681. {
  1682. name: "ProvisionalType",
  1683. value: ProvisionalType,
  1684. mustHasValue:true
  1685. },
  1686. {
  1687. name: "MeterRules",
  1688. value: "",
  1689. },
  1690. {
  1691. name: "Content",
  1692. value: data.jobContentText,
  1693. },
  1694. {
  1695. name: "Remarks",
  1696. value: data.remark,
  1697. },
  1698. /* {
  1699. name: "MpRatio",
  1700. value: MpRatio,
  1701. },
  1702. {
  1703. name: "MaterialRatio",
  1704. value: MaterialRatio,
  1705. },
  1706. {
  1707. name: "MechRatio",
  1708. value: MechRatio,
  1709. },
  1710. {
  1711. name: "AdjustedPrice",
  1712. value: data.feesIndex && data.feesIndex.common ? data.feesIndex.common.tenderUnitFee : "",
  1713. },
  1714. {
  1715. name: "AdjustedSums",
  1716. value: data.feesIndex && data.feesIndex.common ? data.feesIndex.common.tenderTotalFee : "",
  1717. }, */
  1718. {
  1719. name: "ItemType",
  1720. value: getItemType(bNode),
  1721. },
  1722. /* {
  1723. name: "FomulaCode",
  1724. value: ""
  1725. }, */
  1726. ];
  1727. //投标、招标控制价时。取单价。
  1728. //招标时,如果是“安全生产费”或“暂列金额”,取单价,否则取0。
  1729. if (isBidSubmission || isControl || CostKind==1 ||CostKind==2) {
  1730. attrs[5].value = data.feesIndex && data.feesIndex.common ? data.feesIndex.common.tenderUnitFee : "";
  1731. attrs[7].value = data.feesIndex && data.feesIndex.common ? data.feesIndex.common.tenderTotalFee : "";
  1732. //暂列金额 数量为0的时候,单价输出0
  1733. if( CostKind==2 && !gljUtil.isNotEmpty(data.quantity)) attrs[5].value = 0
  1734. }
  1735. Element.call(this, "Item", attrs);
  1736. let cc = CostComposition(bNode);
  1737. if (cc) this.children.push(cc);
  1738. this.children.push(CostStructure(data))
  1739. function CostComposition(bNode) {
  1740. if (isBidInvitation) return null;
  1741. let CostComposition = new emptyElement('CostComposition');
  1742. let Norms = [];
  1743. let Costs = [];
  1744. if (bNode.children && bNode.children.length > 0 && bNode.children[0].sourceType == ModuleNames.ration) {
  1745. for (let r of bNode.children) {
  1746. if (r.data.type == rationType.ration) {
  1747. if(isEmptyRation(r.data)) continue;//定额空行不输出到接口文件中。
  1748. Norms.push(new Ration(r.data));
  1749. } else {
  1750. Costs.push(new Cost(r.data));
  1751. }
  1752. }
  1753. }
  1754. if (Norms.length > 0) CostComposition.children.push(...Norms);
  1755. if (Costs.length > 0) CostComposition.children.push(...Costs);
  1756. if (bNode.data.calcBase) CostComposition.children.push(new Formula(bNode.data));
  1757. return CostComposition.children.length > 0 ? CostComposition : null;
  1758. //定额空行不输出到接口文件中。 //定额空行的判断是:定额编码、定额名称、定额单位、定额单位、定额工程量为零或为空时
  1759. function isEmptyRation(ration){
  1760. return !gljUtil.isNotEmpty(ration.code)&&!gljUtil.isNotEmpty(ration.name)&&!gljUtil.isNotEmpty(ration.unit)&&(!gljUtil.isNotEmpty(ration.quantity)||ration.quantity == 0)
  1761. }
  1762. function Formula(bills) {
  1763. const attrs = [{
  1764. name: "Name",
  1765. value: bills.name
  1766. },
  1767. {
  1768. name: "Formulas",
  1769. value: bills.calcBase
  1770. },
  1771. {
  1772. name: "Ratio",
  1773. value: 1
  1774. },
  1775. {
  1776. name: "Sum",
  1777. value: bills.feesIndex && bills.feesIndex.common ? bills.feesIndex.common.tenderTotalFee : "",
  1778. type:TYPE.DECIMAL
  1779. },
  1780. {
  1781. name: "Remarks",
  1782. value: bills.remark
  1783. }
  1784. ]
  1785. Element.call(this, "Formula", attrs);
  1786. // 1.Name
  1787. // 名称/描述。取清单的名称。
  1788. // 2.Formulas
  1789. // 计算式。读取计算基数的文本。
  1790. // 取基数计算窗口内容,基数直接转换为金额?参考标准文档的 7.11 及 7.12 节。
  1791. // 7.11是定额的费用,7.12是清单累进基数,主要是估概预算中用到,清单里的不同,所以中山的接口直接输出基数文本。
  1792. // 3.Ratio
  1793. // 系数。输出为1,非必填。
  1794. // 4.Sum
  1795. // 取金额。
  1796. // 5.Remarks
  1797. }
  1798. function Cost(item) {
  1799. let BasePrice = 0;
  1800. if (item.type == rationType.volumePrice) { // 当插入的是量价时,基价读取单价列。
  1801. BasePrice = item.feesIndex && item.feesIndex.common ? item.feesIndex.common.tenderUnitFee : 0
  1802. } else {
  1803. BasePrice = getBasePrice(item.projectGLJID, tenderProject)
  1804. }
  1805. let calcMap = tenderProject.calcProgram.compiledTemplateMaps
  1806. let CostTypeNo = '';
  1807. if (feeRateMap[calcMap[item.programID]]) CostTypeNo = feeRateMap[calcMap[item.programID]];
  1808. const attrs = [{
  1809. name: "Code",
  1810. value: item.code,
  1811. }, {
  1812. name: 'Name',
  1813. value: item.name
  1814. }, {
  1815. name: 'Spec',
  1816. value: item.specs
  1817. }, {
  1818. name: 'Unit',
  1819. value: item.unit
  1820. }, {
  1821. name: 'Num',
  1822. value: item.tenderQuantity
  1823. }, {
  1824. name: 'BasePrice',
  1825. value: BasePrice
  1826. }, {
  1827. name: 'Price',
  1828. value: item.feesIndex && item.feesIndex.common ? item.feesIndex.common.tenderUnitFee : 0
  1829. }, {
  1830. name: 'IsEquipment',
  1831. value: item.subType == gljType.EQUIPMENT ? 1 : 0
  1832. }, {
  1833. name: 'CostTypeNo',
  1834. value: CostTypeNo
  1835. }, {
  1836. name: 'ProfitRate',
  1837. value: getFeeRate(item.programID, 'profit', tenderProject)
  1838. },
  1839. {
  1840. name: 'TaxRate',
  1841. value: getFeeRate(item.programID, 'tax', tenderProject)
  1842. },
  1843. {
  1844. name: 'MpRatio',
  1845. value: item.subType == gljType.LABOUR ? 100 : 0
  1846. },
  1847. {
  1848. name: 'MaterialRatio',
  1849. value: item.subType == gljType.GENERAL_MATERIAL ? 100 : 0
  1850. },
  1851. {
  1852. name: 'MechRatio',
  1853. value: item.subType == gljType.GENERAL_MACHINE ? 100 : 0
  1854. }
  1855. ]
  1856. Element.call(this, "Cost", attrs);
  1857. this.children.push(CostStructure(item));
  1858. }
  1859. function Ration(ration) {
  1860. let calcMap = tenderProject.calcProgram.compiledTemplateMaps
  1861. let CostTypeNo = '';
  1862. if (feeRateMap[calcMap[ration.programID]]) CostTypeNo = feeRateMap[calcMap[ration.programID]];
  1863. const attrs = [{
  1864. name: "NormLibNo",
  1865. value: 'YSDE-000000-2018-86',
  1866. }, {
  1867. name: 'DisplayCode',
  1868. value: ration.code
  1869. }, {
  1870. name: 'Name',
  1871. value: ration.name
  1872. }, {
  1873. name: 'Unit',
  1874. value: ration.unit
  1875. }, {
  1876. name: 'Num',
  1877. value: ration.tenderQuantity
  1878. },
  1879. {
  1880. name: 'CostTypeNo',
  1881. value: CostTypeNo
  1882. },
  1883. {
  1884. name: 'ProfitRate',
  1885. value: getFeeRate(ration.programID, 'profit', tenderProject) //tenderProject.ProfitRate
  1886. },
  1887. {
  1888. name: 'TaxRate',
  1889. value: getFeeRate(ration.programID, 'tax', tenderProject) //tenderProject.TaxRate
  1890. },
  1891. {
  1892. name: 'FabricationCost',
  1893. value: ration.feesIndex && ration.feesIndex.common ? ration.feesIndex.common.tenderTotalFee : 0
  1894. },
  1895. {
  1896. name: 'AdjustStatus',
  1897. value: ration.adjustState
  1898. }
  1899. ]
  1900. Element.call(this, "Norm", attrs);
  1901. this.children.push(CostStructure(ration));
  1902. this.children.push(Consume(ration));
  1903. }
  1904. }
  1905. function Consume(ration) {
  1906. let consume = new emptyElement('Consume');
  1907. for (let rg of ration.rationGLJList) {
  1908. consume.children.push(new ConsumeItem(rg));
  1909. }
  1910. return consume;
  1911. function ConsumeItem(rg) {
  1912. const attrs = [{
  1913. name: "Code",
  1914. value: rg.code,
  1915. }, {
  1916. name: "Consumption",
  1917. value: rg.tenderQuantity
  1918. }];
  1919. Element.call(this, "ConsumeItem", attrs);
  1920. }
  1921. }
  1922. function CostStructure(item) {
  1923. let CostStructure = new emptyElement('CostStructure');
  1924. for (let f of cpFeeTypes) {
  1925. if(itemFeeMap[f.type]) CostStructure.children.push(new CostItem(item,f.type))
  1926. }
  1927. if (CostStructure.children.length == 0) CostStructure.children.push(new CostItem({},""))
  1928. function CostItem(item,type) {
  1929. const attrs = [{
  1930. name: "ItemNo",
  1931. value: itemFeeMap[type],
  1932. }, {
  1933. name: 'Sum',
  1934. value: 0 //fee.tenderTotalFee
  1935. }]
  1936. if ((isBidSubmission || isControl) && item.feesIndex && item.feesIndex[type]) attrs[1].value = item.feesIndex[type].tenderTotalFee;
  1937. Element.call(this, "CostItem", attrs);
  1938. }
  1939. return CostStructure;
  1940. }
  1941. }
  1942. }
  1943. }
  1944. function Params(tenderProject) {
  1945. let feature = tenderProject.property.projectFeature ? tenderProject.property.projectFeature : [];
  1946. let featrueMap = {};
  1947. let baseMap = {};
  1948. for (let f of feature) {
  1949. featrueMap[f.key] = f;
  1950. }
  1951. let baseInfo = _.find(tenderProject.property.basicInformation, {
  1952. dispName: "基本信息",
  1953. });
  1954. for (let i of baseInfo.items) {
  1955. let key = i.key;
  1956. //if (i.dispName == "编制日期") key = "编制时间";
  1957. baseMap[key] = i;
  1958. }
  1959. let BuildType = "";
  1960. if (baseMap["natureConstruction"].value == "新建") BuildType = 0;
  1961. if (baseMap["natureConstruction"].value == "改扩建") BuildType = 1;
  1962. let Terrain = "";
  1963. if (baseMap["terrainCategory"].value == "平原微丘") Terrain = 0;
  1964. if (baseMap["terrainCategory"].value == "山岭重丘") Terrain = 1;
  1965. let DesignSpeed = featrueMap["designSpeed"].value;
  1966. let Structure = "";
  1967. if (featrueMap["pavementStructure"].value == "沥青路面") Structure = 0;
  1968. if (featrueMap["pavementStructure"].value == "水泥混凝土路面") Structure = 1;
  1969. if (featrueMap["pavementStructure"].value == "其他类型路面") Structure = 2;
  1970. let RoadGrade = "";
  1971. if (RoadGradeMap[baseMap["roadGrade"].value]) RoadGrade = RoadGradeMap[baseMap["roadGrade"].value];
  1972. const attrs = [{
  1973. name: "PrjArea",
  1974. value: baseMap["location"] ? baseMap["location"].value : ""
  1975. },
  1976. {
  1977. name: "StartPileNo",
  1978. value: baseMap["startChainages"] ? baseMap["startChainages"].value : "",
  1979. mustHasValue: true
  1980. },
  1981. {
  1982. name: "EndPileNo",
  1983. value: baseMap["endChainages"] ? baseMap["endChainages"].value : "",
  1984. mustHasValue: true
  1985. },
  1986. {
  1987. name: "BuildType",
  1988. value: BuildType,
  1989. },
  1990. {
  1991. name: "Terrain",
  1992. value: Terrain,
  1993. mustHasValue: true
  1994. },
  1995. {
  1996. name: "RoadGrade",
  1997. value: RoadGrade,
  1998. mustHasValue: true
  1999. },
  2000. {
  2001. name: "DesignSpeed",
  2002. value: DesignSpeed,
  2003. mustHasValue: true
  2004. },
  2005. {
  2006. name: "Structure",
  2007. value: Structure,
  2008. mustHasValue: true
  2009. },
  2010. {
  2011. name: "SubgradeWidth",
  2012. value: featrueMap["subgradeWidth"] ? featrueMap["subgradeWidth"].value : "",
  2013. mustHasValue: true
  2014. },
  2015. {
  2016. name: "RoadLength",
  2017. value: featrueMap["roadLength"] ? featrueMap["roadLength"].value : "",
  2018. mustHasValue: true
  2019. },
  2020. {
  2021. name: "BridgeLength",
  2022. value: featrueMap["bridgeLength"] ? featrueMap["bridgeLength"].value : "",
  2023. mustHasValue: true
  2024. },
  2025. {
  2026. name: "TunnelLength",
  2027. value: featrueMap["tunnelLength"] ? featrueMap["tunnelLength"].value : "",
  2028. mustHasValue: true
  2029. },
  2030. {
  2031. name: "BriTunRate",
  2032. value: featrueMap["briTunRate"] ? featrueMap["briTunRate"].value : "",
  2033. mustHasValue: true
  2034. },
  2035. {
  2036. name: "InterchangeNum",
  2037. value: featrueMap["interchangeNum"] ? featrueMap["interchangeNum"].value : "",
  2038. mustHasValue: true
  2039. },
  2040. {
  2041. name: "StubLengths",
  2042. value: featrueMap["stubLengths"] ? featrueMap["stubLengths"].value : "",
  2043. mustHasValue: true
  2044. },
  2045. {
  2046. name: "LaneLength",
  2047. value: featrueMap["laneLength"] ? featrueMap["laneLength"].value : "",
  2048. mustHasValue: true
  2049. },
  2050. ];
  2051. Element.call(this, "Params", attrs);
  2052. }
  2053. function SummaryOfCost(totalItem, proItem,safeItem,oneToSevenItem,feature) {
  2054. let attrs = [{
  2055. name: "TenderSumLimit",
  2056. value: totalItem.feesIndex && totalItem.feesIndex.common && totalItem.feesIndex.common.tenderTotalFee ? totalItem.feesIndex.common.tenderTotalFee : 0,
  2057. type: TYPE.DECIMAL,
  2058. toFix:2,
  2059. },
  2060. {
  2061. name: "BidTotal",
  2062. value: totalItem.feesIndex && totalItem.feesIndex.common && totalItem.feesIndex.common.tenderTotalFee ? totalItem.feesIndex.common.tenderTotalFee : 0,
  2063. type: TYPE.DECIMAL,
  2064. toFix:2,
  2065. },
  2066. {
  2067. name: "BillTotal",
  2068. value: oneToSevenItem.feesIndex && oneToSevenItem.feesIndex.common && oneToSevenItem.feesIndex.common.tenderTotalFee ? oneToSevenItem.feesIndex.common.tenderTotalFee : 0,
  2069. type: TYPE.DECIMAL,
  2070. toFix:2,
  2071. },
  2072. {
  2073. name: "CostForHSE",
  2074. value: safeItem && safeItem.feesIndex && safeItem.feesIndex.common && safeItem.feesIndex.common.tenderTotalFee ? safeItem.feesIndex.common.tenderTotalFee : 0,
  2075. type: TYPE.DECIMAL,
  2076. toFix:2,
  2077. },
  2078. {
  2079. name: "ProvisionalSums",
  2080. value: proItem.feesIndex && proItem.feesIndex.common && proItem.feesIndex.common.tenderTotalFee ? proItem.feesIndex.common.tenderTotalFee : 0,
  2081. type: TYPE.DECIMAL,
  2082. toFix:2,
  2083. },
  2084. {
  2085. name: "Appraisal",
  2086. value: totalItem.feesIndex && totalItem.feesIndex.estimate && totalItem.feesIndex.estimate.tenderTotalFee ? totalItem.feesIndex.estimate.tenderTotalFee : 0,
  2087. type: TYPE.DECIMAL,
  2088. toFix:2,
  2089. },
  2090. ];
  2091. if (isBidInvitation) {
  2092. attrs.splice(0, 3) //招标
  2093. }
  2094. //if (isControl) attrs.splice(1, 5); //控制价
  2095. if (isBidSubmission) { //投标文件时,读工程特征中的 招标控制价 值
  2096. let tenderSumLimit = _.find(feature, { "key": "tenderSumLimit" });
  2097. if(tenderSumLimit) attrs[0].value = tenderSumLimit.value
  2098. }
  2099. Element.call(this, "SummaryOfCost", attrs);
  2100. }
  2101. function MakeInfo(tenderProject) {
  2102. let property = tenderProject.property;
  2103. let baseMap = {};
  2104. let baseInfo = _.find(property.basicInformation, {
  2105. dispName: "基本信息",
  2106. });
  2107. for (let i of baseInfo.items) {
  2108. let key = i.key;
  2109. //if (i.dispName == "编制日期") key = "编制时间";
  2110. baseMap[key] = i;
  2111. }
  2112. //mustHasValue
  2113. const attrs = [{
  2114. name: "ValuationModel",
  2115. value: property.taxType,
  2116. },
  2117. {
  2118. name: "Manage",
  2119. value: baseMap["constructingUnit"] ? baseMap["constructingUnit"].value : "",
  2120. },
  2121. {
  2122. name: "Designer",
  2123. value: baseMap["designUnit"] ? baseMap["designUnit"].value : "",
  2124. mustHasValue:true
  2125. },
  2126. {
  2127. name: "Compile",
  2128. value: baseMap["compileUnit"] ? baseMap["compileUnit"].value : "",
  2129. },
  2130. {
  2131. name: "CompileApprover",
  2132. value: baseMap["compileApprover"] ? baseMap["compileApprover"].value : "",
  2133. },
  2134. {
  2135. name: "CompileCertNo",
  2136. value: baseMap["compileCertNo"] ? baseMap["compileCertNo"].value : "",
  2137. mustHasValue:true
  2138. },
  2139. {
  2140. name: "CompileDate",
  2141. value: baseMap["compileDate"] && baseMap["compileDate"].value != "" ? baseMap["compileDate"].value + "T00:00:00" : "",
  2142. mustHasValue:true
  2143. },
  2144. {
  2145. name: "Review",
  2146. value: baseMap["reviewUnit"] ? baseMap["reviewUnit"].value : "",
  2147. mustHasValue:true
  2148. },
  2149. {
  2150. name: "ReviewApprover",
  2151. value: baseMap["reviewApprover"] ? baseMap["reviewApprover"].value : "",
  2152. mustHasValue:true
  2153. },
  2154. {
  2155. name: "ReviewCertNo",
  2156. value: baseMap["reviewCertNo"] ? baseMap["reviewCertNo"].value : "",
  2157. mustHasValue:true
  2158. },
  2159. {
  2160. name: "ReviewDate",
  2161. value: baseMap["reviewDate"] && baseMap["reviewDate"].value != "" ? baseMap["reviewDate"].value + "T00:00:00" : "",
  2162. mustHasValue:true
  2163. },
  2164. {
  2165. name: "Examine",
  2166. value: baseMap["examineUnit"] ? baseMap["examineUnit"].value : "",
  2167. mustHasValue:true
  2168. },
  2169. {
  2170. name: "ExamineApprover",
  2171. value: baseMap["examineApprover"] ? baseMap["examineApprover"].value : "",
  2172. mustHasValue:true
  2173. },
  2174. {
  2175. name: "ExamineCertNo",
  2176. value: baseMap["examineCertNo"] ? baseMap["examineCertNo"].value : "",
  2177. mustHasValue:true
  2178. },
  2179. {
  2180. name: "ExamineDate",
  2181. value: baseMap["examineDate"] && baseMap["examineDate"].value != "" ? baseMap["examineDate"].value + "T00:00:00" : "",
  2182. mustHasValue:true
  2183. },
  2184. {
  2185. name: "CompileExplain",
  2186. value: baseMap["compileExplain"] ? baseMap["compileExplain"].value : "",
  2187. mustHasValue:true
  2188. },
  2189. {
  2190. name: "ExamineExplain",
  2191. value: baseMap["examineExplain"] ? baseMap["examineExplain"].value : "",
  2192. mustHasValue:true
  2193. },
  2194. {
  2195. name: "ProjectExplain",
  2196. value: baseMap["projectExplain"] ? baseMap["projectExplain"].value : "",
  2197. mustHasValue:true
  2198. },
  2199. ];
  2200. if (isBidInvitation) { //招标文件,则以下的8、12~18则不输出
  2201. attrs.splice(11, 7);
  2202. attrs.splice(7, 1);
  2203. }
  2204. Element.call(this, "MakeInfo", attrs);
  2205. }
  2206. let data = new CprjInfo(projectData.name);
  2207. data.children.push(new SystemInfo(projectData));
  2208. data.children.push(new CostBasis());
  2209. let seriNo = 1;
  2210. let Rates = [];
  2211. let Practs = [];
  2212. let EprjInfos = [];
  2213. for (let c of projectData.children) {
  2214. let tenderProject = tenderDetailMap[c.ID];
  2215. let feeRataDatas = tenderProject.FeeRate.datas;
  2216. Rates.push(new Rate(tenderProject, feeRataDatas, seriNo));
  2217. Practs.push(new Pract(tenderProject, seriNo));
  2218. EprjInfos.push(new EprjInfo(tenderProject));
  2219. seriNo++;
  2220. }
  2221. data.children.push(...Rates,...Practs,...EprjInfos);
  2222. return [{
  2223. data: data,
  2224. exportKind: exportKind,
  2225. fileName: projectData.name + INTERFACE_CONFIG[areaKey]["fileSuffix"][exportKind],
  2226. }, ];
  2227. }
  2228. // 山东需求,要有密文校验信息(SM3算法)
  2229. function SM3() {
  2230. if (!(this instanceof SM3)) {
  2231. return new SM3();
  2232. }
  2233. this.reg = new Array(8);
  2234. this.chunk = [];
  2235. this.size = 0;
  2236. this.reset();
  2237. }
  2238. SM3.prototype.reset = function() {
  2239. this.reg[0] = 0x7380166f;
  2240. this.reg[1] = 0x4914b2b9;
  2241. this.reg[2] = 0x172442d7;
  2242. this.reg[3] = 0xda8a0600;
  2243. this.reg[4] = 0xa96f30bc;
  2244. this.reg[5] = 0x163138aa;
  2245. this.reg[6] = 0xe38dee4d;
  2246. this.reg[7] = 0xb0fb0e4e;
  2247. this.chunk = [];
  2248. this.size = 0;
  2249. };
  2250. /**
  2251. * 字符串转byte数组
  2252. */
  2253. SM3.prototype.strToBytes= function (s) {
  2254. var ch, st, re = [];
  2255. for (var i = 0; i < s.length; i++ ) {
  2256. ch = s.charCodeAt(i);
  2257. st = [];
  2258. do {
  2259. st.push( ch & 0xFF );
  2260. ch = ch >> 8;
  2261. }
  2262. while ( ch );
  2263. re = re.concat( st.reverse() );
  2264. }
  2265. return re;
  2266. };
  2267. SM3.prototype.write = function(msg) {
  2268. var m = (typeof msg === 'string') ? this.strToBytes(msg) : msg;
  2269. this.size += m.length;
  2270. var i = 64 - this.chunk.length;
  2271. if (m.length < i) {
  2272. this.chunk = this.chunk.concat(m);
  2273. return;
  2274. }
  2275. this.chunk = this.chunk.concat(m.slice(0, i));
  2276. while (this.chunk.length >= 64) {
  2277. this._compress(this.chunk);
  2278. if (i < m.length) {
  2279. this.chunk = m.slice(i, Math.min(i + 64, m.length));
  2280. } else {
  2281. this.chunk = [];
  2282. }
  2283. i += 64;
  2284. }
  2285. };
  2286. /**
  2287. * 计算hash值
  2288. */
  2289. SM3.prototype.sum = function(msg, enc) {
  2290. if (msg) {
  2291. this.reset();
  2292. this.write(msg);
  2293. }
  2294. this._fill();
  2295. for (var i = 0; i < this.chunk.length; i += 64) {
  2296. this._compress(this.chunk.slice(i, i + 64));
  2297. }
  2298. var digest = null;
  2299. if (enc == 'hex') {
  2300. digest = "";
  2301. for (var i = 0; i < 8; i++) {
  2302. digest += this.reg[i].toString(16);
  2303. }
  2304. } else {
  2305. var digest = new Array(32);
  2306. for (var i = 0; i < 8; i++) {
  2307. var h;
  2308. h = this.reg[i];
  2309. digest[i * 4 + 3] = (h & 0xff) >>> 0;
  2310. h >>>= 8;
  2311. digest[i * 4 + 2] = (h & 0xff) >>> 0;
  2312. h >>>= 8;
  2313. digest[i * 4 + 1] = (h & 0xff) >>> 0;
  2314. h >>>= 8;
  2315. digest[i * 4] = (h & 0xff) >>> 0;
  2316. }
  2317. }
  2318. this.reset();
  2319. return digest;
  2320. };
  2321. SM3.prototype._compress = function(m) {
  2322. if (m < 64) {
  2323. console.error("compress error: not enough data");
  2324. return;
  2325. }
  2326. var w = this._expand(m);
  2327. var r = this.reg.slice(0);
  2328. for (var j = 0; j < 64; j++) {
  2329. var ss1 = this._rotl(r[0], 12) + r[4] + this._rotl(this._t(j), j)
  2330. ss1 = (ss1 & 0xffffffff) >>> 0;
  2331. ss1 = this._rotl(ss1, 7);
  2332. var ss2 = (ss1 ^ this._rotl(r[0], 12)) >>> 0;
  2333. var tt1 = this._ff(j, r[0], r[1], r[2]);
  2334. tt1 = tt1 + r[3] + ss2 + w[j + 68];
  2335. tt1 = (tt1 & 0xffffffff) >>> 0;
  2336. var tt2 = this._gg(j, r[4], r[5], r[6]);
  2337. tt2 = tt2 + r[7] + ss1 + w[j];
  2338. tt2 = (tt2 & 0xffffffff) >>> 0;
  2339. r[3] = r[2];
  2340. r[2] = this._rotl(r[1], 9);
  2341. r[1] = r[0];
  2342. r[0] = tt1;
  2343. r[7] = r[6]
  2344. r[6] = this._rotl(r[5], 19);
  2345. r[5] = r[4];
  2346. r[4] = (tt2 ^ this._rotl(tt2, 9) ^ this._rotl(tt2, 17)) >>> 0;
  2347. }
  2348. for (var i = 0; i < 8; i++) {
  2349. this.reg[i] = (this.reg[i] ^ r[i]) >>> 0;
  2350. }
  2351. };
  2352. SM3.prototype._fill = function() {
  2353. var l = this.size * 8;
  2354. var len = this.chunk.push(0x80) % 64;
  2355. if (64 - len < 8) {
  2356. len -= 64;
  2357. }
  2358. for (; len < 56; len++) {
  2359. this.chunk.push(0x00);
  2360. }
  2361. for (var i = 0; i < 4; i++) {
  2362. var hi = Math.floor(l / 0x100000000);
  2363. this.chunk.push((hi >>> ((3 - i) * 8)) & 0xff);
  2364. }
  2365. for (var i = 0; i < 4; i++) {
  2366. this.chunk.push((l >>> ((3 - i) * 8)) & 0xff);
  2367. }
  2368. };
  2369. SM3.prototype._expand = function(b) {
  2370. var w = new Array(132);
  2371. for (var i = 0; i < 16; i++) {
  2372. w[i] = b[i * 4] << 24;
  2373. w[i] |= b[i * 4 + 1] << 16;
  2374. w[i] |= b[i * 4 + 2] << 8;
  2375. w[i] |= b[i * 4 + 3];
  2376. w[i] >>>= 0;
  2377. }
  2378. for (var j = 16; j < 68; j++) {
  2379. var x;
  2380. x = w[j - 16] ^ w[j - 9] ^ this._rotl(w[j - 3], 15);
  2381. x = x ^ this._rotl(x, 15) ^ this._rotl(x, 23);
  2382. w[j] = (x ^ this._rotl(w[j - 13], 7) ^ w[j - 6]) >>> 0;
  2383. }
  2384. for (var j = 0; j < 64; j++) {
  2385. w[j + 68] = (w[j] ^ w[j + 4]) >>> 0;
  2386. }
  2387. return w;
  2388. };
  2389. SM3.prototype._rotl = function(x, n) {
  2390. n %= 32;
  2391. return ((x << n) | (x >>> (32 - n))) >>> 0;
  2392. };
  2393. SM3.prototype._t = function(j) {
  2394. if (0 <= j && j < 16) {
  2395. return 0x79cc4519;
  2396. } else if (16 <= j && j < 64) {
  2397. return 0x7a879d8a;
  2398. } else {
  2399. console.error("invalid j for constant Tj");
  2400. }
  2401. };
  2402. SM3.prototype._ff = function(j, x, y, z) {
  2403. if (0 <= j && j < 16) {
  2404. return (x ^ y ^ z) >>> 0;
  2405. } else if (16 <= j && j < 64) {
  2406. return ((x & y) | (x & z) | (y & z)) >>> 0;
  2407. } else {
  2408. console.error("invalid j for bool function FF");
  2409. return 0;
  2410. }
  2411. };
  2412. SM3.prototype._gg = function(j, x, y, z) {
  2413. if (0 <= j && j < 16) {
  2414. return (x ^ y ^ z) >>> 0;
  2415. } else if (16 <= j && j < 64) {
  2416. return ((x & y) | (~x & z)) >>> 0;
  2417. } else {
  2418. console.error("invalid j for bool function GG");
  2419. return 0;
  2420. }
  2421. };
  2422. /**
  2423. * 等效于Array.from目的是做浏览器兼容处理 Array.from IE浏览器不支持
  2424. */
  2425. SM3.prototype.toArray = function(s, f){
  2426. var a = [];
  2427. for(var i=0; i<s.length; i++){
  2428. var t = s[i];
  2429. if(f){
  2430. t = f(t);
  2431. }
  2432. a.push(t);
  2433. }
  2434. return a;
  2435. };
  2436. /**
  2437. * SM3加密主函数
  2438. * @param msg
  2439. * @returns
  2440. */
  2441. function sm3Digest(msg){
  2442. var _sm3 = new SM3();
  2443. var digest = _sm3.sum(msg);
  2444. var hashHex = _sm3.toArray(digest, function(byte) {return ('0' + (byte & 0xFF).toString(16)).slice(-2);}).join('');
  2445. return hashHex;
  2446. }
  2447. return {
  2448. entry,
  2449. };
  2450. })();