var gridManager = null;

$(document).ready(function () {
    initializateUI()
    loadBsnMessageListGrid();
})
function initializateUI() {
    UICtrl.layout("#layout", {leftWidth: 3});
}
function loadBsnMessageListGrid() {

    var toolbarOptions = UICtrl.getDefaultToolbarOptions({
        // addHandler: function (){
        //     addHandler()
        // },

    });
    gridManager = UICtrl.grid("#bsnMessageListGrid", {
        columns: [

           // {display: "业务编码", name: "businessCode", width: 120, minWidth: 60, type: "date", align: "left"},
            {display: "创建日期", name: "updateDate", width: 140, minWidth: 60, type: "string", align: "left"},
            //{display: "完成日期", name: "finishedDate", width: 140, minWidth: 60, type: "date", align: "left"},
            {display: "任务描述", name: "taskDescribe", width: 550, minWidth: 60, type: "string", align: "left"},
            {display: "物料描述", name: "title", width: 500, minWidth: 60, type: "string", align: "left"}

        ],
        dataAction: "server",
        url: web_app.name + '/bsnMessage/slicedBsnMessageList.ajax',
        pageSize: 20,
        usePager: true,
        toolbar: toolbarOptions,
        width: "100%",
        height: "100%",
        heightDiff: -8,
        checkbox: true,
        async: false,
        fixedCellHeight: true,
        selectRowButtonOnly: true,
        onDblClickRow: function (data, rowindex, rowobj) {
            doView(data.id,data.businessId,data.executorUrl);
        },
        onAfterShowData: function (data){
            //console.log(data)
        }
    });
    UICtrl.setSearchAreaToggle(gridManager);
}


function query(obj) {
    var param = $(obj).formToJSON();
    UICtrl.gridSearch(gridManager, param);
}
function reloadGrid() {
    gridManager.loadData();
}

function resetForm(obj) {
    $(obj).formClean();
}


function doView(id,businessId,url) {
    var title="维护申请";
    //if (maintenanceType=="modify"){
    //    title="变更申请";
   // } else if (maintenanceType=="extend") {
   //     title="扩展申请";
   // }
    var signal = (url.indexOf("?") >= 0) ? "&" : "?";
    UICtrl.addTabItem({
        tabid: 'showNonProdApply'+id,
        text: "非产品/非半成品类物料主数据"+title+"详情",
        url: web_app.name+'/'+ url+signal+'bizId='+businessId+'&taskId='+id
        //url: web_app.name + '/sapNonProdApply/showNonProdApply.job?isReadOnly=true&bizId='+id+"&isDetailPage=true"
    });
}
