var gridManager = null;

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

    var toolbarOptions = UICtrl.getDefaultToolbarOptions({
        deleteHandler: deleteHandler
    });
    gridManager = UICtrl.grid("#nonProdApplyDeptListGrid", {
        columns: [
            {display: "申请单编号", name: "billCode", width: 60, minWidth: 60, type: "string", align: "left"},
            {display: "申请状态", name: "statusTextView", width: 60, minWidth: 60, type: "string", align: "left"},
            {display: "申请人", name: "personMemberName", width: 120, minWidth: 60, type: "string", align: "left"},
            {display: "申请部门", name: "deptName", width: 120, minWidth: 60, type: "string", align: "left"},
            {display: "申请日期", name: "fillinDate", width: 120, minWidth: 60, type: "string", align: "left"},
            {display: "维护类型", name: "maintenanceTypeTextView", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "批准人", name: "approver", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "批准日期", name: "approvalDate", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "通用品名", name: "genericName", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "适用标准(国标)", name: "applicableStandard", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "基本计量单位", name: "baseUnitTextView", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "规格", name: "specifications", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "材质", name: "material", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "版式", name: "design", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "尺码", name: "size", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "品牌", name: "brand", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "用途", name: "materialUsage", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "物品属性", name: "itemAttributesTextView", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "业务用途", name: "businessUsageTextView", width: 140, minWidth: 60, type: "string", align: "left"},
            {display: "文本说明", name: "textDescription", width: 140, minWidth: 60, type: "string", align: "left"},

        ],
        dataAction: "server",
        url: web_app.name + '/sapNonProdApply/slicedNonProdApplyList.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);
        },
        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 deleteHandler() {
    DataUtil.del({
        action: 'sapNonProdApply/deleteNonProdApply.ajax',
        gridManager: gridManager, idFieldName: 'id',
        onSuccess: function () {
            reloadGrid();
        }
    });
}

function addHandler() {
    UICtrl.addTabItem({
        tabid: 'nonProdApply',
        text: "非产品/非半成品类物料主数据维护申请",
        url: web_app.name + '/sapNonProdApply/forwardNonProdApplyDetail.job'
    });
}

function doView(id) {
    UICtrl.addTabItem({
        tabid: 'showNonProdApply'+id,
        text: "非产品/非半成品类物料主数据维护申请详情",
        url: web_app.name + '/sapNonProdApply/showNonProdApply.job?bizId='+id+"&isDetailPage=true"
    });
}

// function next(){
//     UICtrl.addTabItem({
//         tabid: 'showNonProdApplyNext',
//         text: "非产品/非半成品类物料主数据维护申请详情",
//         url: web_app.name + '/sapNonProdApply/forwardNonProdApplyNext.do?isDetailPage=true'
//     });
// }