zhejiang_hangzhou.js 47 KB

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