| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574 |
- /**
- * Created by zhang on 2019/5/20.
- */
- let exportUtil = {
- setEngineerPriceIndex:function (tender,projectData) {
- let priceIndex = {
- name:"工程造价指标",
- attrs:[],
- children:[],
- };
- let fixMap = {};
- let buildingArea = this.getBuildArea(tender.property.engineerFeatures); //tender.property.projectFeature?getItemValueBykey(tender.property.projectFeature,"buildingArea"):1;//建筑面积
- for(let b of projectData.bills){
- if(b.flags && b.flags.length > 0){
- let f = _.find(b.flags,{"fieldName":"fixed"});
- if(f) fixMap[f.flag] = this.getTotalFee(b);
- }
- }
- //计算其他组织措施费 = 施工组织措施项目下的子项,除了 安全文明施工费、建设工程竣工档案编制费以外的项
- let CONSTRUCTION_ORGANIZATION = fixMap[fixedFlag.CONSTRUCTION_ORGANIZATION]?fixMap[fixedFlag.CONSTRUCTION_ORGANIZATION]:0;
- let SAFETY_CONSTRUCTION = fixMap[fixedFlag.SAFETY_CONSTRUCTION]?fixMap[fixedFlag.SAFETY_CONSTRUCTION]:0;
- let PROJECT_COMPLETE_ARCH_FEE = fixMap[fixedFlag.PROJECT_COMPLETE_ARCH_FEE]? fixMap[fixedFlag.PROJECT_COMPLETE_ARCH_FEE]:0;
- let other_org_fee = CONSTRUCTION_ORGANIZATION - SAFETY_CONSTRUCTION - PROJECT_COMPLETE_ARCH_FEE;
- other_org_fee = other_org_fee >0 ?other_org_fee:0;
- let engineerCost = fixMap[fixedFlag.ENGINEERINGCOST]?fixMap[fixedFlag.ENGINEERINGCOST]:1;
- priceIndex.children.push(this.getFlag("分部分项工程费",fixMap[fixedFlag.SUB_ENGINERRING],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("技术措施费",fixMap[fixedFlag.CONSTRUCTION_TECH],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("安全文明施工费",fixMap[fixedFlag.SAFETY_CONSTRUCTION],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("建设工程竣工档案编制费",fixMap[fixedFlag.PROJECT_COMPLETE_ARCH_FEE],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("其他组织措施费",other_org_fee,engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("暂列金额",fixMap[fixedFlag.PROVISIONAL],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("专业工程暂估价",fixMap[fixedFlag.ENGINEERING_ESITIMATE],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("计日工",fixMap[fixedFlag.DAYWORK],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("总承包服务费",fixMap[fixedFlag.TURN_KEY_CONTRACT],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("索赔与现场签证",fixMap[fixedFlag.CLAIM_VISA],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("规费",fixMap[fixedFlag.CHARGE],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("税金",fixMap[fixedFlag.TAX],engineerCost,buildingArea));
- priceIndex.children.push(this.getFlag("工程造价",fixMap[fixedFlag.ENGINEERINGCOST],engineerCost,buildingArea));
- return priceIndex;
- },
- getTotalFee:function (b) {
- let total = 0;
- if(b.fees && b.fees.length > 0){
- let common = _.find(b.fees,{"fieldName":"common"});
- if(common) total = scMathUtil.roundForObj(common.totalFee,getDecimal("bills.totalPrice"))
- }
- return total;
- },
- getFlag: function (name,totalCost,engineerCost,buildingArea) {
- totalCost = totalCost?totalCost:0;
- let flag = {
- name:name,
- attrs:[
- {name: "金额", value: scMathUtil.roundToString(totalCost,3)},
- {name: "单方造价", value: scMathUtil.roundToString(exportUtil.calcUnitB(totalCost,buildingArea),2)},
- {name: "占造价比例", value: scMathUtil.roundToString(totalCost/engineerCost * 100,2)},
- ],
- };
- return flag;
- },
- getBuildArea:function (features) {
- if(features){
- let areas = [];
- for(let f of features){
- if(f.index == true && f.value && f.value !=="" && IsNumber(f.value)) areas.push(f.value);
- }
- return _.isEmpty(areas)?1:areas;
- }
- return 1
- },
- calcUnitB:function (total,building,coe,decimal = 3) {
- if(Array.isArray(building)){
- for(let b of building){
- total = scMathUtil.roundForObj(total/b,6);
- }
- }else {
- total = scMathUtil.roundForObj(total/building,6);
- }
- coe = gljUtil.isDef(coe)?coe:1;
- return scMathUtil.roundForObj(total*coe,decimal);
- },
- calUnitWidthCoe:function (total,noNeedCoe) {
- let areas = exportUtil.getBuildArea(projectObj.project.property.engineerFeatures);
- let f = _.find(projectObj.project.property.engineerFeatures,{index:true});
- return f && noNeedCoe!==true?exportUtil.calcUnitB(total,areas,f.coe):exportUtil.calcUnitB(total,areas);
- },
- getIndexBills:function (bills) {
- let parentMap = {},datas = [],totalCost = 0;
- let FBFX_b = null,teh_b = null,costNode=null;
- for(let b of bills) {
- parentMap[b.ParentID] ? parentMap[b.ParentID].push(b) : parentMap[b.ParentID] = [b];//有添加,无则生成
- if(b.flags && b.flags.length > 0){
- let f = _.find(b.flags,{"fieldName":"fixed"});
- if(!f) continue;
- if(f.flag == fixedFlag.SUB_ENGINERRING) FBFX_b = b;//过滤出分部分项工程;
- if(f.flag == fixedFlag.CONSTRUCTION_TECH) teh_b = b;//过滤出技术措施项目;
- if(f.flag == fixedFlag.ENGINEERINGCOST) costNode = b;//过滤出工程造价项目;
- }
- }
- if(FBFX_b) getChildren(FBFX_b,parentMap,datas);
- if(teh_b) getChildren(teh_b,parentMap,datas);
- if(costNode) totalCost = exportUtil.getTotalFee(costNode);
- for(let td of datas){
- if(parentMap[td.ID]){
- td.economicType = "";
- td.quantityIndexType = "";
- td.quantityIndexUnit = "";
- td.quantityIndexCoe = "";
- }
- }
- return [datas,totalCost];
- function getChildren(d,map,arr) {
- let tem = {
- ID:d.ID,
- ParentID:d.ParentID,
- code:d.code,
- name:d.name,
- unit:d.unit,
- quantity:d.quantity,
- totalFee:exportUtil.getTotalFee(d),
- economicType:d.economicType,
- quantityIndexType:d.quantityIndexType,
- quantityIndexUnit:d.quantityIndexUnit,
- quantityIndexCoe:d.quantityIndexCoe,
- };
- arr.push(tem);
- if(map[d.ID]){
- for(let s of map[d.ID]){
- getChildren(s,map,arr)
- }
- }
- }
- }
- };
- async function exportSEI(projectID) {
- let tenderProjects = [];
- let result = await ajaxPost("/project/getSEIProjects",{projectID:projectID});
- let pr = new SCComponent.InitProgressBar($('#progress'), $('#progress-title'), $('#progress-content'), $('#progressBar'));
- pr.start('导出数据接口', '正在导出文件,请稍候……');
- console.log(result);
- let project = getProject(result);
- await prepareTenderDatas(tenderProjects,project);
- toXml(project);
- pr.end();
- function getProject(orignal) {//取建设项目信息
- let basicInformation = getBaseInfo(orignal);
- let project = {
- name: "建设项目",
- attrs: [
- {name: "项目名称", value: orignal.name},
- {name:"建设单位",value:getItemValueBykey(basicInformation.items,"constructionUnit")},
- {name:"施工单位",value:getItemValueBykey(basicInformation.items,"buildingUnit")},
- {name: "标准名称", value: "重庆市建设工程造价指标采集标准(清单计价)"},
- {name: "标准版本号", value: "1.1"}
- ],
- basicInformation:basicInformation,
- children:[]
- };
- initAtts(project.attrs);
- for(let c of orignal.children){
- project.children.push(getEngineering(c));
- }
- return project;
- }
- function getEngineering(source){
- let engineer = {
- name:"单项工程",
- attrs:[
- {name: "名称", value: source.name}
- ],
- children:[]
- };
- for(let c of source.children){
- let tenderProject = getTender(c);
- engineer.children.push(tenderProject);
- tenderProjects.push(tenderProject);
- }
- return engineer
- };
- function getTender(source) {
- let tender = {
- ID:source.ID,
- name:"单位工程",
- attrs:[
- {name: "名称", value: source.name}
- ],
- children:[],
- valuationType:source.property.valuationType,
- taxType:source.property.taxType,
- property:source.property
- };
- return tender;
- }
- async function prepareTenderDatas(tenders,project) {
- for(let t of tenders){
- await setTenderData(t,project);
- await setTimeoutSync(null,500);
- }
- }
- async function setTenderData(tender,project) {
- let projectData = await ajaxPost("/project/loadSEIProjectData",{projectID:tender.ID});
- tender.children.push(setEngineerInfo(tender));//设置工程信息
- tender.children.push(setEngineerFeature(tender));//设置工程特征
- tender.children.push(setEngineerIndex(tender,projectData));
- tender.children.push(await setGLJSummy(tender,projectData));
- //
- }
- function setEngineerIndex(tender,projectData) {//设置工程指标
- let index = {
- name:"工程指标",
- attrs:[],
- children:[],
- };
- let indexName = tender.property.indexName?tender.property.indexName:"建筑工程";
- index.children.push(exportUtil.setEngineerPriceIndex(tender,projectData));
- index.children.push(setEngineerEcoIndex(tender,projectData,indexName));
- index.children.push(setMainMaterialIndex(tender,projectData,indexName));
- index.children.push(setQuantityIndex(tender,projectData,indexName));
- return index;
- function setMainMaterialIndex(tender,projectData,indexName){
- let mainIndex = {
- name:`${indexName}工料指标`,
- attrs:[],
- children:[]
- };
- if(projectData) gljUtil.calcProjectGLJQuantity(projectData.projectGLJs,projectData.ration_gljs,projectData.rations,projectData.bills,getDecimal("glj.quantity"),_,scMathUtil);
- let materials = indexObj.getMainMaterialDatas(tender.property.materials,projectData.projectGLJs,tender.property.calcOptions,tender.property.decimal,false,_,scMathUtil);
- for(let m of materials){
- mainIndex.children.push(getMaterial(m))
- }
- let index = {
- name:"主要工料价格及消耗量指标",
- attrs:[],
- children:[mainIndex]
- };
- return index;
- function getMaterial(m) {
- let material = {
- name:m.name,
- attrs:[
- {name:"综合单价",value:scMathUtil.roundToString(m.unitPrice,2)},
- {name:"数量",value:scMathUtil.roundToString(m.quantity,2)},
- {name:"单方指标",value:scMathUtil.roundToString(m.unitIndex,3)},
- {name:"单位",value:m.unit}
- ]
- };
- return material;
- }
- }
- function setQuantityIndex(tender,projectData,indexName) {
- let quantityIndex = {
- name:`${indexName}量指标`,
- attrs:[],
- children:[]
- };
- let quantities = indexObj.getQuantityDatas(tender.property.mainQuantities,projectData.bills);
- for(let q of quantities){
- quantityIndex.children.push(getQuantity(q));
- }
- let index = {
- name:`主要工程量指标`,
- attrs:[],
- children:[quantityIndex]
- };
- return index;
- function getQuantity(q) {
- let quantity = {
- name:q.name,
- attrs:[
- {name:"工程量指标",value:scMathUtil.roundToString(q.quantity,3)},
- {name:"单位",value:q.unit}
- ]
- };
- return quantity;
- }
- }
- function setEngineerEcoIndex(tender,projectData,indexName) {
- let ecoIndex = {
- name:`${indexName}经济指标`,
- attrs:[],
- children:[]
- };
- let economicDatas = indexObj.getEconomicDatas(tender.property.economics,projectData.bills);
- for(let e of economicDatas){
- ecoIndex.children.push(getEco(e))
- }
- let index = {
- name:`工程经济指标`,
- attrs:[],
- children:[ecoIndex]
- };
- return index;
- function getEco(e) {
- let eco = {
- name:e.name,
- attrs:[
- {name:"综合合价",value:scMathUtil.roundToString(e.cost,2)},
- {name:"单方指标",value:scMathUtil.roundToString(e.unitCost,2)},
- {name:"占造价比例",value:scMathUtil.roundToString(e.per,2)}
- ]
- };
- return eco;
- }
- }
- }
- async function setGLJSummy(tender,projectData) {
- let gljs = {
- name:"人材机汇总",
- attrs:[],
- children:[]
- };
- setGLJDetail(projectData,tender.property,gljs);
- return gljs;
- }
- function setGLJDetail(projectData,property,gljs) {
- if(projectData){
- gljUtil.calcProjectGLJQuantity(projectData.projectGLJs,projectData.ration_gljs,projectData.rations,projectData.bills,getDecimal("glj.quantity"),_,scMathUtil);
- }
- for(let g of projectData.projectGLJs.gljList) {
- if (!g.quantity || g.quantity == "") continue;
- g.marketPrice = gljUtil.getMarketPrice(g,projectData.projectGLJs,property.calcOptions,property.decimal,false,_,scMathUtil);
- gljs.children.push(setEachGLJ(g));
- }
- }
- function setEachGLJ(source){
- let g = {
- name:"人材机",
- attrs:[
- {name: "代码", value: source.code},
- {name: "名称", value: source.name},
- {name: "规格型号", value: source.specs},
- {name: "单位", value: source.unit},
- {name: "市场单价", value: source.marketPrice},
- {name: "数量", value: source.quantity},
- {name: "类型", value: source.type},
- {name: "产地", value: source.originPlace},
- {name: "厂家", value: source.vender},
- {name: "备注", value: source.remark}
- ]
- };
- return g;
- }
- function setEngineerInfo(tender) {//设置工程信息
- let infos = tender.property.engineerInfos?tender.property.engineerInfos:[];
- let info = {
- name:"工程信息",
- attrs:[
- {name:"造价编制单位",value:getItemValueByDispName(infos,"造价编制单位")},
- {name:"造价审核单位",value:getItemValueByDispName(infos,"造价审核单位")},
- {name:"项目负责人",value:getItemValueByDispName(infos,"项目负责人")},
- {name:"施工单位编制人员",value:getItemValueByDispName(infos,"施工单位编制人员")},
- {name:"编制人员",value:getItemValueByDispName(infos,"编制人员")},
- {name:"审核人员",value:getItemValueByDispName(infos,"审核人员")},
- {name:"开工日期",value:getItemValueByDispName(infos,"开工日期")},
- {name:"竣工日期",value:getItemValueByDispName(infos,"竣工日期")},
- {name:"工程地点",value:getItemValueByDispName(infos,"工程地点")},
- {name:"工程类型",value:getItemValueByDispName(infos,"工程类型")},
- {name:"合同价类型",value:getItemValueByDispName(infos,"合同价类型")},
- {name:"造价类型",value:getItemValueByDispName(infos,"造价类型")},
- {name:"计价方式及依据",value:getItemValueByDispName(infos,"计价方式及依据")},
- {name:"工程类别",value:getItemValueByDispName(infos,"工程类别")},
- {name:"编制日期",value:getItemValueByDispName(infos,"编制日期")},
- {name:"审查日期",value:getItemValueByDispName(infos,"审查日期")}
- ]
- };
- initAtts(info.attrs);
- return info;
- }
- function setEngineerFeature(tender) {
- let fea = {
- name:"工程特征",
- attrs:[],
- children:[]
- };
- fea.children.push(setIndexName(tender));
- return fea;
- function setIndexName(tender) {
- let indexName = {
- name:tender.property.indexName?tender.property.indexName:"建筑工程",
- attrs:[],
- children:[]
- };
- setFeatures(tender,indexName.children);
- return indexName
- }
- function setFeatures(tender,arr) {
- let features = tender.property.engineerFeatures?tender.property.engineerFeatures:[];
- if(features.length == 0) return;
- let parentMap = _.groupBy(features,"ParentID");
- let rootNodes = parentMap["-1"]?parentMap["-1"]:parentMap[null];
- for(let r of rootNodes){
- arr.push(getFeatrue(r,parentMap))
- }
- }
- function getFeatrue(node,parentMap){
- if(parentMap[node.ID]){//如果有子节点,那么它就是一个节点
- let name = node.exportName?node.exportName:node.name;
- let tem = {
- name:name.replace("*",""),
- attrs:[],
- children:[]
- };
- for(let s of parentMap[node.ID]){
- let f = getFeatrue(s,parentMap);
- f.children?tem.children.push(f):tem.attrs.push(f);//如果有children这个属性,则返回的是一个节点,如果没有,则返回的是一个属性
- }
- return tem;
- }else {//如果没有子节点,那么它就是父节点的一个属性
- if(node.isDetail == true){//如果是明细节点,则造一个明细节点
- return {name:"明细",attrs:[{name:"名称",value:node.value}],children:[]};
- }
- return {name:node.name.replace("*",""),value:node.value};
- }
- }
- }
- function getBaseInfo(project){
- let basicInformation = {items:[]};
- let tem = null;
- if(project.property&&project.property.basicInformation) tem =_.find(project.property.basicInformation,{"key":"basicInfo"});
- if(tem) basicInformation = tem;
- return basicInformation;
- }
- function getItemValueBykey(items,key) {
- let item = _.find(items,{"key":key});
- if(item) return item.value;
- return ""
- }
- function getItemValueByDispName(items,dispName) {
- let item = _.find(items,{"dispName":dispName});
- if(item) return item.value;
- return ""
- }
- function initAtts(arrs) {
- _.remove(arrs,function (item) {
- return item.required == false && _.isEmpty(item.value)
- })
- }
- //开始标签
- function startTag(ele) {
- let rst = `<${ele.name}`;
- for (let attr of ele.attrs) {
- rst += ` ${attr.name}="${ attr.value!=undefined&&attr.value!= null?attr.value:""}"`;
- }
- rst += ele.children&&ele.children.length > 0 ? '>' : '/>';
- return rst;
- }
- //结束标签
- function endTag(ele) {
- return `</${ele.name}>`;
- }
- //拼接成xml字符串
- function toXMLStr(eles) {
- let rst = '';
- for (let ele of eles) {
- rst += startTag(ele);
- if (ele.children&& ele.children.length > 0) {
- rst += toXMLStr(ele.children);
- rst += endTag(ele);
- }
- }
- return rst;
- }
- //格式化xml字符串
- function formatXml(text) {
- //去掉多余的空格
- text = '\n' + text.replace(/>\s*?</g, ">\n<");
- //调整格式
- let rgx = /\n(<(([^\?]).+?)(?:\s|\s*?>|\s*?(\/)>)(?:.*?(?:(?:(\/)>)|(?:<(\/)\2>)))?)/mg;
- let nodeStack = [];
- let output = text.replace(rgx, function($0, all, name, isBegin, isCloseFull1, isCloseFull2, isFull1, isFull2){
- let isClosed = (isCloseFull1 === '/') || (isCloseFull2 === '/' ) || (isFull1 === '/') || (isFull2 === '/');
- let prefix = '';
- if (isBegin === '!') {
- prefix = getPrefix(nodeStack.length);
- } else {
- if (isBegin !== '/') {
- prefix = getPrefix(nodeStack.length);
- if (!isClosed) {
- nodeStack.push(name);
- }
- } else {
- nodeStack.pop();
- prefix = getPrefix(nodeStack.length);
- }
- }
- let ret = '\n' + prefix + all;
- return ret;
- });
- let outputText = output.substring(1);
- return outputText;
- function getPrefix(prefixIndex) {
- let span = ' ';
- let output = [];
- for (let i = 0 ; i < prefixIndex; ++i) {
- output.push(span);
- }
- return output.join('');
- }
- }
- /*
- * 导出数据
- * @param {Number}tenderID(当前界面的单位工程ID,后台根据这个单位工程,根据导出粒度去找其建设项目下相关数据)
- * @return {void}
- * */
- function toXml(eleData) {
- //转换成xml字符串
- let xmlStr = toXMLStr([eleData]);
- //加上xml声明
- xmlStr = `<?xml version="1.0" encoding="utf-8"?>${xmlStr}`;
- //格式化
- xmlStr = formatXml(xmlStr);
- let blob = new Blob([xmlStr], {type: 'text/plain;charset=utf-8'});
- saveAs(blob, '经济指标.ZBF');
- }
- }
- $(function () {
- $("#SEIMenu").click(async function () {
- await exportSEI(projectObj.project.property.rootProjectID);
- $("#exportMenu").removeClass("show");
- })
- });
|