<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改活动</title>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="<?php echo base_url(); ?>public/js/bootstrap/bootstrap.min.css">

</head>

<body>
<div class="content_wrapper">
    <div class="container-fluid">
        <div class="row">
            <div class="col-sm-12">
                <aside>
                    <header><i class="fa fa-fw fa-file"></i>邀请信息查询</header>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <div style="margin-bottom:20px;">
                                        <div class="form-inline" role="form">
                                            <div class="form-group">
                                                <label>被邀请人UID：</label>
                                                <input type="text" class="form-control"
                                                       value="<?php if (isset($invitee)) echo $invitee; ?>"
                                                       placeholder="被邀请人UID"
                                                       name="invitee" id="invitee"/>
                                            </div>
                                            <button onclick="searchInviteInfo('invitee')" class="btn btn-primary">查询
                                            </button>
                                        </div>
                                    </div>
                                    <div style="margin-bottom:20px;">
                                        <div class="form-inline" role="form">
                                            <div class="form-group">
                                                <label>邀请人UID：</label>
                                                <input type="text" class="form-control"
                                                       value="<?php if (isset($inviter)) echo $inviter; ?>"
                                                       placeholder="邀请人UID"
                                                       name="inviter" id="inviter"/>
                                            </div>
                                            <button onclick="searchInviteInfo('inviter')" class="btn btn-primary">查询
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>
                    <section>
                        <div class="container-fluid">
                            <div class="row">
                                <div class="col-sm-12">
                                    <div class="table-responsive">
                                        <table id="exchangeTable" class="table table-striped table-bordered table-hover"
                                               cellspacing="0" width="100%">
                                            <thead>
                                            <tr>
                                                <th>序号</th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <tr>
                                                <td colspan="14">暂无数据</td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </section>
                </aside>
            </div>
        </div>
    </div>
</div>
</body>


<script type="text/javascript">
    //当点击search按钮时按条件重新加载数据
    function searchInviteInfo(type) {
        const invitee = $('#invitee').val();
        const inviter = $('#inviter').val();

        if ((type === 'invitee' && invitee === '') || (type === 'inviter' && inviter === '')) {
            alert('请输入用户UID，再查询！');
        }

        var formData = new FormData();
        formData.append("type",type);
        formData.append("invitee",invitee);
        formData.append("inviter",inviter);

        $.ajax({
            url: rootPath + 'user/searchInviteData',
            type: 'POST',
            data: formData,
            dataType: 'json',
            contentType: false, //必须
            processData: false, //必须
            success: function (response) {
                var tipContent = "";
                if (type === 'invitee') {
                    tipContent += '<thead><tr><th>Index</th><th>首次安装时间</th><th>邀请人id</th><th>渠道</th><th>渠道id</th></tr></thead>'
                    tipContent += '<tbody>'
                    response.data.forEach((item, index) => {
                        tipContent += '<tr><td>' + (parseInt(index) + 1) + '</td><td>' + item.created_at + '</td><td>' + item.label + '</td><td>' + item.tracker_name + '</td><td>' + item.tracker_token + '</td></tr>'
                    });
                    tipContent += '</tbody>'
                } else if (type === 'inviter') {
                    tipContent += '<thead><tr><th>Index</th><th>被邀请人id</th><th>领奖时间</th><th>是否领奖</th></tr></thead>'
                    tipContent += '<tbody>'
                    response.data.forEach((item, index) => {
                        tipContent += '<tr><td>' + (parseInt(index) + 1) + '</td><td>' + item.is_backuid + '</td><td>' + item.is_time + '</td><td>' + (item.is_reward==1?'是':'否') + '</td></tr>'
                    });
                    tipContent += '</tbody>'
                }

                $("#exchangeTable").html(tipContent);
            },
            error: function (data) {
                alert(data.msg);
            }
        });

//         $.post("user/searchInviteData", postData, function (response) {
//             response = JSON.parse(response)
//             console.log(response.data)
//
//             var tipContent = "";
//             if (type === 'invitee') {
//                 tipContent += '<thead><tr><th>Index</th><th>首次安装时间</th><th>邀请人id</th><th>渠道</th><th>渠道id</th></tr></thead>'
//                 tipContent += '<tbody>'
//                 response.data.forEach((item, index) => {
//                     tipContent += '<tr><td>' + (parseInt(index) + 1) + '</td><td>' + item.created_at + '</td><td>' + item.label + '</td><td>' + item.tracker_name + '</td><td>' + item.tracker_token + '</td></tr>'
//                 });
//                 tipContent += '</tbody>'
//             } else if (type === 'inviter') {
//                 tipContent += '<thead><tr><th>Index</th><th>被邀请人id</th><th>领奖时间</th><th>是否领奖</th></tr></thead>'
//                 tipContent += '<tbody>'
//                 response.data.forEach((item, index) => {
//                     tipContent += '<tr><td>' + (parseInt(index) + 1) + '</td><td>' + item.is_backuid + '</td><td>' + item.is_time + '</td><td>' + item.is_reward + '</td></tr>'
//                 });
//                 tipContent += '</tbody>'
//             }
// alert('2222')
//             $("#exchangeTable").html(tipContent);
//         });
    }
</script>
