var mainGridManager = null,refreshFlag = false;
$(document).ready(function () {
        initializeGrid();
    }
);
//初始化提前备料表格
function initializeGrid() {
    let toolbarOptions = UICtrl.getDefaultToolbarOptions({
    });
    mainGridManager = UICtrl.grid('#mainGrid', {
        columns: getGridColumns(),
        dataAction: 'server',
        url: web_app.name + '/sapDialogSelect/sapMaterialSelect.ajax',
        parms: {
            //query:"0"
        },
        width: '100%',
        height: '300',
        checkbox: true,
        heightDiff: -5,
        //sortName: 'createdDate',
        //sortOrder: 'desc',
        toolbar: toolbarOptions

    });
    UICtrl.setSearchAreaToggle(mainGridManager);
}
function getGridColumns(){
    var columns=[];
    columns.push({display:"工厂", name: "werks", title:"工厂", width: 100, minWidth: 60, type: "string", align: "left",});
    columns.push({display:"工厂名称", name: "name1", title: "工厂名称", width: 200, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"物料编码", name: "matnr", title: "物料编码", width: 300, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"物料名称", name: "maktx", title: "物料名称", width: 300, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"库存地点", name: "lgfsb", title: "库存地点", width: 100, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"库存地点名称", name: "lgobe", title: "库存地点名称", width: 200, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"物料组", name: "matkl", title: "物料组", width: 100, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"物料组名称", name: "wgbez", title: "物料组名称", width: 200, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"基本计量单位", name: "meins", title: "基本计量单位", width: 100, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"基本计量单位名称", name: "msehl", title: "基本计量单位名称", width: 100, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"采购组", name: "ekgrp", title: "采购组", width: 100, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"采购组名称", name: "eknam", title: "采购组名称", width: 200, minWidth: 60, type: "string", align: "left"});
    columns.push({display:"价格基数", name: "peinh", title: "价格基数", width: 100, minWidth: 60, type: "string", align: "left"});
    return columns;
}

// 查询
function query(obj) {
    let param = $(obj).formToJSON();
    UICtrl.gridSearch(mainGridManager, param);
}

//关闭对话框
function dialogClose(){
    if(refreshFlag){
        reloadGrid();
        refreshFlag=false;
    }
}

//重置表单
function resetForm(obj) {
    $(obj).formClean();
}