/**
 * Created by zhang on 2018/11/16.
 */
let locateObject={
    bills_setting:{
        header:[
            {headerName: "编码", headerWidth: 120, dataCode: "code", dataType: "String"},
            {headerName: "项目名称", headerWidth: 100, dataCode: "name", dataType: "String"},
            {headerName: "单位", headerWidth: 50, dataCode: "unit", dataType: "String",hAlign: "center"},
            {headerName: "工程量", headerWidth: 65, dataCode: "quantity", dataType: "Number", hAlign: "right"},
            {headerName: "综合单价", headerWidth: 65, dataCode: "unitPrice", dataType: "Number", hAlign: "right"},
            {headerName: "综合合价", headerWidth: 65, dataCode: "totalPrice", dataType: "Number", hAlign: "right"}
        ],
        view: {
            lockColumns: [0,1,2,3,4,5],
            colHeaderHeight:30
        }
    },
    ration_setting:{
        header:[
            {headerName: "定额编码", headerWidth: 100, dataCode: "code", dataType: "String"},
            {headerName: "定额名称", headerWidth: 180, dataCode: "name", dataType: "String"},
            {headerName: "单位", headerWidth: 50, dataCode: "unit", dataType: "String",hAlign: "center"},
            {headerName: "工程量", headerWidth: 65, dataCode: "quantity", dataType: "Number", hAlign: "right",decimalField: "ration.quantity"}
        ],
        view: {
            lockColumns: [0,1,2,3],
            colHeaderHeight:30
        }
    },
    ration_glj_setting:{
        header:[
            {headerName: "编码", headerWidth: 120, dataCode: "code", dataType: "String"},
            {headerName: "名称", headerWidth: 80, dataCode: "name", dataType: "String"},
            {headerName: "规格型号", headerWidth: 80, dataCode: "code", dataType: "String"},
            {headerName: "单位", headerWidth: 50, dataCode: "unit", dataType: "String",hAlign: "center"},
            {headerName: "市场价", headerWidth: 65, dataCode: "marketPrice", dataType: "Number", hAlign: "right"}
        ],
        view: {
            lockColumns: [0,1,2,3,4],
            colHeaderHeight:30
        }
    },
    initMainSpread:function(){
        if(!this.mainSpread){
            this.mainSpread = SheetDataHelper.createNewSpread($("#locate_result")[0],3);
            sheetCommonObj.spreadDefaultStyle(this.mainSpread);
            this.initMainSheet();
        }else {
            this.mainSpread.refresh();
        }
    },
    initMainSheet:function () {
       // this.mainSheet = this.mainSpread .getSheet(0);
        //this.spread.bind(GC.Spread.Sheets.Events.ButtonClicked, this.onReplaceButtonClick);
       //初始化清单表格
        sheetCommonObj.initSheet(this.mainSpread .getSheet(0),this.bills_setting);
        this.mainSpread .getSheet(0).setRowCount(0);
        //初始化定额表格
        sheetCommonObj.initSheet(this.mainSpread .getSheet(1),this.ration_setting);
        this.mainSpread .getSheet(1).setRowCount(0);

        //初始化人材机表格
        sheetCommonObj.initSheet(this.mainSpread.getSheet(2),this.ration_glj_setting);
        this.mainSpread .getSheet(2).setRowCount(0);
    },
    initSubSpread:function () {
        if(!this.subSpread){
            this.subSpread = SheetDataHelper.createNewSpread($("#locate_sub")[0]);
            sheetCommonObj.spreadDefaultStyle(this.subSpread);
            this.initSubSheet();
        }else {
            this.subSpread.refresh();
        }
    },
    refreshWorkBook: function () {
        if (this.mainSpread) {
            this.mainSpread.refresh();
        }
        if (this.subSpread) {
            this.subSpread.refresh();
        }
    },
    initSubSheet:function () {
        this.subSheet = this.subSpread .getSheet(0);
        sheetCommonObj.initSheet( this.subSheet, this.ration_setting);
        this.subSheet.setRowCount(0);
        //this.spread.bind(GC.Spread.Sheets.Events.ButtonClicked, this.onReplaceButtonClick);
        this.subSheet.name('locate_sub');
    },
    showMainData:function () {
        let datas = [];
        //sheetCommonObj.showData(this.mainSheet,this.mainSettiong,datas);
        this.mainSpread.getActiveSheet().setRowCount(datas.length);
    },
    refreshView: function (options, refreshWorkBook) {
        let me = this;
        let mainHeight = $(window).height()-$(".header").height()-$(".toolsbar").height()-$("#searchPanel").height();
        let subHeight = 0;
        $('#locateTopDiv').height(mainHeight);
        $('#locate_result').height(mainHeight);
        $('#locateBottomDiv').height(subHeight);
        $('#locate_sub').height(subHeight - 7);
        if(options == "ration_glj"){
            let locateLibResize = getLocateLibResize();
            SlideResize.loadVerticalHeight(locateLibResize.eleObj.module, locateLibResize.eleObj, locateLibResize.limit, function () {
                locateObject.refreshWorkBook();
            });
        }
        if (refreshWorkBook) {
            me.refreshWorkBook();
        }
    },
    init:function () {
        let me = this;
        let options = $("input[name='content_type']:checked").val();
        let callback = function () {
            me.refreshView(options, false);
            me.initMainSpread();
            me.initSubSpread();
            me.showMainData();
        };
        options == "bills"?$("#outstandingOptions").show(0,callback):$("#outstandingOptions").hide(0,callback);

    },
    findRecodes:function () {

    },
    onshow:function () {
        locateObject.init();
    }
}


$("#locate_btn").click(function () {
    locateObject.findRecodes();
});

$("input[name='content_type']").each(function(){
    $(this).click(function(){
        let optins = $(this).val();
        switch (optins){
            case "bills":
                locateObject.mainSpread.setActiveSheetIndex(0);
                break;
            case "ration":
                locateObject.mainSpread.setActiveSheetIndex(1);
                break;
            case "ration_glj":
                locateObject.mainSpread.setActiveSheetIndex(2);
                break;
        }
        locateObject.init();
    });
});
