var el = {
    searchForm: '#searchForm',
    tb: '#tb',
    dataState: '#dataState',
    companyCode: '#companyCode',
    purchaseBillDetailIds: '#purchaseBillDetailIds',
    transferStatus: '#transferStatus',
    purchaseGroupCode: '#purchaseGroupCode',
    purchaseApplyTypeCode: '#purchaseApplyTypeCode',
    bodyHeight: document.documentElement.clientHeight
};
$(function () {
    $(el.companyCode).combobox({
        url: g.ctx + 'pc/sys/company/rest/listAll',
        panelHeight: 300,
        panelWidth: 340,
        valueField: 'companyCode',
        textField: 'codeWithDesc',
        prompt: '--- 请选择 ---'
    });
    loadGrid();
});
function loadGrid() {
    var searchHeight = $(el.searchForm).outerHeight();
    var pager = initGridPagerNew(el.bodyHeight - searchHeight, 37, 40);
    $(el.tb).datagrid({
        height: el.bodyHeight - searchHeight,
        url: g.ctx + 'pc/finance/img/code/rest/list',
        singleSelect: false,
        pagination: true,
        pageSize: pager.pageSize,
        pageList: pager.pageList,
        loadMsg: '数据加载中......',
        rownumbers: true,
        columns: [
            [
                {
                    field: 'accountStatementNo',
                    title: '对帐单',
                    width: 120
                },
                {
                    field: 'invoiceApplyNo',
                    title: '开票申请单',
                    width: 150
                },
                {
                    field: 'cppNo',
                    title: '请款单',
                    width: 350,
                    formatter: function (value) {
                        return '<span title="'+value+'">'+value+'</span>';

                    }
                },
                {
                    field: 'accountImgCode',
                    title: '对账影像编码',
                    width: 150,
                    formatter: function (value) {
                        if (value) {
                            return '<a href="javascript:void(0)" onclick="showImage(\'' + value + '\')">'+value+'</a>';
                        }
                        return '';
                    }
                },
                {
                    field: 'invoicedImgCode',
                    title: '开票影像编码',
                    width: 150,
                    formatter: function (value) {
                        if (value) {
                            return '<a href="javascript:void(0)" onclick="showImage(\'' + value + '\')">'+value+'</a>';
                        }
                        return '';
                    }
                },
                {
                    field: 'accountImgTime',
                    title: '对账影像创建时间',
                    width: 140,
                    exportDateFormatter:'dateTime',
                    formatter: function (value) {
                        if (value) {
                            return new Date(value).format('yyyy-MM-dd hh:mm:ss');
                        }
                        return value;
                    }
                },
                {
                    field: 'accountImgUserName',
                    title: '对账影像创建人',
                    width: 100
                },
                {
                    field: 'invoicedImgTime',
                    title: '开票影像创建时间',
                    width: 140,
                    exportDateFormatter:'dateTime',
                    formatter: function (value) {
                        if (value) {
                            return new Date(value).format('yyyy-MM-dd hh:mm:ss');
                        }
                        return value;
                    }
                },
                {
                    field: 'invoicedImgUserName',
                    title: '开票影像创建人',
                    width: 100
                },
            ]
        ],
        toolbar: [
            {
                text: '导出',
                iconCls: 'icon-print',
                id: 'icon_print',
                handler: function () {
                    openExportDialog('pc/finance/img/code/rest/export','tb',searchParams());
                }
            }
        ],
    });
}

function showImage(imageCode){
    $.ajax({
        type: 'get',
        url: g.ctx + 'pc/sys/kingdeeImage/rest/getImageViewPath',
        data: {
            imageCode: imageCode
        },
        success: function (data) {
            if (data) {
                window.open(data, "_blank");
            }
        },
        error: function (error) {
            topWin.layer.alert(error.responseJSON.message, {
                icon: 2,
                content: error.responseJSON.message
            });
        }
    });
}
