var gridManager = null;

$(document).ready(function () {
    initializateUI();
    loadProofingApplyListGrid();
});


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

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

        deleteHandler: deleteHandler,
    });
    gridManager = UICtrl.grid("#proofingApplyTableGrid", {
        columns: [
            {display: "申请单号", name: "proofingApplyNo", width: 120, minWidth: 60, type: "string", align: "left"},
            // {display: "产品编号", name: "productId", width: 120, minWidth: 60, type: "string", align: "left"},
            {display: "品牌客户编号", name: "customerCode", width: 140, minWidth: 60, type: "string", align: "left"},
            {
                display: "版面需求时间",
                name: "proofingApplyPageNeedTime",
                width: 120,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "完成日期",
                name: "proofingApplyCompleteDate",
                width: 140,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "样品中文名称",
                name: "proofingApplySampleCnName",
                width: 120,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "样品英文名称",
                name: "proofingApplySampleEnName",
                width: 140,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "样品版次",
                name: "proofingApplySampleVersion",
                width: 120,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "样品规格",
                name: "proofingApplySampleSize",
                width: 140,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "样品数量",
                name: "proofingApplySampleNum",
                width: 120,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "产量情况",
                name: "proofingApplyOutputSituation",
                width: 140,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "产品代号",
                name: "proofingApplyProductNo",
                width: 140,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {display: "版面", name: "materialName", width: 140, minWidth: 60, type: "string", align: "left"},
            {
                display: "分配方式",
                name: "proofingApplyAllocationType",
                width: 140,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            // {display: "产品类别", name: "materialName", width: 140, minWidth: 60, type: "string", align: "left"},
            {
                display: "表面处理",
                name: "proofingApplySurfaceTreatment",
                width: 140,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "NG重新打样原因",
                name: "proofingApplyNgReReason",
                width: 120,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "测试标准",
                name: "proofingApplyTestStandard",
                width: 120,
                minWidth: 60,
                type: "string",
                align: "left"
            },
            {
                display: "申请单状态",
                name: "proofingApplyApplicationStatus",
                width: 120,
                minWidth: 60,
                type: "string",
                align: "left"
            },
        ],
        dataAction: "server",
        url: web_app.name + '/proofingApply/slicedProofingApplyList.ajax',
        pageSize: 20,
        usePager: true,
        toolbar: toolbarOptions,
        width: "100%",
        height: "100%",
        heightDiff: -8,
        checkbox: true,
        fixedCellHeight: true,
        selectRowButtonOnly: true,
        onDblClickRow: function (data, rowindex, rowobj) {
             doView(data.id);
        }
    });
    UICtrl.setSearchAreaToggle(gridManager);
}

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

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


//重写DataUtil的getUpdateRowId函数、它默认取行的id列
DataUtil.getUpdateRowId = function (gridManager) {
    var result = DataUtil.getUpdateRow(gridManager);
    if (result) {
        return result.proofingMakeId;
    }
    return result;
}

//删除按钮
function deleteHandler() {
    DataUtil.del({
        action: 'proofingMake/deleteProofingMakeByProofingMakeId.ajax',
        gridManager: gridManager, idFieldName: 'proofingMakeId',
        onSuccess: function () {
            reloadGrid();
        }
    });
}

function doView(id) {
    UICtrl.addTabItem({
        tabid: 'proofingApply'+id,
        text: "打样单详情",
        url: web_app.name + '/proofingApply/showProofingApply.job?bizId='+id+"&isDetailPage=true"
    });
}