/**
 * 对账管理-供应商选择弹框
 *
 * Created by li.kui on 2019/12/10.
 */
'use strict';
var el = {
    companyCode: '#companyCode',
    singleSelect: '#singleSelect',
    tb: '#tb'
};

$(function () {
    var singleSelect = $(el.singleSelect).val();
    var companyCode = $(el.companyCode).val();
    initSupDataGrid(singleSelect, companyCode);
});

/**
 * 初始化发票数据列表
 *
 * @param singleSelect 是否单选 0:否 1:是
 * @param companyCode 公司代码
 */
function initSupDataGrid(singleSelect, companyCode) {
    $(el.tb).datagrid({
        loadMsg: '数据远程载入中, 请等待...',
        url: '/pc/mall/invoice/rest/list',
        queryParams: {companyCode: companyCode},
        singleSelect: singleSelect !== '0',
        pagination: true,
        pageNumber: 1,
        pageSize: 10,
        pageList: [10, 20, 30, 40, 50],
        checkbox: true,
        height: 460,
        rownumbers: true,
        columns: [
            [
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'invoiceTitle',
                    title: '发票抬头',
                    width: 300
                },
                {
                    field: 'invoiceNo',
                    title: '纳税人识别号',
                    width: 120
                },
                {
                    field: 'invoiceAddress',
                    title: '注册地址',
                    width: 200
                },
                {
                    field: 'invoiceTel',
                    title: '注册电话',
                    width: 90
                },
                {
                    field: 'openingBank',
                    title: '开户银行',
                    width: 100
                },
                {
                    field: 'bankAccount',
                    title: '开户银行账号',
                    width: 120
                },
                {
                    field: 'bankTel',
                    title: '开户行电话',
                    width: 90
                },
                {
                    field: 'bankAddress',
                    title: '开户行地址',
                    width: 200
                }
            ]
        ]
    });
}


/**
 * 确认选择
 */
function confirmChose(callback) {
    var singleSelect = $(el.singleSelect).val(), result = [];
    if (singleSelect === '0') {
        var rows = $(el.tb).datagrid('getSelections');
        result = result.concat(rows);
    } else {
        var row = $(el.tb).datagrid('getSelected');
        result.push(row);
    }
    callback(result);
}