exportStandardInterface.js 95 KB

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