exportStandardInterface.js 87 KB

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