var el = {
    searchForm: '#searchForm',
    tb: '#tb',
    purchaseGroupCode: '#purchaseGroupCode',
    status: '#status',
    type: '#type',
    customs_declaration_add: '#customs_declaration_add',
    customs_declaration_edit: '#customs_declaration_edit',
    customs_declaration_search: '#customs_declaration_search',
    customs_declaration_push_confirm: '#customs_declaration_push_confirm',
    btn_remove: '#btn_remove',
    bodyHeight: document.documentElement.clientHeight
};
$(function () {
    initDict('unit,currency,payment_method')
    initNecessaryDatas('pc/sys/purchaseGroup/rest/listAll');
    initCombo();
    loadGrid();
});

function initCombo(){

    $(el.type).combobox({
        editable: false,
        panelHeight: 'auto',
        valueField: 'value',
        textField: 'label',
        data: [
            {value: '', label: '全部'},
            {label: '报关单', value: 0},
            {label: 'invoice', value: 1}
        ],
    });

    $(el.purchaseGroupCode).combobox({
        valueField: 'code',
        textField: 'codeWithDesc',
        method: 'POST',
        prompt: '--- 请选择 ---',
        data: getNecessaryDataList('pc/sys/purchaseGroup/rest/listAll')
    });
}


function loadGrid() {
    var searchHeight = $(el.searchForm).outerHeight();
    var pager = initGridPagerNew(el.bodyHeight - searchHeight - 20, 37, 40);
    $(el.tb).datagrid({
        height: el.bodyHeight - searchHeight,
        url: g.ctx + 'pc/finance/customs/declaration/detail/rest/dialog/list',
        singleSelect: single===1,
        pagination: true,
        pageSize: pager.pageSize,
        pageList: pager.pageList,
        loadMsg: '数据加载中......',
        rownumbers: true,
        columns: [[
            {
                field: 'ck',
                checkbox: true
            },
            {
                field: 'code',
                title: '委托单号',
                width: '120',
                align: 'left'
            },
            {
                field: 'supplierCode',
                title: '供应商编码',
                width: '140',
                align: 'left'
            },
            {
                field: 'supplierName',
                title: '供应商简称',
                width: '180',
                align: 'left'
            },
            {
                field: 'agentSupplierCode',
                title: '代理商编码',
                width: '140',
                align: 'left'
            },
            {
                field: 'agentSupplierName',
                title: '代理商名称',
                width: '180',
                align: 'left'
            },
            {
                field: 'currencyCode',
                title: '报关币种',
                width: '120',
                align: 'left',
                formatter: function (value) {
                    return getDicName('currency',value)
                }
            },
        ]],
    });
}


/**
 * 确认选择
 */
function confirmChose(callback) {
    callback($(el.tb).datagrid('getSelections'));
}

