importStandardInterface.js 76 KB

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