/**
 * Created by CSL on 2017-09-01.
 */
var test = require('tape');
const analyzer = require('../../web/building_saas/main/js/models/calc_program');

let calcTemplate = {
    ID: 1,
    name: "建筑工程",
    calcItems: [
        {
            ID: "101",
            code: "1",
            name: "基价直接工程费",
            fieldName: "baseDirect",
            dispExpr: "F2+F5+F6+F10",
            expression: "@('2') + @('5') + @('6') + @('10')",
            compiledExpr: "",
            statement: "基价人工费+基价材料费+基价机械费+未计价材料费"
        },
        {
            ID: "102",
            code: "1.1",
            name: "基价人工费",
            fieldName: "baseLabour",
            dispExpr: "F3+F4",
            expression: "@('3') + @('4')",
            compiledExpr: "",
            statement: "定额基价人工费+定额人工单价(基价)调整"
        },
        {
            ID: "103",
            code: "1.1.1",
            name: "定额基价人工费",
            fieldName: "rationBaseLabour",
            dispExpr: "[定额基价人工费]",
            expression: "base('定额基价人工费').toFixed(2)",
            compiledExpr: "",
            statement: "定额基价人工费"
        },
        {
            ID: "104",
            code: "1.1.2",
            name: "定额人工单价(基价)调整",
            fieldName: "rationLabourFixed",
            dispExpr: "F3*(L-1)",
            expression: "@('3') * (L-1)",
            labourCoeID: 22,
            compiledExpr: "",
            statement: "定额基价人工费*[定额人工单价(基价)调整系数-1]",
            memo: "渝建发(2013)51"
        },
        {
            ID: "105",
            code: "1.2",
            name: "基价材料费",
            fieldName: "baseMaterial",
            dispExpr: "[定额基价材料费]",
            expression: "base('定额基价材料费')",
            compiledExpr: "",
            statement: "定额基价材料费"
        },
        {
            ID: "106",
            code: "1.3",
            name: "基价机械费",
            fieldName: "baseMachine",
            dispExpr: "F7+F9",
            expression: "@('7') + @('9')",
            compiledExpr: "",
            statement: "定额基价机械费+定额机上人工单价(基价)调整"
        },
        {
            ID: "107",
            code: "1.3.1",
            name: "定额基价机械费",
            fieldName: "rationBaseMachine",
            dispExpr: "[定额基价机械费]",
            expression: "base('定额基价机械费')",
            compiledExpr: "",
            statement: "定额基价机械费"
        },
        {
            ID: "108",
            code: "1.3.1.1",
            name: "其中：定额基价机上人工费",
            fieldName: "rationBaseMachineLabour",
            dispExpr: "[定额基价机上人工费]",
            expression: "base('定额基价机上人工费')",
            compiledExpr: "",
            statement: "定额基价机上人工费"
        },
        {
            ID: "109",
            code: "1.3.2",
            name: "定额机上人工单价(基价)调整",
            fieldName: "rationBaseMachineLabourFixed",
            dispExpr: "F8*(L-1)",
            expression: "@('8') * (L-1)",
            labourCoeID: 24,
            compiledExpr: "",
            statement: "定额基价机上人工费*[定额机上人工单价(基价)调整系数-1]"
        },
        {
            ID: "110",
            code: "1.4",
            name: "未计价材料费",
            fieldName: "unPriceMaterial",
            dispExpr: "[主材费]+[设备费]",
            expression: "base('主材费') + base('设备费')",
            compiledExpr: "",
            statement: "主材费+设备费"
        },
        {
            ID: "111",
            code: "2",
            name: "企业管理费",
            fieldName: "manageFee",
            dispExpr: "F3+F5+F7",
            feeRateID: 101,
            expression: "@('3') + @('5') + @('7')",
            compiledExpr: "",
            statement: "定额基价人工费",
            memo: "渝建发[2014]27号"
        },
        {
            ID: "112",
            code: "3",
            name: "利润",
            fieldName: "profit",
            dispExpr: "F3+F5+F7",
            feeRateID: 301,
            expression: "@('3') + @('5') + @('7')",
            compiledExpr: "",
            statement: "定额基价人工费"
        },
        {
            ID: "113",
            code: "4",
            name: "风险因素",
            fieldName: "risk",
            dispExpr: "F3+F5+F7",
            feeRateID: 701,
            expression: "@('3') + @('5') + @('7')",
            compiledExpr: "",
            statement: "定额基价人工费",
            memo: "同定额包干费"
        },
        {
            ID: "114",
            code: "5",
            name: "人材机价差",
            fieldName: "lmmDiff",
            dispExpr: "F15+F16+F17",
            expression: "@('15') + @('16') + @('17')",
            compiledExpr: "",
            statement: "人工费价差+材料费价差+机械费价差"
        },
        {
            ID: "115",
            code: "5.1",
            name: "人工费价差",
            fieldName: "labourDiff",
            dispExpr: "[人工费价差]",
            expression: "base('市场价格人工费') - base('定额基价人工费(调整后)')",
            compiledExpr: "",
            statement: "市场价格人工费-调整后的定额人工费(基价)"
        },
        {
            ID: "116",
            code: "5.2",
            name: "材料费价差",
            fieldName: "materialDiff",
            dispExpr: "[材料费价差]",
            expression: "base('市场价格材料费') - base('定额基价材料费(调整后)')",
            compiledExpr: "",
            statement: "市场价格材料费-定额基价材料费"
        },
        {
            ID: "117",
            code: "5.3",
            name: "机械费价差",
            fieldName: "machineDiff",
            dispExpr: "[机械费价差]",
            expression: "base('市场价格机械费') - base('定额基价机械费(调整后)')",
            compiledExpr: "",
            statement: "市场价格机械费-调整后的定额基价机械费(基价)"
        },
        {
            ID: "118",
            code: "6",
            name: "综合单价",
            fieldName: "common",
            dispExpr: "F1+F11+F12+F13+F14",
            expression: "@('1') + @('11') + @('12') + @('13') + @('14')",
            compiledExpr: "",
            statement: "基价直接工程费+企业管理费+利润+风险因素+人材机价差"
        }
    ]
};

/*test('解析测试', function(t){
    let calcItem = {dispExpr: "12 +[人工费]*1.2+f13+　(F6+ f10） +F16+[人工费] + f6+[材料费]"};
    let target = "12+base('人工费')*1.2+@('113')+(@('106')+@('110'))+@('116')+base('人工费')+@('106')+base('材料费')";
    let rst = analyzer.analyzeUserExpr(calcTemplate, calcItem);
    console.log('用户表达式是否正确：' + rst);
    console.log(calcItem.dispExpr);
    console.log(calcItem.expression);
    t.equal(calcItem.expression, target);
    t.end();
});*/

let expr = "F2+F5+F6+F10";
let arr = analyzer.getFArr(expr);
console.log(JSON.stringify(arr));
let id = analyzer.getID('F10', calcTemplate);
console.log(JSON.stringify(id));