
INTERFACE_EXPORT = (() => {
    'use strict';

    /**
     * 
     * @param {String} areaKey - 地区标识，如：'安徽@马鞍山'，有些地区的接口只是取值上有不同，共有一个接口脚本， 需要通过地区标识确定一些特殊处理
     * @param {Number} exportKind - 导出类型，招标、投标、控制价
     * @param {Object} projectData - 项目表数据：{ 建设项目Data, children: [单位工程...] }
     * @param {Object} tenderDetailMap - 单位工程ID与getData接口数据(projectObj.project的结构)的映射。
     * @return {Promise<Array>} - 返回的数据结构必须按照规定：[{ data, exportKind, fileName }]，参考web\building_saas\standard_interface\index.js中的注释说明
     */
    async function entry(areaKey, exportKind, projectData, tenderDetailMap) {
        const {
            CONFIG: { 
                TYPE, 
                WHITE_SPACE
            },
            UTIL: {
                getValueByKey,
                getFee,
                generateHardwareId,
            },
            Element,
        } = INTERFACE_EXPORT_BASE;

        const {
            EXPORT_KIND: { BID_INVITATION, BID_SUBMISSION, CONTROL },
            fixedFlag,
            RationType,
        } = window.commonConstants

        const isBidInvitation = exportKind === BID_INVITATION; // 是否是招标
        const isBidSubmission = exportKind === BID_SUBMISSION; // 是否是投标
        const isControl = exportKind === CONTROL; // 是否是控制价

        let serialNo;
        let vTree;
        const info = projectData.property && projectData.property.basicInformation || [];
        const summary = projectData.summaryInfo[projectData.ID];
        // const feature = tenderDetailMap[projectData.children[0].ID].property.projectFeature;
// ------------------------------------------------------------------------------------------------------------
        // 提取字符串中的数字
        function getNum(str) {
            let num = str.replace(/[^0-9]/ig, "");
            return num;
        }

        function CheckNull(Value) {
            if (!Value)
                return 0
            else
                return Value;
        }

        function GetRationDataType(ration){
            let dt;
            if (calcTools.isRationItem(ration))
               dt = 3
            else if (calcTools.isGljRation(ration))
                dt = 1
            else if (calcTools.isVolumePrice(ration))
                dt = 4;
            return dt;
        }

        const valueMapArr = [
          ['新建', '1'],
          ['改扩建', '2'],
          ['高速公路', '1'],
          ['一级公路', '2'],
          ['二级公路', '3'],
          ['三级公路', '4'],
          ['四级公路', '5'],
          ['独立桥梁', '6'],
          ['独立隧道', '7'],
          ['一般计税', '1'],
          ['简易计税', '2'],
          ['清单', '1'],
          ['招标控制价', '2'],
          ['投标报价', '3'],
          ['支票', '1'],
          ['电汇', '2'],
          ['银行汇票', '3'],
          ['现金', '4'],
          ['银行保函', '5'],
          ['其他保函', '6'],
          ['其他', '7']
        ];

        function valueMap(AValue){
          let rst = AValue;
          for (let i in valueMapArr) {
            if (valueMapArr[i][0] == AValue){
              rst = valueMapArr[i][1];
              break;
            }
          }
          return rst;
        }

      function getRCJLB(AType){   // 1=人工；2=材料；3=机械组成物；4=设备；5=混凝土/砂浆/配合比；6=机械台班
          let rst = 2;
          AType+="";
          debugger;
          if (AType == '1'){
            rst = '1';
          }
          else if (['201', '205', '206', '207', '4'].includes(AType)){
            rst = '2';
          }
          else if (['202', '203', '204'].includes(AType)){
            rst = '5';
          }
          else if (['301'].includes(AType)){
            rst = '6';
          }
          else if (['302', '303'].includes(AType)){
            rst = '3';
          }
          else if (AType == '5'){
            rst = '4';
          };
          return rst;
      }
// ------------------------------------------------------------------------------------------------------------

        function CreateNode(nodeName, attrArr = []) {
            Element.call(this, nodeName, attrArr);
        }

        function GongCXX() {
            const attrs = [
                { name: '项目编号', value: getValueByKey(info, 'projNum') },
                { name: '项目名称', value: projectData.name },    // projName
                { name: '建设单位', value: getValueByKey(info, 'constructingUnits') },
                { name: '起始桩号', value: getValueByKey(info, 'startChainages') },
                { name: '终点桩号', value: getValueByKey(info, 'endChainages') },
                { name: '建设地址', value: getValueByKey(info, 'constructionAddress') },
                { name: '项目概况', value: getValueByKey(info, 'projOverview') },
                { name: '建设性质', value: valueMap(getValueByKey(info, 'natureConstruction')) },
                { name: '专业划分', value: valueMap(getValueByKey(info, 'roadGrade')) },
                { name: '道路里程', value: getValueByKey(info, 'roadDistance') },
                { name: '设计单位', value: getValueByKey(info, 'designUnit') },
                { name: '计税方式', value: valueMap(getValueByKey(info, 'taxMode')) },
                // { name: '文件类型', value: valueMap(getValueByKey(info, 'projType')) },
                {name: '文件类型', value: isBidInvitation ? 1 : (isControl ? 2 : 3)},    // 1=工程量清单；2=招标控制价；3=投标报价；
                { name: '标准版本号', value: '1.0' },
                { name: 'GUID', value: projectData._id }
            ];
            Element.call(this, '工程信息', attrs);
        }
        function ZhaoBiaoXX() {
            const attrs = [
                { name: '招标人', value: getValueByKey(info, 'tendereeName') },
                { name: '招标人纳税识别号', value: getValueByKey(info, 'tendereeTaxpayerIdentificationNo') },
                { name: '招标法定代表人或其授权人', value: getValueByKey(info, 'tenderAuthorizer') },
                { name: '招标法人或其授权人身份证号', value: getValueByKey(info, 'tenderAuthorizerIDNo') },
                { name: '造价咨询人', value: getValueByKey(info, 'costConsultant') },
                { name: '造价咨询人纳税识别号', value: getValueByKey(info, 'costConsultantTaxpayerIdentificationNo') },
                { name: '造价咨询人法定代表人或其授权人', value: getValueByKey(info, 'consultantAuthorizer') },
                { name: '造价咨询法人或其授权人身份证号', value: getValueByKey(info, 'consultantAuthorizerTaxpayerIdentificationNo') },
                { name: '编制人', value: getValueByKey(info, 'compileApprover') },
                { name: '编制人资格证号', value: getValueByKey(info, 'compileCertNo') },
                { name: '编制日期', value: getValueByKey(info, 'compileDate'), type: TYPE.DATE},
                { name: '复核人', value: getValueByKey(info, 'reviewApprover') },
                { name: '复核人资格证号', value: getValueByKey(info, 'reviewCertNo') },
                { name: '复核日期', value: getValueByKey(info, 'reviewDate'), type: TYPE.DATE }
            ];
            Element.call(this, '招标信息', attrs);
        }
        function ZhaoBiaoKZJ() {
            const attrs = [
                { name: '招标人', value: getValueByKey(info, 'tendereeName') },
                { name: '招标人纳税识别号', value: getValueByKey(info, 'tendereeTaxpayerIdentificationNo') },
                { name: '招标法定代表人或其授权人', value: getValueByKey(info, 'tenderAuthorizer') },
                { name: '招标法人或其授权人身份证号', value: getValueByKey(info, 'tenderAuthorizerIDNo') },
                { name: '造价咨询人', value: getValueByKey(info, 'costConsultant') },
                { name: '造价咨询人纳税识别号', value: getValueByKey(info, 'costConsultantTaxpayerIdentificationNo') },
                { name: '造价咨询人法定代表人或其授权人', value: getValueByKey(info, 'consultantAuthorizer') },
                { name: '造价咨询法人或其授权人身份证号', value: getValueByKey(info, 'consultantAuthorizerTaxpayerIdentificationNo') },
                { name: '编制人', value: getValueByKey(info, 'compileApprover') },
                { name: '编制人资格证号', value: getValueByKey(info, 'compileCertNo') },
                { name: '编制日期', value: getValueByKey(info, 'compileDate'), type: TYPE.DATE},
                { name: '复核人', value: getValueByKey(info, 'reviewApprover') },
                { name: '复核人资格证号', value: getValueByKey(info, 'reviewCertNo') },
                { name: '复核日期', value: getValueByKey(info, 'reviewDate'), type: TYPE.DATE },

                { name: '审核人', value: getValueByKey(info, 'examineApprover') },
                { name: '审核人资格证号', value: getValueByKey(info, 'examineCertNo') },
                { name: '审核日期', value: getValueByKey(info, 'examineDate'), type: TYPE.DATE },

                { name: '控制价总价', value: summary.totalCost, type: TYPE.DECIMAL },
                { name: '工期', value: getValueByKey(info, 'timeLimit') },
                { name: '质量要求', value: getValueByKey(info, 'qualityRequirements') }
            ];
            Element.call(this, '招标控制价', attrs);
        }
        function TouBiaoXX() {
            let hardID = generateHardwareId();
            let [cpuId, diskId, macId] = hardID.split(";");

            const attrs = [
                { name: '投标人', value: getValueByKey(info, 'bidderName') },
                { name: '投标人纳税识别号', value: getValueByKey(info, 'bidderAuthorizerIDNo') },
                { name: '投标人法定代表或其授权人', value: getValueByKey(info, 'bidderAuthorizer') },
                { name: '投标人法人或其授权人身份证号', value: getValueByKey(info, 'bidderAuthorizerTaxpayerIdentificationNo') },
                { name: '编制人', value: getValueByKey(info, 'compileApprover') },
                { name: '编制人资格证号', value: getValueByKey(info, 'compileCertNo') },
                { name: '编制日期', value: getValueByKey(info, 'compileDate'), type: TYPE.DATE},
                { name: '复核人', value: getValueByKey(info, 'reviewApprover') },
                { name: '复核人资格证号', value: getValueByKey(info, 'reviewCertNo') },
                { name: '复核日期', value: getValueByKey(info, 'reviewDate'), type: TYPE.DATE },
                { name: '审核人', value: getValueByKey(info, 'examineApprover') },
                { name: '审核人资格证号', value: getValueByKey(info, 'examineCertNo') },
                { name: '审核日期', value: getValueByKey(info, 'examineDate'), type: TYPE.DATE },

                { name: '投标总价', value: summary.totalCost, type: TYPE.DECIMAL },
                { name: '工期', value: getValueByKey(info, 'timeLimit') },
                { name: '投标担保金额', value: getValueByKey(info, 'tenderGuaranteeAmount') },
                { name: '质量承诺', value: getValueByKey(info, 'qualityCommitment') },
                { name: '投标担保方式', value: valueMap(getValueByKey(info, 'tenderGuaranteeMethod')) },

                { name: '造价软件品牌', value: '纵横公路云造价' },
                { name: '造价软件版本', value: "Ver" + VERSION },
                { name: '造价软件加密锁编号', value: userID },
                { name: '计算机硬件信息', value: cpuId + diskId + macId }
            ];
            Element.call(this, '投标信息', attrs);
        }

        function addRationGLJs(rData, rationNode){
            for (let i = 0; i < rData.rationGLJList.length; i++) {
                let glj = rData.rationGLJList[i];
                const attrs = [
                    { name: '人材机标识', value: glj.GLJID},
                    { name: '人材机含量', value: glj.tenderQuantity}
                ];
                let gljNode = new CreateNode('定额人材机含量明细', attrs);
                rationNode.children.push(gljNode);
            }
        }

        function addRations(ABillItem, ABillNode){
            for (let i = 0; i < ABillItem.children.length; i++) {
                let r = ABillItem.children[i];
                let rData = ABillItem.children[i].data;
                const attrs = [
                    { name: '序号', value: r.row()},
                    { name: '定额编号', value: rData.code},
                    { name: '定额名称', value: rData.name},
                    { name: '单位', value: rData.unit},
                    { name: '数量', value: rData.tenderQuantity},
                    { name: '单价', value: rData.feesIndex && rData.feesIndex.common ? rData.feesIndex.common.tenderUnitFee : 0},
                    { name: '合价', value: rData.feesIndex && rData.feesIndex.common ? rData.feesIndex.common.tenderTotalFee : 0},
                    { name: '备注', value: ''},
                    { name: '数据类型', value: GetRationDataType(r)},
                    { name: '人工费', value: getFee(rData.fees, 'marketLabour.tenderTotalFee'), type: TYPE.DECIMAL},
                    { name: '主材费', value: getFee(rData.fees, 'marketMaterial.tenderTotalFee'), type: TYPE.DECIMAL},
                    { name: '辅材费', value: 0},
                    { name: '机械使用费', value: getFee(rData.fees, 'marketMachine.tenderTotalFee'), type: TYPE.DECIMAL},
                    { name: '设备费', value: 0},
                    { name: '措施费1', value: getFee(rData.fees, 'measure.tenderTotalFee'), type: TYPE.DECIMAL},    // FQuery2.FieldByName('OtherDirectFee'},
                    { name: '措施费2', value: 0}, //getFee(r.fees, 'measure.tenderTotalFee'), type: TYPE.DECIMAL
                    { name: '企业管理费', value: getFee(rData.fees, 'manage.tenderTotalFee'), type: TYPE.DECIMAL},
                    { name: '规费', value: getFee(rData.fees, 'force.tenderTotalFee'), type: TYPE.DECIMAL},
                    { name: '利润', value: getFee(rData.fees, 'profit.tenderTotalFee'), type: TYPE.DECIMAL},
                    { name: '税金', value: getFee(rData.fees, 'tax.tenderTotalFee'), type: TYPE.DECIMAL},
                ];
                let rationNode = new CreateNode('定额信息表', attrs);
                ABillNode.children.push(rationNode);

                addRationGLJs(rData, rationNode);
            }
        }

        function recursiveAddBills(AItem, AXMLParent) {
            if (AItem == undefined || !calcTools.isBill(AItem)) return;

            let vBillNode;
            function addBillNode () {
                serialNo++;
                let zmh = (AItem.parent == vTree.roots[0]) ? getNum(AItem.data.name) : AItem.data.code;
                const attrs = [
                    {name: "序号", value: AItem.row()}, //AItem.data.ID
                    {name: "清单章节号", value: zmh},
                    {name: "子目号", value: zmh},
                    {name: "子目名称", value: AItem.data.name},
                    {name: "单位", value: AItem.data.unit},
                    {name: "数量", value: AItem.data.quantity, type: TYPE.DECIMAL}
                ];
               // debugger;
                let dj = 0, hj = 0;
                // if ((isBidSubmission || isControl) || (AItem.data.specialProvisional == '专业工程')){
                if (isBidSubmission || isControl) {
                    hj = CheckNull(AItem.data.feesIndex && AItem.data.feesIndex.common ? AItem.data.feesIndex.common.tenderTotalFee : 0);
                    dj = CheckNull(AItem.data.feesIndex && AItem.data.feesIndex.common ? AItem.data.feesIndex.common.tenderUnitFee : 0);
                }
                attrs.push({name: "单价", value: dj}, {name: "合价", value: hj});
                attrs.push({name: "备注", value: isBidInvitation ? '' : AItem.data.remark});

                let sjlx;
                if (AItem.data.specialProvisional == '专业工程')      // 专项暂定
                   sjlx = 21;
                else {
                    if (calcTools.isLeafBill(AItem)) {
                        if (AItem.data.code == '102-3')                       // 安全生产费
                            sjlx = '22'
                        else if ((AItem.data.code == '-a') && (AItem.parent && (AItem.parent.data.code == '101-1')))               // 工程一切险
                            sjlx = '23'
                        else if ((AItem.data.code == '-b') && (AItem.parent && (AItem.parent.data.code == '101-1')))                  // 第三者责任险
                            sjlx = '24'
                        else
                            sjlx = '20';
                    }
                    else {
                        sjlx = '1';            // 父清单
                        attrs.find(function getE(e) {return e.name == '单位'}).value = '项';
                    }
                }
                attrs.push({name: "数据类型", value: sjlx});

                if (isBidSubmission || isControl){
                    attrs.push(
                        {name: "人工费", value: getFee(AItem.data.fees, 'marketLabour.tenderTotalFee'), type: TYPE.DECIMAL},
                        {name: "主材费", value: getFee(AItem.data.fees, 'marketMaterial.tenderTotalFee'), type: TYPE.DECIMAL},
                        {name: "辅材费", value: 0},
                        {name: "机械使用费", value: getFee(AItem.data.fees, 'marketMachine.tenderTotalFee'), type: TYPE.DECIMAL},
                        {name: "设备费", value: 0},
                        {name: "措施费1", value: getFee(AItem.data.fees, 'measure.tenderTotalFee'), type: TYPE.DECIMAL},
                        {name: "措施费2", value: 0}, // getFee(AItem.data.fees, 'measure.tenderTotalFee'), type: TYPE.DECIMAL},
                        {name: "企业管理费", value: getFee(AItem.data.fees, 'manage.tenderTotalFee'), type: TYPE.DECIMAL},
                        {name: "规费", value: getFee(AItem.data.fees, 'force.tenderTotalFee'), type: TYPE.DECIMAL},
                        {name: "利润", value: getFee(AItem.data.fees, 'profit.tenderTotalFee'), type: TYPE.DECIMAL},
                        {name: "税金", value: getFee(AItem.data.fees, 'tax.tenderTotalFee'), type: TYPE.DECIMAL}
                    );
                }
                else{
                    attrs.push(
                      {name: "人工费", value: 0},
                      {name: "主材费", value: 0},
                      {name: "辅材费", value: 0},
                      {name: "机械使用费", value: 0},
                      {name: "设备费", value: 0},
                      {name: "措施费1", value: 0},
                      {name: "措施费2", value: 0},
                      {name: "企业管理费", value: 0},
                      {name: "规费", value: 0},
                      {name: "利润", value: 0},
                      {name: "税金", value: 0}
                    );
                }

                vBillNode = new CreateNode('工程量清单明细', attrs);
                AXMLParent.children.push(vBillNode);

              if (isBidSubmission || isControl) {
                if (calcTools.isLeafBill(AItem))
                  addRations(AItem, vBillNode)
              };
            }
            addBillNode();

            recursiveAddBills(AItem.children[0], vBillNode);
            recursiveAddBills(AItem.nextSibling, AXMLParent);
        }

        function createGCLQDB(Bid, gongCLQDB){
            vTree = tenderDetailMap[Bid.ID].mainTree;
            serialNo = 0;
            recursiveAddBills(vTree.roots[0].children[0], gongCLQDB);
        };

        function createJiRGXXB(Bid, jiRGXXB){
            let vJRG, vKind, vChild;
            let vJRGNode, vKindNode, vChildNode;

            vJRG = vTree.roots.find(function getElement(e) {return e.getFlag() == fixedFlag.DAYWORK_LABOR});
            let attrs = [
                { name: '序号', value: vJRG.row() },
                { name: '名称', value: vJRG.data.name },
                { name: '数据类型', value: 0 },
                { name: '合价', value: isBidInvitation ? 0 : ( vJRG.data.feesIndex && vJRG.data.feesIndex.common ? vJRG.data.feesIndex.common.tenderTotalFee : 0) },
            ];
            vJRGNode = new CreateNode('计日工信息标题', attrs);
            jiRGXXB.children.push(vJRGNode);

            function getDataType_JRG(name) {
                if (name.includes('劳务'))
                    return 1
                else if (name.includes('材料'))
                    return 2
                else if (name.includes('机械'))
                    return 3
                else
                    return 0;
            }

            for (let i = 0; i < vJRG.children.length; i++) {
                vKind = vJRG.children[i];
                let attrs = [
                    { name: '序号', value: vKind.row() },
                    { name: '名称', value: vKind.data.name },
                    { name: '数据类型', value: getDataType_JRG(vKind.data.name) },
                    { name: '合价', value: isBidInvitation ? 0 : (vKind.data.feesIndex && vKind.data.feesIndex.common ? vKind.data.feesIndex.common.tenderTotalFee : 0) },
                ];
                vKindNode = new CreateNode('计日工信息标题', attrs);
                jiRGXXB.children.push(vKindNode);

                for (let j = 0; j < vKind.children.length; j++) {
                    vChild = vKind.children[j];

                    let attrs = [
                        { name: '编号', value: vChild.data.code },
                        { name: '名称', value: vChild.data.name },
                        { name: '数据类型', value: getDataType_JRG(vKind.data.name) + 3},
                        { name: '单位', value: vChild.data.unit },
                        { name: '暂定数量', value: vChild.data.quantity },
                        { name: '单价', value: isBidInvitation ? 0 : (vChild.data.feesIndex && vChild.data.feesIndex.common ? vChild.data.feesIndex.common.tenderUnitFee : 0) },
                        { name: '合价', value: isBidInvitation ? 0 : (vChild.data.feesIndex && vChild.data.feesIndex.common ? vChild.data.feesIndex.common.tenderTotalFee : 0) }
                    ];
                    vChildNode = new CreateNode('计日工信息明细', attrs);
                    vKindNode.children.push(vChildNode);
                }
            }

        }

        function createZaoJHZB(Bid, ZaoJHZB) {
            const map_ZC_LB = [
                {reg: /(第?100章?至第?700章?)/, zc: '', lb: '1'},
                {reg: /已包含在清单合计中的材料/, zc: '', lb: '2'},
                {reg: /清单合计减去材料/, zc: '', lb: '3'},
                {reg: /计日工合计/, zc: '', lb: '4'},
                {reg: /暂列金额/, zc: '', lb: '5'},
                {reg: /投标报价/, zc: '', lb: '6'},
                {reg: /第100章/, zc: '100', lb: '11'},     // 我们软件"章"字后面有2个空格！
                {reg: /第200章/, zc: '200', lb: '12'},
                {reg: /第300章/, zc: '300', lb: '13'},
                {reg: /第400章/, zc: '400', lb: '14'},
                {reg: /第500章/, zc: '500', lb: '15'},
                {reg: /第600章/, zc: '600', lb: '16'},
                {reg: /第700章/, zc: '700', lb: '17'}
            ]

            function getZCLB(name, kind){
                let rst = '';
                for (let i = 0; i < map_ZC_LB.length; i++){
                    const trimName = (name || '').replace(/\s/g, '');
                    if (map_ZC_LB[i].reg.test(trimName)){
                        if (kind == 1)
                            rst = map_ZC_LB[i].zc
                        else if (kind == 2)
                            rst = map_ZC_LB[i].lb;
                        break;
                    }
                }
                return rst;
            }

            function getJE(node){
                if (isBidInvitation && ![fixedFlag.PROVISIONAL_TOTAL, fixedFlag.PROVISIONAL].includes(node.getFlag()))
                    return 0
                else
                    return (node.data.feesIndex && node.data.feesIndex.common ? node.data.feesIndex.common.tenderTotalFee : 0);
            }

            let nodes = [...vTree.roots, ...vTree.roots[0].children];

            for (let i = 0; i < nodes.length; i++){
                let node = nodes[i];
                let attrs = [
                    { name: '序号', value: node.row() },
                    { name: '章次', value: getZCLB(node.data.name, 1) },
                    { name: '名称', value: node.data.name },
                    { name: '金额', value: getJE(node) },
                    { name: '类别', value: getZCLB(node.data.name, 2) },
                    { name: '备注', value: node.data.remark }
                ];
                const zaoJHZMX = new CreateNode('造价汇总明细', attrs);
                ZaoJHZB.children.push(zaoJHZMX);
            };
        }

        function createRenCJHZ(Bid, RenCJHZ) {
            const pGLJs = tenderDetailMap[Bid.ID].projectGLJ.datas.gljList;
            for (let i = 0; i < pGLJs.length; i++){
                let pGLJ = pGLJs[i];
                let attrs = [
                    { name: '人材机标识', value: pGLJ.glj_id },
                    { name: '人材机编号', value: pGLJ.code },
                    { name: '人材机名称', value: pGLJ.name },
                    { name: '规格型号', value: pGLJ.specs },
                    { name: '单位', value: pGLJ.unit },
                    { name: '数量', value: pGLJ.quantity },
                    { name: '单价', value: pGLJ.unit_price.market_price },
                    { name: '人材机类别', value: getRCJLB(pGLJ.type) },
                    { name: '是否主要材料', value: pGLJ.is_main_material },   // , type: TYPE.BOOL
                    { name: '是否甲供', value: pGLJ.supply },
                    { name: '是否暂估', value: pGLJ.is_evaluate },
                    { name: '备注', value: pGLJ.remark }
                ];
                // if (pGLJ.type != 9){
                    const renCJHZMXB = new CreateNode('人材机汇总明细表', attrs);
                    RenCJHZ.children.push(renCJHZMXB);
                // }
            }
        }

        // 生成标段工程
        function createGLBDGC(Bid, gongLGCSJ, gongLGCHZ, Num){
            let attrs0 = [
                { name: '序号', value: Num },
                { name: '标段名称', value: Bid.name },
                { name: '金额', value: isBidInvitation ? 0 : projectData.summaryInfo[Bid.ID].totalCost }
            ];

            const attrs1 = [{ name: '唯一标识-Guid', value: Bid._id }];           // 公路标段工程
            const gongLBDGC = new CreateNode('公路标段工程', attrs0.concat(attrs1));
            gongLGCSJ.children.push(gongLBDGC);
            const gongCLQDB = new CreateNode('工程量清单表');
            const jiRGXXB = new CreateNode('计日工信息表');
            const ZaoJHZB = new CreateNode('造价汇总表');
            const RenCJHZ = new CreateNode('人材机汇总');
            gongLBDGC.children = [gongCLQDB, jiRGXXB, ZaoJHZB, RenCJHZ];

            createGCLQDB(Bid, gongCLQDB);
            createJiRGXXB(Bid, jiRGXXB);
            createZaoJHZB(Bid, ZaoJHZB);
            createRenCJHZ(Bid, RenCJHZ);

            // 同步生成 公路工程汇总明细 数据
            const attrs2 = [{ name: '备注', value: '' }];
            const gongLGCHZMX = new CreateNode('公路工程汇总明细', attrs0.concat(attrs2));
            gongLGCHZ.children.push(gongLGCHZMX);
        }

        // 组装主体框架数据
        function setupConstruction() {
            const chiZGLGC = new CreateNode('池州公路工程');
            const gongCXX = new GongCXX();   // 工程信息
            const zhaoTBXX = new CreateNode('招投标信息');
            const gongLGCSJ = new CreateNode('公路工程数据');
            chiZGLGC.children = [gongCXX, zhaoTBXX, gongLGCSJ];

            if (isBidInvitation)
                zhaoTBXX.children.push(new ZhaoBiaoXX());
            else if (isControl)
                zhaoTBXX.children.push(new ZhaoBiaoKZJ());
            else
                zhaoTBXX.children.push(new TouBiaoXX());

            const gongLGCHZ = new CreateNode('公路工程汇总');
            gongLGCSJ.children.push(gongLGCHZ);

            let n = 0;
            for (const Bid of projectData.children) {
                n++;
                createGLBDGC(Bid, gongLGCSJ, gongLGCHZ, n);
            }
            gongLGCSJ.children.push(gongLGCSJ.children.shift());

            const suffix = INTERFACE_CONFIG[areaKey]['fileSuffix'][exportKind];
            return [{
                data: chiZGLGC,
                exportKind,
                fileName: `${projectData.name}${suffix}`
            }];
        }

        return setupConstruction();
    }

    return {
        entry
    };
})();
