zhejiang_hangzhou.js 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. // 浙江-杭州(copy from 宁海)
  2. INTERFACE_EXPORT = (() => {
  3. 'use strict';
  4. /**
  5. *
  6. * @param {String} areaKey - 地区标识,如:'安徽@马鞍山',有些地区的接口只是取值上有不同,共有一个接口脚本, 需要通过地区标识确定一些特殊处理
  7. * @param {Number} exportKind - 导出类型,招标、投标、控制价
  8. * @param {Object} projectData - 项目表数据:{ 建设项目Data, children: [单位工程...] }
  9. * @param {Object} tenderDetailMap - 单位工程ID与getData接口数据(projectObj.project的结构)的映射。
  10. * @return {Promise<Array>} - 返回的数据结构必须按照规定:[{ data, exportKind, fileName }],参考web\building_saas\standard_interface\index.js中的注释说明
  11. */
  12. async function entry(areaKey, exportKind, projectData, tenderDetailMap) {
  13. const {
  14. CONFIG: {
  15. TYPE,
  16. WHITE_SPACE
  17. },
  18. UTIL: {
  19. getValueByKey,
  20. getHan,
  21. getFee,
  22. getUnitFee,
  23. getNodeByFlag,
  24. generateHardwareId,
  25. },
  26. Element,
  27. } = INTERFACE_EXPORT_BASE;
  28. const {
  29. EXPORT_KIND: { BID_INVITATION, BID_SUBMISSION, CONTROL },
  30. fixedFlag,
  31. RationType,
  32. } = window.commonConstants
  33. const GljType = gljUtil.gljType;
  34. const { isGLYun } = window.commonUtil;
  35. const isBidInvitation = exportKind === BID_INVITATION; // 是否是招标
  36. const isBidSubmission = exportKind === BID_SUBMISSION; // 是否是投标
  37. const isControl = exportKind === CONTROL; // 是否是控制价
  38. const subArea = areaKey.split('@')[1];
  39. const info = projectData.property && projectData.property.basicInformation || [];
  40. const { summaryInfo } = projectData;
  41. const constructionSummary = summaryInfo[projectData.ID];
  42. let curTender;
  43. // 小数位数(按照需求固定)
  44. const qD = 4; // 消耗量
  45. const fD = 2; // 费用
  46. const pD = 6; // 中间过程
  47. // 值映射表
  48. const valueMap = {
  49. '施工': '1',
  50. '养护': '2',
  51. // '养护': '3',
  52. // '养护(年度经费)': '4',
  53. // '养护(年度经费)': '4',
  54. '高速公路': '1',
  55. '一级公路': '2',
  56. '二级公路': '3',
  57. '三级公路': '4',
  58. '四级公路': '5',
  59. '桥梁工程': '6',
  60. '独立桥梁': '6',
  61. '隧道工程': '7',
  62. '独立隧道': '7',
  63. '其他工程': '8',
  64. '等外工程': '8',
  65. '一般计税': '1',
  66. '简易计税': '2',
  67. }
  68. const chapterMap = {
  69. '第100章': 100,
  70. '第200章': 200,
  71. '第300章': 300,
  72. '第400章': 400,
  73. '第500章': 500,
  74. '第600章': 600,
  75. '第700章': 700,
  76. '第800章': 800,
  77. '第900章': 900,
  78. '第1000章': 1000,
  79. '第1100章': 1100,
  80. '第1200章': 1200,
  81. '第1300章': 1300,
  82. '第1400章': 1400,
  83. '第1500章': 1500,
  84. '第1600章': 1600,
  85. '第1700章': 1700,
  86. '第1800章': 1800,
  87. '第1900章': 1900,
  88. '第2000章': 2000,
  89. };
  90. // 是否是材料
  91. const isMaterial = (type) => {
  92. return /^2/.test(type);
  93. }
  94. // 是否是机械
  95. const isMachine = (type) => {
  96. return /^3/.test(type);
  97. }
  98. // 获取预算价
  99. const getMarketPrice = (glj) => {
  100. const tenderCoe = gljUtil.getTenderPriceCoe(glj, curTender.property);
  101. return gljUtil.getMarketPrice(glj, curTender.projectGLJ.datas, curTender.property.calcOptions, curTender.labourCoe.datas, curTender.property.decimal, false, _, scMathUtil, tenderCoe);
  102. }
  103. // 获取人工单价
  104. const getLabourPrice = () => {
  105. if (isBidInvitation) {
  106. return 0;
  107. }
  108. const glj = curTender.projectGLJ.datas.gljList.find(glj => glj.type === 1);
  109. if (!glj) {
  110. return 0;
  111. }
  112. return getMarketPrice(glj);
  113. }
  114. const subTypeKeyArr = ['code', 'name', 'specs', 'unit', 'subType']
  115. // 获取人工消耗量
  116. const getLabourQuantity = (node) => {
  117. if (isBidInvitation) {
  118. return 0;
  119. }
  120. const quantity = +node.data.quantity || 1;
  121. let total = 0;
  122. const posterity = node.getPosterity();
  123. const rations = posterity.filter(item => calcTools.isRationItem(item));
  124. rations.forEach(ration => {
  125. const labours = curTender.ration_glj.datas.filter(glj => glj.rationID === ration.data.ID && glj.type === 1);
  126. labours.forEach(labour => {
  127. total = scMathUtil.roundForObj(total + labour.tenderQuantity * ration.data.tenderQuantity, qD);
  128. });
  129. });
  130. const labourRations = posterity.filter(item => (calcTools.isVolumePrice(item) || calcTools.isGljRation(item)) && item.data.subType === 1);
  131. labourRations.forEach(labour => {
  132. total = scMathUtil.roundForObj(total + +labour.data.tenderQuantity, qD);
  133. });
  134. return total / quantity;
  135. }
  136. // 获取主材费、辅材费
  137. const getMaterialFee = (node) => {
  138. const rst = {
  139. mainFee: 0,
  140. assFee: 0,
  141. };
  142. if (isBidInvitation) {
  143. return rst;
  144. }
  145. let quantity = calcTools.isBill(node) ? node.data.quantity : node.data.tenderQuantity;
  146. quantity = +quantity || 1;
  147. const posterity = calcTools.isBill(node) ? node.getPosterity() : [node];
  148. // 计算定额下的费用(限定材料)
  149. const rations = posterity.filter(item => calcTools.isRationItem(item));
  150. rations.forEach(ration => {
  151. const rationGljData = curTender.ration_glj.datas.filter(glj => glj.rationID === ration.data.ID && isMaterial(glj.type));
  152. rationGljData.forEach(rGlj => {
  153. const key = gljUtil.getIndex(rGlj);
  154. const projectGlj = curTender.projectGLJ.datas.gljMap[key];
  155. if (projectGlj) {
  156. const gljUnitFee = scMathUtil.roundForObj(rGlj.tenderQuantity * getMarketPrice(projectGlj), pD);
  157. const gljTotalFee = scMathUtil.roundForObj(gljUnitFee * ration.data.tenderQuantity, fD);
  158. if (projectGlj.is_main_material) {
  159. rst.mainFee = scMathUtil.roundForObj(rst.mainFee + gljTotalFee, fD);
  160. } else {
  161. rst.assFee = scMathUtil.roundForObj( rst.assFee + gljTotalFee, fD);
  162. }
  163. }
  164. });
  165. });
  166. // 计算工料机类型定额、量价(限定材料)
  167. const materialRations = posterity.filter(item => calcTools.isGljRation(item) && isMaterial(item.data.subType));
  168. materialRations.forEach(ration => {
  169. const key = gljUtil.getIndex(ration.data, subTypeKeyArr);
  170. const projectGlj = curTender.projectGLJ.datas.gljMap[key];
  171. if (projectGlj) {
  172. if (projectGlj.is_main_material) {
  173. rst.mainFee = scMathUtil.roundForObj(rst.mainFee + getFee(ration.data.fees, 'common.tenderTotalFee'), fD);
  174. } else {
  175. rst.assFee = scMathUtil.roundForObj(rst.assFee + getFee(ration.data.fees, 'common.tenderTotalFee'), fD);
  176. }
  177. }
  178. });
  179. const volumes = posterity.filter(item => calcTools.isVolumePrice(item) && isMaterial(item.data.subType));
  180. volumes.forEach(vol => {
  181. rst.mainFee = scMathUtil.roundForObj(rst.mainFee + getFee(vol.data.fees, 'common.tenderTotalFee'), fD);
  182. });
  183. rst.mainFee = scMathUtil.roundForObj(rst.mainFee / quantity, fD);
  184. rst.assFee = scMathUtil.roundForObj(rst.assFee / quantity, fD);
  185. return rst;
  186. }
  187. // 节点定义--------------------------------
  188. /* 工程信息 */
  189. function GongCXX(md5Str) {
  190. const xmlxStr = isGLYun() ? '施工' : '养护';
  191. const attrs = [
  192. { name: '项目编号', value: getValueByKey(info, 'projNum'), minLen: 1 },
  193. { name: '项目名称', value: projectData.name, minLen: 1 },
  194. { name: '建设单位', value: getValueByKey(info, 'constructingUnits'), minLen: 1 },
  195. { name: '起始桩号', value: getValueByKey(info, 'startChainages') },
  196. { name: '终点桩号', value: getValueByKey(info, 'endChainages') },
  197. { name: '建设地址', value: getValueByKey(info, 'constructionAddress') },
  198. { name: '项目概况', value: getValueByKey(info, 'projOverview') },
  199. // { name: '项目类型', value: valueMap[getValueByKey(info, 'natureConstruction')] },
  200. { name: '项目类型', value: valueMap[xmlxStr] },
  201. { name: '专业划分', value: valueMap[getValueByKey(info, 'roadGrade')] },
  202. { name: '道路里程-公里', value: getValueByKey(info, 'roadDistance') },
  203. { name: '设计单位', value: getValueByKey(info, 'designUnit') },
  204. { name: '计税方式', value: valueMap[getValueByKey(info, 'taxMode')] },
  205. {name: '文件类型', value: isBidInvitation ? 1 : (isControl ? 2 : 3)}, // 1=工程量清单;2=招标控制价;3=投标报价;
  206. { name: '数据校验码', value: md5Str },
  207. { name: '标准版本号', value: '1.0' },
  208. { name: 'GUID', value: projectData.GUID }
  209. ];
  210. Element.call(this, '工程信息', attrs);
  211. }
  212. /* 招标信息 */
  213. function ZhaoBiaoXX() {
  214. const attrs = [
  215. { name: '招标人', value: getValueByKey(info, 'tendereeName'), minLen: 1 },
  216. { name: '招标法定代表人或其授权人', value: getValueByKey(info, 'tenderAuthorizer') },
  217. { name: '编制人', value: getValueByKey(info, 'compileApprover') },
  218. { name: '编制人资格证号', value: getValueByKey(info, 'compileCertNo') },
  219. { name: '编制日期', value: getValueByKey(info, 'compileDate'), type: TYPE.DATE},
  220. { name: '招标代理机构', value: getValueByKey(info, 'proxy'), minLen: 1},
  221. { name: '招标范围', value: getValueByKey(info, 'scopeofBidding')},
  222. { name: '总工期日历天', value: getValueByKey(info, 'timeLimit'), minLen: 1},
  223. ];
  224. Element.call(this, '招标信息', attrs);
  225. }
  226. /* 招标控制价 */
  227. function ZhaoBiaoKZJ() {
  228. const attrs = [
  229. { name: '招标人', value: getValueByKey(info, 'tendereeName'), minLen: 1 },
  230. { name: '招标法定代表人或其授权人', value: getValueByKey(info, 'tenderAuthorizer') },
  231. { name: '编制人', value: getValueByKey(info, 'compileApprover') },
  232. { name: '编制人资格证号', value: getValueByKey(info, 'compileCertNo') },
  233. { name: '编制日期', value: getValueByKey(info, 'compileDate'), type: TYPE.DATE},
  234. { name: '编制说明', value: getValueByKey(info, 'preparationDescription') },
  235. { name: '复核人', value: getValueByKey(info, 'reviewApprover') },
  236. { name: '复核人资格证号', value: getValueByKey(info, 'reviewCertNo') },
  237. { name: '复核日期', value: getValueByKey(info, 'reviewDate'), type: TYPE.DATE },
  238. { name: '审核人', value: getValueByKey(info, 'examineApprover') },
  239. { name: '审核人资格证号', value: getValueByKey(info, 'examineCertNo') },
  240. { name: '审核日期', value: getValueByKey(info, 'examineDate'), type: TYPE.DATE },
  241. { name: '控制价总价', value: constructionSummary.totalCost, type: TYPE.DECIMAL },
  242. { name: '备注', value: getValueByKey(info, '') },
  243. ];
  244. Element.call(this, '招标控制价', attrs);
  245. }
  246. /* 投标信息 */
  247. function TouBiaoXX() {
  248. let hardID = generateHardwareId();
  249. let [cpuId, diskId, macId] = hardID.split(";");
  250. const attrs = [
  251. { name: '投标人', value: getValueByKey(info, 'bidderName'), minLen: 1 },
  252. { name: '投标人法人或其授权人', value: getValueByKey(info, 'bidderAuthorizer') },
  253. { name: '投标人资质证号', value: getValueByKey(info, 'bidderCertNo') },
  254. { name: '总工期日历天', value: getValueByKey(info, 'timeLimit')},
  255. //{ name: '投标总价', value: constructionSummary.totalCost, type: TYPE.DECIMAL },
  256. { name: '投标总价', value: (constructionSummary.totalCost).toFixed(2) }, // 根据需求,固定写死2位小数,所以不设定Decimal,当string来看
  257. { name: '投标下浮率', value: getValueByKey(info, 'downwardFloatingRateOfBid') },
  258. { name: '投标报价说明', value: getValueByKey(info, 'descriptionOfTenderOffer') },
  259. { name: '质量承诺', value: getValueByKey(info, 'qualityCommitment') },
  260. { name: '投标保证金', value: getValueByKey(info, 'bidBond') },
  261. { name: '项目经理或项目负责人', value: getValueByKey(info, 'projectManagers') },
  262. { name: '项目经理或项目负责人资格证号', value: getValueByKey(info, 'projectmanagersCertNo') },
  263. { name: '造价软件品牌', value: '纵横公路云造价', minLen: 1 },
  264. { name: '造价软件版本', value: 'Ver' + VERSION, minLen: 1 },
  265. { name: '造价软件加密锁编号', value: userID, minLen: 1 },
  266. { name: '计算机硬件信息', value: cpuId + diskId + macId, minLen: 1 },
  267. { name: '备注', value: getValueByKey(info, '') },
  268. ];
  269. Element.call(this, '投标信息', attrs);
  270. }
  271. /* 工程量清单明细 */
  272. let billSeq = 1;
  273. // 获取数据类型
  274. function getBillDataType(node) {
  275. // 目录
  276. if (!calcTools.isLeafBill(node)) {
  277. return '1';
  278. }
  279. // 备注:增加判断,有些目录下无子项,原则上属于叶子,但应该还是要设置成目录
  280. if ( (node.data.name.indexOf('第') >= 0) && (node.data.name.indexOf('00章') >= 0) ) {
  281. return '1';
  282. }
  283. // 专项暂定
  284. if (node.data.specialProvisional == '专业工程') {
  285. return '21';
  286. }
  287. // 安全生产费
  288. const safeCode = projectObj.getSaveProductionCostCode();
  289. if (node.data.code == safeCode) {
  290. return '22'
  291. }
  292. // 工程一切险
  293. if ((node.data.code == '-a' || node.data.code == '101-1-1') && (node.parent && (node.parent.data.code == '101-1'))) {
  294. return '23'
  295. }
  296. // 第三者责任险
  297. if ((node.data.code == '-b' || node.data.code == '101-1-2') && (node.parent && (node.parent.data.code == '101-1'))) {
  298. return '24'
  299. }
  300. return '20';
  301. }
  302. // 获取清单章节
  303. const getBillSection = (node) => {
  304. const parentFlag = node.parent ? node.parent.getFlag() : null;
  305. if (parentFlag !== fixedFlag.ONE_SEVEN_BILLS) {
  306. let cur = node;
  307. while (cur) {
  308. if (cur.data.sectionCode) {
  309. return cur.data.sectionCode;
  310. }
  311. cur = cur.parent;
  312. }
  313. return (cur?.data?.name || '').replace(/[^0-9]/g, '');
  314. } else {
  315. const sectionCode = (node.data.name || '').replace(/[^0-9]/g, '');
  316. node.data.sectionCode = sectionCode;
  317. return sectionCode
  318. }
  319. }
  320. const needParentCodeCollection = ['-a', '-b', '-c', '-d', '-e', '-f', '-g', '-h', '-i', '-j', '-k', '-l', '-m', '-n', '-o', '-p', '-q', '-r', '-s', '-t', '-u', '-v', '-w', , '-x', '-y', '-z'];
  321. // 获取子目长号
  322. const getLongBillCode = (node) => {
  323. if (needParentCodeCollection.includes(node.data.code || '')) {
  324. return `${node.parent.data.code || ''}${node.data.code}`;
  325. } else {
  326. return node.data.code || '';
  327. }
  328. };
  329. // 获取子目号
  330. const getBillCode = (node) => {
  331. if (node.data.code) {
  332. return node.data.code;
  333. }
  334. const parentFlag = node.parent ? node.parent.getFlag() : null;
  335. if (parentFlag === fixedFlag.ONE_SEVEN_BILLS) {
  336. return getBillSection(node);
  337. }
  338. return node.data.code;
  339. };
  340. function GongCLQDMX(node, lnStr) {
  341. const { mainFee, assFee } = getMaterialFee(node);
  342. const billDataType = getBillDataType(node);
  343. let unitFee = 0;
  344. let totalFee = 0;
  345. if (!isBidInvitation || billDataType === '21') {
  346. unitFee = getFee(node.data.fees, 'common.tenderUnitFee');
  347. totalFee = getFee(node.data.fees, 'common.tenderTotalFee');
  348. }
  349. const attrs = [
  350. {name: '序号', value: billSeq ++ },
  351. {name: 'GUID', value: node.data.GUID || node.data.ID },
  352. // {name: '清单章节', value: getBillSection(node), minLen: 1, enumeration: [
  353. // '100', '200', '300', '400', '500', '600', '700', '800', '900', '1000', '1100',
  354. // '1200', '1300', '1400', '1500', '1600', '1700', '1800', '1900', '2000',
  355. // ]},
  356. {name: '清单章节', value: lnStr},
  357. // {name: '子目长编号', value: divideObj.getExeBillCode(node.data.ID, node. tree)},
  358. // {name: '子目长编号', value: lnStr},
  359. {name: '子目长编号', value: getLongBillCode(node)},
  360. {name: '子目号', value: getBillCode(node), minLen: 1},
  361. {name: '子目名称', value: node.data.name, minLen: 1},
  362. {name: '单位', value: node.data.unit},
  363. {name: '数量', value: node.data.quantity, type: TYPE.DECIMAL},
  364. {name: '单价', value: unitFee, type: TYPE.DECIMAL},
  365. {name: '合价', value: totalFee, type: TYPE.DECIMAL},
  366. {name: '备注', value: node.data.remark },
  367. {name: '数据类型', value: billDataType },
  368. {name: '人工费', value: getUnitFee(getFee(node.data.fees, 'marketLabour.tenderTotalFee', exportKind), node.data.quantity, 2), type: TYPE.DECIMAL},
  369. {name: '人工单价', value: getLabourPrice(), type: TYPE.DECIMAL},
  370. {name: '人工消耗量', value: getLabourQuantity(node), type: TYPE.DECIMAL},
  371. {name: '主材费', value: mainFee, type: TYPE.DECIMAL},
  372. {name: '辅材费', value: assFee, type: TYPE.DECIMAL},
  373. {name: '设备费', value: getUnitFee(getFee(node.data.fees, 'equipment.tenderTotalFee', exportKind), node.data.quantity, fD), type: TYPE.DECIMAL},
  374. {name: '机械使用费', value: getUnitFee(getFee(node.data.fees, 'machine.tenderTotalFee', exportKind), node.data.quantity, fD), type: TYPE.DECIMAL},
  375. {name: '措施费1', value: getUnitFee(COMPILATION_NAME.includes('公路造价') ? getFee(node.data.fees, 'measure1.tenderTotalFee', exportKind) : getFee(node.data.fees, 'otherDirect.tenderTotalFee', exportKind), node.data.quantity, fD), type: TYPE.DECIMAL},
  376. {name: '措施费2', value: getUnitFee(COMPILATION_NAME.includes('公路造价') ? getFee(node.data.fees, 'measure2.tenderTotalFee', exportKind) : getFee(node.data.fees, 'composite.tenderTotalFee', exportKind), node.data.quantity, fD), type: TYPE.DECIMAL},
  377. {name: '企业管理费', value: getUnitFee(COMPILATION_NAME.includes('公路造价') ? getFee(node.data.fees, 'manage.tenderTotalFee', exportKind) : getFee(node.data.fees, 'local.tenderTotalFee', exportKind), node.data.quantity, fD), type: TYPE.DECIMAL},
  378. {name: '规费', value: getUnitFee(COMPILATION_NAME.includes('公路造价') ? getFee(node.data.fees, 'force.tenderTotalFee', exportKind) : getFee(node.data.fees, 'indirect.tenderTotalFee', exportKind), node.data.quantity, fD), type: TYPE.DECIMAL},
  379. {name: '利润', value: getUnitFee(getFee(node.data.fees, 'profit.tenderTotalFee', exportKind), node.data.quantity, fD), type: TYPE.DECIMAL},
  380. {name: '税金', value: getUnitFee(getFee(node.data.fees, 'tax.tenderTotalFee', exportKind), node.data.quantity, fD), type: TYPE.DECIMAL},
  381. {name: '评审清单', value: isNaN(+node.data.appraisalBills) ? 0 : +node.data.appraisalBills},
  382. ];
  383. Element.call(this, '工程量清单明细', attrs);
  384. }
  385. /* 清单主材表明细 */
  386. let mainMaterialSeq = 1;
  387. function QDZCBMX(material) {
  388. const attrs = [
  389. { name: '序号', value: mainMaterialSeq++, minLen: 1 },
  390. { name: '材料编码', value: material.code, minLen: 1 },
  391. { name: '主材名称', value: material.name, minLen: 1 },
  392. { name: '单位', value: material.unit, minLen: 1 },
  393. { name: '主材消耗量', value: material.quantity, type: TYPE.DECIMAL },
  394. { name: '单价', value: material.unitPrice, type: TYPE.DECIMAL },
  395. { name: '合价', value: material.totalPrice , type: TYPE.DECIMAL},
  396. { name: '备注', value: material.remark },
  397. ];
  398. Element.call(this, '清单主材明细', attrs);
  399. }
  400. /* 定额信息表 */
  401. let rationSeq = 1;
  402. // 获取数据类型
  403. const getRationDataType = (node) => {
  404. const programText = curTender.calcProgram.compiledTemplateMaps[node.data.programID];
  405. return programText === '费率为0' ? '4' : '3';
  406. }
  407. function DEXXB(node) {
  408. const { mainFee, assFee } = getMaterialFee(node);
  409. const attrs = [
  410. {name: '序号', value: rationSeq ++ },
  411. {name: 'GUID', value: node.data.GUID || node.data.ID },
  412. {name: '定额编号', value: node.data.code},
  413. {name: '定额名称', value: node.data.name, minLen: 1 },
  414. {name: '单位', value: node.data.unit, minLen: 1 },
  415. {name: '数量', value: node.data.tenderQuantity, type: TYPE.DECIMAL},
  416. {name: '单价', value: getFee(node.data.fees, 'common.tenderUnitFee', exportKind), type: TYPE.DECIMAL},
  417. {name: '合价', value: getFee(node.data.fees, 'common.tenderTotalFee', exportKind), type: TYPE.DECIMAL},
  418. {name: '备注', value: node.data.remark },
  419. {name: '数据类型', value: getRationDataType(node) },
  420. // {name: '人工费', value: getUnitFee(getFee(node.data.fees, 'marketLabour.tenderTotalFee', exportKind), node.data.tenderQuantity, 2), type: TYPE.DECIMAL},
  421. {name: '人工费', value: getFee(node.data.fees, 'marketLabour.tenderUnitFee', exportKind), type: TYPE.DECIMAL},
  422. {name: '主材费', value: mainFee, type: TYPE.DECIMAL},
  423. {name: '辅材费', value: assFee, type: TYPE.DECIMAL},
  424. // {name: '设备费', value: getUnitFee(getFee(node.data.fees, 'equipment.tenderTotalFee', exportKind), node.data.tenderQuantity, fD), type: TYPE.DECIMAL},
  425. {name: '设备费', value: getFee(node.data.fees, 'equipment.tenderUnitFee', exportKind), type: TYPE.DECIMAL},
  426. // {name: '机械使用费', value: getUnitFee(getFee(node.data.fees, 'machine.tenderTotalFee', exportKind), node.data.tenderQuantity, fD), type: TYPE.DECIMAL},
  427. {name: '机械使用费', value: getFee(node.data.fees, 'machine.tenderUnitFee', exportKind), type: TYPE.DECIMAL},
  428. {name: '措施费1', value: getUnitFee(COMPILATION_NAME.includes('公路造价') ? getFee(node.data.fees, 'measure1.tenderTotalFee', exportKind) : getFee(node.data.fees, 'otherDirect.tenderTotalFee', exportKind), node.data.tenderQuantity, fD), type: TYPE.DECIMAL},
  429. {name: '措施费2', value: getUnitFee(COMPILATION_NAME.includes('公路造价') ? getFee(node.data.fees, 'measure2.tenderTotalFee', exportKind) : getFee(node.data.fees, 'composite.tenderTotalFee', exportKind), node.data.tenderQuantity, fD), type: TYPE.DECIMAL},
  430. {name: '企业管理费', value: getUnitFee(COMPILATION_NAME.includes('公路造价') ? getFee(node.data.fees, 'manage.tenderTotalFee', exportKind) : getFee(node.data.fees, 'local.tenderTotalFee', exportKind), node.data.tenderQuantity, fD), type: TYPE.DECIMAL},
  431. {name: '规费', value: getUnitFee(COMPILATION_NAME.includes('公路造价') ? getFee(node.data.fees, 'force.tenderTotalFee', exportKind) : getFee(node.data.fees, 'indirect.tenderTotalFee', exportKind), node.data.tenderQuantity, fD), type: TYPE.DECIMAL},
  432. // {name: '利润', value: getUnitFee(getFee(node.data.fees, 'profit.tenderTotalFee', exportKind), node.data.tenderQuantity, fD), type: TYPE.DECIMAL},
  433. {name: '利润', value: getFee(node.data.fees, 'profit.tenderUnitFee', exportKind), type: TYPE.DECIMAL},
  434. // {name: '税金', value: getUnitFee(getFee(node.data.fees, 'tax.tenderTotalFee', exportKind), node.data.tenderQuantity, fD), type: TYPE.DECIMAL},
  435. {name: '税金', value: getFee(node.data.fees, 'tax.tenderUnitFee', exportKind), type: TYPE.DECIMAL},
  436. ];
  437. Element.call(this, '定额信息表', attrs);
  438. }
  439. /* 造价汇总明细 */
  440. let hzSeq = 1;
  441. // 获取章次
  442. const getSection = (node) => {
  443. const parentFlag = node.parent ? node.parent.getFlag() : null;
  444. if (parentFlag !== fixedFlag.ONE_SEVEN_BILLS) {
  445. return '';
  446. }
  447. return (node.data.name || '').replace(/[^0-9]/g, '')
  448. }
  449. let curLB = 8;
  450. // 获取类别
  451. const getLB = (node) => {
  452. const flag = node.getFlag();
  453. const parentFlag = node.parent ? node.parent.getFlag() : null;
  454. if (parentFlag === fixedFlag.ONE_SEVEN_BILLS) {
  455. return getSection(node);
  456. }
  457. switch (flag) {
  458. case fixedFlag.ONE_SEVEN_BILLS:
  459. return '1';
  460. case fixedFlag.PROVISIONAL_TOTAL:
  461. return '2';
  462. case fixedFlag.BILLS_TOTAL_WT_PROV:
  463. return '3';
  464. case fixedFlag.DAYWORK_LABOR:
  465. // 根据费用定额判断,用全国2018导出的,就输出4; 用浙江养护2005导出的,就输出7
  466. if (isGLYun()) {
  467. return '4';
  468. } else {
  469. return '7';
  470. }
  471. case fixedFlag.PROVISIONAL:
  472. return '5';
  473. case fixedFlag.TOTAL_COST:
  474. return '6';
  475. default:
  476. return curLB++;
  477. }
  478. }
  479. function ZJHZMX(node, index = 0, isOneSeven) {
  480. let chaptNo = getSection(node);
  481. let lb = getLB(node);
  482. if (isOneSeven) {
  483. // chaptNo = (node.data.name || '').replace(/[^0-9]/g, '')
  484. chaptNo = `${(index + 1) * 100}`;
  485. for (const proKey in chapterMap) {
  486. if (node.data.name && node.data.name.indexOf(proKey) >= 0) {
  487. chaptNo = `${chapterMap[proKey]}`;
  488. break;
  489. }
  490. }
  491. lb = chaptNo;
  492. }
  493. // isBidSubmission //这是投标判断
  494. let ttl = getFee(node.data.fees, 'common.tenderTotalFee');
  495. if (isBidInvitation) ttl = 0;
  496. let dftName = node.data.name;
  497. if (/计日工/.test(dftName) && node.data.type === 1 && dftName.indexOf('计日工') === 0) {
  498. dftName = '计日工合计';
  499. }
  500. const attrs = [
  501. {name: '序号', value: hzSeq++ },
  502. {name: '章次', value: chaptNo },
  503. {name: '名称', value: dftName, minLen: 1 },
  504. {name: '金额', value: ttl, type: TYPE.DECIMAL },
  505. {name: '类别', value: lb },
  506. {name: '备注', value: node.data.remark },
  507. ];
  508. Element.call(this, '造价汇总明细', attrs);
  509. }
  510. /* 人材机汇总明细表 */
  511. // 获取人材机类别
  512. const getGljLB = (glj) => {
  513. if (glj.type === 1) {
  514. return '1';
  515. }
  516. if (!glj.is_main_material && isMaterial(glj.type) && ![202, 203, 204 ].includes(glj.type)) {
  517. return '2';
  518. }
  519. if (isMachine(glj.type) && glj.type !== 301) {
  520. return '3';
  521. }
  522. if (glj.type === 5) {
  523. return '4';
  524. }
  525. if ([202, 203, 204].includes(glj.type)) {
  526. return '5';
  527. }
  528. if (glj.type === 301) {
  529. return '6';
  530. }
  531. if (glj.is_main_material && isMaterial(glj.type) && ![202, 203, 204 ].includes(glj.type)) {
  532. return '7';
  533. }
  534. return '2';
  535. }
  536. function RCJHZMXB(glj) {
  537. const attrs = [
  538. {name: '人材机编号', value: glj.code, minLen: 1 },
  539. {name: '人材机名称', value: glj.name, minLen: 1 },
  540. {name: '规格型号', value: glj.specs },
  541. {name: '单位', value: glj.unit, minLen: 1 },
  542. {name: '数量', value: glj.tenderQuantity },
  543. {name: '单价', value: glj.priceInfo.tenderPrice, type: TYPE.DECIMAL },
  544. {name: '人材机类别', value: getGljLB(glj) },
  545. {name: '是否主要材料', value: +glj.is_main_material },
  546. {name: '是否甲供', value: 0 },
  547. {name: '备注', value: glj.remark },
  548. ];
  549. Element.call(this, '人材机汇总明细表', attrs);
  550. }
  551. // 组装数据 ------------------------------------------------------------
  552. /* 生成清单主材表 */
  553. function createQDZCB(node) {
  554. const qdzcb = new Element('清单主材表');
  555. // 获取主材
  556. const mainMaterials = [];
  557. const materialMap = {};
  558. node.children.forEach(ration => {
  559. const materials = curTender.ration_glj.datas.filter(glj => glj.rationID === ration.data.ID && isMaterial(glj.type));
  560. materials.forEach(material => {
  561. const key = gljUtil.getIndex(material);
  562. const projectGlj = curTender.projectGLJ.datas.gljMap[key];
  563. if (projectGlj && projectGlj.is_main_material) {
  564. if (!materialMap[key]) {
  565. materialMap[key] = {
  566. code: projectGlj.code,
  567. name: projectGlj.name,
  568. unit: projectGlj.unit,
  569. quantity: +material.tenderQuantity,
  570. unitPrice: getMarketPrice(projectGlj),
  571. totalPrice: 0,
  572. remark: projectGlj.remark,
  573. };
  574. mainMaterials.push(materialMap[key]);
  575. } else {
  576. materialMap[key].quantity = scMathUtil.roundForObj(materialMap[key].quantity + +material.tenderQuantity, qD);
  577. }
  578. }
  579. });
  580. });
  581. mainMaterials.forEach(material => {
  582. material.totalPrice = scMathUtil.roundForObj(material.quantity * material.unitPrice, fD);
  583. qdzcb.children.push(new QDZCBMX(material));
  584. });
  585. return qdzcb.children.length ? qdzcb : null;
  586. }
  587. /* 生成定额信息表 */
  588. function createDEXXB(node) {
  589. const rst = [];
  590. if(isBidInvitation) return rst; //招标工程量清单不导出定额数据
  591. node.children.forEach(ration => {
  592. const dexxb = new DEXXB(ration);
  593. rst.push(dexxb);
  594. // 生成定额人材机含量明细
  595. const rGljData = curTender.ration_glj.datas.filter(glj => glj.rationID === ration.data.ID);
  596. rGljData.forEach(rGlj => {
  597. const projectGlj = curTender.projectGLJ.datas.gljMap[gljUtil.getIndex(rGlj)];
  598. if (!projectGlj) {
  599. return;
  600. }
  601. const attrs = [
  602. { name: '人材机编号', value: projectGlj.code },
  603. { name: '人材机含量', value: rGlj.tenderQuantity, type: TYPE.DECIMAL },
  604. ]
  605. const dercjhlmx = new Element('定额人材机含量明细', attrs);
  606. dexxb.children.push(dercjhlmx);
  607. })
  608. });
  609. return rst;
  610. }
  611. /* 生成工程量清单表 */
  612. function createGCLQD() {
  613. // 设置工程量清单明细
  614. function setupGCLQDMX(nodes, longNoStr = '') {
  615. const rst = [];
  616. nodes.forEach((node, index) => {
  617. let lnStr = longNoStr;
  618. if (longNoStr === '') {
  619. lnStr = `${(index + 1) * 100}`;
  620. // lnStr = getBillSection(node);
  621. for (const proKey in chapterMap) {
  622. if (node.data.name && node.data.name.indexOf(proKey) >= 0) {
  623. lnStr = `${chapterMap[proKey]}`;
  624. break;
  625. }
  626. }
  627. }
  628. const glcqdmx = new GongCLQDMX(node, lnStr);
  629. rst.push(glcqdmx);
  630. if (!node.source.children.length && node.children.length) {
  631. // 清单主材表
  632. const qdzcb = createQDZCB(node);
  633. if (qdzcb) {
  634. glcqdmx.children.push(qdzcb);
  635. }
  636. // 定额
  637. glcqdmx.children.push(...createDEXXB(node));
  638. } else {
  639. // 子清单
  640. glcqdmx.children.push(...setupGCLQDMX(node.children, lnStr));
  641. }
  642. });
  643. return rst;
  644. }
  645. const gclqd = new Element('工程量清单表');
  646. // 工程量清单明细为固定清单(第100章至700章清单)下所有清单
  647. const fixedNode = getNodeByFlag(curTender.mainTree, fixedFlag.ONE_SEVEN_BILLS)
  648. gclqd.children.push(...setupGCLQDMX(fixedNode.children));
  649. return gclqd;
  650. }
  651. /* 生成计日工信息表 */
  652. let jrgSeq = 1;
  653. // 获取数据类型
  654. const getJRGDataType = (node) => {
  655. const flag = node.getFlag();
  656. const parentFlag = node.parent ? node.parent.getFlag() : null;
  657. if (flag === fixedFlag.DAYWORK_LABOR) {
  658. return '0';
  659. }
  660. if (flag === fixedFlag.LABOUR_SERVICE) {
  661. return '1';
  662. }
  663. if (flag === fixedFlag.MATERIAL) {
  664. return '2';
  665. }
  666. if (flag === fixedFlag.CONSTRUCTION_MACHINE) {
  667. return '3';
  668. }
  669. if (parentFlag === fixedFlag.LABOUR_SERVICE) {
  670. return '4';
  671. }
  672. if (parentFlag === fixedFlag.MATERIAL) {
  673. return '5';
  674. }
  675. if (parentFlag === fixedFlag.CONSTRUCTION_MACHINE) {
  676. return '6';
  677. }
  678. }
  679. function createJRGXXB() {
  680. const jrgxxb = new Element('计日工信息表');
  681. const fixedNode = getNodeByFlag(curTender.mainTree, fixedFlag.DAYWORK_LABOR);
  682. function createJRG(node) {
  683. // 计日工信息标题
  684. const jrgAttrs = [
  685. { name: '序号', value: jrgSeq++ },
  686. { name: '名称', value: node.data.name },
  687. { name: '数据类型', value: getJRGDataType(node) },
  688. { name: '合价', value: getFee(node.data.fees, 'common.tenderTotalFee'), type: TYPE.DECIMAL},
  689. ];
  690. if (typeof node.data.remark === 'string' && node.data.remark.length > 0) {
  691. jrgAttrs.push({ name: '备注', value: node.data.remark });
  692. }
  693. const jrgxxbt = new Element('计日工信息标题', jrgAttrs);
  694. if (node === fixedNode) {
  695. return jrgxxbt;
  696. }
  697. jrgxxbt.children = node.children.map(child => new Element('计日工信息明细', [
  698. { name: '编号', value: child.data.code, minLen: 1 },
  699. { name: '名称', value: child.data.name, minLen: 1 },
  700. { name: '数据类型', value: getJRGDataType(child) },
  701. { name: '单位', value: child.data.unit, minLen: 1 },
  702. { name: '暂定数量', value: child.data.quantity, type: TYPE.DECIMAL },
  703. { name: '单价', value: getFee(child.data.fees, 'common.tenderUnitFee'), type: TYPE.DECIMAL },
  704. { name: '合价', value: getFee(child.data.fees, 'common.tenderTotalFee'), type: TYPE.DECIMAL },
  705. ]));
  706. return jrgxxbt;
  707. }
  708. jrgxxb.children = [fixedNode, ...fixedNode.children].map(node => createJRG(node));
  709. return jrgxxb;
  710. }
  711. /* 生成造价汇总表 */
  712. function createZJHZB() {
  713. const zjhzb = new Element('造价汇总表');
  714. // 提取需要显示的数据
  715. const nodes = [];
  716. let oneSevenMin = -1, oneSevenMax = -1;
  717. curTender.mainTree.roots.forEach(node => {
  718. nodes.push(node);
  719. if (node.getFlag() === fixedFlag.ONE_SEVEN_BILLS) {
  720. oneSevenMin = nodes.length;
  721. nodes.push(...node.children);
  722. oneSevenMax = nodes.length - 1;
  723. }
  724. });
  725. const tmpNode = nodes[0];
  726. nodes.splice(0, 1);
  727. nodes.splice(oneSevenMax, 0, tmpNode);
  728. // 杭州需求:第100章至700章清单合计放在最后
  729. let startIdx = 0;
  730. oneSevenMin--;
  731. oneSevenMax--;
  732. nodes.forEach((node, index) => {
  733. const isOneSeven = index >= oneSevenMin && index <= oneSevenMax
  734. // 杭州需求:移除 '清单合计减去材料、工程设备、专业工程暂估价合计' 清单
  735. const flag = node.getFlag();
  736. if (flag !== fixedFlag.BILLS_TOTAL_WT_PROV) zjhzb.children.push(new ZJHZMX(node, startIdx, isOneSeven));
  737. if (isOneSeven) startIdx++;
  738. });
  739. return zjhzb;
  740. }
  741. /* 生成人材机汇总 */
  742. function createRCJHZ() {
  743. const rcjhz = new Element('人材机汇总');
  744. rcjhz.children = curTender.projectGLJ.datas.gljList.map(glj => new RCJHZMXB(glj));
  745. return rcjhz;
  746. }
  747. /* 生成标段工程 */
  748. function createGLBDGC(rawTender, seq){
  749. // 标段属性
  750. const tenderAttrs = [
  751. { name: '序号', value: seq, minLen: 1 },
  752. { name: '标段名称', value: rawTender.name, minLen: 1 },
  753. { name: '金额', value: isBidInvitation ? 0 : projectData.summaryInfo[rawTender.ID].totalCost },
  754. { name: '唯一标识-Guid', value: rawTender.GUID }
  755. ];
  756. const gongLBDGC = new Element('公路标段工程', tenderAttrs)
  757. // 工程量清单表
  758. const gclqd = createGCLQD();
  759. // 计日工信息表
  760. const jrgxxb = createJRGXXB();
  761. // 造价汇总表
  762. const zjhzb = createZJHZB();
  763. // 人材机汇总
  764. const rcjhz = createRCJHZ();
  765. gongLBDGC.children = [gclqd, jrgxxb, zjhzb, rcjhz];
  766. // 公路工程汇总明细属性
  767. const hzAttrs = [
  768. ...tenderAttrs,
  769. { name: '备注', value: '' }
  770. ];
  771. return {
  772. gongLBDGC,
  773. hzAttrs,
  774. }
  775. }
  776. /* 组装建设项目数据 */
  777. async function setupConstruction() {
  778. const rootNode = new Element('浙江交通建设工程');
  779. const zhaoTBXX = new Element('招投标信息');
  780. const gongLGCSJ = new Element('公路工程数据');
  781. const newCRCvals = [];
  782. if (isBidInvitation) {
  783. zhaoTBXX.children.push(new ZhaoBiaoXX());
  784. } else if (isControl) {
  785. zhaoTBXX.children.push(new ZhaoBiaoKZJ());
  786. } else {
  787. const TBInfo = new TouBiaoXX();
  788. newCRCvals.push(_toXMLStr([TBInfo]));
  789. zhaoTBXX.children.push(TBInfo);
  790. }
  791. const gongLGCHZ = new Element('公路工程汇总');
  792. const gongLGCHZBT = new Element('公路工程汇总标题');
  793. gongLGCHZ.children.push(gongLGCHZBT);
  794. // 组装标段数据
  795. projectData.children.forEach( (tender, index) => {
  796. billSeq = 1;
  797. mainMaterialSeq = 1;
  798. rationSeq = 1;
  799. jrgSeq = 1;
  800. hzSeq = 1;
  801. curTender = tenderDetailMap[tender.ID];
  802. const {
  803. gongLBDGC,
  804. hzAttrs,
  805. } = createGLBDGC(tender, index + 1);
  806. gongLGCSJ.children.push(gongLBDGC);
  807. const gongLGCHZMX = new Element('公路工程汇总明细', hzAttrs);
  808. gongLGCHZBT.children.push(gongLGCHZMX);
  809. });
  810. gongLGCSJ.children.push(gongLGCHZ);
  811. newCRCvals.push(_toXMLStr([gongLGCHZ]));
  812. for (let crcIdx = 0; crcIdx < newCRCvals.length; crcIdx++) {
  813. newCRCvals[crcIdx] = newCRCvals[crcIdx].replace(/ /g, '').replace(/\r/g, '').replace(/\n/g, '');
  814. }
  815. const md5Str = md5Ex(newCRCvals.join(''));
  816. const binaryStr = hexToBinary(md5Str); // 转成二进制string
  817. const finalMd5Str = window.btoa(binaryStr); // 还要做一次BASE64转换
  818. const gongCXX = new GongCXX(finalMd5Str);
  819. rootNode.children = [gongCXX, zhaoTBXX, gongLGCSJ];
  820. const suffix = INTERFACE_CONFIG[areaKey]['fileSuffix'][exportKind];
  821. return [{
  822. data: rootNode,
  823. exportKind,
  824. fileName: `${projectData.name}${suffix}`
  825. }];
  826. }
  827. return await setupConstruction(projectData);
  828. }
  829. async function md5(message) {
  830. const msgUint8 = new TextEncoder().encode(message); // 将字符串转换为UTF-8编码的字节
  831. // const hashBuffer = await crypto.subtle.digest('MD5', msgUint8); // 计算MD5哈希
  832. const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // 计算MD5哈希
  833. // const hashBuffer = await crypto.subtle.digest('md5', msgUint8); // 计算MD5哈希
  834. const hashArray = Array.from(new Uint8Array(hashBuffer)); // 转换成数组
  835. const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // 转换成16进制字符串
  836. return hashHex;
  837. }
  838. function md5Ex(string) {
  839. function md5_RotateLeft(lValue, iShiftBits) {
  840. return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
  841. }
  842. function md5_AddUnsigned(lX, lY) {
  843. var lX4, lY4, lX8, lY8, lResult;
  844. lX8 = (lX & 0x80000000);//2147483648
  845. lY8 = (lY & 0x80000000);//2147483648
  846. lX4 = (lX & 0x40000000);//1073741824
  847. lY4 = (lY & 0x40000000);//1073741824
  848. lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
  849. if (lX4 & lY4) {
  850. return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
  851. }
  852. if (lX4 | lY4) {
  853. if (lResult & 0x40000000) {
  854. return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
  855. } else {
  856. return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
  857. }
  858. } else {
  859. return (lResult ^ lX8 ^ lY8);
  860. }
  861. }
  862. function md5_F(x, y, z) {
  863. return (x & y) | ((~x) & z);
  864. }
  865. function md5_G(x, y, z) {
  866. return (x & z) | (y & (~z));
  867. }
  868. function md5_H(x, y, z) {
  869. return (x ^ y ^ z);
  870. }
  871. function md5_I(x, y, z) {
  872. return (y ^ (x | (~z)));
  873. }
  874. function md5_FF(a, b, c, d, x, s, ac) {
  875. a = md5_AddUnsigned(a, md5_AddUnsigned(md5_AddUnsigned(md5_F(b, c, d), x), ac));
  876. return md5_AddUnsigned(md5_RotateLeft(a, s), b);
  877. };
  878. function md5_GG(a, b, c, d, x, s, ac) {
  879. a = md5_AddUnsigned(a, md5_AddUnsigned(md5_AddUnsigned(md5_G(b, c, d), x), ac));
  880. return md5_AddUnsigned(md5_RotateLeft(a, s), b);
  881. };
  882. function md5_HH(a, b, c, d, x, s, ac) {
  883. a = md5_AddUnsigned(a, md5_AddUnsigned(md5_AddUnsigned(md5_H(b, c, d), x), ac));
  884. return md5_AddUnsigned(md5_RotateLeft(a, s), b);
  885. };
  886. function md5_II(a, b, c, d, x, s, ac) {
  887. a = md5_AddUnsigned(a, md5_AddUnsigned(md5_AddUnsigned(md5_I(b, c, d), x), ac));
  888. return md5_AddUnsigned(md5_RotateLeft(a, s), b);
  889. };
  890. function md5_ConvertToWordArray(string) {
  891. var lWordCount;
  892. var lMessageLength = string.length;
  893. var lNumberOfWords_temp1 = lMessageLength + 8;
  894. var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
  895. var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
  896. var lWordArray = Array(lNumberOfWords - 1);
  897. var lBytePosition = 0;
  898. var lByteCount = 0;
  899. while (lByteCount < lMessageLength) {
  900. lWordCount = (lByteCount - (lByteCount % 4)) / 4;
  901. lBytePosition = (lByteCount % 4) * 8;
  902. lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
  903. lByteCount++;
  904. }
  905. lWordCount = (lByteCount - (lByteCount % 4)) / 4;
  906. lBytePosition = (lByteCount % 4) * 8;
  907. lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
  908. lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
  909. lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
  910. return lWordArray;
  911. };
  912. function md5_WordToHex(lValue) {
  913. var WordToHexValue = "",
  914. WordToHexValue_temp = "",
  915. lByte, lCount;
  916. for (lCount = 0; lCount <= 3; lCount++) {
  917. lByte = (lValue >>> (lCount * 8)) & 255;
  918. WordToHexValue_temp = "0" + lByte.toString(16);
  919. WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
  920. }
  921. return WordToHexValue;
  922. };
  923. function md5_Utf8Encode(string) {
  924. string = string.replace(/\r\n/g, "\n");
  925. var utftext = "";
  926. for (var n = 0; n < string.length; n++) {
  927. var c = string.charCodeAt(n);
  928. if (c < 128) {
  929. utftext += String.fromCharCode(c);
  930. } else if ((c > 127) && (c < 2048)) {
  931. utftext += String.fromCharCode((c >> 6) | 192);
  932. utftext += String.fromCharCode((c & 63) | 128);
  933. } else {
  934. utftext += String.fromCharCode((c >> 12) | 224);
  935. utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  936. utftext += String.fromCharCode((c & 63) | 128);
  937. }
  938. }
  939. return utftext;
  940. };
  941. var x = Array();
  942. var k, AA, BB, CC, DD, a, b, c, d;
  943. var S11 = 7,
  944. S12 = 12,
  945. S13 = 17,
  946. S14 = 22;
  947. var S21 = 5,
  948. S22 = 9,
  949. S23 = 14,
  950. S24 = 20;
  951. var S31 = 4,
  952. S32 = 11,
  953. S33 = 16,
  954. S34 = 23;
  955. var S41 = 6,
  956. S42 = 10,
  957. S43 = 15,
  958. S44 = 21;
  959. string = md5_Utf8Encode(string);
  960. x = md5_ConvertToWordArray(string);
  961. a = 0x67452301;//1732584193
  962. b = 0xEFCDAB89;//4023233417
  963. c = 0x98BADCFE;//2562383102
  964. d = 0x10325476;//271733878
  965. for (k = 0; k < x.length; k += 16) {
  966. AA = a;
  967. BB = b;
  968. CC = c;
  969. DD = d;
  970. a = md5_FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
  971. d = md5_FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
  972. c = md5_FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
  973. b = md5_FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
  974. a = md5_FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
  975. d = md5_FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
  976. c = md5_FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
  977. b = md5_FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
  978. a = md5_FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
  979. d = md5_FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
  980. c = md5_FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
  981. b = md5_FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
  982. a = md5_FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
  983. d = md5_FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
  984. c = md5_FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
  985. b = md5_FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
  986. a = md5_GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
  987. d = md5_GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
  988. c = md5_GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
  989. b = md5_GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
  990. a = md5_GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
  991. d = md5_GG(d, a, b, c, x[k + 10], S22, 0x2441453);
  992. c = md5_GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
  993. b = md5_GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
  994. a = md5_GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
  995. d = md5_GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
  996. c = md5_GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
  997. b = md5_GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
  998. a = md5_GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
  999. d = md5_GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
  1000. c = md5_GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
  1001. b = md5_GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
  1002. a = md5_HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
  1003. d = md5_HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
  1004. c = md5_HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
  1005. b = md5_HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
  1006. a = md5_HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
  1007. d = md5_HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
  1008. c = md5_HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
  1009. b = md5_HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
  1010. a = md5_HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
  1011. d = md5_HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
  1012. c = md5_HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
  1013. b = md5_HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
  1014. a = md5_HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
  1015. d = md5_HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
  1016. c = md5_HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
  1017. b = md5_HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
  1018. a = md5_II(a, b, c, d, x[k + 0], S41, 0xF4292244);
  1019. d = md5_II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
  1020. c = md5_II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
  1021. b = md5_II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
  1022. a = md5_II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
  1023. d = md5_II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
  1024. c = md5_II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
  1025. b = md5_II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
  1026. a = md5_II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
  1027. d = md5_II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
  1028. c = md5_II(c, d, a, b, x[k + 6], S43, 0xA3014314);
  1029. b = md5_II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
  1030. a = md5_II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
  1031. d = md5_II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
  1032. c = md5_II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
  1033. b = md5_II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
  1034. a = md5_AddUnsigned(a, AA);
  1035. b = md5_AddUnsigned(b, BB);
  1036. c = md5_AddUnsigned(c, CC);
  1037. d = md5_AddUnsigned(d, DD);
  1038. }
  1039. return (md5_WordToHex(a) + md5_WordToHex(b) + md5_WordToHex(c) + md5_WordToHex(d)).toLowerCase();
  1040. }
  1041. function hexToBinary(hex) {
  1042. return hex.replace(/^(.{2})(.*)$/g, function(_, $1, $2) {
  1043. return String.fromCharCode(parseInt($1, 16)) + hexToBinary($2);
  1044. });
  1045. }
  1046. // 开始标签
  1047. function _startTag(ele) {
  1048. let rst = `<${ele.name}`;
  1049. for (const attr of ele.attrs) {
  1050. rst += ` ${attr.name}="${attr.value}"`;
  1051. }
  1052. rst += ele.children.length > 0 ? '>' : '/>';
  1053. return rst;
  1054. }
  1055. // 结束标签
  1056. function _endTag(ele) {
  1057. return `</${ele.name}>`;
  1058. }
  1059. // 拼接成xml字符串
  1060. function _toXMLStr(eles) {
  1061. let rst = '';
  1062. for (const ele of eles) {
  1063. rst += _startTag(ele);
  1064. if (ele.children.length > 0) {
  1065. rst += _toXMLStr(ele.children);
  1066. rst += _endTag(ele);
  1067. }
  1068. }
  1069. return rst;
  1070. }
  1071. return {
  1072. entry,
  1073. };
  1074. })();