importStandardInterface.js 76 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574
  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. addFixedBlock(fixedFlag.CONSTRUCTION_ORGANIZATION, zzcsSubs, tenderData.csxm.zzcs.fees);
  1061. //更新原本的最后一个节点
  1062. if (zzcsSubs.length && lastItem) {
  1063. lastItem.NextSiblingID = zzcsSubs[0].ID;
  1064. }
  1065. //技术措施
  1066. addFixedBlock(fixedFlag.CONSTRUCTION_TECH, tenderData.csxm.jscs.items, tenderData.csxm.jscs.fees);
  1067. //暂列金额
  1068. addFixedBlock(fixedFlag.PROVISIONAL, tenderData.other.provisional.items, tenderData.other.provisional.fees);
  1069. //专业工程暂估价
  1070. addFixedBlock(fixedFlag.ENGINEERING_ESITIMATE, tenderData.other.engineeringPro.items, tenderData.other.engineeringPro.fees);
  1071. //计日工
  1072. addFixedBlock(fixedFlag.DAYWORK, null, tenderData.other.dayWork.fees);
  1073. //人工
  1074. addFixedBlock(fixedFlag.LABOUR, tenderData.other.dayWork.labour);
  1075. //材料
  1076. addFixedBlock(fixedFlag.MATERIAL,tenderData.other.dayWork.material);
  1077. //机械
  1078. addFixedBlock(fixedFlag.MACHINE, tenderData.other.dayWork.machine);
  1079. //总承包服务费
  1080. addFixedBlock(fixedFlag.TURN_KEY_CONTRACT, tenderData.other.service.items, tenderData.other.service.fees);
  1081. //索赔
  1082. addFixedBlock(fixedFlag.CLAIM, tenderData.other.claim.items, tenderData.other.claim.fees);
  1083. //签证
  1084. addFixedBlock(fixedFlag.VISA, tenderData.other.visa.items, tenderData.other.visa.fees);
  1085. //其他
  1086. if (tenderData.other.others.items.length) {
  1087. //特殊处理材料(工程设备暂估价)
  1088. let materialProIdx = tenderData.other.others.items.findIndex(item => item.name === '材料(工程设备)暂估价');
  1089. if (~materialProIdx) {
  1090. let materialPro = tenderData.other.others.items.splice(materialProIdx, 1)[0];
  1091. let fixedMaterialPro = billsTarget.find(data => getFlag(data) === fixedFlag.MATERIAL_PROVISIONAL);
  1092. if (fixedMaterialPro) {
  1093. fixedMaterialPro.fees = materialPro.fees;
  1094. fixedMaterialPro.feeRate = materialPro.feeRate;
  1095. fixedMaterialPro.calcBase = materialPro.calcBase;
  1096. }
  1097. }
  1098. if (tenderData.other.others.items.length) {
  1099. let othersParent = {
  1100. ID: uuid.v1(),
  1101. NextSiblingID: -1,
  1102. name: '其他',
  1103. fees: tenderData.other.others.fees || []
  1104. };
  1105. addFixedBlock(fixedFlag.OTHER, [othersParent]);
  1106. addFixedBlock(othersParent, tenderData.other.others.items);
  1107. }
  1108. }
  1109. //删掉有feeRate的feeRateID
  1110. billsTarget.forEach(data => {
  1111. if (data.feeRate) {
  1112. data.feeRateID = null;
  1113. }
  1114. });
  1115. function addFixedBlock(flag, items, fees = null) {
  1116. let fixedBills = flag;
  1117. if (typeof flag === 'number') {
  1118. fixedBills = billsTarget.find(d => getFlag(d) === flag);
  1119. }
  1120. if (fixedBills) {
  1121. if (fees) {
  1122. fixedBills.fees = fees || [];
  1123. }
  1124. if (Array.isArray(items) && items.length) {
  1125. addBills(fixedBills.ID, items);
  1126. }
  1127. }
  1128. }
  1129. //设置清单的ID数据并添加清单到目标数组
  1130. function addBills(parentID, items) {
  1131. for (let i = 0; i < items.length; i++) {
  1132. let curBills = items[i],
  1133. preBills = items[i - 1];
  1134. curBills.ID = uuid.v1();
  1135. curBills.ParentID = parentID;
  1136. curBills.NextSiblingID = -1;
  1137. if (preBills) {
  1138. preBills.NextSiblingID = curBills.ID;
  1139. }
  1140. billsTarget.push(curBills);
  1141. if (curBills.items && curBills.items.length) {
  1142. addBills(curBills.ID, curBills.items);
  1143. }
  1144. }
  1145. }
  1146. }
  1147. //计算基数字典
  1148. const CalcBaseMap = {
  1149. FBFXHJ: '{分部分项工程费}',
  1150. RGF: '{分部分项定额人工费}',
  1151. CLF: '{分部分项定额材料费}',
  1152. JXF: '{分部分项定额施工机具使用费}',
  1153. ZCF: '{分部分项主材费}',
  1154. GR: '{分部分项人工工日}',
  1155. CSXMHJ: '{措施项目费}',
  1156. ZZCSF: '{组织措施项目费}',
  1157. JSCSF: '{技术措施项目费}',
  1158. JSCS_RGF: '{技术措施项目定额人工费}',
  1159. JSCS_CLF: '{技术措施项目定额材料费}',
  1160. JSCS_JXF: '{技术措施项目定额施工机具使用费}',
  1161. JSCS_ZCF: '{技术措施项目主材费}',
  1162. JSCS_GR: '{技术措施项目人工工日}',
  1163. JZMZ: '{建筑面积}',
  1164. RCJJC: '{人材机价差}',
  1165. RGJC: '{人工价差}',
  1166. CLJC: '{材料价差}',
  1167. JXJC: '{机械价差}',
  1168. JRGLF: '{甲供人工费}',
  1169. JGCLF: '{甲供材料费}',
  1170. JGJXF: '{甲供施工机具使用费}',
  1171. JGZCF: '{甲供主材费}',
  1172. FBF: '{分包费}',
  1173. FBRGF: '{分包定额人工费}',
  1174. FBCLF: '{分包定额材料费}',
  1175. FBJXF: '{分包定额机械费}',
  1176. FBZCF: '{分包主材费}',
  1177. FBSBF: '{分包设备费}',
  1178. FBGR: '{分包人工工日}',
  1179. QTXMHJ: '{其他项目费}',
  1180. GF: '{规费}',
  1181. SJ: '{税金}',
  1182. SJHJ: '{税金}',
  1183. };
  1184. //转换计算基数
  1185. //1.有子项数据,则清空基数
  1186. //2.行代号引用转换为ID引用
  1187. //3.对应字典代号转换,对应字典里找不到则设置成金额
  1188. function transformCalcBase(billsData) {
  1189. //行代号 - ID映射
  1190. let rowCodeMap = {};
  1191. billsData.forEach(data => {
  1192. if (data.rowCode) {
  1193. rowCodeMap[data.rowCode] = data.ID;
  1194. }
  1195. });
  1196. for (let bills of billsData) {
  1197. if (!bills.calcBase) {
  1198. continue;
  1199. }
  1200. let sub = billsData.find(data => data.ParentID === bills.ID);
  1201. //有子项数据,则清空基数,费率
  1202. if (sub) {
  1203. bills.calcBase = '';
  1204. bills.feeRate = '';
  1205. continue;
  1206. }
  1207. //提取基数
  1208. bills.calcBase = bills.calcBase.replace(/\s/g, '');
  1209. let bases = bills.calcBase.split(/[\+\-\*\/]/g);
  1210. //提取操作符
  1211. let oprs = bills.calcBase.match(/[\+\-\*\/]/g);
  1212. //转换后的基数
  1213. let newBase = [];
  1214. let illegal = false; //不合法
  1215. for (let base of bases) {
  1216. if (rowCodeMap[base]) { //行引用
  1217. newBase.push(`@${rowCodeMap[base]}`);
  1218. } else if (CalcBaseMap[base]) { //基数字典
  1219. /*illegal = true;
  1220. break;*/
  1221. newBase.push(CalcBaseMap[base]);
  1222. } else { //都没匹配到,说明软件无法识别此基数
  1223. illegal = true;
  1224. break;
  1225. }
  1226. };
  1227. if (illegal) {
  1228. let fee = getFee(bills.fees, ['common', 'totalFee']);
  1229. let feeRate = bills.feeRate && parseFloat(bills.feeRate) !== 0 ? parseFloat(bills.feeRate) : 0;
  1230. if (fee && parseFloat(fee) !== 0 && feeRate) {
  1231. bills.calcBase = scMathUtil.roundForObj(parseFloat(fee) * 100 / feeRate, 2);
  1232. } else {
  1233. bills.calcBase = fee !== '0' ? fee : '';
  1234. }
  1235. } else {
  1236. let newCalcBase = '';
  1237. for (let i = 0; i < newBase.length; i++) {
  1238. newCalcBase += newBase[i];
  1239. if (oprs && oprs[i]) {
  1240. newCalcBase += oprs[i];
  1241. }
  1242. }
  1243. bills.calcBase = newCalcBase;
  1244. }
  1245. }
  1246. }
  1247. //从xml文件中提取数据
  1248. this.extractData = async (file) => {
  1249. //将二进制文件转换成字符串
  1250. let xmlStr = await readAsTextSync(file);
  1251. //将xml格式良好的字符串转换成对象
  1252. let x2js = new X2JS();
  1253. let xmlObj = x2js.xml_str2json(xmlStr);
  1254. if (!xmlObj) {
  1255. throw '无有效数据。';
  1256. }
  1257. //console.log(xmlObj);
  1258. //提取数据
  1259. return loadProject(xmlObj);
  1260. };
  1261. //把数据转换成适应项目的数据
  1262. this.transformData = async (xmlObj) => {
  1263. //获取占位ID数据
  1264. countData.unitPriceCount = countData.projectGLJCount;
  1265. if (importFileKind !== FileKind.tender) {
  1266. countData = {
  1267. projectCount: countData.projectCount,
  1268. unitPriceFileCount: countData.unitPriceFileCount
  1269. };
  1270. }
  1271. let IDPlaceholder = await ajaxPost('/pm/import/getProjectPlaceholder', countData);
  1272. xmlObj.ID = IDPlaceholder.project++;
  1273. //获取到的转换后的最终上传数据
  1274. let postConstructData = {
  1275. ID: xmlObj.ID,
  1276. ParentID: xmlObj.ParentID,
  1277. NextSiblingID: xmlObj.NextSiblingID,
  1278. preID: xmlObj.preID,
  1279. name: xmlObj.name,
  1280. basicInformation: xmlObj.basicInformation,
  1281. projType: xmlObj.projType,
  1282. property: xmlObj.property,
  1283. shareInfo: [],
  1284. engs: []
  1285. };
  1286. for (let i = 0; i < xmlObj.engs.length; i++) {
  1287. let curEng = xmlObj.engs[i],
  1288. preEng = postConstructData.engs[i - 1];
  1289. curEng.ID = IDPlaceholder.project++;
  1290. curEng.ParentID = xmlObj.ID;
  1291. curEng.NextSiblingID = -1;
  1292. if (preEng) {
  1293. preEng.NextSiblingID = curEng.ID;
  1294. }
  1295. let postEngData = {
  1296. ID: curEng.ID,
  1297. ParentID: curEng.ParentID,
  1298. NextSiblingID: curEng.NextSiblingID,
  1299. code: curEng.code,
  1300. name: curEng.name,
  1301. projType: curEng.projType,
  1302. shareInfo: [],
  1303. tenders: []
  1304. };
  1305. postConstructData.engs.push(postEngData);
  1306. for (let j = 0; j < curEng.tenders.length; j++) {
  1307. let curTender = curEng.tenders[j],
  1308. preTender = postEngData.tenders[j - 1];
  1309. curTender.ID = IDPlaceholder.project++;
  1310. curTender.ParentID = curEng.ID;
  1311. curTender.NextSiblingID = -1;
  1312. curTender.property.unitPriceFile.id = IDPlaceholder.unitPriceFile++;
  1313. if (preTender) {
  1314. preTender.tender.NextSiblingID = curTender.ID;
  1315. }
  1316. //提取详细数据
  1317. let postTenderData = await transformTender(curTender, IDPlaceholder);
  1318. postTenderData.tender.property.rootProjectID = postConstructData.ID;
  1319. postEngData.tenders.push(postTenderData);
  1320. }
  1321. }
  1322. //console.log(postConstructData);
  1323. return postConstructData;
  1324. };
  1325. //转换单位工程的数据(直接可插入数据库的数据),返回{tender: {}, bills: [], ration: [], rationGLJ: [], projectGLJ: [], unitPrice: [], mixRatio: []}
  1326. async function transformTender(tenderData, IDPlaceholder) {
  1327. let detailData = await transformBills(tenderData, IDPlaceholder);
  1328. //提取需要插入的单位工程数据
  1329. let tender = {
  1330. ID: tenderData.ID,
  1331. ParentID: tenderData.ParentID,
  1332. NextSiblingID: tenderData.NextSiblingID,
  1333. code: tenderData.code,
  1334. name: tenderData.name,
  1335. projType: tenderData.projType,
  1336. property: tenderData.property,
  1337. projectFeature: tenderData.projectFeature,
  1338. engineering: tenderData.engineering,
  1339. defaultRationLib: tenderData.defaultRationLib,
  1340. rationLibIDs: tenderData.rationLibIDs,
  1341. gljLibIDs: tenderData.gljLibIDs,
  1342. shareInfo: []
  1343. };
  1344. tender.property.gljAdjustType = getAdjustType(tenderData);
  1345. detailData.tender = tender;
  1346. return detailData;
  1347. }
  1348. //转换清单数据
  1349. async function transformBills(tenderData, IDPlaceholder) {
  1350. //获取清单模板数据
  1351. let needfulTemplate = await ajaxPost('/template/bills/api/getNeedfulTemplate',
  1352. {templateLibID: tenderData.property.templateLibID});
  1353. //处理单位工程费用汇总的清单,这一部分没有靠谱的规则,特殊处理。
  1354. setupFeeSummary(tenderData.feeSummary, needfulTemplate);
  1355. //处理添加清单数据
  1356. setupBills(tenderData, needfulTemplate);
  1357. //转换清单基数表达式
  1358. transformCalcBase(needfulTemplate);
  1359. //转换提取需要插入的详细数据
  1360. let detailData = transformDetail(tenderData, needfulTemplate, IDPlaceholder);
  1361. //console.log(detailData);
  1362. return detailData;
  1363. }
  1364. //提取转换后的定额、定额人材机、人材机汇总、单价文件、组成物数据
  1365. function transformDetail(tenderData, billsData, IDPlaceholder) {
  1366. let rst = {
  1367. bills: [], //清单
  1368. ration: [], //定额
  1369. rationGLJ: [], //定额人材机
  1370. rationCoe: [], //定额系数,全为默认
  1371. projectGLJ: [], //项目人材机
  1372. unitPrice: [], //单价文件
  1373. mixRatio: [] //组成物
  1374. };
  1375. //工料机汇总code-数据映射
  1376. //项目人材机customCode-原始代码数据映射
  1377. let projectGLJMap = {};
  1378. //投标文件才需要导入定额等数据
  1379. if (importFileKind === FileKind.tender) {
  1380. tenderData.gljSummary.forEach(pGLJ => {
  1381. pGLJ.project_id = tenderData.ID;
  1382. pGLJ.id = IDPlaceholder.projectGLJ++;
  1383. //gljCodeMap[pGLJ.code] = pGLJ;
  1384. projectGLJMap[pGLJ.customCode] = pGLJ;
  1385. });
  1386. //处理项目人材机数据
  1387. tenderData.gljSummary.forEach(pGLJ => {
  1388. //组成物数据
  1389. pGLJ.ratios.forEach(ratio => {
  1390. let matchData = projectGLJMap[ratio.code];
  1391. ratio.code = matchData.original_code;
  1392. ratio.projectGLJID = pGLJ.id; //后端查找标准数据后,方便更新组成物数据
  1393. ratio.id = IDPlaceholder.ratio++;
  1394. ratio.unit_price_file_id = tenderData.property.unitPriceFile.id;
  1395. ratio.unit = matchData ? matchData.unit : '';
  1396. ratio.name = matchData ? matchData.name : '';
  1397. ratio.specs = matchData ? matchData.specs : '';
  1398. ratio.type = matchData ? matchData.type : 1;
  1399. ratio.connect_key = [pGLJ.original_code || 'null', pGLJ.name || 'null', pGLJ.specs || 'null', pGLJ.unit || 'null', pGLJ.type].join('|-|');
  1400. rst.mixRatio.push(ratio);
  1401. });
  1402. delete pGLJ.ratios;
  1403. rst.projectGLJ.push(pGLJ);
  1404. //单价文件数据
  1405. rst.unitPrice.push(getUnitPrice(pGLJ));
  1406. });
  1407. //处理评标材料
  1408. tenderData.evalBidSummary.forEach(glj => {
  1409. let pGLJ = projectGLJMap[glj.code];
  1410. if (pGLJ) {
  1411. pGLJ.is_eval_material = true;
  1412. }
  1413. });
  1414. //处理承包人材料差额法表
  1415. tenderData.differentiaSummary.forEach(glj => {
  1416. let pGLJ = projectGLJMap[glj.code];
  1417. if (pGLJ) {
  1418. pGLJ.is_info_adjust = 1;
  1419. pGLJ.riskCoe = glj.riskCoe;
  1420. pGLJ.standardPrice = glj.standardPrice;
  1421. pGLJ.remark = glj.remark;
  1422. }
  1423. });
  1424. //处理承包人材料指数法表
  1425. tenderData.exponentialSummary.forEach(glj => {
  1426. let pGLJ = projectGLJMap[glj.code];
  1427. if (pGLJ) {
  1428. pGLJ.is_coe_adjust = 1;
  1429. pGLJ.varWeight = glj.varWeight;
  1430. pGLJ.FO = glj.FO;
  1431. pGLJ.FI = glj.FI;
  1432. pGLJ.remark = glj.remark;
  1433. }
  1434. });
  1435. //处理定额数据
  1436. //获取含有定额数据的清单
  1437. handleRation(billsData);
  1438. }
  1439. //处理清单 设置必要数据 设置无用属性
  1440. billsData.forEach(bills => {
  1441. //处理综合单价
  1442. //1.没有子清单,且没有综合单价,则综合单价=综合合价/工程量
  1443. let children = billsData.find(data => data.ParentID === bills.ID),
  1444. unitFee = getFee(bills.fees, ['common', 'unitFee']),
  1445. totalFee = getFee(bills.fees, ['common', 'totalFee']);
  1446. if (!children && !parseFloat(unitFee) && totalFee && parseFloat(totalFee)) {
  1447. //不存工程量
  1448. if (!bills.quantity || !parseFloat(bills.quantity)) {
  1449. unitFee = totalFee;
  1450. //源不存在工程量,没有计算基数、但是却有综合合价,工程量要设置为1
  1451. if (!bills.calcBase) {
  1452. bills.quantity = '1';
  1453. }
  1454. } else {
  1455. //综合合价的小数位数
  1456. let totalFeeDecimal = totalFee.match(/\.\d+/);
  1457. unitFee = scMathUtil.roundForObj(totalFee / bills.quantity, totalFeeDecimal
  1458. ? totalFeeDecimal[0] : 0);
  1459. }
  1460. let commonFee = bills.fees.find(fee => fee.fieldName === 'common');
  1461. if (commonFee) {
  1462. commonFee.unitFee = unitFee;
  1463. }
  1464. }
  1465. bills.projectID = tenderData.ID;
  1466. bills.quantityEXP = bills.quantity;
  1467. delete bills.items;
  1468. delete bills.rations;
  1469. rst.bills.push(bills);
  1470. });
  1471. return rst;
  1472. function handleRation(billsData) {
  1473. let billsHasRations = billsData.filter(bills => Array.isArray(bills.rations) && bills.rations.length);
  1474. billsHasRations.forEach(bills => {
  1475. //处理定额
  1476. bills.rations.forEach(ration => {
  1477. ration.programID = tenderData.property.projectEngineering; //默认取单位工程取费类别,后台匹配到标准的再设置
  1478. ration.ID = uuid.v1();
  1479. ration.projectID = tenderData.ID;
  1480. ration.billsItemID = bills.ID;
  1481. //含量:定额工程量/清单工程量
  1482. if (!bills.quantity || !ration.quantity){
  1483. ration.contain = '0';
  1484. } else {
  1485. ration.contain = scMathUtil.roundForObj(ration.quantity / bills.quantity, 6);
  1486. }
  1487. //工程量表达式:工程量 * 单位前的量
  1488. if (!ration.unit) {
  1489. ration.quantityEXP = ration.quantity;
  1490. } else {
  1491. let unitNum = ration.unit.match(/^\d+/);
  1492. //工程量小数位数
  1493. let qDecimal = ration.quantity.match(/\.\d+/);
  1494. ration.quantityEXP = unitNum
  1495. ? scMathUtil.roundForObj(ration.quantity * unitNum[0], qDecimal ? qDecimal[0] - 1 : 0)
  1496. : ration.quantity;
  1497. }
  1498. //处理定额人材机,添加需要的数据
  1499. ration.rationGljs.forEach(rGLJ => {
  1500. let matchGLJ = projectGLJMap[rGLJ.code];
  1501. if (matchGLJ) {
  1502. rGLJ.projectGLJID = matchGLJ.id;
  1503. rGLJ.code = matchGLJ.original_code;
  1504. rGLJ.type = matchGLJ.type;
  1505. rGLJ.shortName = matchGLJ.shortName;
  1506. rGLJ.name = matchGLJ.name;
  1507. rGLJ.original_code = matchGLJ.original_code;
  1508. rGLJ.unit = matchGLJ.unit;
  1509. rGLJ.specs = matchGLJ.specs;
  1510. }
  1511. rGLJ.ID = uuid.v1();
  1512. rGLJ.projectID = tenderData.ID;
  1513. rGLJ.billsItemID = bills.ID;
  1514. rGLJ.rationID = ration.ID;
  1515. rGLJ.rationCode = ration.code; //暂时跟定额编码关联,后端好匹配标准数据
  1516. rGLJ.rationItemQuantity = rGLJ.quantity; //定额消耗,暂时取消耗量,需要后端匹配标准数据后更新
  1517. rst.rationGLJ.push(rGLJ);
  1518. });
  1519. delete ration.rationGljs;
  1520. rst.ration.push(ration);
  1521. rst.rationCoe.push(getRationCoe(ration));
  1522. });
  1523. });
  1524. }
  1525. function getRationCoe(ration) {
  1526. return {
  1527. projectID: ration.projectID,
  1528. rationID: ration.ID,
  1529. coeID: -1,
  1530. ID: uuid.v1(),
  1531. seq: 1, //以前排序有的字段,暂时没什么用,不过还是赋上一个值
  1532. name: '自定义系数',
  1533. content: '人工×1,材料×1,机械×1,主材×1,设备×1',
  1534. coes: [
  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. {amount: 1, operator: '*', gljCode: null, coeType: '设备'},
  1541. ],
  1542. option_list: []
  1543. }
  1544. }
  1545. function getUnitPrice(projectGLJ) {
  1546. return {
  1547. projectGLJID: projectGLJ.id, //做个标记,后端查找标准数据后,方便更新组成物数据
  1548. unit_price_file_id: tenderData.property.unitPriceFile.id,
  1549. id: IDPlaceholder.unitPrice++,
  1550. code: projectGLJ.code,
  1551. original_code: projectGLJ.original_code,
  1552. name: projectGLJ.name,
  1553. unit: projectGLJ.unit,
  1554. specs: projectGLJ.specs,
  1555. type: projectGLJ.type,
  1556. short_name: projectGLJ.shortName,
  1557. base_price: projectGLJ.base_price,
  1558. market_price: projectGLJ.market_price
  1559. };
  1560. }
  1561. }
  1562. };
  1563. })();