var itemGridManager = null;
$(function () {
    initItemGrid();
    bindEvent();
});

function bindEvent() {


}

function initItemGrid() {
    var toolbarOptions = UICtrl.getDefaultToolbarOptions({

    });
        itemGridManager = UICtrl.grid('#maingrid', {
            columns: getGridColumns(),
            dataAction: 'server',
            _tableKey: 'productScrapApplyItem',
            _local: true,
            url: web_app.name + '/productScrapApply/queryProductScrapApplyItems.ajax',
            parms:{productScrapApplyId:getId()},
            height: '95%',
            heightDiff: -4,
            sortName: 'id',
            sortOrder: 'asc',
            checkbox: true,
            usePager: true,
            rownumbers: true,
            enabledEdit: false,
            fixedCellHeight: true,
            selectRowButtonOnly: true,
            //autoApplyNextEditor:false,
            toolbar: toolbarOptions,
        }
    );
    UICtrl.setSearchAreaToggle(itemGridManager);
}

function getGridColumns() {
    var columns = [];
    columns = [
         {display: "报废申请号", name: "zsanum", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "项目", name: "zsapos", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "物料", name: "matnr", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "物料描述", name: "maktx", width: 300, minWidth: 60, type: "string", align: "center"}
        , {display: "数量", name: "erfmg", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "单位", name: "erfme", width: 150, minWidth: 60, type: "string", align: "center"}
        //, {display: "单位描述", name: "erfmeName", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "工厂", name: "werks", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "工厂描述", name: "werksName", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "存储地点", name: "lgort", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "存储地点描述", name: "lgortName", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "成本中心", name: "kostl", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "成本中心描述", name: "kostlName", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "批次", name: "charg", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "序列号/PL号", name: "sernr", width: 150, minWidth: 60, type: "string", align: "center"}
        , {display: "文本", name: "ztxt", width: 300, minWidth: 60, type: "string", align: "center"}
        , {display: "SAP创建人", name: "zuser1", width: 140, minWidth: 60, type: "date", align: "center"}
        , {display: "SAP创建日期", name: "zdat", width: 140, minWidth: 60, type: "date", align: "center"}
    ]
    return columns;
}

//获取数据保存的参数
function getExtendedData(processAction) {
    //回退、打回、转交时，不需要验证必填项是否已经填写；
    if (processAction == ProcessAction.BACK
        || processAction == ProcessAction.REPLENISH
        || processAction == ProcessAction.TRANSMIT) {
        //不验证
        $('#submitForm').attr('check', false);
    }
    var extendedData = {};
    var _grid = UICtrl.getGridManager('#maingrid');
    if (_grid) {
        var datas = DataUtil.getGridData({
            gridManager: _grid,
            isAllData: true
        });
        if (!datas) {
            return false;
        }
        extendedData.productScrapApplyItems = Public.encodeJSONURI(datas);
    }
    return extendedData;
}

function getId() {
    return $('#id').val();
}

function setId(value) {
    $("#id").val(value);
    var _grid=UICtrl.getGridManager('#maingrid');
    _grid.options.parms.productScrapApplyId = value;
}

function reloadGrid() {
    itemGridManager.loadData();
}

function getGridData(){
    var _grid = UICtrl.getGridManager('#maingrid');
    var datas = DataUtil.getGridData({
        gridManager: _grid,
        isAllData: true
    });
    return datas;
}


