exportStandardInterface.js 88 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Zhong
  6. * @date 2019/3/15
  7. * @version
  8. */
  9. /*
  10. * 数据标准接口
  11. * 导出符合标准接口要求的xml
  12. * */
  13. const XMLStandard = (function () {
  14. return function (userID, granularity) {
  15. this.GRANULARITY = {
  16. PROJECT: 1, //导出建设项目
  17. ENGINEERING: 2, //导出单项工程
  18. TENDER: 3 //导出单位工程
  19. };
  20. //默认导出建设项目
  21. if (!granularity || ![1, 2, 3].includes(granularity)) {
  22. granularity = this.GRANULARITY.PROJECT;
  23. }
  24. //属性类型
  25. const TYPE = {
  26. DATE: 1, //日期类型YYYY-MM-DD
  27. DATE_TIME: 2, //日期类型YYY-MM-DDTHH:mm:ss
  28. INT: 3, //整数类型
  29. DECIMAL: 4, //数值类型,不限制小数位数
  30. NUM2: 5, //数值类型2:最多两位小数
  31. BOOL: 6 //布尔型
  32. };
  33. const WHITE_SPACE = {
  34. COLLAPSE: 1 //移除所有空白字符(换行、回车、空格以及制表符会被替换为空格,开头和结尾的空格会被移除,而多个连续的空格会被缩减为一个单一的空格)
  35. };
  36. //加载数据间隔,减少服务器压力
  37. const TIMEOUT_TIME = 500;
  38. function isDef(v) {
  39. return typeof v !== 'undefined' && v !== null;
  40. }
  41. /*
  42. * 检查
  43. * 创建节点时检查节点的数据
  44. * 1.长度限制minLen,maxLen
  45. * 2.值的限制,固定范围:enumeration
  46. * @param {Array}datas(需要检查的属性数据)
  47. * @return {Object} failHints没通过的属性提示 filterAttrs过滤后的属性数据(失败提示在属性是必须的时候才提示,如果该属性失败了,但是是非必要属性,那么该属性不显示)
  48. * */
  49. function check(datas) {
  50. let rst = {failHints: [], filterAttrs: []};
  51. let dateReg = /([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8])))/;
  52. for (let data of datas) {
  53. data.value = typeof data.value === 'undefined' || data.value === null ? '' : data.value.toString();
  54. if (data.whiteSpace && data.whiteSpace === WHITE_SPACE.COLLAPSE) { //处理空格相关
  55. data.value = data.value.replace(/[\r,\n,\t]/g, ' ');
  56. data.value = data.value.trim();
  57. data.value = data.value.replace(/\s{1,}/g, ' ');
  58. }
  59. if (!data.value && !data.minLen && !data.enumeration) { //值为空,且没有限制最小字符数,且没有限制值,则不需判断
  60. rst.filterAttrs.push(data);
  61. continue;
  62. }
  63. let isFail = false;
  64. if (data.minLen && data.value.length < data.minLen){
  65. isFail = true;
  66. rst.failHints.push(`“${data.name}”字符数不可小于${data.minLen}个`);
  67. } else if (data.maxLen && data.value.length > data.maxLen) {
  68. isFail = true;
  69. rst.failHints.push(`“${data.name}”字符数不可大于${data.maxLen}个`);
  70. } else if (data.enumeration && !data.enumeration.includes(data.value)) {
  71. isFail = true;
  72. rst.failHints.push(`“${data.name}”只能从“${data.enumeration.join(';')}”中选择`);
  73. } else if (data.type && data.type === TYPE.DATE && !dateReg.test(data.value)) {
  74. isFail = true;
  75. rst.push(`“${data.name}”日期格式必须是YYYY-MM-DD`);
  76. } else if (data.type && data.type === TYPE.INT && !Number.isInteger(parseFloat(data.value))) {
  77. isFail = true;
  78. rst.failHints.push(`“${data.name}”必须为整数`);
  79. } else if (data.type && data.type === TYPE.DECIMAL && isNaN(parseFloat(data.value))) {
  80. isFail = true;
  81. rst.failHints.push(`“${data.name}”必须为数值`)
  82. } else if (data.type && data.type === TYPE.NUM2) {
  83. let v = parseFloat(data.value);
  84. if (isNaN(v)) {
  85. isFail = true;
  86. rst.failHints.push(`“${data.name}”必须为数值`);
  87. } else if (!data.value.length || (data.value.split('.').length > 1 && data.value.split('.')[1].length > 2)){
  88. isFail = true;
  89. rst.failHints.push(`“${data.name}”小数位数不得多于两位`);
  90. }
  91. } else if (data.type && data.type === TYPE.BOOL && !['true', 'false'].includes(data.value.toString())) {
  92. isFail = true;
  93. rst.failHints.push(`“${data.name}”必须为true或false`);
  94. }
  95. if (!isFail || data.required) {
  96. rst.filterAttrs.push(data);
  97. }
  98. }
  99. return rst;
  100. }
  101. //从fees数组中获取相关费用
  102. function getFee(fees, feeFields) {
  103. if (!fees) {
  104. return 0;
  105. }
  106. let fields = feeFields.split('.');
  107. let fee = fees.find(data => data.fieldName === fields[0]);
  108. if (!fee) {
  109. return 0;
  110. }
  111. return fee[fields[1]] || 0;
  112. }
  113. //根据字段获取基本信息、工程特征
  114. function getValueByKey(data, key) {
  115. for (let d of data) {
  116. if (d.key === key) {
  117. return d.value;
  118. }
  119. if (d.items && d.items.length > 0) {
  120. let findData = d.items.find(x => x.key === key);
  121. if (findData) {
  122. return findData.value;
  123. }
  124. }
  125. }
  126. return '';
  127. }
  128. //造成导出失败
  129. let failList = [];
  130. /*
  131. * 定义不设置一个Node方法统一进入的原因:模板化比较直观,不分开定义节点的话,调用传参也很麻烦而且不直观。
  132. * 一个节点对应一个构造方法,方便调整配置、方便其他版本开发、接手的人看起来更直观
  133. * @param {String}name(节点名) {Array}attrs(节点属性数据)
  134. * @return {void}
  135. * */
  136. function element(name, attrs) {
  137. this.name = name;
  138. let checkData = check(attrs);
  139. this.fail = checkData.failHints;
  140. this.attrs = checkData.filterAttrs;
  141. this.children = [];
  142. for (let fail of this.fail) {
  143. failList.push(`${name}-${fail}`);
  144. }
  145. }
  146. //建设项目定义
  147. //source:来源数据
  148. function Project(source) {
  149. let attrs = [
  150. {name: '项目编号', value: getValueByKey(source.basicInformation, 'projNumber'), required: true, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE},
  151. {name: '项目名称', value: source.name, required: true, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE},
  152. {name: '建设单位', value: getValueByKey(source.basicInformation, 'constructionUnit'), required: true},
  153. {name: '标准版本号', value: '3.2.2', required: true},
  154. {name: '标准名称', value: '重庆造价软件数据交换标准(清单计价)', required: true,},
  155. {name: '文件类型', value: getValueByKey(source.basicInformation, 'fileKind'), required: true, enumeration: ['招标', '投标', '控制价', '结算', '其他']},
  156. {name: '计税方法', value: 'todo', required: true},
  157. ];
  158. //唯一约束
  159. this.constraints = {
  160. engCode: [], //单项工程编号
  161. tenderCode: [], //单位工程编号
  162. };
  163. element.call(this, '标段', attrs);
  164. }
  165. //项目信息定义
  166. function ProjectInfo(source) {
  167. let attrs = [
  168. {name: '工程规模', value: getValueByKey(source.basicInformation, 'projectScale'), required: true},
  169. {name: '工程所在地', value: getValueByKey(source.basicInformation, 'projLocation'), required: true},
  170. {name: '工程地址', value: getValueByKey(source.basicInformation, 'projAddress'), required: true},
  171. {name: '施工单位', value: getValueByKey(source.basicInformation, 'buildingUnit')},
  172. {name: '编制单位', value: getValueByKey(source.basicInformation, 'establishmentUnit'), required: true},
  173. {name: '审核单位', value: getValueByKey(source.basicInformation, 'auditUnit')},
  174. {name: '编制人', value: getValueByKey(source.basicInformation, 'buildingUnitAuthor'), required: true},
  175. {name: '审核人', value: 'todo'},
  176. {name: '开工日期', value: getValueByKey(source.basicInformation, 'commencementDate'), type: TYPE.DATE},
  177. {name: '竣工日期', value: getValueByKey(source.basicInformation, 'completionDate'), type: TYPE.DATE},
  178. {name: '编制日期', value: getValueByKey(source.basicInformation, 'establishDate'), type: TYPE.DATE, required: true},
  179. {name: '审核日期', value: getValueByKey(source.basicInformation, 'auditDate'), type: TYPE.DATE},
  180. {name: '材料价格期', value: getValueByKey(source.basicInformation, 'materialPricePeriod'), required: true},
  181. {name: '合同价类型', value: getValueByKey(source.basicInformation, 'contractPriceType')},
  182. ];
  183. element.call(this, '项目信息', attrs);
  184. }
  185. //招标信息定义
  186. function BiddingInfo(source) {
  187. let attrs = [
  188. {name: '招标代理机构', value: getValueByKey(source.basicInformation, 'tenderingAgency')},
  189. {name: '造价工程师', value: getValueByKey(source.basicInformation, 'tenderCostEngineer'), required: true},
  190. {name: '造价工程师注册证号', value: getValueByKey(source.basicInformation, 'tenderCostEngineerNo'), required: true},
  191. {name: '招标工期', value: getValueByKey(source.basicInformation, 'tenderPeriod'), required: true, type: TYPE.INT},
  192. {name: '控制总价', value: source.summaryInfo.engineeringCost, required: true, type: TYPE.NUM2},
  193. ];
  194. element.call(this, '招标信息', attrs);
  195. }
  196. //投标信息定义
  197. function BidInfo(source) {
  198. let attrs = [
  199. {name: '投标人', value: getValueByKey(source.basicInformation, 'bidder'), required: true},
  200. {name: '造价工程师', value: getValueByKey(source.basicInformation, 'bidCostEngineer'), required: true},
  201. {name: '造价工程师注册证号', value: getValueByKey(source.basicInformation, 'bidCostEngineerNo'), required: true},
  202. {name: '项目经理', value: getValueByKey(source.basicInformation, 'projectManager')},
  203. {name: '投标工期', value: getValueByKey(source.basicInformation, 'biddingPeriod')},
  204. {name: '投标保证金', value: getValueByKey(source.basicInformation, 'biddingMargin'), type: TYPE.NUM2},
  205. {name: '质量承诺', value: getValueByKey(source.basicInformation, 'qualityCommitment')},
  206. {name: '担保类型', value: getValueByKey(source.basicInformation, 'guaranteeType')},
  207. {name: '投标总价', value: source.summaryInfo.engineeringCost, required: true, type: TYPE.NUM2},
  208. ];
  209. element.call(this, '投标信息', attrs);
  210. }
  211. //编制说明定义
  212. function CompilationIllustration(source) {
  213. let attrs = [
  214. {name: '内容', value: source.compilationIllustration, required: true},
  215. ];
  216. element.call(this, '编制说明', attrs);
  217. }
  218. //系统信息定义
  219. function SystemInfo(source) {
  220. let attrs = [
  221. {name: 'ID1', value: source.softInfo, required: true},
  222. {name: 'ID2', value: '', required: true},
  223. {name: '生成时间', value: source.generatedTime, type: TYPE.DATE_TIME, required: true},
  224. ];
  225. element.call(this, '系统信息', attrs);
  226. }
  227. //费用构成定义
  228. function FeeFrom(summaryInfo) {
  229. let attrs = [
  230. {name: '工程费合计', value: summaryInfo.engineeringCost, required: true, type: TYPE.NUM2},
  231. {name: '分部分项清单合计', value: summaryInfo.subEngineering, required: true, type: TYPE.NUM2},
  232. {name: '措施项目清单合计', value: summaryInfo.measure, required: true, type: TYPE.NUM2},
  233. {name: '安全文明施工专项费', value: summaryInfo.safetyConstruction, required: true, type: TYPE.NUM2},
  234. {name: '其他项目清单合计', value: summaryInfo.other, required: true, type: TYPE.NUM2},
  235. {name: '规费', value: summaryInfo.charge, required: true, type: TYPE.NUM2},
  236. {name: '税金', value: summaryInfo.tax, required: true, type: TYPE.NUM2},
  237. ];
  238. element.call(this, '费用构成', attrs);
  239. }
  240. //单项工程定义
  241. function Engineering(source) {
  242. let attrs = [
  243. {name: '编号', value: source.code, required: true, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE},
  244. {name: '名称', value: source.name, required: true, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE},
  245. {name: '金额', value: source.summaryInfo.engineeringCost, type: TYPE.NUM2},
  246. ];
  247. element.call(this, '单项工程', attrs);
  248. }
  249. //单位工程定义
  250. function Tender(source) {
  251. const TAX = {
  252. 1: '一般计税',
  253. 2: '简易计税'
  254. };
  255. let attrs = [
  256. {name: '编号', value: source.code, required: true, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE},
  257. {name: '名称', value: source.name, required: true, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE},
  258. {name: '专业', value: source.engineeringName, required: true, enumeration: [
  259. '土建工程', '装饰工程', '安装工程', '市政工程', '园林绿化工程',
  260. '仿古建筑工程', '房修工程', '轨道工程', '构筑物工程', '机械(爆破)土石方',
  261. '围墙工程', '幕墙工程', '市政安装工程', '城市轨道交通安装', '人工土石方',
  262. '房屋安装修缮工程', '房屋修缮单拆除'
  263. ]},
  264. {name: '金额', value: source.summaryInfo.engineeringCost, type: TYPE.NUM2},
  265. {name: '定额库编码', value: source.defaultRationLibCode},
  266. {name: '计税方法', value: TAX[source.taxType], required: true},
  267. ];
  268. this.constraints = {
  269. billsCode: [], //清单项目项目编码
  270. formulaMeasureNo: [], //公式计算措施项序号
  271. gljCode: [], //人材机代码
  272. provisionalDetailCode: [], //暂列金额明细编号
  273. engEstimateDetailCode: [], //专业工程暂估明细
  274. turnKeyContractCode: [], //总承包服务费费用项编号
  275. labourDayWorkCode: [], //人工计日工项目编号
  276. materialDayWorkCode: [], //材料计日工项目编号
  277. machineDayWorkCode: [], //机械计日工项目编号
  278. otherItemNo: [], //其他列项序号
  279. feeItemNo: [], //费用项序号
  280. mainBillsCode: [], //主要清单明细项目编码 (标准文件中constraint中没有定义此唯一性,但是主要清单明细的备注那里说明了,这里处理一下)
  281. };
  282. element.call(this, '单位工程', attrs);
  283. }
  284. //工程特征定义
  285. function EngFeature(source) {
  286. let attrs = [
  287. {name: '建筑分类', value: source.feature.buildingClass, required: true},
  288. {name: '工程分类', value: source.feature.projClass, required: true},
  289. {name: '建设规模', value: 'todo', required: true},
  290. {name: '工程类别', value: getValueByKey(source.basicInformation, 'projectCategory'), required: true} //取建设项目的工程类别
  291. ];
  292. element.call(this, '工程特征', attrs);
  293. }
  294. //特征项定义
  295. function FeatureItem(feature) {
  296. let attrs = [
  297. {name: '编码', value: ''},
  298. {name: '名称', value: feature.dispName, required: true},
  299. {name: '内容', value: feature.value, required: true},
  300. ];
  301. element.call(this, '特征项', attrs);
  302. }
  303. //单位工程费汇总定义
  304. function TenderFeeSummary() {
  305. element.call(this, '单位工程费汇总', []);
  306. }
  307. //计价程序费用行定义
  308. function DXFYRow(source) {
  309. let attrs = [
  310. {name: '序号', value: source.code},
  311. {name: '行代号', value: source.rowCode, required: true},
  312. {name: '项目名称', value: source.name, required: true},
  313. {name: '计算基础表达式', value: source.calcBase, required: true},
  314. {name: '计算基础说明', value: source.calcBase},
  315. {name: '费率', value: source.feeRate},
  316. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2},
  317. {name: '其中暂估价', value: getFee(source.fees, 'estimate.totalFee'), type: TYPE.NUM2},
  318. {name: '费用类别', value: source.feeType, type: TYPE.INT, required: true},
  319. {name: '备注', value: source.remark},
  320. ];
  321. element.call(this, '计价程序费用行', attrs);
  322. }
  323. //分部分项清单
  324. function FBFXBills() {
  325. element.call(this, '分部分项清单', []);
  326. }
  327. //清单分部定义
  328. function FBBills(source) {
  329. let attrs = [
  330. {name: '编号', value: source.code, required: true, maxLen: 20},
  331. {name: '名称', value: source.name, required: true, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE},
  332. {name: '金额', value: getFee(source.fees, 'common.totalFee'), required: true, type: TYPE.NUM2},
  333. {name: '其中暂估价', value: getFee(source.fees, 'estimate.totalFee'), required: true},
  334. {name: '备注', value: source.remark}
  335. ];
  336. element.call(this, '清单分部', attrs);
  337. }
  338. //清单项目定义
  339. function FXbills(source) {
  340. let attrs = [
  341. {name: '项目编码', value: source.code, required: true, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE},
  342. {name: '项目名称', value: source.name, required: true, minLen: 1, maxLen: 500, whiteSpace: WHITE_SPACE.COLLAPSE},
  343. {name: '单位', value: source.unit, required: true, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE},
  344. {name: '工程量', value: source.quantity, required: true, type: TYPE.DECIMAL},
  345. {name: '综合单价', value: getFee(source.fees, 'common.unitFee'), required: true, type: TYPE.DECIMAL},
  346. {name: '综合合价', value: getFee(source.fees, 'common.totalFee'), required: true, type: TYPE.NUM2},
  347. {name: '其中暂估价', value: getFee(source.fees, 'estimate.totalFee'), required: true, type: TYPE.NUM2},
  348. {name: '主要清单标志', value: !!source.mainBills, type: TYPE.BOOL},
  349. {name: '暂估清单标志', value: !!source.isEstimate, type: TYPE.BOOL},
  350. {name: '备注', value: source.remark},
  351. ];
  352. element.call(this, '清单项目', attrs);
  353. }
  354. //项目特征定义
  355. function ItemCharacter() {
  356. element.call(this, '项目特征', []);
  357. }
  358. //特征定义
  359. function Feature(source) {
  360. let attrs = [
  361. {name: '特征名称', value: source.name, required: true},
  362. {name: '特征描述', value: source.value, required: true},
  363. ];
  364. element.call(this, '特征', attrs);
  365. }
  366. //工程内容定义
  367. function JobContent() {
  368. element.call(this, '工程内容', []);
  369. }
  370. //内容定义
  371. function Content(content) {
  372. let attrs = [
  373. {name: '内容', value: content, required: true}
  374. ];
  375. element.call(this, '内容', attrs);
  376. }
  377. //组价内容定义
  378. function PriceContent() {
  379. element.call(this, '组价内容', []);
  380. }
  381. //定额子目定义
  382. function Ration(source) {
  383. let attrs = [
  384. {name: '定额编号', value: source.viewCode, required: true, minLen: 1, maxLen: 80, whiteSpace: WHITE_SPACE.COLLAPSE},
  385. {name: '项目名称', value: source.name, required: true, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE},
  386. {name: '单位', value: source.unit, required: true, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE},
  387. {name: '定额库编码', value: source.libCode, required: true},
  388. {name: '原始定额编号', value: source.code, minLen: 1, maxLen: 80, whiteSpace: WHITE_SPACE.COLLAPSE},
  389. {name: '子目类型', value: source.subType, required: true, type: TYPE.INT, enumeration: ['0', '1', '2', '3', '4', '5', '6']}, //todo
  390. {name: '工程量', value: source.quantity, required: true, type: TYPE.DECIMAL},
  391. {name: '工程量计算式', value: source.quantityEXP},
  392. {name: '定额单价', value: getFee(source.fees, 'rationUnitPrice.unitFee'), required: true, type: TYPE.DECIMAL},
  393. {name: '定额合价', value: getFee(source.fees, 'rationUnitPrice.totalFee'), required: true, type: TYPE.NUM2},
  394. {name: '综合单价', value: getFee(source.fees, 'common.unitFee'), required: true, type: TYPE.DECIMAL},
  395. {name: '综合合价', value: getFee(source.fees, 'common.totalFee'), required: true, type: TYPE.NUM2},
  396. {name: '单价构成文件ID', value: 0, required: true, type: TYPE.INT}, //todo
  397. {name: '分包标志', value: !!source.isSubcontract, type: TYPE.BOOL},
  398. {name: '备注', value: source.remark}
  399. ];
  400. element.call(this, '定额子目', attrs);
  401. }
  402. //工料分析定义
  403. function GljAnalyze() {
  404. element.call(this, '工料分析', []);
  405. }
  406. //人材机含量定义
  407. function GljContent(source) {
  408. let attrs = [
  409. {name: '人材机代码', value: source.code, required: true, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE},
  410. {name: '消耗量', value: source.quantity, required: true, type: TYPE.DECIMAL},
  411. {name: '总消耗量', value: source.totalQuantity, required: true, type: TYPE.DECIMAL},
  412. {name: '数量计算方式', value: 1, required: true, type: TYPE.INT},
  413. ];
  414. element.call(this, '人材机含量', attrs);
  415. }
  416. //费用组成
  417. function FeeContent(source) {
  418. let attrs = [
  419. {name: '基价人工费单价', value: getFee(source.fees, 'labour.unitFee'), type: TYPE.DECIMAL, required: true},
  420. {name: '基价人工费合价', value: getFee(source.fees, 'labour.totalFee'), type: TYPE.NUM2, required: true},
  421. {name: '定额人工基价调整单价', value: 0, type: TYPE.DECIMAL}, //调整价目前只有08有,默认设置成0
  422. {name: '定额人工基价调整合价', value: 0, type: TYPE.NUM2},
  423. {name: '基价材料费单价', value: getFee(source.fees, 'material.unitFee'), type: TYPE.DECIMAL, required: true},
  424. {name: '基价材料费合价', value: getFee(source.fees, 'material.totalFee'), type: TYPE.NUM2, required: true},
  425. {name: '基价机械费单价', value: getFee(source.fees, 'machine.unitFee'), type: TYPE.DECIMAL, required: true},
  426. {name: '基价机械费合价', value: getFee(source.fees, 'machine.totalFee'), type: TYPE.NUM2, required: true},
  427. {name: '定额机上人工基价调整单价', value: 0, type: TYPE.DECIMAL, required: true},
  428. {name: '定额机上人工基价调整合价', value: 0, type: TYPE.NUM2, required: true},
  429. {name: '未计材料单价', value: getFee(source.fees, 'unratedMaterial.unitFee'), type: TYPE.DECIMAL, required: true},
  430. {name: '未计材料合价', value: getFee(source.fees, 'unratedMaterial.totalFee'), type: TYPE.NUM2, required: true},
  431. {name: '人材机价差单价', value: getFee(source.fees, 'gljDiff.unitFee'), type: TYPE.DECIMAL, required: true}, //人材机价差通过人工、材料、机械价差相加得出
  432. {name: '人材机价差合价', value: getFee(source.fees, 'gljDiff.totalFee'), type: TYPE.NUM2, required: true},
  433. {name: '暂估材料单价', value: getFee(source.fees, 'estimate.unitFee'), type: TYPE.DECIMAL, required: true},
  434. {name: '暂估材料合价', value: getFee(source.fees, 'estimate.totalFee'), type: TYPE.NUM2, required: true},
  435. {name: '管理费单价', value: getFee(source.fees, 'manage.unitFee'), type: TYPE.DECIMAL, required: true},
  436. {name: '管理费合价', value: getFee(source.fees, 'manage.totalFee'), type: TYPE.NUM2, required: true},
  437. {name: '利润单价', value: getFee(source.fees, 'profit.unitFee'), type: TYPE.DECIMAL, required: true},
  438. {name: '利润合价', value: getFee(source.fees, 'profit.totalFee'), type: TYPE.NUM2, required: true},
  439. {name: '风险单价', value: getFee(source.fees, 'risk.unitFee'), type: TYPE.DECIMAL, required: true}, //重庆08叫风险费 重庆18叫一般风险费
  440. {name: '风险合价', value: getFee(source.fees, 'risk.totalFee'), type: TYPE.NUM2, required: true},
  441. {name: '一般风险单价', value: getFee(source.fees, 'risk.unitFee'), type: TYPE.DECIMAL, required: true},
  442. {name: '一般风险合价', value: getFee(source.fees, 'risk.totalFee'), type: TYPE.NUM2, required: true},
  443. {name: '其他风险单价', value: getFee(source.fees, 'otherRisk.unitFee'), type: TYPE.DECIMAL, required: true},
  444. {name: '其他风险合价', value: getFee(source.fees, 'otherRisk.totalFee'), type: TYPE.NUM2, required: true},
  445. ];
  446. element.call(this, '费用组成', attrs);
  447. }
  448. //措施项目清单定义
  449. function CSXMBills(source) {
  450. let attrs = [
  451. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  452. {name: '其中暂估价', value: getFee(source.fees, 'estimate.totalFee'), type: TYPE.NUM2, required: true},
  453. ];
  454. element.call(this, '措施项目清单', attrs);
  455. }
  456. //组织措施清单定义
  457. function ZZCSBills(source) {
  458. let attrs = [
  459. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  460. ];
  461. element.call(this, '组织措施清单', attrs);
  462. }
  463. //组织措施分类定义
  464. function ZZCSClass(source) {
  465. let attrs = [
  466. {name: '编码', value: source.code, maxLen: 20, required: true},
  467. {name: '名称', value: source.name, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  468. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  469. {name: '备注', value: source.remark}
  470. ];
  471. element.call(this, '组织措施分类', attrs);
  472. }
  473. //公式计算措施项
  474. function FormulaCalcMeasure(source) {
  475. let attrs = [
  476. {name: '序号', value: source.code, minLen: 1, maxLen:20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  477. {name: '名称', value: source.name, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  478. {name: '计算基础表达式', value: source.calcBase, required: true},
  479. {name: '计算基础说明', value: source.calcBase},
  480. {name: '费率', value: source.feeRate, required: true},
  481. {name: '金额', value: getFee(source.fees, 'common.totalFee'), required: true},
  482. {name: '暂估价标志', value: getFee(source.fees, 'common.totalFee')},
  483. {name: '备注', value: source.remark},
  484. {name: '费用类别', value: source.feeType, enumeration: ['120201', '1204', '10041', '1206'], required: true},
  485. ];
  486. element.call(this, '公式计算措施项', attrs);
  487. }
  488. //技术措施清单定义
  489. function JSCSBills(source) {
  490. let attrs = [
  491. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  492. {name: '其中暂估价', value: getFee(source.fees, 'estimate.totalFee'), type: TYPE.NUM2, required: true},
  493. ];
  494. element.call(this, '技术措施清单', attrs);
  495. }
  496. //技术措施分类
  497. function JSCSClass(source) {
  498. let attrs = [
  499. {name: '编号', value: source.code},
  500. {name: '名称', value: source.name, required: true},
  501. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  502. {name: '其中暂估价', value: getFee(source.fees, 'estimate.totalFee'), type: TYPE.DECIMAL, required: true},
  503. ];
  504. element.call(this, '技术措施分类', attrs);
  505. }
  506. //其他项目清单定义
  507. function OtherBills() {
  508. element.call(this, '其他项目清单', []);
  509. }
  510. //暂列金额定义
  511. function Provisional(source) {
  512. let attrs = [
  513. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2}
  514. ];
  515. element.call(this, '暂列金额', attrs);
  516. }
  517. //暂列金额明细定义
  518. function ProvisionalDetail(source) {
  519. let attrs = [
  520. {name: '编号', value: source.code, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  521. {name: '项目名称', value: source.name, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  522. {name: '计量单位', value: source.unit, maxLen: 20, required: true},
  523. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  524. {name: '备注', value: source.remark, required: true}
  525. ];
  526. element.call(this, '暂列金额明细', attrs);
  527. }
  528. //专业工程暂估价定义
  529. function EngEstimate(source) {
  530. let attrs = [
  531. {name: '金额', value: getFee(source.fees, 'common.totalFee')}
  532. ];
  533. element.call(this, '专业工程暂估价', attrs);
  534. }
  535. //专业工程暂估明细定义
  536. function EngEstimateDetail(source) {
  537. let attrs = [
  538. {name: '编号', value: source.code, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  539. {name: '工程名称', value: source.name, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  540. {name: '工程内容', value: source.engineeringContent, maxLen: 2000, required: true},
  541. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  542. {name: '备注', value: source.remark, required: true}
  543. ];
  544. element.call(this, '专业工程暂估明细', attrs);
  545. }
  546. //计日工定义
  547. function DayWork(source) {
  548. let attrs = [
  549. {name: '金额', value: getFee(source.fees, 'common.totalFee')}
  550. ];
  551. element.call(this, '', attrs);
  552. }
  553. //人工定义
  554. function Labour() {
  555. element.call(this, '人工', []);
  556. }
  557. //材料定义
  558. function Material() {
  559. element.call(this, '材料', []);
  560. }
  561. //施工机械定义
  562. function Machine() {
  563. element.call(this, '施工机械', []);
  564. }
  565. //计日工项目定义
  566. function DayWorkItem(source) {
  567. let attrs = [
  568. {name: '编号', value: source.code, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  569. {name: '名称', value: source.name, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  570. {name: '单位', value: source.unit, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  571. {name: '数量', value: source.quantity, type: TYPE.DECIMAL, required: true},
  572. {name: '综合单价', value: source.quantity, type: TYPE.DECIMAL, required: true},
  573. {name: '综合合价', value: source.quantity, type: TYPE.NUM2, required: true},
  574. {name: '备注', value: source.remark}
  575. ];
  576. element.call(this, '计日工项目', attrs);
  577. }
  578. //总承包服务费定义
  579. function TurnKeyContract(source) {
  580. let attrs = [
  581. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2}
  582. ];
  583. element.call(this, '总承包服务费', attrs);
  584. }
  585. //总承包服务费分类定义
  586. function TurnKeyContractClass(source) {
  587. let attrs = [
  588. {name:'编号', value: source.code, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE},
  589. {name:'名称', value: source.name, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  590. {name:'备注', value: source.remark}
  591. ];
  592. element.call(this, '总承包服务费分类', attrs);
  593. }
  594. //总承包服务费费用项定义
  595. function TurnKeyContractItem(source) {
  596. let attrs = [
  597. {name: '编号', value: source.code, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  598. {name: '工程名称', value: source.name, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  599. {name: '计算基础', value: 0, type: TYPE.DECIMAL, required: true}, //todo
  600. {name: '服务内容', value: source.serviceContent, maxLen: 255, required: true},
  601. {name: '费率', value: source.feeRate, type: TYPE.DECIMAL, required: true},
  602. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  603. {name: '备注', value: source.remark}
  604. ];
  605. element.call(this, '总承包服务费费用项', attrs);
  606. }
  607. //签证索赔计价汇总费用项
  608. function ClaimVisaFeeItem(source) {
  609. let attrs = [
  610. {name: '编号', value: source.code, required: true},
  611. {name: '项目名称', value: source.name, required: true},
  612. {name: '计量单位', value: source.unit, required: true},
  613. {name: '数量', value: source.quantity, type: TYPE.DECIMAL, required: true},
  614. {name: '单价', value: getFee(source.fees, 'common.unitFee'), type: TYPE.DECIMAL, required: true},
  615. {name: '合价', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  616. {name: '依据', value: '', required: true},
  617. ]
  618. }
  619. //其他定义
  620. function Other(source) {
  621. let attrs = [
  622. {name: '金额', value: source.commonTotalFee, type: TYPE.NUM2}
  623. ];
  624. element.call(this, '其他', attrs);
  625. }
  626. //其他列项定义
  627. function OtherItem(source) {
  628. let attrs = [
  629. {name: '序号', value: source.code, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  630. {name: '名称', value: source.name, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  631. {name: '计算基础', value: source.calcBase, maxLen: 255},
  632. {name: '费率', value: source.feeRate, type: TYPE.DECIMAL},
  633. {name: '金额', value: source.commonTotalFee, type: TYPE.NUM2, required: true},
  634. {name: '不计入合价标志', value: false, type: TYPE.BOOL},
  635. {name: '招标人标志', value: true, type: TYPE.BOOL},
  636. {name: '备注', value: source.remark, maxLen: 255}
  637. ];
  638. element.call(this, '其他列项', attrs);
  639. }
  640. //规费和税金清单定义
  641. function ChargeTaxBills() {
  642. element.call(this, '规费和税金清单', []);
  643. }
  644. //费用项定义
  645. function FeeItem(source) {
  646. let attrs = [
  647. {name: '序号', value: source.code, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  648. {name: '行代号', value: source.rowCode, maxLen: 20, required: true},
  649. {name: '名称', value: source.name, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  650. {name: '计算基础表达式', value: source.calcBase, maxLen: 255, required: true},
  651. {name: '计算基础说明', value: source.calcBase, maxLen: 255},
  652. {name: '费率', value: source.feeRate, type: TYPE.DECIMAL, required: true},
  653. {name: '金额', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  654. {name: '费用类别', value: source.feeType, enumeration: ['800', '900', '9001', '9002', '9003'], required: true},
  655. {name: '备注', value: source.remark, maxLen: 255}
  656. ];
  657. element.call(this, '费用项', attrs);
  658. }
  659. //人材机汇总定义
  660. function GljSummary() {
  661. element.call(this, '人材机汇总', []);
  662. }
  663. //人材机定义
  664. function Glj(source) {
  665. let attrs = [
  666. {name: '代码', value: source.code, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  667. {name: '名称', value: source.name, minLen: 1, maxLen: 255, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  668. {name: '规格', value: source.spec, maxLen: 255},
  669. {name: '单位', value: source.unit, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  670. {name: '原始代码', value: source.orgCode, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE},
  671. {name: '费用类别', value: source.feeType, enumeration: ['1', '2', '3', '4'], required: true},
  672. {name: '配比类别', value: '', type: TYPE.INT}, //todo
  673. {name: '主要材料类别', value: '', type: TYPE.INT}, //todo
  674. {name: '主要材料单位系数', value: '', type: TYPE.DECIMAL}, //todo
  675. {name: '材料耗用类型', value: '', type: TYPE.INT, required: true}, //todo
  676. {name: '供货方式', value: '', type: TYPE.INT}, //todo
  677. {name: '暂估材料标志', value: !!source.is_evaluate, type: TYPE.BOOL},
  678. {name: '不计税设备标志', value: !!source.is_adjust_price, type: TYPE.BOOL, required: true}, //todo
  679. {name: '单价不从明细汇总标志', value: !!source.excludeRatio, type: TYPE.BOOL}, //todo
  680. {name: '定额价', value: source.basePrice, type: TYPE.DECIMAL, required: true},
  681. {name: '定额价调整', value: '', type: TYPE.DECIMAL, required: true}, //todo
  682. {name: '市场价', value: source.marketPrice, type: TYPE.DECIMAL, required: true},
  683. {name: '数量', value: source.quantity, type: TYPE.DECIMAL, required: true},
  684. {name: '产地', value: source.originPlace, maxLen: 255},
  685. {name: '厂家', value: source.vender, maxLen: 255},
  686. {name: '质量等级', value: source.qualityGrace, maxLen: 255},
  687. {name: '品牌', value: source.brand, maxLen: 255},
  688. {name: '备注', value: source.remark, maxLen: 255},
  689. ];
  690. element.call(this, '人材机', attrs);
  691. }
  692. //人材机配比定义
  693. function GljRatio(source) {
  694. let attrs = [
  695. {name: '明细材料代码', value: source.code, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  696. {name: '数量', value: source.quantity, type: TYPE.DECIMAL, required: true}
  697. ];
  698. element.call(this, '人材机配比', attrs);
  699. }
  700. //主要清单汇总定义
  701. function MainBillsSummary() {
  702. element.call(this, '主要清单汇总', []);
  703. }
  704. //主要清单明细定义
  705. function MainBillsItem(source) {
  706. let attrs = [
  707. {name: '项目编码', value: source.code, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  708. {name: '项目名称', value: source.name, minLen: 1, maxLen: 500, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  709. {name: '单位', value: source.unit, minLen: 1, maxLen: 20, whiteSpace: WHITE_SPACE.COLLAPSE, required: true},
  710. {name: '工程量', value: source.quantity, type: TYPE.DECIMAL, required: true},
  711. {name: '综合单价', value: getFee(source.fees, 'common.unitFee'), type: TYPE.DECIMAL, required: true},
  712. {name: '综合合价', value: getFee(source.fees, 'common.totalFee'), type: TYPE.NUM2, required: true},
  713. {name: '其中暂估价', value: getFee(source.fees, 'estimate.totalFee'), type: TYPE.DECIMAL},
  714. {name: '备注', value: source.remark, maxLen: 255},
  715. ];
  716. element.call(this, '主要清单明细', attrs);
  717. }
  718. async function setTimeoutSync(handle, time) {
  719. return new Promise(function(resolve, reject) {
  720. setTimeout(function () {
  721. if (handle && typeof handle === 'function') {
  722. handle();
  723. }
  724. resolve();
  725. }, time);
  726. });
  727. }
  728. this.failList = failList;
  729. this.granularity = granularity;
  730. //目前的数据
  731. let curPMData = {project: null, engineering: null, tender: null}, //项目管理项目数据
  732. curProjectEle = null, //建设项目节点
  733. curTenderEle = null; //单位工程节点
  734. //自增编码
  735. let incrementData = {
  736. projectCode: 1, //项目编号,单项工程、单位工程编号自动生成
  737. };
  738. function getIncreamentData(field) {
  739. if (!incrementData[field]) {
  740. incrementData[field] = 1;
  741. }
  742. return incrementData[field]++;
  743. }
  744. //数组打平成对象
  745. function arrayToObj(arr) {
  746. let rst = {};
  747. for (let data of arr) {
  748. rst[data.key] = data.value;
  749. }
  750. return rst;
  751. }
  752. //获取节点固定ID
  753. function getNodeFlag(node) {
  754. if (!node || !node.data || !node.data.flags || !node.data.flags[0] || ! node.data.flags[0].flag) {
  755. return 0;
  756. }
  757. return node.data.flags[0].flag;
  758. }
  759. //获取节点所属固定ID
  760. function belongToFlag(node) {
  761. while (node) {
  762. if (node.data && node.data.flags && node.data.flags[0] && node.data.flags[0].flag) {
  763. return node.data.flags[0].flag;
  764. }
  765. node = node.parent;
  766. }
  767. return null;
  768. }
  769. //获取节点后代节点
  770. function getPosterity(node) {
  771. let posterity = [];
  772. getNodes(node.children);
  773. return posterity;
  774. function getNodes(nodes) {
  775. for (let node of nodes) {
  776. posterity.push(node);
  777. if (node.children.length > 0){
  778. getNodes(node.children);
  779. }
  780. }
  781. }
  782. }
  783. //检测层数
  784. //@param {Number}maxDepth(最大深度) {Object}node(需要检测的清单树节点)
  785. //@return {Boolean}
  786. function validDepth(maxDepth, node) {
  787. let nodeDepth = node.depth();
  788. let allNodes = getPosterity(node);
  789. //检测相对深度
  790. for (let n of allNodes) {
  791. let relativeDepth = n.depth() - nodeDepth;
  792. if (relativeDepth > maxDepth) {
  793. return false;
  794. }
  795. }
  796. return true;
  797. }
  798. //检测唯一性
  799. //@param {Object}constraints(约束池) {All}data(检测的数据) {String}hint(提示已存在的内容)
  800. //@return {void}
  801. function checkUnique(constraints, data, hint) {
  802. if (constraints.includes(data)) {
  803. failList.push(`${hint}“${data}”已存在`);
  804. } else if (data) {
  805. constraints.push(data);
  806. }
  807. }
  808. //根据数据的NextSiblingID进行排序,返回排序后的数组
  809. function sortByNext(datas) {
  810. let target = [],
  811. temp = {};
  812. for (let data of datas) {
  813. temp[data.ID] = {me: data, next: null, prev: null};
  814. }
  815. for (let data of datas) {
  816. let next = temp[data.NextSiblingID] || null;
  817. temp[data.ID].next = next;
  818. if (next) {
  819. next.prev = temp[data.ID];
  820. }
  821. }
  822. let first = null;
  823. for (let data of datas) {
  824. let me = temp[data.ID];
  825. if (!me.prev) {
  826. first = me;
  827. }
  828. }
  829. if (!first) {
  830. return datas;
  831. }
  832. while (first) {
  833. target.push(first.me);
  834. first = first.next;
  835. }
  836. return target;
  837. }
  838. //获取需要导出的项目数据
  839. //@param {Number}tenderID(当前界面的单位工程ID,后台根据这个单位工程,去找其建设项目下所有数据)
  840. //@return {Object}(eleObj)
  841. async function loadProject(tenderID) {
  842. //拉取标段数据:建设项目、单项工程、单位工程数据
  843. let projectData = curPMData.project = await ajaxPost('/pm/api/getProjectByGranularity', {user_id: userID, tenderID: tenderID, granularity: granularity});
  844. if (!projectData) {
  845. throw '获取项目数据错误';
  846. }
  847. //单项工程、单位工程按照树结构数据进行排序
  848. projectData.children = sortByNext(projectData.children);
  849. for (let engData of projectData.children) {
  850. engData.children = sortByNext(engData.children);
  851. }
  852. //标段
  853. let project = curProjectEle = new Project({basicInformation: projectData.property.basicInformation, name: projectData.name});
  854. //项目信息
  855. let projectInfo = new ProjectInfo({basicInformation: projectData.property.basicInformation});
  856. project.children.push(projectInfo);
  857. //招标信息
  858. let biddingInfo = new BiddingInfo({basicInformation: projectData.property.basicInformation, summaryInfo: projectData.summaryInfo[projectData.ID]});
  859. projectInfo.children.push(biddingInfo);
  860. //投标信息
  861. let bidInfo = new BidInfo({basicInformation: projectData.property.basicInformation, summaryInfo: projectData.summaryInfo[projectData.ID]});
  862. projectInfo.children.push(bidInfo);
  863. //编制说明
  864. let compilationIll = new CompilationIllustration({compilationIllustration: projectData.property.compilationIllustration});
  865. project.children.push(compilationIll);
  866. //系统信息
  867. let generatedTime = moment(Date.now()).format('YYYY-MM-DDTHH:mm:ss'),
  868. sysInfoSource = {softInfo: projectData.softInfo, generatedTime},
  869. sysInfo = new SystemInfo(sysInfoSource);
  870. project.children.push(sysInfo);
  871. //费用构成
  872. let feeForm = new FeeFrom(projectData.summaryInfo[projectData.ID]);
  873. project.children.push(feeForm);
  874. //主要清单汇总 主要清单明细在loadTender中设置
  875. let mainBillsSummaryEle = new MainBillsSummary();
  876. project.children.unshift(mainBillsSummaryEle); //插入到第一个位置,必须要排在loadTender前,这样才能添加到明细数据,插在第一位方便后面排序
  877. //单项工程
  878. for (let eng of projectData.children) {
  879. curPMData.engineering = eng;
  880. let engElement = await loadEngineering(projectData.summaryInfo, eng);
  881. project.children.push(engElement);
  882. }
  883. //主要清单汇总 排在后面
  884. project.children.shift(mainBillsSummaryEle);
  885. project.children.push(mainBillsSummaryEle);
  886. return project;
  887. }
  888. /*
  889. * 加载单项工程数据
  890. * @param {Object}summaryInfo(项目汇总信息映射) {Object}engData(单项工程数据)
  891. * */
  892. async function loadEngineering(summaryInfo, engData) {
  893. let source = {summaryInfo: summaryInfo[engData.ID], name: engData.name, code: getIncreamentData('projectCode')};
  894. let engineering = new Engineering(source);
  895. //单项工程编号要唯一
  896. checkUnique(curProjectEle.constraints.engCode, source.code, '单项工程编号');
  897. //分批次获取单位工程
  898. for (let tenderData of engData.children) {
  899. curPMData.tender = tenderData;
  900. await setTimeoutSync(() => {},TIMEOUT_TIME); //间隔一段时间再初始单位工程数据,减少服务器压力
  901. let tender = await loadTender(summaryInfo, tenderData);
  902. engineering.children.push(tender);
  903. }
  904. return engineering;
  905. }
  906. /*
  907. * 加载单位工程数据
  908. * @param {Object}summaryInfo(项目汇总信息映射) {Object}tenderData(单位工程数据)
  909. * @return {Object}
  910. * */
  911. async function loadTender(summaryInfo, tenderData) {
  912. //获取单位工程详细数据
  913. let tenderDetail = PROJECT.createNew(tenderData.ID, userID);
  914. await tenderDetail.loadDataSync();
  915. //设置定额库编码
  916. tenderDetail.rationLibMap = {};
  917. let defaultLib = null;
  918. if (tenderDetail.projectInfo.engineeringInfo && Array.isArray(tenderDetail.projectInfo.engineeringInfo.ration_lib)) {
  919. defaultLib = tenderDetail.projectInfo.engineeringInfo.ration_lib.find(data => data.isDefault);
  920. for (let lib of tenderDetail.projectInfo.engineeringInfo.ration_lib) {
  921. tenderDetail.rationLibMap[lib.id] = lib;
  922. }
  923. }
  924. //单位工程
  925. let tenderSource = {
  926. code: getIncreamentData('projectCode'),
  927. name: tenderData.name,
  928. engineeringName: tenderData.property.engineeringName,
  929. summaryInfo: summaryInfo[tenderData.ID],
  930. defaultRationLibCode: defaultLib.libCode,
  931. taxType: tenderData.property.taxType
  932. };
  933. let tender = curTenderEle = new Tender(tenderSource);
  934. //单位工程编号要唯一
  935. checkUnique(curProjectEle.constraints.tenderCode, tenderSource.code, '单位工程编号');
  936. //工程特征
  937. let featureObj = arrayToObj(tenderData.property.projectFeature);
  938. let engFeature = new EngFeature({feature:featureObj, basicInformation: curPMData.project.property.basicInformation});
  939. tender.children.push(engFeature);
  940. //特征项:每一项工程特征
  941. for (let data of tenderData.property.projectFeature) {
  942. let featureItem = new FeatureItem(data);
  943. engFeature.children.push(featureItem);
  944. }
  945. //单位工程费汇总
  946. tender.children.push(loadDXFY(tenderDetail));
  947. //分部分项清单
  948. tender.children.push(loadFBFX(tenderDetail));
  949. //措施项目清单
  950. tender.children.push(loadCSXM(tenderDetail));
  951. //其他项目清单
  952. let other = loadOtherBills(tenderDetail);
  953. if (other) {
  954. tender.children.push(other);
  955. }
  956. //规费和税金清单
  957. let chargeTax = loadChargeTax(tenderDetail);
  958. tender.children.push(chargeTax);
  959. //人材机汇总
  960. let gljSummary = loadGlj(tenderDetail);
  961. if (gljSummary) {
  962. tender.children.push(gljSummary);
  963. }
  964. //给建设项目下主要清单汇总设置主要清单明细
  965. let curMainBillsSummary = curProjectEle.children.find(ele => ele.name === '主要清单汇总');
  966. if (curMainBillsSummary) {
  967. loadMainBillsItems(curMainBillsSummary, tenderDetail);
  968. }
  969. return tender;
  970. }
  971. /*
  972. * 加载计算程序费用行
  973. * @param {Object}detail(单位工程的详细数据,清单定额等等)
  974. * @return {Object}
  975. * */
  976. function loadDXFY(detail) {
  977. //单位工程费汇总
  978. let tenderFeeSummary = new TenderFeeSummary();
  979. //计价程序费用行,筛选大项费用行数据
  980. let dxfyNodes = detail.Bills.tree.roots;
  981. for (let node of dxfyNodes) {
  982. let mainTreeNode = detail.mainTree.getNodeByID(node.data.ID),
  983. serialNo = mainTreeNode ? mainTreeNode.serialNo() + 1 : 1;
  984. let flag = getNodeFlag(node) || 0;
  985. let source = {
  986. code: node.data.code,
  987. rowCode: `F${serialNo}`,
  988. name: node.data.name,
  989. calcBase: node.data.calcBase,
  990. feeRate: node.data.feeRate,
  991. fees: node.data.fees,
  992. feeType: FEE_TYPE[flag],
  993. remark: node.data.remark
  994. };
  995. let dxfy = new DXFYRow(source);
  996. tenderFeeSummary.children.push(dxfy);
  997. }
  998. return tenderFeeSummary;
  999. }
  1000. /*
  1001. * 加载清单项目
  1002. * @param {Object}node(清单树节点) {Object}detail
  1003. * */
  1004. function loadBills(node, detail) {// allRation, allRationGlj, decimal,
  1005. let allRation = detail.Ration.datas,
  1006. allRationGlj = detail.ration_glj.datas,
  1007. decimal = detail.projectInfo.property.decimal;
  1008. let source = {
  1009. code: node.data.code,
  1010. name: node.data.name,
  1011. unit: node.data.unit,
  1012. quantity: node.data.quantity,
  1013. fees: node.data.fees,
  1014. mainBills: node.data.mainBills,
  1015. isEstimate: node.data.isEstimate,
  1016. remark: node.data.remark
  1017. };
  1018. let bills = new FXbills(source);
  1019. //清单项目项目编码要在单位工程中唯一
  1020. checkUnique(curTenderEle.constraints.billsCode, source.code, '清单项目项目编号');
  1021. //加载特征及内容
  1022. function loadFeatureContent() {
  1023. let job = [],
  1024. feature = [];
  1025. let jobText = node.data.jobContentText || '';
  1026. let featureText = node.data.itemCharacterText || '';
  1027. let jobSplit = jobText.split(/[\r,\n]/g),
  1028. featureSplit = featureText.split(/[\r,\n]/g);
  1029. //将特征和内容分类,通过[项目特征][工作内容]区分。若没有,则不区分:工作内容列全部数据为工作内容,项目特征列全部数据为项目特征
  1030. //@param {Array}data(splitdata) {String}field(job、feature)
  1031. function classifyData(data, field) {
  1032. let rst = {
  1033. job: [],
  1034. feature: []
  1035. };
  1036. let featureIndex = data.findIndex(x => x === '[项目特征]');
  1037. if (featureIndex < 0) {
  1038. rst[field] = data;
  1039. return rst;
  1040. }
  1041. let jobIndex = data.findIndex(x => x === '[工作内容]');
  1042. if (jobIndex < 0) { //有[项目特征],没有[工作内容],则其数据全为项目特征数据
  1043. rst.feature = data;
  1044. return rst;
  1045. }
  1046. //有[项目特征],有[工作内容],进行数据分类
  1047. rst.feature = data.slice(featureIndex, jobIndex);
  1048. rst.job = data.slice(jobIndex);
  1049. return rst;
  1050. }
  1051. let classifiedJob = classifyData(jobSplit, 'job');
  1052. job = job.concat(classifiedJob.job);
  1053. feature = feature.concat(classifiedJob.feature);
  1054. let classifiedFeature = classifyData(featureSplit, 'feature');
  1055. job = job.concat(classifiedFeature.job);
  1056. feature = feature.concat(classifiedFeature.feature);
  1057. job = job.filter(x => x && !['[项目特征]', '[工作内容]'].includes(x));
  1058. feature = feature.filter(x => x && !['[项目特征]', '[工作内容]'].includes(x));
  1059. //创建项目特征节点
  1060. if (feature.length > 0) {
  1061. let itemChac = new ItemCharacter();
  1062. let reg = /(.{0,}):(.{0,})/;
  1063. for (let f of feature) {
  1064. let source = {name: '', value: ''};
  1065. let execRst = reg.exec(f);
  1066. if (execRst) {
  1067. source.name = execRst[1].replace(/^\d+\.{1}/, '').trim(); //去除开头(1.)序号,首位空格
  1068. source.value = execRst[2].trim();
  1069. }
  1070. let featureEle = new Feature(source);
  1071. itemChac.children.push(featureEle);
  1072. }
  1073. bills.children.push(itemChac);
  1074. }
  1075. //创建工作内容节点
  1076. if (job.length > 0) {
  1077. let jobContent = new JobContent();
  1078. for (let j of job) {
  1079. let data = j.replace(/^\d+\.{1}/, '').trim();
  1080. let content = new Content(data);
  1081. jobContent.children.push(content);
  1082. }
  1083. bills.children.push(jobContent);
  1084. }
  1085. }
  1086. loadFeatureContent();
  1087. /*
  1088. * 加载定额子目
  1089. * @param {Array}rationData(清单项目下定额数据) {Array}rationGljData(定额的人材机数据) {Object}decimal(项目小数位数)
  1090. * @return {Object}
  1091. * */
  1092. function loadRation(rationData, rationGljData) {
  1093. let viewCode = rationData.code;
  1094. if (rationData.prefix) {
  1095. viewCode = rationData.prefix + viewCode;
  1096. }
  1097. if (rationData.adjustState) {
  1098. viewCode += '换';
  1099. }
  1100. let rationSource = {
  1101. viewCode: viewCode,
  1102. name: rationData.name,
  1103. unit: rationData.unit,
  1104. libCode: '',
  1105. code: rationData.code,
  1106. subType: 1,
  1107. quantity: rationData.quantity,
  1108. quantityEXP: rationData.quantityEXP,
  1109. fees: rationData.fees,
  1110. isSubcontract: rationData.isSubcontract,
  1111. remark: rationData.remark
  1112. };
  1113. if (rationData.from === 'std' && isDef(rationData.libID)) { //来自标准库,设置定额库编码
  1114. rationSource.libCode = detail.rationLibMap[rationData.libID].libCode;
  1115. }
  1116. let ration = new Ration(rationSource);
  1117. //创建工料分析
  1118. let gljAnalyze = new GljAnalyze();
  1119. ration.children.push(gljAnalyze);
  1120. //定额人材机排序
  1121. rationGljData = gljUtil.sortRationGLJ(rationGljData);
  1122. for (let rGlj of rationGljData) {
  1123. let gljSource = {
  1124. code: rGlj.code,
  1125. quantity: rGlj.quantity,
  1126. totalQuantity: gljUtil.getTotalQuantity(rGlj, rationData, decimal.glj.quantity, decimal.ration.quantity)
  1127. };
  1128. let gljContent = new GljContent(gljSource);
  1129. gljAnalyze.children.push(gljContent);
  1130. }
  1131. //创建费用组成
  1132. let feeContent = new FeeContent({fees: rationData.fees});
  1133. ration.children.push(feeContent);
  1134. return ration;
  1135. }
  1136. //加载组价内容
  1137. let rationData = allRation.filter(x => x.billsItemID === node.data.ID);
  1138. if (rationData.length > 0) {
  1139. let priceContent = new PriceContent();
  1140. bills.children.push(priceContent);
  1141. //加载定额子目
  1142. rationData.sort((x, y) => x.serialNo - y.serialNo); //定额排序
  1143. for (let rData of rationData) {
  1144. let rationGlj = allRationGlj.filter(x => x.rationID === rData.ID);
  1145. priceContent.children.push(loadRation(rData, rationGlj));
  1146. }
  1147. }
  1148. return bills;
  1149. }
  1150. /*
  1151. * 加载分部分项清单
  1152. * @param {Object}detail
  1153. * @return {Object || NULL}
  1154. * */
  1155. function loadFBFX(detail) {
  1156. let fbfxBills = new FBFXBills();
  1157. let subEngNode = detail.Bills.tree.roots.find((node) => getNodeFlag(node) === fixedFlag.SUB_ENGINERRING);
  1158. if (!subEngNode) {
  1159. failList.push('不存在分部分项清单');
  1160. return fbfxBills;
  1161. }
  1162. if (subEngNode.children.length === 0) {
  1163. failList.push('分部分项清单下必须要有清单分部或清单项目');
  1164. }
  1165. for (let node of subEngNode.children) {
  1166. if (node.data.type === billType.FB) {
  1167. if (node.children.length === 0) {
  1168. failList.push('清单分部下至少要有一条清单项目');
  1169. }
  1170. //创建清单分部节点
  1171. let fbSource = {
  1172. code: node.data.code,
  1173. name: node.data.name,
  1174. fees: node.data.fees,
  1175. remark: node.data.remark
  1176. };
  1177. let fbBills = new FBBills(fbSource);
  1178. fbfxBills.children.push(fbBills);
  1179. //创建清单项目节点
  1180. for (let subNode of node.children) {
  1181. let fx = loadBills(subNode, detail);
  1182. fbBills.children.push(fx);
  1183. }
  1184. } else {
  1185. let fxBills = loadBills(node, detail);
  1186. fbfxBills.children.push(fxBills);
  1187. }
  1188. }
  1189. return fbfxBills;
  1190. }
  1191. /*
  1192. * 加载措施项目清单
  1193. * @param {Object}detail
  1194. * @return {Object}
  1195. * */
  1196. function loadCSXM(detail) {
  1197. let measureNode = detail.Bills.tree.roots.find((node) => getNodeFlag(node) === fixedFlag.MEASURE);
  1198. if (!measureNode) {
  1199. failList.push('不存在措施项目清单');
  1200. return new element('措施项目清单', []);
  1201. }
  1202. let csxmBills = new CSXMBills({fees: measureNode.data.fees});
  1203. //加载组织措施清单
  1204. let zzcsNode = detail.Bills.tree.items.find(node => getNodeFlag(node) === fixedFlag.CONSTRUCTION_ORGANIZATION);
  1205. if (zzcsNode) {
  1206. let zzcsBills = new ZZCSBills({fees: zzcsNode.data.fees});
  1207. csxmBills.children.push(zzcsBills);
  1208. loadZZCS(zzcsBills, zzcsNode.children);
  1209. }
  1210. //加载技术措施清单
  1211. let jscsNode = detail.Bills.tree.items.find(node => getNodeFlag(node) === fixedFlag.CONSTRUCTION_TECH);
  1212. let maxDepth = 2; //技术措施清单最多深度是2层:技术措施分类-清单项目
  1213. if (jscsNode) {
  1214. let jscsBills = new JSCSBills({fees: jscsNode.data.fees});
  1215. csxmBills.children.push(jscsBills);
  1216. let isValidDepth = validDepth(maxDepth, jscsNode);
  1217. if (!isValidDepth) {
  1218. failList.push('技术措施清单子项超过两层');
  1219. } else {
  1220. loadJSCS(jscsBills, jscsNode.children);
  1221. }
  1222. }
  1223. return csxmBills;
  1224. function loadZZCS(parent, nodes) {
  1225. for (let node of nodes) {
  1226. if (node.children.length > 0) { //组织措施分类
  1227. let classSource = {
  1228. code: node.data.code,
  1229. name: node.data.name,
  1230. fees: node.data.fees,
  1231. remark: node.data.remark
  1232. };
  1233. let zzcsClass = new ZZCSClass(classSource);
  1234. parent.children.push(zzcsClass);
  1235. loadZZCS(zzcsClass, node.children);
  1236. } else { //公式计算措施项
  1237. let source = {
  1238. code: node.data.code,
  1239. name: node.data.name,
  1240. calcBase: node.data.calcBase,
  1241. feeRate: node.data.feeRate,
  1242. fees: node.data.fees,
  1243. remark: node.data.remark,
  1244. feeType: FEE_TYPE[fixedFlag.CONSTRUCTION_ORGANIZATION]
  1245. };
  1246. let formula = new FormulaCalcMeasure(source);
  1247. parent.children.push(formula);
  1248. }
  1249. }
  1250. }
  1251. function loadJSCS(parent, nodes) {
  1252. for (let node of nodes) {
  1253. if (node.children.length > 0) { //技术措施分类
  1254. let classSource = {
  1255. code: node.data.code,
  1256. name: node.data.name,
  1257. fees: node.data.fees
  1258. };
  1259. let jscsClass = new JSCSClass(classSource);
  1260. parent.children.push(jscsClass);
  1261. loadJSCS(jscsClass, node.children);
  1262. } else { //清单项目
  1263. parent.children.push(loadBills(node, detail));
  1264. }
  1265. }
  1266. }
  1267. }
  1268. /*
  1269. * 加载其他项目清单,要出现此节点,需要遵循标准条件(至少含有一条相关明细)
  1270. * @param {Object}detail
  1271. * @return {Object || Null}
  1272. * */
  1273. function loadOtherBills(detail) {
  1274. let otherNode = detail.Bills.tree.roots.find(node => getNodeFlag(node) === fixedFlag.OTHER);
  1275. if (otherNode.children.length === 0) {
  1276. return null;
  1277. }
  1278. //其他项目清单元素
  1279. let otherEle = new OtherBills();
  1280. //添加暂列金额元素
  1281. let provisionalNode = detail.Bills.tree.items.find(node => getNodeFlag(node) === fixedFlag.PROVISIONAL);
  1282. if (provisionalNode && provisionalNode.children.length > 0) {
  1283. otherEle.children.push(loadProvisional(provisionalNode));
  1284. }
  1285. //添加专业工程暂估价元素
  1286. let engEstimateNode = detail.Bills.tree.items.find(node => getNodeFlag(node) === fixedFlag.ENGINEERING_ESITIMATE);
  1287. if (engEstimateNode && engEstimateNode.children.length > 0) {
  1288. otherEle.children.push(loadEngEstimate(engEstimateNode));
  1289. }
  1290. //添加计日工元素
  1291. let dayWorkNode = detail.Bills.tree.items.find(node => getNodeFlag(node) === fixedFlag.DAYWORK);
  1292. let dayWorkEle = new DayWorkItem({fees: dayWorkNode.data.fees});
  1293. if (dayWorkNode && dayWorkNode.children.length > 0) {
  1294. //要显示计日工元素,人工、材料、施工机械,最少有一条含有子项(计日工项目)
  1295. let filterNodes = dayWorkNode.children.filter(node => [fixedFlag.LABOUR, fixedFlag.MATERIAL, fixedFlag.MACHINE].includes(getNodeFlag(node)));
  1296. for (let fNode of filterNodes) {
  1297. let ele,
  1298. constraints;
  1299. let flag = getNodeFlag(fNode);
  1300. if (flag === fixedFlag.LABOUR) {
  1301. ele = new Labour();
  1302. constraints = curTenderEle.constraints.labourDayWorkCode;
  1303. } else if (flag === fixedFlag.MATERIAL) {
  1304. ele = new Material();
  1305. constraints = curTenderEle.constraints.materialDayWorkCode;
  1306. } else if (flag === fixedFlag.MACHINE) {
  1307. ele = new Machine();
  1308. constraints = curTenderEle.constraints.machineDayWorkCode;
  1309. }
  1310. if (fNode.children.length > 0) {
  1311. let isValidDepth = validDepth(1, fNode);
  1312. if (!isValidDepth) {
  1313. failList.push(`计日工${ele.name}子项超过一层`);
  1314. } else {
  1315. for (let itemNode of fNode.children) {
  1316. ele.children.push(loadDayWorkItem(itemNode, constraints, `${ele.name}计日工项目编号`));
  1317. }
  1318. dayWorkEle.children.push(ele);
  1319. }
  1320. }
  1321. }
  1322. //如果计日工下有计日工项目,则显示计日工元素
  1323. if (dayWorkEle.children.length > 0) {
  1324. otherEle.children.push(dayWorkEle);
  1325. }
  1326. }
  1327. //添加总承包服务费元素
  1328. let tkcNode = detail.Bills.tree.items.find(node => getNodeFlag(node) === fixedFlag.TURN_KEY_CONTRACT);
  1329. if (tkcNode && tkcNode.children.length > 0) { //必须要有子项才显示总承包服务费元素
  1330. let isValidDepth = validDepth(2, tkcNode); //最多2层子项:总承包服务费分类-总承包服务费费用项
  1331. if (!isValidDepth) {
  1332. failList.push('总承包服务费子项超过两层');
  1333. } else {
  1334. let tkcEle = new TurnKeyContract({fees: tkcNode.data.fees});
  1335. otherEle.children.push(tkcEle);
  1336. loadService(tkcEle, tkcNode.children);
  1337. }
  1338. }
  1339. //添加索赔计价汇总元素
  1340. let claimNode = detail.Bills.tree.items.find(node => getNodeFlag(node) === fixedFlag.CLAIM);
  1341. if (claimNode && claimNode.children.length > 0) { //必须要有子项才能显示索赔计价汇总元素
  1342. let claimEle = new element('索赔计价汇总', []);
  1343. for (let n of claimNode.children) {
  1344. claimEle.children.push(new ClaimVisaFeeItem(n.data));
  1345. }
  1346. otherEle.children.push(claimEle);
  1347. }
  1348. //添加现场签证计价汇总元素
  1349. let visaNode = detail.Bills.tree.items.find(node => getNodeFlag(node) === fixedFlag.VISA);
  1350. if (visaNode && visaNode.children.length > 0) { //必须要有子项才能显示现场签证计价汇总元素
  1351. let visaEle = new element('现场签证计价汇总', []);
  1352. for (let n of visaNode.children) {
  1353. visaEle.children.push(new ClaimVisaFeeItem(n.data));
  1354. }
  1355. otherEle.children.push(visaEle);
  1356. }
  1357. //添加其他元素
  1358. let posetriy = getPosterity(otherNode);
  1359. let subOtherEle = loadOthers(posetriy);
  1360. if (subOtherEle) {
  1361. otherEle.children.push(subOtherEle);
  1362. }
  1363. //必须有有效子项,才能显示其他项目清单元素
  1364. return otherEle.children.length > 0 ? otherEle : null;
  1365. //加载暂列金额
  1366. function loadProvisional(node) {
  1367. let provisionalEle = new Provisional({fees: node.data.fees});
  1368. //暂列金额最多只有一层子节点
  1369. let isValidDepth = validDepth(1, node);
  1370. if (!isValidDepth) {
  1371. failList.push('暂列金额子项超过一层');
  1372. } else { //加载暂列金额明细
  1373. for (let n of node.children) {
  1374. let pDetailSource = {
  1375. code: n.data.code,
  1376. name: n.data.name,
  1377. unit: n.data.unit,
  1378. fees: n.data.fees,
  1379. remark: n.data.remark
  1380. },
  1381. pDetailEle = new ProvisionalDetail(pDetailSource);
  1382. //暂列金额明细编号在单位工程中唯一
  1383. checkUnique(curTenderEle.constraints.provisionalDetailCode, pDetailSource.code, '暂列金额明细编号');
  1384. provisionalEle.children.push(pDetailEle);
  1385. }
  1386. }
  1387. return provisionalEle;
  1388. }
  1389. //加载专业工程暂估价
  1390. function loadEngEstimate(node) {
  1391. let engEstimateEle = new EngEstimate({fees: node.data.fees});
  1392. //专业工程暂估价最多只有一层子节点
  1393. let isValidDepth = validDepth(1, node);
  1394. if (!isValidDepth) {
  1395. failList.push('专业工程暂估价子项超过一层');
  1396. } else { //加载专业工程暂估明细
  1397. for (let n of node.children) {
  1398. let eDetailSource = {
  1399. code: n.data.code,
  1400. name: n.data.name,
  1401. engineeringContent: n.data.engineeringContent,
  1402. fees: n.data.fees,
  1403. remark: n.data.remark
  1404. },
  1405. eDetailEle = new EngEstimateDetail(eDetailSource);
  1406. //暂列金额明细编号在单位工程中唯一
  1407. checkUnique(curTenderEle.constraints.engEstimateDetailCode, eDetailSource.code, '专业工程暂估明细编号');
  1408. engEstimateEle.children.push(eDetailEle);
  1409. }
  1410. }
  1411. return engEstimateEle;
  1412. }
  1413. //加载计日工项目
  1414. function loadDayWorkItem(node, constraints, hint) {
  1415. let source = {
  1416. code: node.data.code,
  1417. name: node.data.name,
  1418. unit: node.data.unit,
  1419. quantity: node.data.quantity,
  1420. fees: node.data.fees,
  1421. remark: node.data.remark
  1422. };
  1423. checkUnique(constraints, source.code, hint);
  1424. return new DayWorkItem(source);
  1425. }
  1426. //加载服务费项
  1427. function loadService(parent, nodes) {
  1428. for (let node of nodes) {
  1429. if (node.children.length > 0) { //总承包服务费分类
  1430. let classSource = {
  1431. code: node.data.code,
  1432. name: node.data.name,
  1433. remark: node.data.remark
  1434. };
  1435. let tkcClass = new TurnKeyContractClass(classSource);
  1436. parent.children.push(tkcClass);
  1437. loadService(tkcClass, node.children);
  1438. } else { //总承包服务费费用项
  1439. let source = {
  1440. code: node.data.code,
  1441. serviceContent: node.data.serviceContent,
  1442. feeRate: node.data.feeRate,
  1443. fees: node.data.fees,
  1444. remark: node.data.remark
  1445. };
  1446. parent.children.push(new TurnKeyContractItem(source));
  1447. }
  1448. }
  1449. }
  1450. //加载其他列项,不符合上述情况的,其他所有清单子项
  1451. function loadOthers(nodes) {
  1452. //排除项
  1453. let exclusionFlags = [
  1454. fixedFlag.PROVISIONAL,
  1455. fixedFlag.ENGINEERING_ESITIMATE,
  1456. fixedFlag.LABOUR,
  1457. fixedFlag.MATERIAL,
  1458. fixedFlag.MACHINE,
  1459. fixedFlag.TURN_KEY_CONTRACT,
  1460. fixedFlag.CLAIM,
  1461. fixedFlag.VISA
  1462. ];
  1463. //生成其他列项
  1464. let otherItems = [],
  1465. summaryFee = 0;
  1466. for (let node of nodes) {
  1467. let belongFlag = belongToFlag(node);
  1468. if (node.children.length > 0 || (belongFlag && exclusionFlags.includes(belongFlag))) {
  1469. continue;
  1470. }
  1471. //汇总其他列项金额
  1472. let totalFee = getFee(node.data.fees, 'common.totalFee');
  1473. summaryFee = scMathUtil.roundForObj(summaryFee + totalFee, curPMData.tender.property.decimal.bills.totalPrice);
  1474. let otherItemEle = new OtherItem({
  1475. code: node.data.code,
  1476. name: node.data.name,
  1477. calcBase: node.data.calcBase,
  1478. feeRate: node.data.feeRate,
  1479. commonTotalFee: totalFee,
  1480. remark: node.data.remark
  1481. });
  1482. otherItems.push(otherItemEle);
  1483. checkUnique(curTenderEle.constraints.otherItemNo, node.data.code, '其他列项编号');
  1484. }
  1485. let otherEle = new Other({commonTotalFee: summaryFee});
  1486. for (let ele of otherItems) {
  1487. otherEle.children.push(ele);
  1488. }
  1489. return otherEle.children.length > 0 ? otherEle : null; //有其他列项才能显示其他元素
  1490. }
  1491. }
  1492. /*
  1493. * 加载规费和税金清单,固定显示:规费、税金、增值税、附加税、环境保护税这几个清单
  1494. * @param {Object}detail
  1495. * @return {Object}
  1496. * */
  1497. function loadChargeTax(detail) {
  1498. let chargeTaxEle = new ChargeTaxBills();
  1499. let filterFlags = [
  1500. fixedFlag.CHARGE,
  1501. fixedFlag.TAX,
  1502. fixedFlag.ADDED_VALUE_TAX,
  1503. fixedFlag.ADDITIONAL_TAX,
  1504. fixedFlag.ENVIRONMENTAL_PROTECTION_TAX
  1505. ];
  1506. let fitlerNodes = detail.Bills.tree.items.filter(node => filterFlags.includes(getNodeFlag(node)));
  1507. for (let node of fitlerNodes) {
  1508. let mainTreeNode = detail.mainTree.getNodeByID(node.data.ID),
  1509. serialNo = mainTreeNode ? mainTreeNode.serialNo() + 1 : 1;
  1510. let source = {
  1511. code: node.data.code,
  1512. rowCode: `F${serialNo}`,
  1513. name: node.data.name,
  1514. calcBase: node.data.calcBase,
  1515. feeRate: node.data.feeRate,
  1516. fees: node.data.fees,
  1517. feeType: FEE_TYPE[getNodeFlag(node)],
  1518. remark: node.data.remark
  1519. };
  1520. //序号唯一
  1521. checkUnique(curTenderEle.constraints.feeItemNo, source.code, '规费和税金费用项编号');
  1522. chargeTaxEle.children.push(new FeeItem(source));
  1523. }
  1524. return chargeTaxEle;
  1525. }
  1526. /*
  1527. * 加载主要清单明细
  1528. * @param {Obejct}parent(设置到的父项:主要清单汇总元素) {Object}detail
  1529. * @return {void}
  1530. * */
  1531. function loadMainBillsItems(parent, detail) {
  1532. let mainBills = detail.Bills.datas.filter(data => data.mainBills);
  1533. for (let bills of mainBills) {
  1534. let source = {
  1535. code: bills.code,
  1536. name: bills.name,
  1537. unit: bills.unit,
  1538. quantity: bills.quantity,
  1539. fees: bills.fees,
  1540. remark: bills.remark
  1541. };
  1542. let mainBillsItemEle = new MainBillsItem(source);
  1543. //主要清单明细项目编码唯一
  1544. checkUnique(curTenderEle.constraints.mainBillsCode, source.code, '主要清单明细项目编码');
  1545. parent.children.push(mainBillsItemEle);
  1546. }
  1547. }
  1548. /*
  1549. * 加载人材机汇总
  1550. * @param {Object}detail
  1551. * @return {Object}
  1552. * */
  1553. function loadGlj(detail) {
  1554. let gljList = detail.projectGLJ.datas.gljList;
  1555. if (gljList.length > 0) {
  1556. //创建人材机汇总节点
  1557. let gljSummary = new GljSummary();
  1558. //人材机节点
  1559. let allGljs = gljUtil.sortRationGLJ(gljList); //人材机汇总排序
  1560. //计算总消耗量
  1561. gljUtil.calcProjectGLJQuantity(detail.projectGLJ.datas,
  1562. detail.ration_glj.datas, detail.Ration.datas, detail.Bills.datas, curPMData.tender.property.decimal.glj.quantity, _, scMathUtil);
  1563. for (let glj of allGljs) {
  1564. let price = gljUtil.getGLJPrice(glj, detail.projectGLJ.datas,
  1565. curPMData.tender.property.calcOptions, detail.labourCoe.datas, curPMData.tender.property.decimal, false, _, scMathUtil);
  1566. let gljSource = {
  1567. code: glj.code,
  1568. name: glj.name,
  1569. spec: glj.spec,
  1570. unit: glj.unit,
  1571. orgCode: glj.original_code,
  1572. is_evaluate: glj.is_evaluate,
  1573. basePrice: price.base,
  1574. marketPrice: price.marketPrice,
  1575. quantity: glj.quantity,
  1576. originPlace: glj.originPlace,
  1577. vender: glj.vender,
  1578. qualityGrace: glj.qualityGrace,
  1579. brand: glj.brand,
  1580. remark: glj.remark
  1581. };
  1582. let gljEle = new Glj(gljSource);
  1583. //人材机代码唯一
  1584. checkUnique(curTenderEle.constraints.gljCode, gljSource.code, '人材机代码');
  1585. //人材机配比
  1586. let connectKey = gljUtil.getIndex(glj, gljKeyArray),
  1587. ratioData = detail.projectGLJ.datas.mixRatioMap[connectKey];
  1588. if (ratioData && Array.isArray(ratioData)) {
  1589. for (let ratio of ratioData) {
  1590. let gljRatio = new GljRatio({code: ratio.code, quantity: ratio.consumption});
  1591. gljEle.children.push(gljRatio);
  1592. }
  1593. }
  1594. gljSummary.children.push(gljEle);
  1595. }
  1596. return gljSummary;
  1597. }
  1598. }
  1599. //开始标签
  1600. function startTag(ele) {
  1601. let rst = `<${ele.name}`;
  1602. for (let attr of ele.attrs) {
  1603. rst += ` ${attr.name}="${attr.value}"`;
  1604. }
  1605. rst += ele.children.length > 0 ? '>' : '/>';
  1606. return rst;
  1607. }
  1608. //结束标签
  1609. function endTag(ele) {
  1610. return `</${ele.name}>`;
  1611. }
  1612. //拼接成xml字符串
  1613. function toXMLStr(eles) {
  1614. let rst = '';
  1615. for (let ele of eles) {
  1616. rst += startTag(ele);
  1617. if (ele.children.length > 0) {
  1618. rst += toXMLStr(ele.children);
  1619. rst += endTag(ele);
  1620. }
  1621. }
  1622. return rst;
  1623. }
  1624. //格式化xml字符串
  1625. function formatXml(text) {
  1626. //去掉多余的空格
  1627. text = '\n' + text.replace(/>\s*?</g, ">\n<");
  1628. //调整格式
  1629. let rgx = /\n(<(([^\?]).+?)(?:\s|\s*?>|\s*?(\/)>)(?:.*?(?:(?:(\/)>)|(?:<(\/)\2>)))?)/mg;
  1630. let nodeStack = [];
  1631. let output = text.replace(rgx, function($0, all, name, isBegin, isCloseFull1, isCloseFull2, isFull1, isFull2){
  1632. let isClosed = (isCloseFull1 === '/') || (isCloseFull2 === '/' ) || (isFull1 === '/') || (isFull2 === '/');
  1633. let prefix = '';
  1634. if (isBegin === '!') {
  1635. prefix = getPrefix(nodeStack.length);
  1636. } else {
  1637. if (isBegin !== '/') {
  1638. prefix = getPrefix(nodeStack.length);
  1639. if (!isClosed) {
  1640. nodeStack.push(name);
  1641. }
  1642. } else {
  1643. nodeStack.pop();
  1644. prefix = getPrefix(nodeStack.length);
  1645. }
  1646. }
  1647. let ret = '\n' + prefix + all;
  1648. return ret;
  1649. });
  1650. let outputText = output.substring(1);
  1651. return outputText;
  1652. function getPrefix(prefixIndex) {
  1653. let span = ' ';
  1654. let output = [];
  1655. for (let i = 0 ; i < prefixIndex; ++i) {
  1656. output.push(span);
  1657. }
  1658. return output.join('');
  1659. }
  1660. }
  1661. /*
  1662. * 导出数据
  1663. * @param {Number}tenderID(当前界面的单位工程ID,后台根据这个单位工程,去找其建设项目下所有数据)
  1664. * @return {void}
  1665. * */
  1666. this.toXml = async function (tenderID) {
  1667. let eleData = await loadProject(tenderID);
  1668. if (!eleData) {
  1669. return;
  1670. }
  1671. //转换成xml字符串
  1672. let xmlStr = toXMLStr([eleData]);
  1673. //加上xml声明
  1674. xmlStr = `<?xml version="1.0" encoding="utf-8"?>${xmlStr}`;
  1675. //格式化
  1676. xmlStr = formatXml(xmlStr);
  1677. let blob = new Blob([xmlStr], {type: 'text/plain;charset=uft-8'});
  1678. saveAs(blob, '重庆标准交换数据.xml');
  1679. }
  1680. }
  1681. })();