<?php include_once(mvc::$cfg['PATH_TPL'].'public/topSeller.php');?>
<div class="maintb">
    <?php include_once(mvc::$cfg['PATH_TPL'].'seller/leftMenu.php');?>
    <div id="memberList-main-middle" class="main_middle">
        <div class="navrow">
            <ul class="navrow_ul">
               <li>
                    <a href="memberRegister">已注册用户（公众号）</a>
                </li>
                <li>
                    <a href="memberList">店铺会员</a>
                </li>
				<li>
                    <a href="member">会员等级</a>
                </li>
                <li class="active">
                    <a href="memberColl">店铺收藏</a>
                </li>
            </ul>
        </div>
        <div style="margin-top: 18px;" id="searchTable">
            <form class="form-inline" action="/seller/memberColl" method="get" id="searchForm">
                <table class="table">
                    <tbody>
                        <tr>
                            <td class="thr">用户名称：</td>
                            <td><input type="text" class="form-control" name="userName" value="<?php echo $_GET['userName'];?>"></td>
                            <td class="thr">收藏时间：</td>
                            <td>
                                <input type="text" id="start" onchange="reformatend(this)" style="width: 123px;" readonly="" placeholder="点击选择开始时间" class="form-control" name="starttime" value="<?php echo $_GET['starttime'];?>">
                                <strong>到</strong>
                                <input type="text" id="end"  style="width: 123px;"  readonly="" placeholder="点击选择结束时间" class="form-control" name="endtime" value="<?php echo $_GET['endtime'];?>">
                                <span class="add-on"><i class="icon-remove"></i></span>
                            </td>
                        </tr>
                        <tr>

                            <td class="thr">用户ID：</td>
                            <td><input type="text" class="form-control" name="userId" value="<?php echo $_GET['userId'];?>"></td>
                        </tr>
                        <tr>
                            <td align="center" colspan="6">
                                <button type="button" class="btn btn-default w100 marr10" onclick="window.location.href='/seller/memberList'">清空</button>
                                <button type="button" class="btn btn-danger w100" onclick="return submit();">搜索</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </form>
        </div>
        <div class="inner_container col-tab-box">
            <table class="table table-striped coll-tab">
                <thead>
                    <tr>
                        <th><input type="checkbox" onclick="checkallcheckbox(this)" name="checkall"/></th>
                        <th>ID</th>
                        <th>用户名</th>
                        <th>会员等级</th>
                        <th>收藏时间</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if(!empty($data)){ ?>
                        <?php foreach($data as $v){ ?>
                            <tr>
                                <td><input type="checkbox" class="memluids" value="<?php echo $v['ub_uid'];?>" /></td>
                                <td><?php echo $v['ub_uid'];?></td>
                                <td><?php echo $v['ub_username'];?></td>
                                <td><?php if(empty($userLevel[$v['ub_uid']])) echo '非会员'; else echo $userLevel[$v['ub_uid']]; ?></td>
                                <td><?php echo date('Y-m-d H:i:s',$v['shc_add_time']);?></td>
                            </tr>
                        <?php } ?>
                    <?php }else{ ?>
                        <tr><td colspan="5" class="center orange">非常抱歉，未找到对应条件的会员</td></tr>        
                    <?php } ?>
                </tbody>
            </table>
            <?php echo $Page;?>
        </div>
        <button type="button" onclick="setColMem()" class="btn btn-primary set-col-mem btn-sm">设置会员等级</button>

        <div class="modal fade bs-example-modal-sm"  tabindex="-1" role="dialog" id="setmodel" aria-labelledby="myModalLabel">
            <div class="modal-dialog modal-sm" 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="myModalLabel">设置会员等级</h4>
                    </div>
                    <div class="modal-body">
                        会员级别：
                        <select class="form-control" name="level" id="level-model">
                            <option value="">请选择</option>
                            <?php foreach($level as $v){ ?>
                                <option <?php if($_GET['level'] == $v['mel_id']){echo 'selected';}?> value="<?php echo $v['mel_id'];?>">
                                    <?php echo $v['mel_name'];?>
                                </option>
                            <?php } ?>
                        </select>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary save-col-mem">保存</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php include_once(mvc::$cfg['PATH_TPL'].'public/footAll.php');?>


<script type="text/javascript">
    //设置会员等级
    function setColMem(){
        var ids = new Array();
        $(".coll-tab").find("tbody").find("input[type='checkbox']").each(function(index,i){
            if(i.checked){
                ids.push($(i).val());
            }
        });
        if(ids.length==0){
            return false;
        }
        $('#setmodel').modal('show');
        // 监听提交
        $(".save-col-mem").bind('click',function(){

            var level = $("#level-model").val();
            if(level==""){
                $("#level-model").focus();
                return false;
            } 
            $.ajax({
                url:HOMEURL+'seller/setColMem?isAjax=1',
                data:{'ids':ids.toString(),'level':level},
                dataType:'json',
                type:'post',
                success:function(res){
                    if(MESSAGE.ajaxError(res)){
                        location.reload();
                    }
                }
            });
        });
    }
    var level = <?php echo json_encode($level);?>;
        laydate.render({
        elem: '#start' //指定元素
        ,type: 'datetime'
    });
    laydate.render({
        elem: '#end' //指定元素
        ,type: 'datetime'
    }); 
</script>