/**
 * Created by zhang on 2018/8/14.
 */

//重庆综合里程、工地转移费率值修改特殊处理

if (typeof feeRateObject !== "undefined") {
  feeRateObject.feeRateSpecialHandle = function (subRate, value) {
    let result = {};
    if (subRate.name == "工地转移(km)" && value && value < 50) {
      //工地转移50km以内按50km算
      result.valueKey = "50";
      result.value = scMathUtil.roundForObj(value, getDecimal("feeRate")); //设置显示的节点值
    }
    if (subRate.name == "综合里程(km)" && value && value < 3) {
      //综合里程3km以内按3km算
      result.valueKey = "3";
      result.value = scMathUtil.roundForObj(value, getDecimal("feeRate")); //设置显示的节点值
    }
    return result;
  };
}

// 累进的基数名称
const progression = [
  "施工场地建设费",
  "养护单位(业主)管理费",
  "信息化费",
  "路线工程监理费",
  "独立桥梁隧道工程监理费",
  "设计文件审查费",
  "路线勘察设计费",
  "独立桥梁隧道维修加固勘察设计费",
  "招标代理及标底(最高投标限价)编制费",
];
// 累进计算金额不足时的处理映射
const deficiency = {
  路线工程监理费: 20000, // 不足2万按2万
  独立桥梁隧道工程监理费: 20000,
  设计文件审查费: 3000,
};

if (typeof module !== "undefined") {
  module.exports = {
    progression,
    deficiency,
  };
}

// {定额建安费(不含定额设备购置费)}
if (typeof baseFigureTemplate !== "undefined") {
  baseFigureTemplate.boq.DEJAFBHDESBGZF = function (tender) {
    // 旧：汇总定额的定额建安费（不含设备类型的定额、不含工料机定额、不含量x价清单）。因缺少量x价清单的定额建安费，新版本不再使用。
    if (isLowVer(historyVer1)) {
      const feeField = "rationCommon";
      const subFeeField = tender ? "tenderTotalFee" : "totalFee";
      let rations = projectObj.project.Ration.datas.filter((ration) => !(ration.type === rationType.gljRation && ration.subType === gljType.EQUIPMENT));
      const summaryFee = rations.reduce((total, ration) => {
        const fee = cbTools.getFee(ration, feeField, subFeeField);
        return (total += fee);
      }, 0);
      return summaryFee.toDecimal(decimalObj.bills.totalPrice);
    } else {
      // 新：根结点的定额建安费（含 量x价清单的定额建安费），扣除定额设备费+税金。其中，设备费：传入rationCommon时，表示定额设备费+税金。传入equipment表示定额设备费
      const baseFee = cbTools.getBaseFee(fixedFlag.ONE_SEVEN_BILLS, tender, "rationCommon");
      const fixedNode = projectObj.project.mainTree.roots.find((node) => node.getFlag() === fixedFlag.ONE_SEVEN_BILLS);
      const equipmentTaxFee = cbTools.getEquipmentFee(fixedNode, tender, "rationCommon");
      return (baseFee - equipmentTaxFee).toDecimal(decimalObj.bills.totalPrice);
    }
  };
}
