/**
 * Created by zhang on 2018/7/3.
 */
let gljCol = {
    ration_glj_setting: {
        header: [
            {headerName: "编号", headerWidth: 110, dataCode: "code", dataType: "String", formatter: "@"},
            {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String",cellType:'tipsCell'},
            {headerName: "规格", headerWidth: 120, dataCode: "specs", dataType: "String", hAlign: "left",cellType:'tipsCell'},
            {headerName: "单位", headerWidth: 45, dataCode: "unit", dataType: "String", hAlign: "center"},
            {headerName: "预算价", headerWidth: 65, dataCode: "marketPrice", dataType: "Number", hAlign: "right"},//, decimalField: "glj.unitPrice"
            {headerName: "调整价", headerWidth: 65, dataCode: "adjustPrice", dataType: "Number", hAlign: "right"},//, decimalField: "glj.unitPrice"1
            {headerName: "自定消耗", headerWidth: 65, dataCode: "customQuantity", dataType: "Number", hAlign: "right", decimalField: "glj.quantity"},
            {headerName: "消耗量", headerWidth: 65, dataCode: "quantity", dataType: "Number", hAlign: "right", decimalField: "glj.quantity"},
            {headerName: "定额价", headerWidth: 65, dataCode: "basePrice", dataType: "Number", hAlign: "right"},//, decimalField: "glj.unitPrice"
            {headerName: "定额消耗", headerWidth: 65, dataCode: "rationItemQuantity", dataType: "Number", hAlign: "right", decimalField: "glj.quantity"},   // dataType: "Number", formatter: "0.00"
            {headerName: "总消耗量", headerWidth: 80, dataCode: "totalQuantity", dataType: "Number", hAlign: "right", decimalField: "glj.quantity"}
            //{headerName: "暂估", headerWidth: 45, dataCode: "isEstimate", dataType: "String", hAlign: "center", vAlign: "center", cellType: "checkBox"}
        ],
        view: {
            lockColumns: [ "adjustPrice", "rationItemQuantity", "quantity", "totalQuantity", "isEstimate"],//这里以后改成dataCode好一点
            rowHeaderWidth:25
        },
        getStyle:function (data) {
            if(data&&data.type == gljType.MAIN_MATERIAL){//是主材的话字体蓝色显示
                return {foreColor:"#4D7BFF"};
            }
            return null;
        },
        navigationRightCol:['name','specs','unit'],//选中这几列时，按enter键跳到右边一列
        // 工料机类型是混凝土、砂浆、配合比、机械台班时，价格不可编辑。
        editedTyep:[GLJTypeConst.MAIN_MATERIAL,GLJTypeConst.EQUIPMENT]//主材设备
    },
    project_glj_setting:{
        header: [
            {headerName: "编号", headerWidth: 80, dataCode: "code", dataType: "String"},
            {headerName: "名称", headerWidth: 160, dataCode: "name", dataType: "String",cellType:'tipsCell'},
            {headerName: "单位", headerWidth: 45, dataCode: "unit", hAlign: "center", dataType: "String"},
            {headerName: "总消耗量", headerWidth: 90, dataCode: "quantity", hAlign: "right", dataType: "Number",decimalField:'glj.quantity'},
            {headerName: "定额价", headerWidth: 70, dataCode: "basePrice", hAlign: "right", dataType: "Number",validator:"number"},//decimalField:'glj.unitPrice',
            {headerName: "预算价", headerWidth: 70, dataCode: "marketPrice", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:"glj.unitPrice"
            {headerName: "规格", headerWidth: 120, dataCode: "specs", hAlign: "left", dataType: "String",cellType:'tipsCell'},
            {headerName: "主要\n材料", headerWidth: 45, dataCode: "is_main_material", hAlign: "center", dataType: "String",cellType:'checkBox'},
            {headerName: "新工料机", headerWidth: 50, dataCode: "is_add", hAlign: "center", dataType: "String",cellType:'checkBox'},
            {headerName: "不调价", headerWidth: 55, dataCode: "is_adjust_price", dataType: "String",cellType: "checkBox",},
            {headerName: "类型", headerWidth: 45, dataCode: "short_name", hAlign: "center", dataType: "String"},
            {headerName: "备注", headerWidth: 100, dataCode: "remark", hAlign: "left", dataType: "String"}
        ],
        view: {
            lockColumns: ["code","name","specs","unit","short_name","quantity","is_add"]
        },
        getStyle:function (data,row,activeRow) {
            if(row == activeRow){//选中黄色显示
                return {backColor:"#FFFACD"};
            }
            return null;
        },
        frozenCols:4
    },
    mixRatio_Setting:{
        header:[
            {headerName: "编号", headerWidth: 80, dataCode: "code", dataType: "String"},
            {headerName: "名称", headerWidth: 240, dataCode: "name", dataType: "String"},
            {headerName: "规格", headerWidth: 190, dataCode: "specs", dataType: "String"},
            {headerName: "单位", headerWidth: 45, dataCode: "unit", hAlign: "center", dataType: "String"},
            {headerName: "类型", headerWidth: 45, dataCode: "short_name", hAlign: "center", dataType: "String"},
            {headerName: "定额价", headerWidth: 80, dataCode: "basePrice", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:'glj.unitPrice'
            {headerName: "调整价", headerWidth: 80, dataCode: "adjustPrice", hAlign: "right", dataType: "Number"},//,decimalField:"glj.unitPrice"
            {headerName: "预算价", headerWidth: 80, dataCode: "marketPrice", hAlign: "right", dataType: "Number",validator:"number"},//,decimalField:"glj.unitPrice"
            {headerName: "消耗量", headerWidth: 80, dataCode: "consumption", hAlign: "right", dataType: "Number",decimalField:"glj.quantity",validator:"number"}
        ],
        view: {
            lockColumns: [0,1,2,3,4,5,6,7],
            rowHeaderWidth: 25
        }
    },
    scopeSetting:{
        "emptyRows":0,
        "headRows":1,
        "headRowHeight":[30],
        "defaultRowHeight": 21,
        "treeCol": 1,
        "cols":[
            {
                "width":40,
                "readOnly": true,
                "head":{
                    "titleNames":["选择"],
                    "spanCols":[1],
                    "spanRows":[1],
                    "vAlign":[1],
                    "hAlign":[1],
                    "font":["Arial"]
                },
                "data":{
                    "field":"selected",
                    "vAlign":1,
                    "hAlign":1,
                    "font":"Arial",
                    "cellType":function (node) {
                            return new GC.Spread.Sheets.CellTypes.CheckBox();
                    }
                }
            },
            {
                "width":140,
                "readOnly": true,
                "head":{
                    "titleNames":["编号"],
                    "spanCols":[1],
                    "spanRows":[1],
                    "vAlign":[1],
                    "hAlign":[1],
                    "font":["Arial"]
                },
                "data":{
                    "field":"code",
                    "vAlign":1,
                    "hAlign":0,
                    "font":"Arial"
                }
            },
            {
                "width":240,
                "readOnly": true,
                "head":{
                    "titleNames":["名称"],
                    "spanCols":[1],
                    "spanRows":[1],
                    "vAlign":[1],
                    "hAlign":[1],
                    "font":["Arial"]
                },
                "data":{
                    "field":"name",
                    "vAlign":0,
                    "hAlign":0,
                    "font":"Arial"
                }
            },
            {
                "width":70,
                "readOnly": true,
                "head":{
                    "titleNames":["单位"],
                    "spanCols":[1],
                    "spanRows":[1],
                    "vAlign":[1],
                    "hAlign":[1],
                    "font":["Arial"]
                },
                "data":{
                    "field":"unit",
                    "vAlign":1,
                    "hAlign":1,
                    "font":"Arial"
                }
            },
            {
                "width":80,
                "readOnly": true,
                "head":{
                    "titleNames":["工程量"],
                    "spanCols":[1],
                    "spanRows":[1],
                    "vAlign":[1],
                    "hAlign":[1],
                    "font":["Arial"]
                },
                "data":{
                    "field":"quantity",
                    "vAlign":1,
                    "hAlign":2,
                    "font":"Arial"
                }
            },
            {
                "width":80,
                "readOnly": true,
                "head":{
                    "titleNames":["单价"],
                    "spanCols":[1],
                    "spanRows":[1],
                    "vAlign":[1],
                    "hAlign":[1],
                    "font":["Arial"]
                },
                "data":{
                    "field":"unitPrice",
                    "vAlign":1,
                    "hAlign":2,
                    "font":"Arial"
                }
            },
            {
                "width":80,
                "readOnly": true,
                "head":{
                    "titleNames":["金额"],
                    "spanCols":[1],
                    "spanRows":[1],
                    "vAlign":[1],
                    "hAlign":[1],
                    "font":["Arial"]
                },
                "data":{
                    "field":"totalPrice",
                    "vAlign":1,
                    "hAlign":2,
                    "font":"Arial"
                }
            }
        ]
    },
    removeCol:function (dataCode,setting) {
        let colIndex = _.findIndex(setting.header,{'dataCode':dataCode});
        if(colIndex != -1){
            setting.header.splice(colIndex,1);//去掉列;
            let newArray = [];
            for(let l of setting.view.lockColumns){
                if(_.isString(l)) return;//如果是用dataCode表示的,不用处理
                if(l == colIndex)  continue;
                if(l > colIndex)  l = l -1;
                newArray.push(l);
            }
            setting.view.lockColumns = newArray;
        }
    },
    initGljCol:function (showAdjustPrice) {
        let me = gljCol;
        if(showAdjustPrice !== true){
            me.removeCol('adjustPrice',me.ration_glj_setting);
            me.removeCol('adjustPrice',me.project_glj_setting);
            me.removeCol('adjustPrice',me.mixRatio_Setting);
        }
        if(projectObj.project.projectInfo.property && projectObj.project.projectInfo.property.valuationType == "bill"){
            me.removeCol('is_adjust_price',me.project_glj_setting);
        }
        gljOprObj.setting = me.ration_glj_setting;
        projectGljObject.projectGljSetting = me.project_glj_setting;
        projectGljObject.mixRatioSetting = me.mixRatio_Setting;
        me.setScopeFormater();
        gljOprObj.scopeSetting = me.scopeSetting;
    },
    setScopeFormater:function () {
        // 综合单价、综合合价，小数部分应补0对齐。  CSL
        for(let col of this.scopeSetting.cols){
            if (col.data.field=="totalPrice") col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.totalPrice, true);
            if (col.data.field== "unitPrice")  col.data.formatter = MainTreeCol.getNumberFormatter(decimalObj.ration.unitPrice, true);
        }
    }

};
/*
$(function () {
    $('#fullpath').click(function () {
        checkfeeRate();

    });

})

async function checkfeeRate() {
    let result = await ajaxPost('/feeRates/checkFeeRateName', data = {name: '编辑工程量表达式', rootProjectID: 3163});
    console.log(result);
}*/
