zhejiang_hangzhou.js 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154
  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. let bName = node.data.name || '';
  487. bName = bName.replace(/ /g, '');
  488. if (bName.indexOf(proKey) >= 0) {
  489. chaptNo = `${chapterMap[proKey]}`;
  490. break;
  491. }
  492. }
  493. lb = chaptNo;
  494. }
  495. // isBidSubmission //这是投标判断
  496. let ttl = getFee(node.data.fees, 'common.tenderTotalFee');
  497. if (isBidInvitation) ttl = 0;
  498. let dftName = node.data.name;
  499. if (/计日工/.test(dftName) && node.data.type === 1 && dftName.indexOf('计日工') === 0) {
  500. dftName = '计日工合计';
  501. }
  502. const attrs = [
  503. {name: '序号', value: hzSeq++ },
  504. {name: '章次', value: chaptNo },
  505. {name: '名称', value: dftName, minLen: 1 },
  506. {name: '金额', value: ttl, type: TYPE.DECIMAL },
  507. {name: '类别', value: lb },
  508. {name: '备注', value: node.data.remark },
  509. ];
  510. Element.call(this, '造价汇总明细', attrs);
  511. }
  512. /* 人材机汇总明细表 */
  513. // 获取人材机类别
  514. const getGljLB = (glj) => {
  515. if (glj.type === 1) {
  516. return '1';
  517. }
  518. if (!glj.is_main_material && isMaterial(glj.type) && ![202, 203, 204 ].includes(glj.type)) {
  519. return '2';
  520. }
  521. if (isMachine(glj.type) && glj.type !== 301) {
  522. return '3';
  523. }
  524. if (glj.type === 5) {
  525. return '4';
  526. }
  527. if ([202, 203, 204].includes(glj.type)) {
  528. return '5';
  529. }
  530. if (glj.type === 301) {
  531. return '6';
  532. }
  533. if (glj.is_main_material && isMaterial(glj.type) && ![202, 203, 204 ].includes(glj.type)) {
  534. return '7';
  535. }
  536. return '2';
  537. }
  538. function RCJHZMXB(glj) {
  539. const attrs = [
  540. {name: '人材机编号', value: glj.code, minLen: 1 },
  541. {name: '人材机名称', value: glj.name, minLen: 1 },
  542. {name: '规格型号', value: glj.specs },
  543. {name: '单位', value: glj.unit, minLen: 1 },
  544. {name: '数量', value: glj.tenderQuantity },
  545. {name: '单价', value: glj.priceInfo.tenderPrice, type: TYPE.DECIMAL },
  546. {name: '人材机类别', value: getGljLB(glj) },
  547. {name: '是否主要材料', value: +glj.is_main_material },
  548. {name: '是否甲供', value: 0 },
  549. {name: '备注', value: glj.remark },
  550. ];
  551. Element.call(this, '人材机汇总明细表', attrs);
  552. }
  553. // 组装数据 ------------------------------------------------------------
  554. /* 生成清单主材表 */
  555. function createQDZCB(node) {
  556. const qdzcb = new Element('清单主材表');
  557. // 获取主材
  558. const mainMaterials = [];
  559. const materialMap = {};
  560. node.children.forEach(ration => {
  561. const materials = curTender.ration_glj.datas.filter(glj => glj.rationID === ration.data.ID && isMaterial(glj.type));
  562. materials.forEach(material => {
  563. const key = gljUtil.getIndex(material);
  564. const projectGlj = curTender.projectGLJ.datas.gljMap[key];
  565. if (projectGlj && projectGlj.is_main_material) {
  566. if (!materialMap[key]) {
  567. materialMap[key] = {
  568. code: projectGlj.code,
  569. name: projectGlj.name,
  570. unit: projectGlj.unit,
  571. quantity: +material.tenderQuantity,
  572. unitPrice: getMarketPrice(projectGlj),
  573. totalPrice: 0,
  574. remark: projectGlj.remark,
  575. };
  576. mainMaterials.push(materialMap[key]);
  577. } else {
  578. materialMap[key].quantity = scMathUtil.roundForObj(materialMap[key].quantity + +material.tenderQuantity, qD);
  579. }
  580. }
  581. });
  582. });
  583. mainMaterials.forEach(material => {
  584. material.totalPrice = scMathUtil.roundForObj(material.quantity * material.unitPrice, fD);
  585. qdzcb.children.push(new QDZCBMX(material));
  586. });
  587. return qdzcb.children.length ? qdzcb : null;
  588. }
  589. /* 生成定额信息表 */
  590. function createDEXXB(node) {
  591. const rst = [];
  592. if(isBidInvitation) return rst; //招标工程量清单不导出定额数据
  593. node.children.forEach(ration => {
  594. const dexxb = new DEXXB(ration);
  595. rst.push(dexxb);
  596. // 生成定额人材机含量明细
  597. const rGljData = curTender.ration_glj.datas.filter(glj => glj.rationID === ration.data.ID);
  598. rGljData.forEach(rGlj => {
  599. const projectGlj = curTender.projectGLJ.datas.gljMap[gljUtil.getIndex(rGlj)];
  600. if (!projectGlj) {
  601. return;
  602. }
  603. const attrs = [
  604. { name: '人材机编号', value: projectGlj.code },
  605. { name: '人材机含量', value: rGlj.tenderQuantity, type: TYPE.DECIMAL },
  606. ]
  607. const dercjhlmx = new Element('定额人材机含量明细', attrs);
  608. dexxb.children.push(dercjhlmx);
  609. })
  610. });
  611. return rst;
  612. }
  613. /* 生成工程量清单表 */
  614. function createGCLQD() {
  615. // 设置工程量清单明细
  616. function setupGCLQDMX(nodes, longNoStr = '') {
  617. const rst = [];
  618. nodes.forEach((node, index) => {
  619. let lnStr = longNoStr;
  620. if (longNoStr === '') {
  621. lnStr = `${(index + 1) * 100}`;
  622. // lnStr = getBillSection(node);
  623. for (const proKey in chapterMap) {
  624. let bName = node.data.name || '';
  625. bName = bName.replace(/ /g, '');
  626. if (bName.indexOf(proKey) >= 0) {
  627. lnStr = `${chapterMap[proKey]}`;
  628. break;
  629. }
  630. }
  631. }
  632. const glcqdmx = new GongCLQDMX(node, lnStr);
  633. rst.push(glcqdmx);
  634. if (!node.source.children.length && node.children.length) {
  635. // 清单主材表
  636. const qdzcb = createQDZCB(node);
  637. if (qdzcb) {
  638. glcqdmx.children.push(qdzcb);
  639. }
  640. // 定额
  641. glcqdmx.children.push(...createDEXXB(node));
  642. } else {
  643. // 子清单
  644. glcqdmx.children.push(...setupGCLQDMX(node.children, lnStr));
  645. }
  646. });
  647. return rst;
  648. }
  649. const gclqd = new Element('工程量清单表');
  650. // 工程量清单明细为固定清单(第100章至700章清单)下所有清单
  651. const fixedNode = getNodeByFlag(curTender.mainTree, fixedFlag.ONE_SEVEN_BILLS)
  652. gclqd.children.push(...setupGCLQDMX(fixedNode.children));
  653. return gclqd;
  654. }
  655. /* 生成计日工信息表 */
  656. let jrgSeq = 1;
  657. // 获取数据类型
  658. const getJRGDataType = (node) => {
  659. const flag = node.getFlag();
  660. const parentFlag = node.parent ? node.parent.getFlag() : null;
  661. if (flag === fixedFlag.DAYWORK_LABOR) {
  662. return '0';
  663. }
  664. if (flag === fixedFlag.LABOUR_SERVICE) {
  665. return '1';
  666. }
  667. if (flag === fixedFlag.MATERIAL) {
  668. return '2';
  669. }
  670. if (flag === fixedFlag.CONSTRUCTION_MACHINE) {
  671. return '3';
  672. }
  673. if (parentFlag === fixedFlag.LABOUR_SERVICE) {
  674. return '4';
  675. }
  676. if (parentFlag === fixedFlag.MATERIAL) {
  677. return '5';
  678. }
  679. if (parentFlag === fixedFlag.CONSTRUCTION_MACHINE) {
  680. return '6';
  681. }
  682. }
  683. function createJRGXXB() {
  684. const jrgxxb = new Element('计日工信息表');
  685. const fixedNode = getNodeByFlag(curTender.mainTree, fixedFlag.DAYWORK_LABOR);
  686. function createJRG(node) {
  687. // 计日工信息标题
  688. const jrgAttrs = [
  689. { name: '序号', value: jrgSeq++ },
  690. { name: '名称', value: node.data.name },
  691. { name: '数据类型', value: getJRGDataType(node) },
  692. { name: '合价', value: getFee(node.data.fees, 'common.tenderTotalFee'), type: TYPE.DECIMAL},
  693. ];
  694. if (typeof node.data.remark === 'string' && node.data.remark.length > 0) {
  695. jrgAttrs.push({ name: '备注', value: node.data.remark });
  696. }
  697. const jrgxxbt = new Element('计日工信息标题', jrgAttrs);
  698. if (node === fixedNode) {
  699. return jrgxxbt;
  700. }
  701. jrgxxbt.children = node.children.map(child => new Element('计日工信息明细', [
  702. { name: '编号', value: child.data.code, minLen: 1 },
  703. { name: '名称', value: child.data.name, minLen: 1 },
  704. { name: '数据类型', value: getJRGDataType(child) },
  705. { name: '单位', value: child.data.unit, minLen: 1 },
  706. { name: '暂定数量', value: child.data.quantity, type: TYPE.DECIMAL },
  707. { name: '单价', value: getFee(child.data.fees, 'common.tenderUnitFee'), type: TYPE.DECIMAL },
  708. { name: '合价', value: getFee(child.data.fees, 'common.tenderTotalFee'), type: TYPE.DECIMAL },
  709. ]));
  710. return jrgxxbt;
  711. }
  712. jrgxxb.children = [fixedNode, ...fixedNode.children].map(node => createJRG(node));
  713. return jrgxxb;
  714. }
  715. /* 生成造价汇总表 */
  716. function createZJHZB() {
  717. const zjhzb = new Element('造价汇总表');
  718. // 提取需要显示的数据
  719. const nodes = [];
  720. let oneSevenMin = -1, oneSevenMax = -1;
  721. const isTotalChapterFirst = !!curTender.property.adhocInfoIsTotalChapterFirst;
  722. curTender.mainTree.roots.forEach(node => {
  723. nodes.push(node);
  724. if (node.getFlag() === fixedFlag.ONE_SEVEN_BILLS) {
  725. oneSevenMin = nodes.length;
  726. nodes.push(...node.children);
  727. oneSevenMax = nodes.length - 1;
  728. }
  729. });
  730. const tmpNode = nodes[0];
  731. if (!isTotalChapterFirst) {
  732. nodes.splice(0, 1);
  733. nodes.splice(oneSevenMax, 0, tmpNode);
  734. oneSevenMin--;
  735. oneSevenMax--;
  736. }
  737. // 杭州需求:第100章至700章清单合计放在最后
  738. let startIdx = 0;
  739. nodes.forEach((node, index) => {
  740. let isOneSeven = index >= oneSevenMin && index <= oneSevenMax;
  741. // 杭州需求:移除 '清单合计减去材料、工程设备、专业工程暂估价合计' 清单
  742. const flag = node.getFlag();
  743. if (flag !== fixedFlag.BILLS_TOTAL_WT_PROV) zjhzb.children.push(new ZJHZMX(node, startIdx, isOneSeven));
  744. if (isOneSeven) startIdx++;
  745. });
  746. return zjhzb;
  747. }
  748. /* 生成人材机汇总 */
  749. function createRCJHZ() {
  750. const rcjhz = new Element('人材机汇总');
  751. rcjhz.children = curTender.projectGLJ.datas.gljList.map(glj => new RCJHZMXB(glj));
  752. return rcjhz;
  753. }
  754. /* 生成标段工程 */
  755. function createGLBDGC(rawTender, seq){
  756. // 标段属性
  757. const tenderAttrs = [
  758. { name: '序号', value: seq, minLen: 1 },
  759. { name: '标段名称', value: rawTender.name, minLen: 1 },
  760. { name: '金额', value: isBidInvitation ? 0 : projectData.summaryInfo[rawTender.ID].totalCost },
  761. { name: '唯一标识-Guid', value: rawTender.GUID }
  762. ];
  763. const gongLBDGC = new Element('公路标段工程', tenderAttrs)
  764. // 工程量清单表
  765. const gclqd = createGCLQD();
  766. // 计日工信息表
  767. const jrgxxb = createJRGXXB();
  768. // 造价汇总表
  769. const zjhzb = createZJHZB();
  770. // 人材机汇总
  771. const rcjhz = createRCJHZ();
  772. gongLBDGC.children = [gclqd, jrgxxb, zjhzb, rcjhz];
  773. // 公路工程汇总明细属性
  774. const hzAttrs = [
  775. ...tenderAttrs,
  776. { name: '备注', value: '' }
  777. ];
  778. return {
  779. gongLBDGC,
  780. hzAttrs,
  781. }
  782. }
  783. /* 组装建设项目数据 */
  784. async function setupConstruction() {
  785. const rootNode = new Element('浙江交通建设工程');
  786. const zhaoTBXX = new Element('招投标信息');
  787. const gongLGCSJ = new Element('公路工程数据');
  788. const newCRCvals = [];
  789. if (isBidInvitation) {
  790. zhaoTBXX.children.push(new ZhaoBiaoXX());
  791. } else if (isControl) {
  792. zhaoTBXX.children.push(new ZhaoBiaoKZJ());
  793. } else {
  794. const TBInfo = new TouBiaoXX();
  795. newCRCvals.push(_toXMLStr([TBInfo]));
  796. zhaoTBXX.children.push(TBInfo);
  797. }
  798. const gongLGCHZ = new Element('公路工程汇总');
  799. const gongLGCHZBT = new Element('公路工程汇总标题');
  800. gongLGCHZ.children.push(gongLGCHZBT);
  801. // 组装标段数据
  802. projectData.children.forEach( (tender, index) => {
  803. billSeq = 1;
  804. mainMaterialSeq = 1;
  805. rationSeq = 1;
  806. jrgSeq = 1;
  807. hzSeq = 1;
  808. curTender = tenderDetailMap[tender.ID];
  809. const {
  810. gongLBDGC,
  811. hzAttrs,
  812. } = createGLBDGC(tender, index + 1);
  813. gongLGCSJ.children.push(gongLBDGC);
  814. const gongLGCHZMX = new Element('公路工程汇总明细', hzAttrs);
  815. gongLGCHZBT.children.push(gongLGCHZMX);
  816. });
  817. gongLGCSJ.children.push(gongLGCHZ);
  818. newCRCvals.push(_toXMLStr([gongLGCHZ]));
  819. for (let crcIdx = 0; crcIdx < newCRCvals.length; crcIdx++) {
  820. newCRCvals[crcIdx] = newCRCvals[crcIdx].replace(/ /g, '').replace(/\r/g, '').replace(/\n/g, '');
  821. }
  822. const md5Str = md5Ex(newCRCvals.join(''));
  823. const binaryStr = hexToBinary(md5Str); // 转成二进制string
  824. const finalMd5Str = window.btoa(binaryStr); // 还要做一次BASE64转换
  825. const gongCXX = new GongCXX(finalMd5Str);
  826. rootNode.children = [gongCXX, zhaoTBXX, gongLGCSJ];
  827. const suffix = INTERFACE_CONFIG[areaKey]['fileSuffix'][exportKind];
  828. return [{
  829. data: rootNode,
  830. exportKind,
  831. fileName: `${projectData.name}${suffix}`
  832. }];
  833. }
  834. return await setupConstruction(projectData);
  835. }
  836. async function md5(message) {
  837. const msgUint8 = new TextEncoder().encode(message); // 将字符串转换为UTF-8编码的字节
  838. // const hashBuffer = await crypto.subtle.digest('MD5', msgUint8); // 计算MD5哈希
  839. const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // 计算MD5哈希
  840. // const hashBuffer = await crypto.subtle.digest('md5', msgUint8); // 计算MD5哈希
  841. const hashArray = Array.from(new Uint8Array(hashBuffer)); // 转换成数组
  842. const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); // 转换成16进制字符串
  843. return hashHex;
  844. }
  845. function md5Ex(string) {
  846. function md5_RotateLeft(lValue, iShiftBits) {
  847. return (lValue << iShiftBits) | (lValue >>> (32 - iShiftBits));
  848. }
  849. function md5_AddUnsigned(lX, lY) {
  850. var lX4, lY4, lX8, lY8, lResult;
  851. lX8 = (lX & 0x80000000);//2147483648
  852. lY8 = (lY & 0x80000000);//2147483648
  853. lX4 = (lX & 0x40000000);//1073741824
  854. lY4 = (lY & 0x40000000);//1073741824
  855. lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
  856. if (lX4 & lY4) {
  857. return (lResult ^ 0x80000000 ^ lX8 ^ lY8);
  858. }
  859. if (lX4 | lY4) {
  860. if (lResult & 0x40000000) {
  861. return (lResult ^ 0xC0000000 ^ lX8 ^ lY8);
  862. } else {
  863. return (lResult ^ 0x40000000 ^ lX8 ^ lY8);
  864. }
  865. } else {
  866. return (lResult ^ lX8 ^ lY8);
  867. }
  868. }
  869. function md5_F(x, y, z) {
  870. return (x & y) | ((~x) & z);
  871. }
  872. function md5_G(x, y, z) {
  873. return (x & z) | (y & (~z));
  874. }
  875. function md5_H(x, y, z) {
  876. return (x ^ y ^ z);
  877. }
  878. function md5_I(x, y, z) {
  879. return (y ^ (x | (~z)));
  880. }
  881. function md5_FF(a, b, c, d, x, s, ac) {
  882. a = md5_AddUnsigned(a, md5_AddUnsigned(md5_AddUnsigned(md5_F(b, c, d), x), ac));
  883. return md5_AddUnsigned(md5_RotateLeft(a, s), b);
  884. };
  885. function md5_GG(a, b, c, d, x, s, ac) {
  886. a = md5_AddUnsigned(a, md5_AddUnsigned(md5_AddUnsigned(md5_G(b, c, d), x), ac));
  887. return md5_AddUnsigned(md5_RotateLeft(a, s), b);
  888. };
  889. function md5_HH(a, b, c, d, x, s, ac) {
  890. a = md5_AddUnsigned(a, md5_AddUnsigned(md5_AddUnsigned(md5_H(b, c, d), x), ac));
  891. return md5_AddUnsigned(md5_RotateLeft(a, s), b);
  892. };
  893. function md5_II(a, b, c, d, x, s, ac) {
  894. a = md5_AddUnsigned(a, md5_AddUnsigned(md5_AddUnsigned(md5_I(b, c, d), x), ac));
  895. return md5_AddUnsigned(md5_RotateLeft(a, s), b);
  896. };
  897. function md5_ConvertToWordArray(string) {
  898. var lWordCount;
  899. var lMessageLength = string.length;
  900. var lNumberOfWords_temp1 = lMessageLength + 8;
  901. var lNumberOfWords_temp2 = (lNumberOfWords_temp1 - (lNumberOfWords_temp1 % 64)) / 64;
  902. var lNumberOfWords = (lNumberOfWords_temp2 + 1) * 16;
  903. var lWordArray = Array(lNumberOfWords - 1);
  904. var lBytePosition = 0;
  905. var lByteCount = 0;
  906. while (lByteCount < lMessageLength) {
  907. lWordCount = (lByteCount - (lByteCount % 4)) / 4;
  908. lBytePosition = (lByteCount % 4) * 8;
  909. lWordArray[lWordCount] = (lWordArray[lWordCount] | (string.charCodeAt(lByteCount) << lBytePosition));
  910. lByteCount++;
  911. }
  912. lWordCount = (lByteCount - (lByteCount % 4)) / 4;
  913. lBytePosition = (lByteCount % 4) * 8;
  914. lWordArray[lWordCount] = lWordArray[lWordCount] | (0x80 << lBytePosition);
  915. lWordArray[lNumberOfWords - 2] = lMessageLength << 3;
  916. lWordArray[lNumberOfWords - 1] = lMessageLength >>> 29;
  917. return lWordArray;
  918. };
  919. function md5_WordToHex(lValue) {
  920. var WordToHexValue = "",
  921. WordToHexValue_temp = "",
  922. lByte, lCount;
  923. for (lCount = 0; lCount <= 3; lCount++) {
  924. lByte = (lValue >>> (lCount * 8)) & 255;
  925. WordToHexValue_temp = "0" + lByte.toString(16);
  926. WordToHexValue = WordToHexValue + WordToHexValue_temp.substr(WordToHexValue_temp.length - 2, 2);
  927. }
  928. return WordToHexValue;
  929. };
  930. function md5_Utf8Encode(string) {
  931. string = string.replace(/\r\n/g, "\n");
  932. var utftext = "";
  933. for (var n = 0; n < string.length; n++) {
  934. var c = string.charCodeAt(n);
  935. if (c < 128) {
  936. utftext += String.fromCharCode(c);
  937. } else if ((c > 127) && (c < 2048)) {
  938. utftext += String.fromCharCode((c >> 6) | 192);
  939. utftext += String.fromCharCode((c & 63) | 128);
  940. } else {
  941. utftext += String.fromCharCode((c >> 12) | 224);
  942. utftext += String.fromCharCode(((c >> 6) & 63) | 128);
  943. utftext += String.fromCharCode((c & 63) | 128);
  944. }
  945. }
  946. return utftext;
  947. };
  948. var x = Array();
  949. var k, AA, BB, CC, DD, a, b, c, d;
  950. var S11 = 7,
  951. S12 = 12,
  952. S13 = 17,
  953. S14 = 22;
  954. var S21 = 5,
  955. S22 = 9,
  956. S23 = 14,
  957. S24 = 20;
  958. var S31 = 4,
  959. S32 = 11,
  960. S33 = 16,
  961. S34 = 23;
  962. var S41 = 6,
  963. S42 = 10,
  964. S43 = 15,
  965. S44 = 21;
  966. string = md5_Utf8Encode(string);
  967. x = md5_ConvertToWordArray(string);
  968. a = 0x67452301;//1732584193
  969. b = 0xEFCDAB89;//4023233417
  970. c = 0x98BADCFE;//2562383102
  971. d = 0x10325476;//271733878
  972. for (k = 0; k < x.length; k += 16) {
  973. AA = a;
  974. BB = b;
  975. CC = c;
  976. DD = d;
  977. a = md5_FF(a, b, c, d, x[k + 0], S11, 0xD76AA478);
  978. d = md5_FF(d, a, b, c, x[k + 1], S12, 0xE8C7B756);
  979. c = md5_FF(c, d, a, b, x[k + 2], S13, 0x242070DB);
  980. b = md5_FF(b, c, d, a, x[k + 3], S14, 0xC1BDCEEE);
  981. a = md5_FF(a, b, c, d, x[k + 4], S11, 0xF57C0FAF);
  982. d = md5_FF(d, a, b, c, x[k + 5], S12, 0x4787C62A);
  983. c = md5_FF(c, d, a, b, x[k + 6], S13, 0xA8304613);
  984. b = md5_FF(b, c, d, a, x[k + 7], S14, 0xFD469501);
  985. a = md5_FF(a, b, c, d, x[k + 8], S11, 0x698098D8);
  986. d = md5_FF(d, a, b, c, x[k + 9], S12, 0x8B44F7AF);
  987. c = md5_FF(c, d, a, b, x[k + 10], S13, 0xFFFF5BB1);
  988. b = md5_FF(b, c, d, a, x[k + 11], S14, 0x895CD7BE);
  989. a = md5_FF(a, b, c, d, x[k + 12], S11, 0x6B901122);
  990. d = md5_FF(d, a, b, c, x[k + 13], S12, 0xFD987193);
  991. c = md5_FF(c, d, a, b, x[k + 14], S13, 0xA679438E);
  992. b = md5_FF(b, c, d, a, x[k + 15], S14, 0x49B40821);
  993. a = md5_GG(a, b, c, d, x[k + 1], S21, 0xF61E2562);
  994. d = md5_GG(d, a, b, c, x[k + 6], S22, 0xC040B340);
  995. c = md5_GG(c, d, a, b, x[k + 11], S23, 0x265E5A51);
  996. b = md5_GG(b, c, d, a, x[k + 0], S24, 0xE9B6C7AA);
  997. a = md5_GG(a, b, c, d, x[k + 5], S21, 0xD62F105D);
  998. d = md5_GG(d, a, b, c, x[k + 10], S22, 0x2441453);
  999. c = md5_GG(c, d, a, b, x[k + 15], S23, 0xD8A1E681);
  1000. b = md5_GG(b, c, d, a, x[k + 4], S24, 0xE7D3FBC8);
  1001. a = md5_GG(a, b, c, d, x[k + 9], S21, 0x21E1CDE6);
  1002. d = md5_GG(d, a, b, c, x[k + 14], S22, 0xC33707D6);
  1003. c = md5_GG(c, d, a, b, x[k + 3], S23, 0xF4D50D87);
  1004. b = md5_GG(b, c, d, a, x[k + 8], S24, 0x455A14ED);
  1005. a = md5_GG(a, b, c, d, x[k + 13], S21, 0xA9E3E905);
  1006. d = md5_GG(d, a, b, c, x[k + 2], S22, 0xFCEFA3F8);
  1007. c = md5_GG(c, d, a, b, x[k + 7], S23, 0x676F02D9);
  1008. b = md5_GG(b, c, d, a, x[k + 12], S24, 0x8D2A4C8A);
  1009. a = md5_HH(a, b, c, d, x[k + 5], S31, 0xFFFA3942);
  1010. d = md5_HH(d, a, b, c, x[k + 8], S32, 0x8771F681);
  1011. c = md5_HH(c, d, a, b, x[k + 11], S33, 0x6D9D6122);
  1012. b = md5_HH(b, c, d, a, x[k + 14], S34, 0xFDE5380C);
  1013. a = md5_HH(a, b, c, d, x[k + 1], S31, 0xA4BEEA44);
  1014. d = md5_HH(d, a, b, c, x[k + 4], S32, 0x4BDECFA9);
  1015. c = md5_HH(c, d, a, b, x[k + 7], S33, 0xF6BB4B60);
  1016. b = md5_HH(b, c, d, a, x[k + 10], S34, 0xBEBFBC70);
  1017. a = md5_HH(a, b, c, d, x[k + 13], S31, 0x289B7EC6);
  1018. d = md5_HH(d, a, b, c, x[k + 0], S32, 0xEAA127FA);
  1019. c = md5_HH(c, d, a, b, x[k + 3], S33, 0xD4EF3085);
  1020. b = md5_HH(b, c, d, a, x[k + 6], S34, 0x4881D05);
  1021. a = md5_HH(a, b, c, d, x[k + 9], S31, 0xD9D4D039);
  1022. d = md5_HH(d, a, b, c, x[k + 12], S32, 0xE6DB99E5);
  1023. c = md5_HH(c, d, a, b, x[k + 15], S33, 0x1FA27CF8);
  1024. b = md5_HH(b, c, d, a, x[k + 2], S34, 0xC4AC5665);
  1025. a = md5_II(a, b, c, d, x[k + 0], S41, 0xF4292244);
  1026. d = md5_II(d, a, b, c, x[k + 7], S42, 0x432AFF97);
  1027. c = md5_II(c, d, a, b, x[k + 14], S43, 0xAB9423A7);
  1028. b = md5_II(b, c, d, a, x[k + 5], S44, 0xFC93A039);
  1029. a = md5_II(a, b, c, d, x[k + 12], S41, 0x655B59C3);
  1030. d = md5_II(d, a, b, c, x[k + 3], S42, 0x8F0CCC92);
  1031. c = md5_II(c, d, a, b, x[k + 10], S43, 0xFFEFF47D);
  1032. b = md5_II(b, c, d, a, x[k + 1], S44, 0x85845DD1);
  1033. a = md5_II(a, b, c, d, x[k + 8], S41, 0x6FA87E4F);
  1034. d = md5_II(d, a, b, c, x[k + 15], S42, 0xFE2CE6E0);
  1035. c = md5_II(c, d, a, b, x[k + 6], S43, 0xA3014314);
  1036. b = md5_II(b, c, d, a, x[k + 13], S44, 0x4E0811A1);
  1037. a = md5_II(a, b, c, d, x[k + 4], S41, 0xF7537E82);
  1038. d = md5_II(d, a, b, c, x[k + 11], S42, 0xBD3AF235);
  1039. c = md5_II(c, d, a, b, x[k + 2], S43, 0x2AD7D2BB);
  1040. b = md5_II(b, c, d, a, x[k + 9], S44, 0xEB86D391);
  1041. a = md5_AddUnsigned(a, AA);
  1042. b = md5_AddUnsigned(b, BB);
  1043. c = md5_AddUnsigned(c, CC);
  1044. d = md5_AddUnsigned(d, DD);
  1045. }
  1046. return (md5_WordToHex(a) + md5_WordToHex(b) + md5_WordToHex(c) + md5_WordToHex(d)).toLowerCase();
  1047. }
  1048. function hexToBinary(hex) {
  1049. return hex.replace(/^(.{2})(.*)$/g, function(_, $1, $2) {
  1050. return String.fromCharCode(parseInt($1, 16)) + hexToBinary($2);
  1051. });
  1052. }
  1053. // 开始标签
  1054. function _startTag(ele) {
  1055. let rst = `<${ele.name}`;
  1056. for (const attr of ele.attrs) {
  1057. rst += ` ${attr.name}="${attr.value}"`;
  1058. }
  1059. rst += ele.children.length > 0 ? '>' : '/>';
  1060. return rst;
  1061. }
  1062. // 结束标签
  1063. function _endTag(ele) {
  1064. return `</${ele.name}>`;
  1065. }
  1066. // 拼接成xml字符串
  1067. function _toXMLStr(eles) {
  1068. let rst = '';
  1069. for (const ele of eles) {
  1070. rst += _startTag(ele);
  1071. if (ele.children.length > 0) {
  1072. rst += _toXMLStr(ele.children);
  1073. rst += _endTag(ele);
  1074. }
  1075. }
  1076. return rst;
  1077. }
  1078. return {
  1079. entry,
  1080. };
  1081. })();