importStandardInterface.js 76 KB

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