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


/**
 * 文档就绪
 */
$(function () {
    var singleSelect = $(el.singleSelect).val();
    var supCodes = $(el.supCodes).val();
    initSupDataGrid(singleSelect, supCodes);
});


/**
 * 初始化供应商数据列表
 *
 * @param singleSelect 是否单选 0:否 1:是
 * @param supCodes 已选择的供应商编码
 */
function initSupDataGrid(singleSelect, supCodes) {
    $(el.tb).datagrid({
        loadMsg: DZGL.CGDZDGL_SJYCZRZ,
        url: '/pc/mall/address/rest/list',
        queryParams: {},
        singleSelect: singleSelect !== '0',
        pagination: true,
        pageNumber: 1,
        pageSize: 10,
        pageList: [10, 20, 30, 40, 50],
        checkbox: true,
        height: 460,
        idField: 'supplierCode',
        rownumbers: true,
        columns: [
            [
                {
                    field: 'ck',
                    checkbox: true
                },
                {
                    field: 'receivingUser',
                    title: '收货人',
                    width: 120
                },
                {
                    field: 'receivingTel',
                    title: '收货人电话',
                    width: 120
                },
                {
                    field: 'provinceName',
                    title: '省/市/区',
                    width: 150,
                    formatter: function (value, row) {
                        return value + "/" + row.cityName  + "/" + row.countyName;
                    }
                },
                {
                    field: 'address',
                    title: '详细地址',
                    width: 300
                }
            ]
        ]
    });
}


/**
 * 确认选择
 */
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);
}