importStandardInterface.js 83 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2019/5/14
  7. * @version
  8. */
  9. /*
  10. * 尽可能减少服务器压力,前端提取后端所需数据,提取成更符合我们程序数据结构的数据
  11. * 源数据中,含有前缀"_"的数据,为原xml节点中的属性,不含前缀的数据为原xml节点的节点名
  12. * */
  13. const ImportXML = (() => {
  14. const fixedFlag = {
  15. // 分部分项工程
  16. SUB_ENGINERRING: 1,
  17. // 措施项目
  18. MEASURE: 2,
  19. // 施工技术措施项目
  20. CONSTRUCTION_TECH: 3,
  21. // 安全文明施工按实计算费用
  22. SAFETY_CONSTRUCTION_ACTUAL: 4,
  23. // 施工组织措施专项费用
  24. CONSTRUCTION_ORGANIZATION: 5,
  25. // 安全文明施工专项费用
  26. SAFETY_CONSTRUCTION: 6,
  27. // 其他项目
  28. OTHER: 7,
  29. // 暂列金额
  30. PROVISIONAL: 8,
  31. // 暂估价
  32. ESTIMATE: 9,
  33. // 材料(工程设备)暂估价
  34. MATERIAL_PROVISIONAL: 10,
  35. // 专业工程暂估价
  36. ENGINEERING_ESITIMATE: 11,
  37. // 计日工
  38. DAYWORK: 12,
  39. // 总承包服务费
  40. TURN_KEY_CONTRACT: 13,
  41. // 索赔与现场签证
  42. CLAIM_VISA: 14,
  43. // 规费
  44. CHARGE: 15,
  45. // 社会保险费及住房公积金 Social insurance fee and housing accumulation fund
  46. SOCIAL_INSURANCE_HOUSING_FUND: 16,
  47. // 工程排污费 charges for disposing pollutants
  48. POLLUTANTS: 17,
  49. // 税金
  50. TAX: 18,
  51. //工程造价
  52. ENGINEERINGCOST: 19,
  53. //增值税
  54. ADDED_VALUE_TAX: 20,
  55. //专项技术措施暂估价
  56. SPECIAL_TECH_PROVISIONAL: 21,
  57. //专业发包工程管理费
  58. LET_CONTRACT_MANAGEMENT: 22,
  59. //人工
  60. LABOUR: 23,
  61. //材料
  62. MATERIAL: 24,
  63. //施工机械
  64. MACHINE: 25,
  65. //索赔
  66. CLAIM: 26,
  67. //现场签证
  68. VISA: 27,
  69. ADDITIONAL_TAX: 28,
  70. //环境保护税
  71. ENVIRONMENTAL_PROTECTION_TAX: 29,
  72. //建设工程竣工档案编制费
  73. PROJECT_COMPLETE_ARCH_FEE:30,
  74. //住宅工程质量分户验收费
  75. HOUSE_QUALITY_ACCEPT_FEE:31,
  76. //组织措施费
  77. ORGANIZATION:32
  78. };
  79. // 限定取值的取费类别与固定ID对应
  80. const FEE_TYPE_FLAG = {
  81. '120201': fixedFlag.CONSTRUCTION_ORGANIZATION,
  82. '1204': fixedFlag.SAFETY_CONSTRUCTION,
  83. '10041': fixedFlag.PROJECT_COMPLETE_ARCH_FEE,
  84. '1206': fixedFlag.HOUSE_QUALITY_ACCEPT_FEE,
  85. '800': fixedFlag.CHARGE,
  86. '900': fixedFlag.TAX,
  87. '9001': fixedFlag.ADDED_VALUE_TAX,
  88. '9002': fixedFlag.ADDITIONAL_TAX,
  89. '9003': fixedFlag.ENVIRONMENTAL_PROTECTION_TAX
  90. };
  91. //导入的文件类型,界面选的文件类型是生成项目的文件类型,这里的文件类型指的是,要导入文件的类型,
  92. //导入文件类型不同,导入数据不同
  93. let importFileKind = '';
  94. //文件类型
  95. const FileKind = {
  96. '投标': 1,
  97. 'tender': 1,
  98. '招标': 2,
  99. 'bid': 2,
  100. '控制价': 3,
  101. 'control': 3
  102. };
  103. //计税方法
  104. const TaxTypeMap = {
  105. '一般计税法': 1,
  106. '一般计税': 1,
  107. '简易计税法': 2,
  108. '简易计税': 2,
  109. '': 1 //默认
  110. };
  111. //清单类型
  112. const BillsType ={
  113. DXFY: 1, //大项费用
  114. FB: 2, //分部
  115. FX: 3, //分项
  116. BILLS: 4, //清单
  117. BX: 5 //补项
  118. };
  119. // 定额类型
  120. const RationType = {
  121. ration: 1,
  122. volumePrice: 2, // 量价
  123. volumePriceMaterial: 201, // 量材
  124. gljRation: 3,
  125. install: 4
  126. };
  127. //项目类型
  128. const ProjectType = {
  129. Project: 'Project',
  130. Engineering: 'Engineering',
  131. Tender: 'Tender'
  132. };
  133. //人材机调整法
  134. const AdjustType = {
  135. info: 'priceInfo', //造价信息差额调整法
  136. coe: 'priceCoe' //价格指数调整法
  137. };
  138. // xml字符实体
  139. const XML_ENTITY = {
  140. ' ': 'escape{space}',
  141. ' ': 'escape{simpleSpace}',
  142. '	': 'escape{tab}',
  143. '	': 'escape{simpleTab}',
  144. '
': 'escape{return}',
  145. '
': 'escape{simpleReturn}',
  146. '&#000A;': 'escape{newLine}',
  147. '
': 'escape{simpleNewLine}',
  148. '<': 'escape{less}',
  149. '>': 'escape{greater}',
  150. '&': 'escape{and}',
  151. '"': 'escape{quot}',
  152. ''': 'escape{apos}'
  153. };
  154. // 避免字符实体进行转义。原文本中含有xml字符实体,转换为其他字符。
  155. function escapeXMLEntity(str) {
  156. for (let [key, value] of Object.entries(XML_ENTITY)) {
  157. str = str.replace(new RegExp(key, 'g'), value);
  158. }
  159. return str;
  160. }
  161. // 将文本还原为字符实体
  162. function restoreXMLEntity(str) {
  163. for (let [key, value] of Object.entries(XML_ENTITY)) {
  164. str = str.replace(new RegExp(value, 'g'), key);
  165. }
  166. return str;
  167. }
  168. //读取文件转换为utf-8编码的字符串
  169. function readAsTextSync(file) {
  170. return new Promise((resolve, reject) => {
  171. let fr = new FileReader();
  172. fr.readAsText(file); //默认utf-8,如果出现乱码,得看导入文件是什么编码
  173. fr.onload = function () {
  174. resolve(this.result);
  175. };
  176. fr.onerror = function () {
  177. reject('读取文件失败,请重试。');
  178. }
  179. });
  180. }
  181. /*
  182. * 根据字段数组获得所要字段的值 eg: 要获取标段下的单项工程: ['标段', '单项工程'];
  183. * @param {Object}source源数据 {Array}fields字段数组
  184. * */
  185. function getValue(source, fields) {
  186. let cur = source;
  187. for (let field of fields) {
  188. if (!cur[field]) {
  189. return '';
  190. }
  191. cur = cur[field];
  192. }
  193. return cur || '';
  194. }
  195. /*
  196. * 获取某字段的值,强制返回数组
  197. * */
  198. function arrayValue(source, fields) {
  199. let target = getValue(source, fields);
  200. if (plainType(target) === 'Object') {
  201. target = [target];
  202. } else if (plainType(target) !== 'Array') {
  203. target = []
  204. }
  205. return target;
  206. }
  207. function plainType(v) {
  208. return Object.prototype.toString.call(v).slice(8, -1);
  209. }
  210. // 根据费用类别给清单数据设置flags字段
  211. function initFlags(feeType) {
  212. let flag = FEE_TYPE_FLAG[feeType];
  213. return flag
  214. ? [{fieldName: 'fixed', flag: flag}]
  215. : [];
  216. }
  217. return function () {
  218. let countData = {
  219. projectCount: 0, //项目数量
  220. projectGLJCount: 0, //项目人材机数量
  221. ratioCount: 0, //组成物数量
  222. unitPriceCount: 0, //单价数量
  223. unitPriceFileCount: 0, //单价文件数量
  224. };
  225. //获取费用
  226. function getFee(fees, fields) {
  227. if (!Array.isArray(fees) || !fees.length) {
  228. return '0';
  229. }
  230. let feeData = fees.find(fee => fee.fieldName === fields[0]);
  231. return feeData[fields[1]] || '0';
  232. }
  233. //标段
  234. function loadProject(source) {
  235. countData.projectCount++;
  236. importFileKind = FileKind[getValue(source, ['标段', '_文件类型'])];
  237. let obj = {
  238. projType: ProjectType.Project,
  239. name: getValue(source, ['标段', '_项目名称']),
  240. engs: loadEng(source),
  241. property: {
  242. compilationIllustration: getValue(source, ['标段', '编制说明', '_内容'])
  243. },
  244. basicInformation: loadBasicInfo(source),
  245. };
  246. //统计项目数量
  247. let count = 1 + obj.engs.length;
  248. obj.engs.forEach(eng => {
  249. count += eng.tenders.length;
  250. });
  251. obj.projectCount = count;
  252. return obj;
  253. }
  254. //基本信息相关
  255. function loadBasicInfo(source) {
  256. let info = [];
  257. info.push({key: 'projNum', value: getValue(source, ['标段', '_项目编号'])});
  258. info.push({key: 'constructionUnit', value: getValue(source, ['标段', '_建设单位'])});
  259. //项目信息
  260. let projInfoSrc = getValue(source, ['标段', '项目信息']);
  261. if (projInfoSrc) {
  262. info.push({key: 'projectScale', value: getValue(projInfoSrc, ['_工程规模'])});
  263. info.push({key: 'projLocation', value: getValue(projInfoSrc, ['_工程所在地'])});
  264. info.push({key: 'projAddress', value: getValue(projInfoSrc, ['_工程地址'])});
  265. info.push({key: 'buildingUnit', value: getValue(projInfoSrc, ['_施工单位'])});
  266. info.push({key: 'establishUnit', value: getValue(projInfoSrc, ['_编制单位'])});
  267. info.push({key: 'auditUnit', value: getValue(projInfoSrc, ['_审核单位'])});
  268. info.push({key: 'establishUnitAuthor', value: getValue(projInfoSrc, ['_编制人'])});
  269. info.push({key: 'auditUnitAuditor', value: getValue(projInfoSrc, ['_审核人'])});
  270. info.push({key: 'commencementDate', value: getValue(projInfoSrc, ['_开工日期'])});
  271. info.push({key: 'completionDate', value: getValue(projInfoSrc, ['_竣工日期'])});
  272. info.push({key: 'establishDate', value: getValue(projInfoSrc, ['_编制日期'])});
  273. info.push({key: 'auditDate', value: getValue(projInfoSrc, ['_审核日期'])});
  274. info.push({key: 'materialPricePeriod', value: getValue(projInfoSrc, ['_材料价格期'])});
  275. info.push({key: 'contractPriceType', value: getValue(projInfoSrc, ['_合同价类型'])});
  276. //招标信息
  277. info.push({key: 'agency', value: getValue(projInfoSrc, ['招标信息', '_招标代理机构'])});
  278. info.push({key: 'tenderCostEngineer', value: getValue(projInfoSrc, ['招标信息', '_造价工程师'])});
  279. info.push({key: 'tenderingRegistrationCertificateNumber', value: getValue(projInfoSrc, ['招标信息', '_造价工程师注册证号'])});
  280. info.push({key: 'tenderingPeriod', value: getValue(projInfoSrc, ['招标信息', '_招标工期'])});
  281. info.push({key: 'engineeringCost', value: getValue(projInfoSrc, ['招标信息', '_控制总价'])});
  282. //投标信息
  283. info.push({key: 'bidder', value: getValue(projInfoSrc, ['投标信息', '_投标人'])});
  284. info.push({key: 'bidCostEngineer', value: getValue(projInfoSrc, ['投标信息', '_造价工程师'])});
  285. info.push({key: 'bidRegistrationCertificateNumber', value: getValue(projInfoSrc, ['投标信息', '_造价工程师注册证号'])});
  286. info.push({key: 'projectManager', value: getValue(projInfoSrc, ['投标信息', '_项目经理'])});
  287. info.push({key: 'bidPeriod', value: getValue(projInfoSrc, ['投标信息', '_投标工期'])});
  288. info.push({key: 'biddingMargin', value: getValue(projInfoSrc, ['投标信息', '_投标保证金'])});
  289. info.push({key: 'qualityCommitment', value: getValue(projInfoSrc, ['投标信息', '_质量承诺'])});
  290. info.push({key: 'guaranteeType', value: getValue(projInfoSrc, ['投标信息', '_担保类型'])});
  291. info.push({key: 'engineeringCost', value: getValue(projInfoSrc, ['投标信息', '_投标总价'])});
  292. let firstEng = arrayValue(source, ['标段', '单项工程'])[0];
  293. if (firstEng) {
  294. let firstTender = arrayValue(firstEng, ['单位工程'])[0];
  295. if (firstTender) {
  296. info.push({key: 'projectCategory', value: getValue(firstTender, ['工程特征', '_工程类别'])});
  297. }
  298. }
  299. }
  300. return info;
  301. }
  302. //单项工程
  303. function loadEng(source) {
  304. return arrayValue(source, ['标段', '单项工程']).map(src => {
  305. countData.projectCount++;
  306. return {
  307. projType: ProjectType.Engineering,
  308. name: getValue(src, ['_名称']),
  309. code: getValue(src, ['_编号']),
  310. tenders: loadTender(src)
  311. };
  312. });
  313. }
  314. //单位工程
  315. function loadTender(engSrc) {
  316. return arrayValue(engSrc, ['单位工程']).map(src => {
  317. countData.projectCount++;
  318. countData.unitPriceFileCount++;
  319. return {
  320. projType: ProjectType.Tender,
  321. name: getValue(src, ['_名称']),
  322. code: getValue(src, ['_编号']),
  323. engineering: getValue(src, ['_专业']), //可能跟我们软件里的工程专业对应不上
  324. projectFeature: loadProjectFeature(src),
  325. feeSummary: loadFeeSummary(src), //单位工程费汇总
  326. fbfx: loadFBFX(src),
  327. csxm: loadCSXM(src),
  328. other: loadOther(src),
  329. chargeTax: loadChargeTax(src),
  330. gljSummary: loadGljSummary(src),
  331. differentiaSummary: loadDifferentiaSummary(src) ,//承包人材料差额法表
  332. exponentialSummary: loadExponentialSummary(src) ,//承包人材料指数法表
  333. evalBidSummary: loadEvalBidSummary(src), //评标材料表
  334. };
  335. });
  336. }
  337. //工程特征相关,特征项没有固定的项,不清楚导入的项无法用已有key对应,而且工程特征名称不会有重复,因此用名称与我们软件的工程特征对应
  338. function loadProjectFeature(tenderSrc) {
  339. let feature = [];
  340. feature.push({name: '建筑分类', value: getValue(tenderSrc, ['工程特征', '_建筑分类'])});
  341. feature.push({name: '工程分类', value: getValue(tenderSrc, ['工程特征', '_工程分类'])});
  342. feature.push({name: '建设规模', value: getValue(tenderSrc, ['工程特征', '_建设规模'])});
  343. let items = arrayValue(tenderSrc, ['工程特征', '特征项']);
  344. feature.push(...items.map(item => {
  345. return {name: getValue(item, ['_名称']), value: getValue(item, ['_内容'])};
  346. }));
  347. return feature;
  348. }
  349. /*
  350. * 递归获取相关数据,eg:获取组织措施清单下的所有子清单,该子清单们可能由分类及公式措施项各种组合组成。(参考调用处)
  351. * @param {Object}src(数据源) {Array}fields(二维数组,数组里的成员由需要取的字段组成)
  352. * eg: ['组织措施分类'], ['公式计算措施项'],该层数据可能由组织措施分类 或 公式计算措施项组成 (同层不可同时存在)
  353. * {Function} 获得源数据后,需要提取的数据方法
  354. * @return {Array}
  355. * */
  356. function getItemsRecur(src, fields, extractFuc) {
  357. let itemsSrc = [],
  358. curField = [''];
  359. for (let field of fields) {
  360. itemsSrc = arrayValue(src, field);
  361. if (itemsSrc.length) {
  362. curField = field;
  363. break;
  364. }
  365. }
  366. return itemsSrc.map(itemSrc => {
  367. let obj = extractFuc(itemSrc, curField);
  368. obj.items = getItemsRecur(itemSrc, fields, extractFuc);
  369. return obj;
  370. });
  371. }
  372. //单位工程费汇总-计价程序费用行
  373. function loadFeeSummary(tenderSrc) {
  374. let feeItems = arrayValue(tenderSrc, ['单位工程费汇总', '计价程序费用行']);
  375. return feeItems.map(itemSrc => {
  376. let obj = {
  377. rowCode: getValue(itemSrc, ['_行代号']),
  378. name: getValue(itemSrc, ['_项目名称']),
  379. };
  380. if (importFileKind === FileKind.tender) {
  381. obj.calcBase = getValue(itemSrc, ['_计算基础表达式']);
  382. obj.feeRate = getValue(itemSrc, ['_费率']);
  383. obj.fees = [{fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0'}];
  384. }
  385. return obj;
  386. });
  387. }
  388. //分部分项,两种情况 分部分项-清单分部-清单项目、分部分项-清单项目
  389. //return {Array}
  390. function loadFBFX(tenderSrc) {
  391. let fbfxSrc = getValue(tenderSrc, ['分部分项清单']),
  392. fields = [['清单分部'], ['清单项目']];
  393. return getItemsRecur(fbfxSrc, fields, (itemSrc, curField) => {
  394. if (curField[0] === fields[0][0]) { //提取分部所需数据
  395. let obj = {
  396. type: BillsType.FB,
  397. code: getValue(itemSrc, ['_编号']),
  398. name: getValue(itemSrc, ['_名称']),
  399. remark: getValue(itemSrc, ['_备注']),
  400. };
  401. if (importFileKind === FileKind.tender) {
  402. obj.fees = [
  403. {fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0'},
  404. {fieldName: 'estimate', totalFee: getValue(itemSrc, ['_其中暂估价']) || '0'},
  405. ];
  406. }
  407. return obj;
  408. } else { //提取清单项目所需数据
  409. return extractBills(itemSrc, BillsType.FX);
  410. }
  411. });
  412. }
  413. //提取清单项目数据
  414. function extractBills(billsSrc, type) {
  415. let {features, contents} = getFeaturesAndContents(billsSrc);
  416. // 特征及内容窗口
  417. let {itemCharacter, jobContent} = featureAndContent(features, contents);
  418. let obj = {
  419. type: type, //清单类型
  420. code: getValue(billsSrc, ['_项目编码']),
  421. name: getValue(billsSrc, ['_项目名称']),
  422. unit: getValue(billsSrc, ['_单位']),
  423. isEstimate: getValue(billsSrc, ['_暂估清单标志']) === 'true' ? true : false,
  424. mainBills: getValue(billsSrc, ['_主要清单标志']) === 'true' ? true : false,
  425. quantity: getValue(billsSrc, ['_工程量']) || '0' ,
  426. remark: getValue(billsSrc, ['_备注']),
  427. itemCharacterText: featureAndContentText(features, contents),
  428. itemCharacter: itemCharacter,
  429. jobContent: jobContent
  430. };
  431. //投标和控制价,需要导入最高限价
  432. if ([FileKind.tender ,FileKind.control].includes(importFileKind)) {
  433. let maxPrice = getValue(billsSrc, ['_最高限价']);
  434. //不为0才输出
  435. if (maxPrice && maxPrice !== '0') {
  436. obj.outPutMaxPrice = true;
  437. obj.maxPrice = maxPrice;
  438. }
  439. }
  440. if (importFileKind === FileKind.tender) { //投标
  441. obj.fees = [
  442. {fieldName: 'common', unitFee: getValue(billsSrc, ['_综合单价']), totalFee: getValue(billsSrc, ['_综合合价'])},
  443. {fieldName: 'estimate', totalFee: getValue(billsSrc, ['_其中暂估价'])},
  444. ];
  445. //费用组成
  446. obj.fees.push(...extractFeeContent(getValue(billsSrc, ['费用组成'])));
  447. //组价内容
  448. obj.rations = extractRation(billsSrc);
  449. }
  450. return obj;
  451. // 获取特征及内容源数据
  452. function getFeaturesAndContents(billsSrc) {
  453. let features = arrayValue(billsSrc, ['项目特征', '特征']).map(fSrc => {
  454. return {
  455. name: getValue(fSrc, ['_特征名称']),
  456. eigenvalue: getValue(fSrc, ['_特征描述'])
  457. };
  458. });
  459. let contents = arrayValue(billsSrc, ['工程内容', '内容']).map(cSrc => {
  460. return {
  461. name: getValue(cSrc, ['_内容'])
  462. }
  463. });
  464. return {features, contents};
  465. }
  466. // 特征及内容窗口
  467. function featureAndContent(features, contents) {
  468. // 项目特征
  469. let itemCharacter = features.map((feature, idx) => {
  470. let obj = {
  471. character: feature.name,
  472. isChecked: true,
  473. serialNo: idx + 1,
  474. eigenvalue: []
  475. };
  476. if (feature.eigenvalue) {
  477. obj.eigenvalue.push({value: feature.eigenvalue, isSelected: true});
  478. }
  479. return obj;
  480. });
  481. // 工作内容
  482. let jobContent = contents.map((content, idx) => {
  483. return {
  484. content: content.name,
  485. serialNo: idx + 1,
  486. isChecked: true
  487. };
  488. });
  489. return {itemCharacter, jobContent};
  490. }
  491. // 特征及内容文本(默认显示在项目特征列)
  492. function featureAndContentText(features, contents) {
  493. let textArr = [];
  494. // 项目特征
  495. if (features.length) {
  496. textArr.push('[项目特征]');
  497. textArr.push(...features.map(feature => {
  498. //若不存在特征描述,同时特征名称中含有“:”,则直接返回特征名称 (广联达招标文件中,特征名称包含了特征名:值)
  499. if (!feature.eigenvalue && /[\:,:]/.test(feature.name)) {
  500. return feature.name;
  501. } else {
  502. return `${feature.name}: ${feature.eigenvalue}`;
  503. }
  504. }));
  505. }
  506. // 工作内容
  507. if (textArr.length) {
  508. textArr.push('[工作内容]');
  509. }
  510. textArr.push(...contents.map(content => content.name));
  511. return textArr.join('\n');
  512. }
  513. }
  514. //提取定额子目
  515. function extractRation(billsSrc) {
  516. let rationSrcs = arrayValue(billsSrc, ['组价内容', '定额子目']),
  517. serialNo = 1;
  518. return rationSrcs.map(rationSrc => {
  519. let rationData = {
  520. serialNo: serialNo++,
  521. code: getValue(rationSrc, ['_原始定额编号']).replace('换', ''),
  522. name: getValue(rationSrc, ['_项目名称']),
  523. caption: getValue(rationSrc, ['_项目名称']),
  524. unit: getValue(rationSrc, ['_单位']),
  525. libCode: getValue(rationSrc, ['_定额库编码']),
  526. quantity: getValue(rationSrc, ['_工程量']) || '0',
  527. quantityEXP: getValue(rationSrc, ['_工程量计算式']),
  528. adjustState: getValue(rationSrc, ['_子目类型']) == '2' ? '1' : '', //子目类型2为换算定额,标记一下我们软件才能显示
  529. isSubcontract: getValue(rationSrc, ['_分包标志']) === 'false' ? false : true,
  530. remark: getValue(rationSrc, ['_备注']),
  531. programID: parseInt(getValue(rationSrc, ['_单价构成文件ID'])),
  532. };
  533. //'6'认为量材,其他都认为是定额
  534. let type = getValue(rationSrc, ['_子目类型']);
  535. if (type == '6') {
  536. rationData.type = RationType.volumePrice;
  537. rationData.subType = RationType.volumePriceMaterial;
  538. } else {
  539. rationData.type = RationType.ration;
  540. }
  541. rationData.fees = [
  542. {fieldName: 'rationUnitPrice', unitFee: getValue(rationSrc, ['_定额单价']) || '0',
  543. totalFee: getValue(rationSrc, ['_定额合价']) || '0'},
  544. {fieldName: 'common', unitFee: getValue(rationSrc, ['_综合单价']) || '0',
  545. totalFee: getValue(rationSrc, ['_综合合价']) || '0'},
  546. ];
  547. rationData.fees.push(...extractFeeContent(getValue(rationSrc, ['费用组成'])));
  548. //定额人材机
  549. let rationGljSrc = arrayValue(rationSrc, ['工料分析', '人材机含量']);
  550. rationData.rationGljs = rationGljSrc.map(rjSrc => {
  551. return {
  552. code: getValue(rjSrc, ['_人材机代码']),
  553. quantity: getValue(rjSrc, ['_消耗量']) || '0',
  554. }
  555. });
  556. return rationData;
  557. });
  558. }
  559. //获取费用组成
  560. function extractFeeContent(src) {
  561. let rst = [];
  562. //减少数据量
  563. function addFee(feeData) {
  564. //有不为空的价格,才会插入
  565. let match = Object.entries(feeData).find(data => {
  566. let [k, v] = data;
  567. return k !== 'fieldName' && v && v !== '0' && v !== '0.00';
  568. });
  569. if (match) {
  570. rst.push(feeData);
  571. }
  572. }
  573. addFee({
  574. fieldName: 'labour',
  575. unitFee: getValue(src, ['_基价人工费单价']),
  576. totalFee: getValue(src, ['_基价人工费合价']),
  577. });
  578. addFee({
  579. fieldName: 'material',
  580. unitFee: getValue(src, ['_基价材料费单价']),
  581. totalFee: getValue(src, ['_基价材料费合价']),
  582. });
  583. addFee( {
  584. fieldName: 'machine',
  585. unitFee: getValue(src, ['_基价机械费单价']),
  586. totalFee: getValue(src, ['_基价机械费合价']),
  587. });
  588. addFee({
  589. fieldName: 'unratedMaterial',
  590. unitFee: getValue(src, ['_未计材料单价']),
  591. totalFee: getValue(src, ['_未计材料合价']),
  592. });
  593. addFee({
  594. fieldName: 'gljDiff',
  595. unitFee: getValue(src, ['_人材机价差单价']),
  596. totalFee: getValue(src, ['_人材机价差合价']),
  597. });
  598. addFee({
  599. fieldName: 'estimate',
  600. unitFee: getValue(src, ['_暂估材料单价']),
  601. totalFee: getValue(src, ['_暂估材料合价']),
  602. });
  603. addFee({
  604. fieldName: 'manage',
  605. unitFee: getValue(src, ['_管理费单价']),
  606. totalFee: getValue(src, ['_管理费合价']),
  607. });
  608. addFee({
  609. fieldName: 'profit',
  610. unitFee: getValue(src, ['_利润单价']),
  611. totalFee: getValue(src, ['_利润合价']),
  612. });
  613. addFee({
  614. fieldName: 'risk',
  615. unitFee: getValue(src, ['_一般风险单价']),
  616. totalFee: getValue(src, ['_一般风险合价']),
  617. });
  618. addFee({
  619. fieldName: 'otherRisk',
  620. unitFee: getValue(src, ['_其他风险单价']),
  621. totalFee: getValue(src, ['_其他风险合价']),
  622. });
  623. return rst;
  624. }
  625. //措施项目
  626. function loadCSXM(tenderSrc) {
  627. let target = {};
  628. let zzcsxmSrc = getValue(tenderSrc, ['措施项目清单', '组织措施清单']);
  629. target.zzcs = {items: loadZZCS(zzcsxmSrc)};
  630. let jscsxmSrc = getValue(tenderSrc, ['措施项目清单', '技术措施清单']);
  631. target.jscs = {items: loadJSCS(jscsxmSrc)};
  632. if (importFileKind === FileKind.tender) { //投标
  633. target.fees = [
  634. {fieldName: 'common', totalFee: getValue(tenderSrc, ['措施项目清单', '_金额']) || '0'},
  635. {fieldName: 'estimate', totalFee: getValue(tenderSrc, ['措施项目清单', '_其中暂估价']) || '0'},
  636. ];
  637. target.zzcs.fees = [{fieldName: 'common', totalFee: getValue(tenderSrc, ['措施项目清单', '组织措施清单', '_金额']) || '0'}];
  638. target.jscs.fees = [
  639. {fieldName: 'common', totalFee: getValue(tenderSrc, ['措施项目清单', '技术措施清单', '_金额']) || '0'},
  640. {fieldName: 'estimate', totalFee: getValue(tenderSrc, ['措施项目清单', '技术措施清单', '_其中暂估价']) || '0'},
  641. ];
  642. }
  643. return target;
  644. //组织措施清单
  645. function loadZZCS(zzcsSrc) {
  646. let fields = [['组织措施分类'], ['公式计算措施项']];
  647. return getItemsRecur(zzcsSrc, fields, (itemSrc, curField) => {
  648. let rstObj;
  649. if (curField[0] === fields[0][0]) { //组织措施分类
  650. rstObj = {
  651. type: BillsType.BILLS,
  652. code: getValue(itemSrc, ['_编码']),
  653. name: getValue(itemSrc, ['_名称']),
  654. remark: getValue(itemSrc, ['_备注'])
  655. }
  656. } else {
  657. rstObj = { //公式计算措施项
  658. type: BillsType.BILLS,
  659. code:getValue(itemSrc, ['_序号']),
  660. name: getValue(itemSrc, ['_名称']),
  661. calcBase: getValue(itemSrc, ['_计算基础表达式']),
  662. feeRate: getValue(itemSrc, ['_费率']),
  663. isEstimate: getValue(itemSrc, ['_暂估价标志']) === 'true' ? true : false,
  664. remark: getValue(itemSrc, ['_备注']),
  665. flags: initFlags(getValue(itemSrc, ['_费用类别']))
  666. };
  667. }
  668. if (importFileKind === FileKind.tender) {
  669. rstObj.fees = [{fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0'}];
  670. }
  671. return rstObj;
  672. });
  673. }
  674. //技术措施清单
  675. function loadJSCS(jscsSrc) {
  676. let fields = [['技术措施分类'], ['清单项目']];
  677. return getItemsRecur(jscsSrc, fields, (itemSrc, curField) => {
  678. if (curField[0] === fields[0][0]) { //技术措施分类
  679. let obj = {
  680. type: BillsType.BILLS,
  681. code: getValue(itemSrc, ['_编号']),
  682. name: getValue(itemSrc, ['_名称'])
  683. };
  684. if (importFileKind === FileKind.tender) {
  685. obj.fees = [
  686. {fieldName: 'common', totalFee: getValue(itemSrc, ['_金额']) || '0'},
  687. {fieldName: 'estimate', totalFee: getValue(itemSrc, ['_其中暂估价']) || '0'},
  688. ];
  689. }
  690. return obj;
  691. } else { //清单项目
  692. return extractBills(itemSrc, BillsType.BILLS);
  693. }
  694. });
  695. }
  696. }
  697. //其他项目
  698. function loadOther(tenderSrc) {
  699. let otherSrc = getValue(tenderSrc, ['其他项目清单']);
  700. //暂列金额
  701. let provisional = {items: arrayValue(otherSrc, ['暂列金额', '暂列金额明细']).map(src => {
  702. let obj = {
  703. type: BillsType.BILLS,
  704. code: getValue(src, ['_编号']),
  705. name: getValue(src, ['_项目名称']),
  706. unit: getValue(src, ['_计量单位']),
  707. remark: getValue(src, ['_备注'])
  708. };
  709. //if (importFileKind === FileKind.tender) {
  710. obj.fees = [{fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0'},];
  711. //}
  712. return obj;
  713. })};
  714. //专业工程暂估价
  715. let engineeringPro = {items: arrayValue(otherSrc, ['专业工程暂估价', '专业工程暂估明细']).map(src => {
  716. let obj = {
  717. type: BillsType.BILLS,
  718. code: getValue(src, ['_编号']),
  719. name: getValue(src, ['_工程名称']),
  720. engineeringContent: getValue(src, ['_工程内容']),
  721. remark: getValue(src, ['_备注'])
  722. };
  723. //if (importFileKind === FileKind.tender) {
  724. obj.fees = [{fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0'},];
  725. //}
  726. return obj;
  727. })};
  728. //计日工
  729. function extractDayWorkItem(src) {
  730. let obj = {
  731. type: BillsType.BILLS,
  732. code: getValue(src, ['_编号']),
  733. name: getValue(src, ['_名称']),
  734. unit: getValue(src, ['_单位']),
  735. quantity: getValue(src, ['_数量']),
  736. remark: getValue(src, ['_备注'])
  737. };
  738. if (importFileKind === FileKind.tender) {
  739. obj.fees = [
  740. {fieldName: 'common', unitFee: getValue(src, ['_综合单价']) || '0', totalFee: getValue(src, ['_综合合价']) || '0'}
  741. ];
  742. }
  743. return obj;
  744. }
  745. let labour = arrayValue(otherSrc, ['计日工', '人工', '计日工项目']).map(extractDayWorkItem),
  746. material = arrayValue(otherSrc, ['计日工', '材料', '计日工项目']).map(extractDayWorkItem),
  747. machine = arrayValue(otherSrc, ['计日工', '施工机械', '计日工项目']).map(extractDayWorkItem);
  748. let dayWork = {labour, material, machine};
  749. //总承包服务费
  750. let fields = [['总承包服务费分类'], ['总承包服务费费用项']],
  751. serviceSrc = getValue(otherSrc, ['总承包服务费']);
  752. let service = {items: getItemsRecur(serviceSrc, fields, (src, curField) => {
  753. if (curField[0] === fields[0][0]) {
  754. return { //总承包服务费分类
  755. type: BillsType.BILLS,
  756. code: getValue(src, ['_编号']),
  757. name: getValue(src, ['_名称']),
  758. remark: getValue(src, ['_备注'])
  759. }
  760. } else {
  761. let obj = { //总承包服务费费用项
  762. type: BillsType.BILLS,
  763. code:getValue(src, ['_编号']),
  764. name: getValue(src, ['_工程名称']),
  765. calcBase: getValue(src, ['_计算基础']),
  766. serviceContent: getValue(src, ['_服务内容']),
  767. feeRate: getValue(src, ['_费率']),
  768. remark: getValue(src, ['_备注'])
  769. };
  770. if (importFileKind === FileKind.tender) {
  771. obj.fees = [
  772. {fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0'}
  773. ];
  774. }
  775. return obj;
  776. }
  777. })};
  778. //索赔、签证
  779. function extractClaimVisa(src) {
  780. let obj = {
  781. type: BillsType.BILLS,
  782. code: getValue(src, ['_编号']),
  783. name: getValue(src, ['_项目名称']),
  784. unit: getValue(src, ['_计量单位']),
  785. quantity: getValue(src, ['_数量']),
  786. claimVisa: getValue(src, ['_依据'])
  787. };
  788. //if (importFileKind === FileKind.tender) {
  789. obj.fees = [
  790. {fieldName: 'common', unitFee: getValue(src, ['_单价']) || '0', totalFee: getValue(src, ['_合价']) || '0'}
  791. ];
  792. //}
  793. return obj;
  794. }
  795. let claim = {items: arrayValue(otherSrc, ['索赔计价汇总', '签证索赔计价汇总费用项']).map(extractClaimVisa)},
  796. visa = {items: arrayValue(otherSrc, ['现场签证计价汇总', '签证索赔计价汇总费用项']).map(extractClaimVisa)};
  797. //其他
  798. let others = {items: arrayValue(otherSrc, ['其他', '其他列项']).map(src => {
  799. let obj = {
  800. type: BillsType.BILLS,
  801. code: getValue(src, ['_序号']),
  802. name: getValue(src, ['_名称']),
  803. calcBase: getValue(src, ['_计算基础']),
  804. feeRate: getValue(src, ['_费率']),
  805. remark: getValue(src, ['_备注'])
  806. };
  807. if (importFileKind === FileKind.tender) {
  808. obj.fees = [{fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0'}];
  809. }
  810. return obj;
  811. })};
  812. if (importFileKind === FileKind.tender) {
  813. provisional.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['暂列金额', '_金额']) || '0'}];
  814. engineeringPro.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['专业工程暂估价', '_金额']) || '0'}];
  815. dayWork.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['计日工', '_金额']) || '0'}];
  816. service.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['总承包服务费', '_金额']) || '0'}];
  817. claim.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['索赔计价汇总', '_金额']) || '0'}];
  818. visa.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['现场签证计价汇总', '_金额']) || '0'}];
  819. others.fees = [{fieldName: 'common', totalFee: getValue(otherSrc, ['其他', '_金额']) || '0'}];
  820. }
  821. return {provisional, engineeringPro, dayWork, service, claim, visa, others};
  822. }
  823. //规费和税金清单
  824. function loadChargeTax(tenderSrc) {
  825. // 由于规费和规费子项的费用类别都是800,因此要处理(重复出现的费用类别不设置固定ID,保证没有相同的固定清单);
  826. // 记录出现过的费用类别
  827. let occurs = [];
  828. return arrayValue(tenderSrc, ['规费和税金清单', '费用项']).map(src => {
  829. let feeType = getValue(src, ['_费用类别']);
  830. let obj = {
  831. type: BillsType.BILLS,
  832. rowCode: getValue(src, ['_行代号']),
  833. code: getValue(src, ['_序号']),
  834. name: getValue(src, ['_名称']),
  835. calcBase: getValue(src, ['_计算基础表达式']),
  836. feeRate: getValue(src, ['_费率']),
  837. remark: getValue(src, ['_备注']),
  838. flags: occurs.includes(feeType) ? [] : initFlags(feeType)
  839. };
  840. occurs.push(feeType);
  841. if (importFileKind === FileKind.tender) {
  842. obj.fees = [{fieldName: 'common', totalFee: getValue(src, ['_金额']) || '0'}];
  843. }
  844. return obj;
  845. });
  846. }
  847. //根据费用类别、配比类比获取人材机类别(后端匹配不到标准人材机的时候用)
  848. function getGljTypeData(feeType, ratioType, name) {
  849. let map = {
  850. '-': {type: 201, shortName: '材'},
  851. '1-': {type: 1, shortName: '人'},
  852. '2-': {type: 201, shortName: '材'},
  853. '2-1': {type: 202, shortName: '砼'},
  854. '2-2': {type: 205, shortName: '商砼'},
  855. '2-3': {type: 203, shortName: '浆'},
  856. '2-4': {type: 206, shortName: '商浆'},
  857. '2-5': {type: 204, shortName: '配比'},
  858. '3-': {type: 301, shortName: '机'},
  859. '4-': {type: 4, shortName: '主'},
  860. };
  861. let nameMap = {
  862. '柴油': {type: 305, shortName: '动'},
  863. '柴油(机械用)': {type: 305, shortName: '动'},
  864. '柴油(机械用)': {type: 305, shortName: '动'},
  865. '汽油': {type: 305, shortName: '动'},
  866. '汽油(机械用)': {type: 305, shortName: '动'},
  867. '汽油(机械用)': {type: 305, shortName: '动'},
  868. '电': {type: 305, shortName: '动'},
  869. '电(机械用)': {type: 305, shortName: '动'},
  870. '电(机械用)': {type: 305, shortName: '动'},
  871. '机上人工': {type: 303, shortName: '机人'},
  872. };
  873. if (feeType === '3' && nameMap[name]) {
  874. return nameMap[name] || null;
  875. }
  876. return map[`${feeType}-${ratioType}`] || null;
  877. }
  878. //主要材料类别-三材类别映射、、
  879. const MaterialMap = {
  880. '100': 1, //钢材钢筋认为钢材,因为文件没细分
  881. '200': 4, //水泥
  882. '300': 3, //木材
  883. '400': 5 //商品砼
  884. };
  885. //人材机汇总
  886. function loadGljSummary(tenderSrc) {
  887. let gljsSrc = arrayValue(tenderSrc, ['人材机汇总', '人材机']);
  888. return gljsSrc.map(gljSrc => {
  889. countData.projectGLJCount++;
  890. //编码都取原始编码,如果原始编码为空,都取编码
  891. let orgCode = getValue(gljSrc, ['_原始代码']),
  892. code = getValue(gljSrc, ['_代码']);
  893. if (!orgCode) {
  894. orgCode = code;
  895. }
  896. let gljData = {
  897. customCode: code, //处理自定义的代码 (有的公司定额人材机代码、人材机代码是用自动生成的代码)
  898. code: orgCode,
  899. original_code: orgCode,
  900. name: getValue(gljSrc, ['_名称']),
  901. specs: getValue(gljSrc, ['_规格']),
  902. unit: getValue(gljSrc, ['_单位']),
  903. supply: getValue(gljSrc, ['_供应方式']) == '2' ? 2 : 0, //不是完全甲供就取自行采购
  904. is_evaluate: getValue(gljSrc, ['_暂估材料标志']) === 'true' ? true : false,
  905. no_tax_eqp: getValue(gljSrc, ['_不计税设备标志']) === 'true' ? true : false,
  906. base_price: getValue(gljSrc, ['_定额价']),
  907. market_price: getValue(gljSrc, ['_市场价']),
  908. originPlace: getValue(gljSrc, ['_产地']),
  909. vender: getValue(gljSrc, ['_厂家']),
  910. qualityGrace: getValue(gljSrc, ['_质量等级']),
  911. brand: getValue(gljSrc, ['_品牌']),
  912. remark: getValue(gljSrc, ['_备注'])
  913. };
  914. if (MaterialMap[getValue(gljSrc, ['_主要材料类别'])]) {
  915. gljData.materialType = MaterialMap[getValue(gljSrc, ['_主要材料类别'])];
  916. gljData.materialCoe = getValue(gljSrc, ['_主要材料单位系数']);
  917. }
  918. let typeData = getGljTypeData(getValue(gljSrc, ['_费用类别']), getValue(gljSrc, ['_配比类别']), gljData.name);
  919. if (typeData) {
  920. gljData.type = typeData.type;
  921. gljData.shortName = typeData.shortName;
  922. }
  923. //人材机配比
  924. let ratioSrc = arrayValue(gljSrc, ['人材机配比']);
  925. gljData.ratios = ratioSrc.map(rSrc => {
  926. countData.ratioCount++;
  927. return {
  928. code: getValue(rSrc, ['_明细材料代码']),
  929. consumption: getValue(rSrc, ['_数量'])
  930. }
  931. });
  932. return gljData;
  933. });
  934. }
  935. //承包人材料差额法表
  936. function loadDifferentiaSummary(tenderSrc) {
  937. let gljsSrc = arrayValue(tenderSrc, ['承包人材料差额法表', '承包人材料差额法明细']);
  938. return gljsSrc.map(gljSrc => {
  939. return {
  940. code: getValue(gljSrc, ['_关联材料号']),
  941. riskCoe: getValue(gljSrc, ['_风险系数']),
  942. standardPrice: getValue(gljSrc, ['_基准单价']),
  943. remark: getValue(gljSrc, ['_备注']),
  944. };
  945. });
  946. }
  947. //承包人材料指数法表
  948. function loadExponentialSummary(tenderSrc) {
  949. let gljsSrc = arrayValue(tenderSrc, ['承包人材料指数法表', '承包人材料指数法明细']);
  950. return gljsSrc.map(gljSrc => {
  951. return {
  952. code: getValue(gljSrc, ['_关联材料号']),
  953. varWeight: getValue(gljSrc, ['_变值权重B']),
  954. FO: getValue(gljSrc, ['_基本价格指数']),
  955. FI: getValue(gljSrc, ['_现行价格指数']),
  956. remark: getValue(gljSrc, ['_备注']),
  957. };
  958. });
  959. }
  960. //评标材料
  961. function loadEvalBidSummary(tenderSrc) {
  962. let gljsSrc = arrayValue(tenderSrc, ['评标材料表', '材料明细']);
  963. return gljsSrc.map(gljSrc => {
  964. return {code: getValue(gljSrc, ['_关联材料号'])};
  965. });
  966. }
  967. //-------------------------提取数据后的数据处理
  968. function getFlag(data) {
  969. return data.flags && data.flags[0] && data.flags[0].flag || 0;
  970. }
  971. //获取人材机调整法(差额法还是指数法)
  972. function getAdjustType(tenderData) {
  973. //如果承包人材料指数法里,所有数据的,变值权重B、基本价额指数,现行价格指数全为0,则为指数法,否则为差额法
  974. let isCoe = tenderData.exponentialSummary.length && tenderData.exponentialSummary.every(data =>
  975. !(data.varWeight === '0' && data.FO === '0' && data.FI === '0')
  976. );
  977. return isCoe ? AdjustType.coe : AdjustType.info;
  978. }
  979. let toMatches = [
  980. {reg: /分部分项/, flag: fixedFlag.SUB_ENGINERRING},
  981. {reg: /^措施项目/, flag: fixedFlag.MEASURE},
  982. {reg: /技术措施/, flag: fixedFlag.CONSTRUCTION_TECH},
  983. {reg: /组织措施/, flag: fixedFlag.CONSTRUCTION_ORGANIZATION},
  984. {reg: /组织措施/, flag: fixedFlag.CONSTRUCTION_ORGANIZATION},
  985. {reg: /安全文明/, flag: fixedFlag.SAFETY_CONSTRUCTION},
  986. {reg: /其他项目/, flag: fixedFlag.OTHER},
  987. {reg: /暂列金额/, flag: fixedFlag.PROVISIONAL},
  988. {reg: /暂估价/, flag: fixedFlag.ESTIMATE},
  989. {reg: /计日工/, flag: fixedFlag.DAYWORK},
  990. {reg: /总承包服务/, flag: fixedFlag.TURN_KEY_CONTRACT},
  991. {reg: /索赔(?:及|与|和)现场签证/, flag: fixedFlag.TURN_KEY_CONTRACT},
  992. {reg: /规费/, flag: fixedFlag.CHARGE},
  993. {reg: /税金/, flag: fixedFlag.TAX},
  994. {reg: /增值税/, flag: fixedFlag.ADDED_VALUE_TAX},
  995. {reg: /^附加税/, flag: fixedFlag.ADDITIONAL_TAX},
  996. {reg: /环境保护税/, flag: fixedFlag.ENVIRONMENTAL_PROTECTION_TAX},
  997. {reg: /(?:合\s*价)|(?:工程造价)/, flag: fixedFlag.ENGINEERINGCOST},
  998. ];
  999. //处理单位工程费用汇总的清单,这一部分没有靠谱的规则,特殊处理并添加相关清单
  1000. function setupFeeSummary(feeSummary, needfulTemplate) {
  1001. let preDXFY = null, //记录上一条添加的大项费用
  1002. preSubTax = null; //记录上一条添加的附加税子项(特殊处理城市xx、教育xx附加...名称的清单)
  1003. let addtionalTax = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.ADDITIONAL_TAX), //附加税
  1004. engineeringCost = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.ENGINEERINGCOST); //工程造价
  1005. for (let feeBills of feeSummary) {
  1006. //匹配固定的附加税子项
  1007. if (addtionalTax &&
  1008. (/城市维护建设/.test(feeBills.name) ||
  1009. /教育费附加/.test(feeBills.name) ||
  1010. /地方教育附加/.test(feeBills.name))
  1011. ) {
  1012. let subTaxData ={
  1013. ID: uuid.v1(),
  1014. ParentID: addtionalTax.ID,
  1015. NextSiblingID: -1,
  1016. name: feeBills.name,
  1017. rowCode: feeBills.rowCode,
  1018. feeRate: feeBills.feeRate,
  1019. };
  1020. if (importFileKind === FileKind.tender) {
  1021. //subTaxData.rowCode = feeBills.rowCode;
  1022. subTaxData.fees = feeBills.fees;
  1023. }
  1024. if (preSubTax) {
  1025. preSubTax.NextSiblingID = subTaxData.ID;
  1026. }
  1027. needfulTemplate.push(subTaxData);
  1028. preSubTax = subTaxData;
  1029. } else { //匹配固定项
  1030. let isMatched = false;
  1031. //匹配固定项
  1032. for (let match of toMatches) {
  1033. if (!match.reg.test(feeBills.name)) {
  1034. continue;
  1035. }
  1036. let findBills = needfulTemplate.find(nData => getFlag(nData) === match.flag);
  1037. if (!findBills) {
  1038. //如果模板中没有安全文明施工费,计价汇总行中安全文明施工费,将其设置为组织清单子项
  1039. if (/安全文明施工/.test(feeBills.name)) {
  1040. let fixedCSXM = needfulTemplate.find(nData => getFlag(nData) === fixedFlag.CONSTRUCTION_ORGANIZATION);
  1041. if (fixedCSXM) {
  1042. needfulTemplate.push({
  1043. ID: uuid.v1(),
  1044. ParentID: fixedCSXM.ID,
  1045. NextSiblingID: -1,
  1046. name: feeBills.name,
  1047. calcBase: feeBills.calcBase,
  1048. feeRate: feeBills.feeRate,
  1049. });
  1050. isMatched = true;
  1051. break; //不添加到大项费用
  1052. }
  1053. }
  1054. continue;
  1055. }
  1056. isMatched = true;
  1057. findBills.calcBase = feeBills.calcBase;
  1058. findBills.feeRate = feeBills.feeRate;
  1059. findBills.rowCode = feeBills.rowCode;
  1060. //后台配置的feeRateID优先级比feeRate高,导入数据有费率值时,需要清空这个配置
  1061. if (findBills.feeRate && parseFloat(findBills.feeRate) !== 0) {
  1062. findBills.feeRateID = null;
  1063. }
  1064. if (importFileKind === FileKind.tender) {
  1065. //findBills.rowCode = feeBills.rowCode;
  1066. findBills.fees = feeBills.fees;
  1067. }
  1068. break;
  1069. }
  1070. //匹配不到固定项,认为是大项费用
  1071. if (!isMatched) {
  1072. let dxfyData = {
  1073. ID: uuid.v1(),
  1074. ParentID: -1,
  1075. NextSiblingID: -1,
  1076. name: feeBills.name,
  1077. rowCode: feeBills.rowCode,
  1078. calcBase: feeBills.calcBase,
  1079. feeRate: feeBills.feeRate,
  1080. };
  1081. if (importFileKind === FileKind.tender) {
  1082. //dxfyData.rowCode = feeBills.rowCode;
  1083. dxfyData.fees = feeBills.fees;
  1084. }
  1085. if (!preDXFY) {
  1086. preDXFY = engineeringCost;
  1087. }
  1088. preDXFY.NextSiblingID = dxfyData.ID;
  1089. needfulTemplate.push(dxfyData);
  1090. preDXFY = dxfyData;
  1091. }
  1092. }
  1093. }
  1094. }
  1095. //处理、添加清单
  1096. function setupBills(tenderData, billsTarget) {
  1097. //规费和税金 这个地方不靠谱,先特殊处理(无法兼容所有情况)
  1098. //1.如果在清单中出现(匹配名称相关关键字),则更新数据
  1099. //2.否则新增(在税金出现前,全作为规费的子清单,否则作为税金子清单)
  1100. let charge = null,
  1101. tax = null,
  1102. additionalTax = null;
  1103. for (let i = 0; i < tenderData.chargeTax.length; i++) {
  1104. let curBills = tenderData.chargeTax[i];
  1105. let matchBills = billsTarget.find(d => (d.rowCode && d.rowCode === curBills.rowCode) || d.name === curBills.name);
  1106. //匹配到,更新
  1107. if (matchBills) {
  1108. if (getFlag(matchBills) === fixedFlag.CHARGE) {
  1109. charge = matchBills;
  1110. } else if (getFlag(matchBills) === fixedFlag.TAX) {
  1111. tax = matchBills;
  1112. } else if (getFlag(matchBills) === fixedFlag.ADDITIONAL_TAX) {
  1113. additionalTax = matchBills;
  1114. }
  1115. matchBills.calcBase = curBills.calcBase;
  1116. matchBills.feeRate = curBills.feeRate;
  1117. matchBills.fees = curBills.fees || [];
  1118. matchBills.rowCode = curBills.rowCode;
  1119. if (curBills.flags && curBills.flags.length) {
  1120. matchBills.flags = curBills.flags;
  1121. }
  1122. } else { //新增
  1123. if (!charge && !tax) {
  1124. continue;
  1125. }
  1126. //存在规费,还未找到税金,后面数据作为规费的子项 已找到税金,后面数据作为税金子项
  1127. let curParent = !tax ? charge : tax;
  1128. //特殊处理"城市维护建设税" "教育费附加" "地方教育附加",这三项固定设为税金下附加税的子项
  1129. if (additionalTax &&
  1130. (/城市维护建设/.test(curBills.name) ||
  1131. /教育费附加/.test(curBills.name) ||
  1132. /地方教育附加/.test(curBills.name))) {
  1133. curParent = additionalTax;
  1134. }
  1135. curBills.ID = uuid.v1();
  1136. curBills.NextSiblingID = -1;
  1137. curBills.ParentID = curParent.ID;
  1138. let pre = billsTarget.find(d => d.ParentID === curParent.ID && d.NextSiblingID === -1);
  1139. if (pre) {
  1140. pre.NextSiblingID = curBills.ID;
  1141. }
  1142. billsTarget.push(curBills);
  1143. if (!additionalTax && /^附加税/.test(curBills.name)) {
  1144. additionalTax = curBills;
  1145. }
  1146. }
  1147. }
  1148. //分部分项
  1149. addFixedBlock(fixedFlag.SUB_ENGINERRING, tenderData.fbfx);
  1150. //措施项目
  1151. addFixedBlock(fixedFlag.MEASURE, null, tenderData.csxm.fees);
  1152. //组织措施 //特殊处理子项
  1153. //需要添加的组织措施子项
  1154. function updateZZCSItem(org, tar) {
  1155. for(let [k, v] of Object.entries(tar)) {
  1156. // 如果匹配到的清单自身已有固定ID,不更新固定ID
  1157. if (k === 'flags' && Array.isArray(tar.flags) && tar.flags.length) {
  1158. continue;
  1159. }
  1160. org[k] = v;
  1161. }
  1162. }
  1163. let zzcsSubs = [];
  1164. let fixedOrganization = billsTarget.find(data => /组织措施费/.test(data.name)),
  1165. fixedSafe = billsTarget.find(data => /安全文明/.test(data.name)),
  1166. fixedProjectComplete = billsTarget.find(data => /建设工程竣工档案编制/.test(data.name)),
  1167. fixedHouseQuality = billsTarget.find(data => /住宅工程质量分户验收/.test(data.name)),
  1168. fixedZZCS = billsTarget.find(data => getFlag(data) === fixedFlag.CONSTRUCTION_ORGANIZATION),
  1169. lastItem = billsTarget.find(data => data.ParentID === fixedZZCS.ID && data.NextSiblingID === -1);
  1170. for (let item of tenderData.csxm.zzcs.items) {
  1171. if (/组织措施费/.test(item.name) && fixedOrganization) {
  1172. updateZZCSItem(fixedOrganization, item);
  1173. } else if (/安全文明/.test(item.name) && fixedSafe) {
  1174. updateZZCSItem(fixedSafe, item);
  1175. } else if (/建设工程竣工档案/.test(item.name) && fixedProjectComplete) {
  1176. updateZZCSItem(fixedProjectComplete, item);
  1177. } else if (/住宅工程质量分户验收/.test(item.name) && fixedHouseQuality) {
  1178. updateZZCSItem(fixedHouseQuality, item);
  1179. } else {
  1180. zzcsSubs.push(item);
  1181. }
  1182. }
  1183. addFixedBlock(fixedFlag.CONSTRUCTION_ORGANIZATION, zzcsSubs, tenderData.csxm.zzcs.fees);
  1184. //更新原本的最后一个节点
  1185. if (zzcsSubs.length && lastItem) {
  1186. lastItem.NextSiblingID = zzcsSubs[0].ID;
  1187. }
  1188. //技术措施
  1189. addFixedBlock(fixedFlag.CONSTRUCTION_TECH, tenderData.csxm.jscs.items, tenderData.csxm.jscs.fees);
  1190. //暂列金额
  1191. addFixedBlock(fixedFlag.PROVISIONAL, tenderData.other.provisional.items, tenderData.other.provisional.fees);
  1192. //专业工程暂估价
  1193. addFixedBlock(fixedFlag.ENGINEERING_ESITIMATE, tenderData.other.engineeringPro.items, tenderData.other.engineeringPro.fees);
  1194. //计日工
  1195. addFixedBlock(fixedFlag.DAYWORK, null, tenderData.other.dayWork.fees);
  1196. //人工
  1197. addFixedBlock(fixedFlag.LABOUR, tenderData.other.dayWork.labour);
  1198. //材料
  1199. addFixedBlock(fixedFlag.MATERIAL,tenderData.other.dayWork.material);
  1200. //机械
  1201. addFixedBlock(fixedFlag.MACHINE, tenderData.other.dayWork.machine);
  1202. //总承包服务费
  1203. addFixedBlock(fixedFlag.TURN_KEY_CONTRACT, tenderData.other.service.items, tenderData.other.service.fees);
  1204. //索赔
  1205. addFixedBlock(fixedFlag.CLAIM, tenderData.other.claim.items, tenderData.other.claim.fees);
  1206. //签证
  1207. addFixedBlock(fixedFlag.VISA, tenderData.other.visa.items, tenderData.other.visa.fees);
  1208. //其他
  1209. if (tenderData.other.others.items.length) {
  1210. //特殊处理材料(工程设备暂估价)
  1211. let materialProIdx = tenderData.other.others.items.findIndex(item => item.name === '材料(工程设备)暂估价');
  1212. if (~materialProIdx) {
  1213. let materialPro = tenderData.other.others.items.splice(materialProIdx, 1)[0];
  1214. let fixedMaterialPro = billsTarget.find(data => getFlag(data) === fixedFlag.MATERIAL_PROVISIONAL);
  1215. if (fixedMaterialPro) {
  1216. fixedMaterialPro.fees = materialPro.fees;
  1217. fixedMaterialPro.feeRate = materialPro.feeRate;
  1218. fixedMaterialPro.calcBase = materialPro.calcBase;
  1219. }
  1220. }
  1221. if (tenderData.other.others.items.length) {
  1222. let othersParent = {
  1223. ID: uuid.v1(),
  1224. NextSiblingID: -1,
  1225. name: '其他',
  1226. fees: tenderData.other.others.fees || []
  1227. };
  1228. addFixedBlock(fixedFlag.OTHER, [othersParent]);
  1229. addFixedBlock(othersParent, tenderData.other.others.items);
  1230. }
  1231. }
  1232. //删掉有feeRate的feeRateID
  1233. billsTarget.forEach(data => {
  1234. if (data.feeRate) {
  1235. data.feeRateID = null;
  1236. }
  1237. });
  1238. function addFixedBlock(flag, items, fees = null) {
  1239. let fixedBills = flag;
  1240. if (typeof flag === 'number') {
  1241. fixedBills = billsTarget.find(d => getFlag(d) === flag);
  1242. }
  1243. if (fixedBills) {
  1244. if (fees) {
  1245. fixedBills.fees = fees || [];
  1246. }
  1247. if (Array.isArray(items) && items.length) {
  1248. addBills(fixedBills.ID, items);
  1249. }
  1250. }
  1251. }
  1252. //设置清单的ID数据并添加清单到目标数组
  1253. function addBills(parentID, items) {
  1254. for (let i = 0; i < items.length; i++) {
  1255. let curBills = items[i],
  1256. preBills = items[i - 1];
  1257. curBills.ID = uuid.v1();
  1258. curBills.ParentID = parentID;
  1259. curBills.NextSiblingID = -1;
  1260. if (preBills) {
  1261. preBills.NextSiblingID = curBills.ID;
  1262. }
  1263. billsTarget.push(curBills);
  1264. if (curBills.items && curBills.items.length) {
  1265. addBills(curBills.ID, curBills.items);
  1266. }
  1267. }
  1268. }
  1269. }
  1270. //计算基数字典
  1271. const CalcBaseMap = {
  1272. FBFXHJ: '{分部分项工程费}',
  1273. RGF: '{分部分项定额人工费}',
  1274. CLF: '{分部分项定额材料费}',
  1275. JXF: '{分部分项定额施工机具使用费}',
  1276. ZCF: '{分部分项主材费}',
  1277. GR: '{分部分项人工工日}',
  1278. CSXMHJ: '{措施项目费}',
  1279. ZZCSF: '{组织措施项目费}',
  1280. JSCSF: '{技术措施项目费}',
  1281. JSCS_RGF: '{技术措施项目定额人工费}',
  1282. JSCS_CLF: '{技术措施项目定额材料费}',
  1283. JSCS_JXF: '{技术措施项目定额施工机具使用费}',
  1284. JSCS_ZCF: '{技术措施项目主材费}',
  1285. JSCS_GR: '{技术措施项目人工工日}',
  1286. JZMZ: '{建筑面积}',
  1287. RCJJC: '{人材机价差}',
  1288. RGJC: '{人工价差}',
  1289. CLJC: '{材料价差}',
  1290. JXJC: '{机械价差}',
  1291. JRGLF: '{甲供人工费}',
  1292. JGCLF: '{甲供材料费}',
  1293. JGJXF: '{甲供施工机具使用费}',
  1294. JGZCF: '{甲供主材费}',
  1295. FBF: '{分包费}',
  1296. FBRGF: '{分包定额人工费}',
  1297. FBCLF: '{分包定额材料费}',
  1298. FBJXF: '{分包定额机械费}',
  1299. FBZCF: '{分包主材费}',
  1300. FBSBF: '{分包设备费}',
  1301. FBGR: '{分包人工工日}',
  1302. QTXMHJ: '{其他项目费}',
  1303. GF: '{规费}',
  1304. SJ: '{税金}',
  1305. SJHJ: '{税金}',
  1306. };
  1307. //转换计算基数
  1308. //1.有子项数据,则清空基数
  1309. //2.行代号引用转换为ID引用
  1310. //3.对应字典代号转换,对应字典里找不到则设置成金额
  1311. function transformCalcBase(billsData) {
  1312. //行代号 - ID映射
  1313. let rowCodeMap = {};
  1314. billsData.forEach(data => {
  1315. if (data.rowCode) {
  1316. rowCodeMap[data.rowCode] = data.ID;
  1317. }
  1318. });
  1319. for (let bills of billsData) {
  1320. if (!bills.calcBase) {
  1321. continue;
  1322. }
  1323. let sub = billsData.find(data => data.ParentID === bills.ID);
  1324. //有子项数据,则清空基数,费率
  1325. if (sub) {
  1326. bills.calcBase = '';
  1327. bills.feeRate = '';
  1328. continue;
  1329. }
  1330. //提取基数
  1331. bills.calcBase = bills.calcBase.replace(/\s/g, '');
  1332. let bases = bills.calcBase.split(/[\+\-\*\/]/g);
  1333. //提取操作符
  1334. let oprs = bills.calcBase.match(/[\+\-\*\/]/g);
  1335. //转换后的基数
  1336. let newBase = [];
  1337. let illegal = false; //不合法
  1338. for (let base of bases) {
  1339. if (rowCodeMap[base]) { //行引用
  1340. newBase.push(`@${rowCodeMap[base]}`);
  1341. } else if (CalcBaseMap[base]) { //基数字典
  1342. newBase.push(CalcBaseMap[base]);
  1343. } else { //都没匹配到,说明软件无法识别此基数
  1344. illegal = true;
  1345. break;
  1346. }
  1347. };
  1348. if (illegal) {
  1349. let fee = getFee(bills.fees, ['common', 'totalFee']);
  1350. let feeRate = bills.feeRate && parseFloat(bills.feeRate) !== 0 ? parseFloat(bills.feeRate) : 0;
  1351. if (fee && parseFloat(fee) !== 0 && feeRate) {
  1352. bills.calcBase = scMathUtil.roundForObj(parseFloat(fee) * 100 / feeRate, 2);
  1353. } else {
  1354. bills.calcBase = fee !== '0' ? fee : '';
  1355. }
  1356. } else {
  1357. let newCalcBase = '';
  1358. for (let i = 0; i < newBase.length; i++) {
  1359. newCalcBase += newBase[i];
  1360. if (oprs && oprs[i]) {
  1361. newCalcBase += oprs[i];
  1362. }
  1363. }
  1364. bills.calcBase = newCalcBase;
  1365. }
  1366. }
  1367. }
  1368. //从xml文件中提取数据
  1369. this.extractData = async (file, escape = false) => {
  1370. //将二进制文件转换成字符串
  1371. let xmlStr = await readAsTextSync(file);
  1372. //将xml格式良好的字符串转换成对象
  1373. let x2js = new X2JS();
  1374. if (escape) {
  1375. xmlStr = escapeXMLEntity(xmlStr);
  1376. }
  1377. let xmlObj = x2js.xml_str2json(xmlStr);
  1378. xmlObj = JSON.parse(restoreXMLEntity(JSON.stringify(xmlObj)));
  1379. if (!xmlObj) {
  1380. throw '无有效数据。';
  1381. }
  1382. //console.log(xmlObj);
  1383. //提取数据
  1384. return loadProject(xmlObj);
  1385. };
  1386. //把数据转换成适应项目的数据
  1387. this.transformData = async (xmlObj) => {
  1388. //获取占位ID数据
  1389. countData.unitPriceCount = countData.projectGLJCount;
  1390. if (importFileKind !== FileKind.tender) {
  1391. countData = {
  1392. projectCount: countData.projectCount,
  1393. unitPriceFileCount: countData.unitPriceFileCount
  1394. };
  1395. }
  1396. let IDPlaceholder = await ajaxPost('/pm/import/getProjectPlaceholder', countData);
  1397. xmlObj.ID = IDPlaceholder.project++;
  1398. //获取到的转换后的最终上传数据
  1399. let postConstructData = {
  1400. ID: xmlObj.ID,
  1401. ParentID: xmlObj.ParentID,
  1402. NextSiblingID: xmlObj.NextSiblingID,
  1403. preID: xmlObj.preID,
  1404. name: xmlObj.name,
  1405. basicInformation: xmlObj.basicInformation,
  1406. projType: xmlObj.projType,
  1407. property: xmlObj.property,
  1408. shareInfo: [],
  1409. engs: []
  1410. };
  1411. for (let i = 0; i < xmlObj.engs.length; i++) {
  1412. let curEng = xmlObj.engs[i],
  1413. preEng = postConstructData.engs[i - 1];
  1414. curEng.ID = IDPlaceholder.project++;
  1415. curEng.ParentID = xmlObj.ID;
  1416. curEng.NextSiblingID = -1;
  1417. if (preEng) {
  1418. preEng.NextSiblingID = curEng.ID;
  1419. }
  1420. let postEngData = {
  1421. ID: curEng.ID,
  1422. ParentID: curEng.ParentID,
  1423. NextSiblingID: curEng.NextSiblingID,
  1424. code: curEng.code,
  1425. name: curEng.name,
  1426. projType: curEng.projType,
  1427. shareInfo: [],
  1428. tenders: []
  1429. };
  1430. postConstructData.engs.push(postEngData);
  1431. for (let j = 0; j < curEng.tenders.length; j++) {
  1432. let curTender = curEng.tenders[j],
  1433. preTender = postEngData.tenders[j - 1];
  1434. curTender.ID = IDPlaceholder.project++;
  1435. curTender.ParentID = curEng.ID;
  1436. curTender.NextSiblingID = -1;
  1437. curTender.property.unitPriceFile.id = IDPlaceholder.unitPriceFile++;
  1438. if (preTender) {
  1439. preTender.tender.NextSiblingID = curTender.ID;
  1440. }
  1441. //提取详细数据
  1442. let postTenderData = await transformTender(curTender, IDPlaceholder);
  1443. postTenderData.tender.property.rootProjectID = postConstructData.ID;
  1444. postEngData.tenders.push(postTenderData);
  1445. }
  1446. }
  1447. //console.log(postConstructData);
  1448. return postConstructData;
  1449. };
  1450. //转换单位工程的数据(直接可插入数据库的数据),返回{tender: {}, bills: [], ration: [], rationGLJ: [], projectGLJ: [], unitPrice: [], mixRatio: []}
  1451. async function transformTender(tenderData, IDPlaceholder) {
  1452. let detailData = await transformBills(tenderData, IDPlaceholder);
  1453. //提取需要插入的单位工程数据
  1454. let tender = {
  1455. ID: tenderData.ID,
  1456. ParentID: tenderData.ParentID,
  1457. NextSiblingID: tenderData.NextSiblingID,
  1458. code: tenderData.code,
  1459. name: tenderData.name,
  1460. projType: tenderData.projType,
  1461. property: tenderData.property,
  1462. projectFeature: tenderData.projectFeature,
  1463. engineering: tenderData.engineering,
  1464. defaultRationLib: tenderData.defaultRationLib,
  1465. rationLibIDs: tenderData.rationLibIDs,
  1466. gljLibIDs: tenderData.gljLibIDs,
  1467. shareInfo: []
  1468. };
  1469. tender.property.gljAdjustType = getAdjustType(tenderData);
  1470. detailData.tender = tender;
  1471. return detailData;
  1472. }
  1473. //转换清单数据
  1474. async function transformBills(tenderData, IDPlaceholder) {
  1475. //获取清单模板数据
  1476. let needfulTemplate = await ajaxPost('/template/bills/api/getNeedfulTemplate',
  1477. {templateLibID: tenderData.property.templateLibID});
  1478. //处理单位工程费用汇总的清单,这一部分没有靠谱的规则,特殊处理。
  1479. setupFeeSummary(tenderData.feeSummary, needfulTemplate);
  1480. //处理添加清单数据
  1481. setupBills(tenderData, needfulTemplate);
  1482. //转换清单基数表达式
  1483. transformCalcBase(needfulTemplate);
  1484. //转换提取需要插入的详细数据
  1485. let detailData = transformDetail(tenderData, needfulTemplate, IDPlaceholder);
  1486. //console.log(detailData);
  1487. return detailData;
  1488. }
  1489. //提取转换后的定额、定额人材机、人材机汇总、单价文件、组成物数据
  1490. function transformDetail(tenderData, billsData, IDPlaceholder) {
  1491. let rst = {
  1492. bills: [], //清单
  1493. ration: [], //定额
  1494. rationGLJ: [], //定额人材机
  1495. rationCoe: [], //定额系数,全为默认
  1496. projectGLJ: [], //项目人材机
  1497. unitPrice: [], //单价文件
  1498. mixRatio: [] //组成物
  1499. };
  1500. //工料机汇总code-数据映射
  1501. // 项目人材机customCode、original_code-原始数据映射,有的导入数据中,有一部分关联自生成材料号CX,有的关联原始代码...
  1502. // 因此customCode、original_code都需要跟原始数据映射,通过customCode取不到数据的时候,通过orgCode获取
  1503. let projectGLJMap = {};
  1504. //投标文件才需要导入定额等数据
  1505. if (importFileKind === FileKind.tender) {
  1506. tenderData.gljSummary.forEach(pGLJ => {
  1507. pGLJ.project_id = tenderData.ID;
  1508. pGLJ.id = IDPlaceholder.projectGLJ++;
  1509. //gljCodeMap[pGLJ.code] = pGLJ;
  1510. projectGLJMap[pGLJ.customCode] = pGLJ;
  1511. projectGLJMap[pGLJ.original_code] = pGLJ;
  1512. });
  1513. //处理项目人材机数据
  1514. tenderData.gljSummary.forEach(pGLJ => {
  1515. //组成物数据
  1516. pGLJ.ratios.forEach(ratio => {
  1517. let matchData = projectGLJMap[ratio.code];
  1518. ratio.code = matchData.original_code;
  1519. ratio.projectGLJID = pGLJ.id; //后端查找标准数据后,方便更新组成物数据
  1520. ratio.id = IDPlaceholder.ratio++;
  1521. ratio.unit_price_file_id = tenderData.property.unitPriceFile.id;
  1522. ratio.unit = matchData ? matchData.unit : '';
  1523. ratio.name = matchData ? matchData.name : '';
  1524. ratio.specs = matchData ? matchData.specs : '';
  1525. ratio.type = matchData ? matchData.type : 1;
  1526. ratio.connect_key = [pGLJ.original_code || 'null', pGLJ.name || 'null', pGLJ.specs || 'null', pGLJ.unit || 'null', pGLJ.type].join('|-|');
  1527. rst.mixRatio.push(ratio);
  1528. });
  1529. delete pGLJ.ratios;
  1530. rst.projectGLJ.push(pGLJ);
  1531. //单价文件数据
  1532. rst.unitPrice.push(getUnitPrice(pGLJ));
  1533. });
  1534. //处理评标材料
  1535. tenderData.evalBidSummary.forEach(glj => {
  1536. let pGLJ = projectGLJMap[glj.code];
  1537. if (pGLJ) {
  1538. pGLJ.is_eval_material = true;
  1539. }
  1540. });
  1541. //处理承包人材料差额法表
  1542. tenderData.differentiaSummary.forEach(glj => {
  1543. let pGLJ = projectGLJMap[glj.code];
  1544. if (pGLJ) {
  1545. pGLJ.is_info_adjust = 1;
  1546. pGLJ.riskCoe = glj.riskCoe;
  1547. pGLJ.standardPrice = glj.standardPrice;
  1548. pGLJ.remark = glj.remark;
  1549. }
  1550. });
  1551. //处理承包人材料指数法表
  1552. tenderData.exponentialSummary.forEach(glj => {
  1553. let pGLJ = projectGLJMap[glj.code];
  1554. if (pGLJ) {
  1555. pGLJ.is_coe_adjust = 1;
  1556. pGLJ.varWeight = glj.varWeight;
  1557. pGLJ.FO = glj.FO;
  1558. pGLJ.FI = glj.FI;
  1559. pGLJ.remark = glj.remark;
  1560. }
  1561. });
  1562. //处理定额数据
  1563. //获取含有定额数据的清单
  1564. handleRation(billsData);
  1565. }
  1566. //处理清单 设置必要数据 删除无用属性
  1567. billsData.forEach(bills => {
  1568. //处理综合单价
  1569. //1.没有子清单,且没有综合单价,则综合单价=综合合价/工程量
  1570. let children = billsData.find(data => data.ParentID === bills.ID),
  1571. unitFee = getFee(bills.fees, ['common', 'unitFee']),
  1572. totalFee = getFee(bills.fees, ['common', 'totalFee']);
  1573. if (!children && !parseFloat(unitFee) && totalFee && parseFloat(totalFee)) {
  1574. //不存工程量
  1575. if (!bills.quantity || !parseFloat(bills.quantity)) {
  1576. unitFee = totalFee;
  1577. //源不存在工程量,没有计算基数、但是却有综合合价,工程量要设置为1
  1578. if (!bills.calcBase) {
  1579. bills.quantity = '1';
  1580. }
  1581. } else {
  1582. //综合合价的小数位数
  1583. let totalFeeDecimal = totalFee.match(/\.\d+/);
  1584. unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, totalFeeDecimal
  1585. ? totalFeeDecimal[0] : 0);
  1586. }
  1587. let commonFee = bills.fees.find(fee => fee.fieldName === 'common');
  1588. if (commonFee) {
  1589. commonFee.unitFee = unitFee;
  1590. }
  1591. }
  1592. bills.projectID = tenderData.ID;
  1593. bills.quantityEXP = bills.quantity;
  1594. delete bills.items;
  1595. delete bills.rations;
  1596. rst.bills.push(bills);
  1597. });
  1598. return rst;
  1599. function handleRation(billsData) {
  1600. let billsHasRations = billsData.filter(bills => Array.isArray(bills.rations) && bills.rations.length);
  1601. billsHasRations.forEach(bills => {
  1602. //处理定额
  1603. bills.rations.forEach(ration => {
  1604. // 定额的取费专业在定额库默认为空的话,取定额取费专业
  1605. // 如果是量价、与定额同级的人材机,则取单位工程取费专业
  1606. ration.programID = ration.type === RationType.ration
  1607. ? tenderData.property.engineering
  1608. : tenderData.property.projectEngineering;
  1609. ration.ID = uuid.v1();
  1610. ration.projectID = tenderData.ID;
  1611. ration.billsItemID = bills.ID;
  1612. //含量:定额工程量/清单工程量
  1613. if (!bills.quantity || !ration.quantity){
  1614. ration.contain = '0';
  1615. } else {
  1616. ration.contain = scMathUtil.roundForObj(ration.quantity / bills.quantity, 6);
  1617. }
  1618. //工程量表达式:工程量 * 单位前的量
  1619. /*if (!ration.unit) {
  1620. ration.quantityEXP = ration.quantity;
  1621. } else {
  1622. let unitNum = ration.unit.match(/^\d+/);
  1623. //工程量小数位数
  1624. let qDecimal = ration.quantity.match(/\.\d+/);
  1625. ration.quantityEXP = unitNum
  1626. ? scMathUtil.roundForObj(ration.quantity * unitNum[0], qDecimal ? qDecimal[0] - 1 : 0)
  1627. : ration.quantity;
  1628. }*/
  1629. //处理定额人材机,添加需要的数据
  1630. ration.rationGljs.forEach(rGLJ => {
  1631. let matchGLJ = projectGLJMap[rGLJ.code];
  1632. if (matchGLJ) {
  1633. rGLJ.projectGLJID = matchGLJ.id;
  1634. rGLJ.code = matchGLJ.original_code;
  1635. rGLJ.type = matchGLJ.type;
  1636. rGLJ.shortName = matchGLJ.shortName;
  1637. rGLJ.name = matchGLJ.name;
  1638. rGLJ.original_code = matchGLJ.original_code;
  1639. rGLJ.unit = matchGLJ.unit;
  1640. rGLJ.specs = matchGLJ.specs;
  1641. }
  1642. rGLJ.ID = uuid.v1();
  1643. rGLJ.projectID = tenderData.ID;
  1644. rGLJ.billsItemID = bills.ID;
  1645. rGLJ.rationID = ration.ID;
  1646. rGLJ.rationCode = ration.code; //暂时跟定额编码关联,后端好匹配标准数据
  1647. rGLJ.rationItemQuantity = rGLJ.quantity; //定额消耗,暂时取消耗量,需要后端匹配标准数据后更新
  1648. rst.rationGLJ.push(rGLJ);
  1649. });
  1650. delete ration.rationGljs;
  1651. rst.ration.push(ration);
  1652. rst.rationCoe.push(getRationCoe(ration));
  1653. });
  1654. });
  1655. }
  1656. function getRationCoe(ration) {
  1657. return {
  1658. projectID: ration.projectID,
  1659. rationID: ration.ID,
  1660. coeID: -1,
  1661. ID: uuid.v1(),
  1662. seq: 1, //以前排序有的字段,暂时没什么用,不过还是赋上一个值
  1663. name: '自定义系数',
  1664. content: '人工×1,材料×1,机械×1,主材×1,设备×1',
  1665. coes: [
  1666. {amount: 1, operator: '*', gljCode: null, coeType: '定额'},
  1667. {amount: 1, operator: '*', gljCode: null, coeType: '人工'},
  1668. {amount: 1, operator: '*', gljCode: null, coeType: '材料'},
  1669. {amount: 1, operator: '*', gljCode: null, coeType: '机械'},
  1670. {amount: 1, operator: '*', gljCode: null, coeType: '主材'},
  1671. {amount: 1, operator: '*', gljCode: null, coeType: '设备'},
  1672. ],
  1673. option_list: []
  1674. }
  1675. }
  1676. function getUnitPrice(projectGLJ) {
  1677. return {
  1678. projectGLJID: projectGLJ.id, //做个标记,后端查找标准数据后,方便更新组成物数据
  1679. unit_price_file_id: tenderData.property.unitPriceFile.id,
  1680. id: IDPlaceholder.unitPrice++,
  1681. code: projectGLJ.code,
  1682. original_code: projectGLJ.original_code,
  1683. name: projectGLJ.name,
  1684. unit: projectGLJ.unit,
  1685. specs: projectGLJ.specs,
  1686. type: projectGLJ.type,
  1687. short_name: projectGLJ.shortName,
  1688. base_price: projectGLJ.base_price,
  1689. market_price: projectGLJ.market_price
  1690. };
  1691. }
  1692. }
  1693. };
  1694. })();