/**新增 修改弹框中的列表渲染及分页操作**/

var innerPage = 1;


// 新增修改 组织人员 列表渲染 ajax请求
function getTeamInnerList(queryParam = {}, innerPage = 1) {
    queryParam.page = innerPage;
    queryParam.limit = 1; // 每页显示条数
    queryParam.start = (queryParam.page - 1) * queryParam.limit;
    ajaxRequest(TEAM_INNERLIST, "POST", queryParam, function(result) {
        let data = result.RESULT;
        let items = '';
        if (result.totalCount > 0) {
            data.forEach(function(item, key) {
                items += "<tr>" + "<td class='status' data-username='" + item.username + "' data-phone='" + item.phone + "'></td>" + "<td>" + item.username + "</td>" + "<td>" + item.phone + "</td>" + "</tr>"
            })
            $('#dataList2').html(items);
            $('#dataList3').html(items);
        } else {
            $('#dataList2').html('');
            $('#dataList3').html('');
        }
        console.log(result)
        totalPages = result.totalCount / result.limit;
        totalPages = Math.ceil(totalPages);
        $('#totalPage2').html(totalPages); // 总共多少页
        $('#dataTotal2').html(result.totalCount); // 总共多少条数据
        $('#currentPage2').val(innerPage); // 当前页面
        let pageFrom = (innerPage - 1) * result.limit + 1; // 开始
        let pageTo = result.page * result.limit; // 结束
        pageTo = pageTo > result.totalCount ? result.totalCount : pageTo;
        $('#pageFrom2').html(pageFrom);
        $('#pageTo2').html(pageTo);

        // 无数据时
        if (!result.totalCount) {
            $('.pager2.has-data').hide()
            $('.pager2.no-data').show()
        } else {
            $('.pager2.has-data').show()
            $('.pager2.no-data').hide()
        }
        if (innerPage < totalPages) {
            $('#nextPageButton2,#lastPageButton2').removeClass('disabled');
        } else {
            $('#nextPageButton2,#lastPageButton2').addClass('disabled');
        }
        if (innerPage === 1) {
            $('#firstPageButton2,#prevPageButton2').addClass('disabled');
        } else {
            $('#firstPageButton2,#prevPageButton2').removeClass('disabled');
        }
    }, function(errorMsg) {
        alert("请求数据失败!");
    }, 3)
};


// 分页操作
$('#firstPageButton2').on('click', function() {
    innerPage = 1;
    getTeamInnerList({}, 1);
});

$('#lastPageButton2').on('click', function() {
    innerPage = totalPages;
    getTeamInnerList({}, innerPage);
});

$('#prevPageButton2').on('click', function() {
    innerPage -= 1;
    getTeamInnerList({}, innerPage);
});

$('#nextPageButton2').on('click', function() {
    innerPage += 1;
    getTeamInnerList({}, innerPage);
})

// 分页刷新按钮
$('.pg-refresh2').click(resetForm);

// 重置表单
function resetForm() {
    innerPage = 1;
    getTeamInnerList();
}