
let el = {
    searchForm: '#searchForm',
    tb: '#tb',
    title: '#title',
    bodyHeight: document.documentElement.clientHeight
};

let selfData = {
    toolbar: []
};

$(function () {
    initNecessaryDatas('pc/sys/purchaseGroup/rest/listAll,pc/sys/company/rest/listAll')
    initDictName('payment_stage')
    initColumns();
    loadGrid();

});

/**
 * 初始化表格列
 */
function initColumns() {
    selfData.toolbar = [
        {
            text: '导出',
            iconCls: 'icon-print',
            id: 'btn_export',
            handler: function () {
                setOperationLog("导出按钮", "合同应付款");
                openExportDialog('pc/contract/pay/stage/rest/export','tb',searchParams());
            }
        }
    ];
}

function loadGrid() {
    var searchHeight = $(el.searchForm).outerHeight();
    var pager = initGridPagerNew(el.bodyHeight - searchHeight, 37, 40);
    $(el.tb).datagrid({
        url: '/pc/contract/pay/stage/rest/list',
        iconCls: 'icon-list',
        height: el.bodyHeight - searchHeight,
        singleSelect: true,
        fitColumns: false,
        pagination: true,
        loadMsg: "数据加载中......",
        rownumbers: true,
        nowrap: true,
        striped: true,
        page: 1,
        pageSize: 10,
        columns: [[
            // { field: 'ck', checkbox: true},
            { field: 'contractCompanyCode', title: '公司编码', align: 'left',width: 80 },
            { field: 'contractPurchaseGroup', title: '采购组描述', align: 'left',width: 120,
                exportEnum:getNecessaryDataList('pc/sys/purchaseGroup/rest/listAll'),
                formatter: function (value, row) {
                    return getNecessaryDataName('pc/sys/purchaseGroup/rest/listAll',value);
                }
                },
            { field: 'contractSupplierName', title: '供应商名称', align: 'left',width: 200 },
            { field: 'contractTitle', title: '合同名称', align: 'left',width: 200 },
            { field: 'contractCode', title: '合同编号', align: 'left',width: 120 },
            { field: 'contractAmount', title: '合同总金额', align: 'left',width: 100 },
            { field: 'orderCode', title: 'SAP订单号', align: 'left',width: 100 },
            { field: 'contractCurrency', title: '币别', align: 'left',width: 50 },
            { field: 'paymentStage', title: '付款阶段', align: 'left',width: 100,
                exportEnum:getDictList('payment_stage'),
                formatter: function (value, row) {
                    return getDicName('payment_stage',value);
                }},
            { field: 'paymentAmount', title: '金额', align: 'left',width: 100 },
            { field: 'paymentRatio', title: '付款比例', align: 'left',width: 100 },
            { field: 'paymentAlreadyAmount', title: '已付金额', align: 'left',width: 100 },
            { field: 'paymentIngAmount', title: '在途付款金额', align: 'left',width: 100 },
            { field: 'paymentUnAmount', title: '未付金额', align: 'left',width: 100 },
            ]],
        toolbar: selfData.toolbar,
    });
}

/**
 * 查询
 */
function searchGrid() {
    $(el.tb).datagrid('options').queryParams = $("#searchForm").serializeJson();
    $(el.tb).datagrid('load');
}

/**
 * 重置筛选条件
 */
function resetGrid() {
    $(el.title).textbox('setValue', '');
    searchGrid();
}