exportStandardInterface.js 113 KB

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