<template>
    <section class="content">
        <div class="box box-primary">
            <div class="box-body">
                <!-- Content Header (Page header) -->
                <section class="content-header">
                    <h1 id="itemTitle"></h1>
                </section>
                <div id="toolbar">
                    主播ID：<input type="text" class="input-sm" name="erbanNo" id="erbanNo"  placeholder="请输入主播ID">
                    <button id="btnSearch" class="btn btn-default">
                        <i class="glyphicon glyphicon-search"></i>查询
                    </button>
                </div>
            </div>

            <!-- .content -->
            <div id="table"></div>
        </div>
    </section>

    <div class="modal fade" id="roundDetailModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span>
                    </button>
                    <h4 class="modal-title" id="roundDetailModalTitle">粉丝列表</h4>
                </div>
                <div class="modal-body">
                    <div id="roundDetailTable"></div>
                </div>

            </div>
        </div>
    </div>
</template>

<script>
import TableHelper from '@/utils/bootstrap-table-helper';

export default {
    name: "AnchorFansTeamStatsView",
    setup() {
        return {};
    },
    created() {
        this.$nextTick(function () {
            this.initData();
        });
    },
    methods: {
        initData() {
            $(function () {
                let startTimeStr;
                let endTimeStr;
                let teamUid;
                $('#table').bootstrapTable('destroy');
                $('#table').bootstrapTable({
                    columns: [
                        { field: 'erbanNo', title: '主播ID', align: 'center', width: '10%' },
                        { field: 'nick', title: '主播名称', align: 'center', width: '10%' },
                        {
                            field: 'isOpen', title: '是否开通粉丝团', align: 'center', width: '10%',
                            formatter: function (val) {
                                if (val == null || val == undefined) return '-';
                                if (val == true) {
                                    return '是';
                                } else {
                                    return '否';
                                }
                            }
                        },
                        {
                            field: 'fansNum', title: '粉丝团人数', align: 'center', width: '10%',
                            formatter: function (val, row, index) {
                                if (row.isOpen == true) {
                                    return val;
                                } else {
                                    return '-';
                                }
                            }
                        },
                        {
                            field: 'sendGiftTotal', title: '送礼总额', align: 'center', width: '10%',
                            formatter: function (val, row, index) {
                                if (row.isOpen == true) {
                                    return val;
                                } else {
                                    return '-';
                                }
                            }
                        },
                        {
                            field: 'groupDate',
                            title: '操作',
                            align: 'center',
                            width: '10%',
                            formatter: function (val, row, index) {
                                if (row.isOpen == true) {
                                    return '<button id="btnEdit" name="btnEdit" class="btn btn-sm btn-success opt-info" data-id=' + row.uid + '>' +
                                        '<i class="glyphicon glyphicon-edit"></i>查看详情</button>';
                                } else {
                                    return '-';
                                }
                            }
                        }
                    ],
                    undefinedText: 0,
                    cache: false,
                    striped: true,
                    showRefresh: false,
                    pageSize: 20,
                    pagination: true,
                    pageList: [20, 50, 100, 200, 300, 500],
                    search: false,
                    sidePagination: "server", //表示服务端请求
                    queryParamsType: "undefined",
                    queryParams: function queryParams(params) {   //设置查询参数
                        var param = {
                            page: params.pageNumber,
                            pageSize: params.pageSize,
                            erbanNo: $('#erbanNo').val(),
                        };
                        return param;
                    },
                    toolbar: '#toolbar',
                    uniqueId: 'uid',
                    url: '/admin/anchorFansTeam/statis/statisList',
                    onLoadSuccess: function () {  //加载成功时执行
                        console.log("load success");
                    },
                    onLoadError: function () {  //加载失败时执行
                        console.log("load fail");
                    }
                });

                // 查询刷新
                $('#btnSearch').on('click', function () {
                    TableHelper.doRefresh('#table');
                });


                // 获取轮次详情
                $('#table').on('click', '.opt-info', function () {
                    const uid = $(this).attr("data-id");
                    console.log(uid)
                    $('#roundDetailModal #roundDetailModalTitle').text(`${uid} 粉丝团详情`)
                    $('#roundDetailTable').bootstrapTable('destroy');
                    $('#roundDetailTable').bootstrapTable({
                        columns: [
                            { field: 'erbanNo', title: '粉丝ID', align: 'center', width: '5%' },
                            { field: 'nick', title: '粉丝名称', align: 'center', width: '5%' },
                            { field: 'levelSeq', title: '粉丝等级', align: 'center', width: '5%' },
                            { field: 'sendGiftTotal', title: '送礼金额', align: 'center', width: '5%' },
                            {
                                field: 'createTime', title: '加入粉丝团时间', align: 'center', width: '5%',
                                formatter: function (val, row, index) {
                                    if (val) {
                                        var date = new Date(val);
                                        return date.format("yyyy-MM-dd hh:mm:00");
                                    } else {
                                        return '-';
                                    }
                                }
                            },
                        ],
                        undefinedText: 0,
                        cache: false,
                        striped: true,
                        showRefresh: false,
                        pageSize: 20,
                        pagination: true,
                        pageList: [20, 50, 100, 200, 300, 500],
                        search: false,
                        sidePagination: "server", //表示服务端请求
                        queryParamsType: "undefined",
                        queryParams: function queryParams(params) {   //设置查询参数
                            var param = {
                                page: params.pageNumber,
                                pageSize: params.pageSize,
                                uid: uid,
                            };
                            return param;
                        },
                        url: '/admin/anchorFansTeam/statis/team/DetailList',
                        onLoadSuccess: function () {  //加载成功时执行
                            $("#roundDetailModal").modal('show');
                        },
                        onLoadError: function () {  //加载失败时执行
                            console.log("load fail");
                        }
                    });
                });

                // 导出轮次明细
                $("#exportRoundDetail").on("click", function () {
                    const startTime = $('#startTime').val();
                    const endTime = $('#endTime').val();
                    startTimeStr = startTime;
                    endTimeStr = endTime;
                    console.log("--------roomUid", teamUid);
                    window.location.href = `/admin/guards/export?startTime=${startTime}&endTime=${endTime}&teamUid=${teamUid}`
                });

                $('#editStock').on('click', function () {
                    $("#editStockModal").modal('show');
                });


            });
        }
    },

};
</script>

<style scoped></style>