<?php include_once(mvc::$cfg['PATH_TPL'].'seller/publicHead.php');?>
<style>
    .page-box {
        float: left;
        height: 28px;
        margin: 5px;
        line-height: 28px;
        margin: 30px 0 20px 15px;
    }
    .lay-inline {display: inline;width: auto;}
</style>
<div class="maintb">
    <div id="memberList-main-middle" class="main_middle">
        <div class="layui-tab layui-tab-card">
            <ul class="layui-tab-title">
				<!-- <li class="layui-this">
                    <a href="<?php echo mvc::$cfg['SELF_URL'];?>seller/memberRegister">已注册用户</a>
                </li> -->
                <li>
                    <a href="<?php echo mvc::$cfg['SELF_URL'];?>seller/memberList" style="color:#000">店铺会员</a>
                </li>
				<li>
                    <a href="<?php echo mvc::$cfg['SELF_URL'];?>seller/member" style="color:#000">会员等级</a>
                </li>
                <li>
                    <a href="<?php echo mvc::$cfg['SELF_URL'];?>seller/memberColl" style="color:#000">店铺收藏</a>
                </li>
            </ul>  
            <div class="layui-tab-conten" style="padding:10px">
                <div id="searchTable">
                    <form class="form-inline" action="<?php echo mvc::$cfg['SELF_URL'];?>/seller/memberRegister" method="get" id="searchForm">
                        <table class="table">
                            <tbody>
                            <tr>
                                <td class="thr">用户名称：</td>
                                <td><input type="text" class="layui-input lay-inline" 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="layui-input lay-inline" name="starttime" value="<?php echo $_GET['starttime'];?>">
                                    <strong>到</strong>
                                    <input type="text" id="end"  style="width: 123px;"  readonly="" placeholder="点击选择结束时间" class="layui-input lay-inline" name="endtime" value="<?php echo $_GET['endtime'];?>">
                                    <span class="add-on"><i class="icon-remove"></i></span>
                                </td>

                            </tr>
                            <tr>
                                <td class="thr">手机号</td>
                                <td><input type="text" class="layui-input lay-inline" name="mobile" value="<?php echo $_GET['mobile'];?>"></td>
                                <td colspan="6">
                                    <button type="button" class="layui-btn layui-btn-primary" onclick="window.location.href='<?php echo mvc::$cfg['SELF_URL'];?>seller/memberRegister'">清空</button>
                                    <button type="button" class="layui-btn" onclick="return submit();">搜索</button>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </form>
                </div>
                <div style="margin-top:15px;" class="inner_container">
                    <table style="border: 1px solid #ccc;width: 90%;margin-bottom: 10px;" class="layui-table">
                        <thead>
                        <tr>
                            <th style="width:5%;"><input type="checkbox" onclick="checkallcheckbox(this)" name="checkall"/></th>
                            <th style="width: 10%">用户名名称</th>
                            <th style="width: 10%">手机号</th>
                            <th style="width: 10%">姓名</th>
                            <th style="width: 20%">公司</th>
                            <th style="width: 15%;">地区</th>
                            <th style="width: 10%">会员级别</th>
                            <th style="width: 20%">注册时间</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php if(!empty($list)){ ?>
                            <?php foreach($list as $key => $value){ ?>
                                <tr>
                                    <td><input type="checkbox" class="memluids" value="<?php echo $value['u_id'];?>" /></td>
                                    <td><?php echo $value['u_name'];?></td>
                                    <td><?php echo $value['u_mobile']; ?></td>
                                    <td><?php echo $value['u_real_name']; ?></td>
                                    <td><?php echo $value['ui_company']; ?></td>
                                    <td><?php echo $value['address'];?></td>
                                    <td> <select onchange="addMemer(this,'<?php echo $value['u_id']; ?>');" class="layui-input lay-inline" name="level">
                                            <option value="-1">无</option>
                                            <?php foreach($level as $v){ ?>
                                                <option <?php if($value['level'] == $v['mel_name']){echo 'selected';}?> value="<?php echo $v['mel_id'];?>">
                                                    <?php echo $v['mel_name'];?>
                                                </option>
                                            <?php } ?>
                                        </select>
                                    </td>
                                    <td><?php echo $value['u_register_time'];?></td>
                                </tr>
                            <?php } ?>
                        <?php }else{ ?>
                            <tr><td colspan="5" class="center orange">非常抱歉，未找到对应条件的会员</td></tr>
                        <?php } ?>
                        </tbody>
                    </table>
                    <div>
                        <button class="layui-btn" onclick="setRegisterMem()">修改级别</button>
                    </div>
                    <?php echo $Page;?>   
                </div>
                
            </div>
        </div>
    </div>

    <div id="setLevelModel" style="display: none;">
        <div class="modal-body">
            <table id="addnewUserName" class="layui-table">
                <tbody>
                <tr>
                    <td class="success">
                        会员等级
                    </td>
                    <td>
                        <select id="editlevels" name="level" class="layui-input lay-inline">
                            <option value="-1">无</option>
                            <?php foreach($level as $v){ ?>
                            <option value="<?php echo $v['mel_id'];?>">
                                <?php echo $v['mel_name'];?>
                            </option>
                            <?php } ?>
                        </select>
                        </td>
                    </tr>
                </tbody>
            </table>
        </div>
        <div class="modal-footer" style="text-align:center;">
            <button type="button" id="submitSetLevel" class="layui-btn">提交</button>
            <button type="button" class="layui-btn" id="closeSetLevel" data-dismiss="modal">关闭</button>
        </div>
    </div>
    
</div>

<?php include_once(mvc::$cfg['PATH_TPL'].'public/footBase.php');?>
<script type="text/javascript">
    var level = <?php echo json_encode($level);?>;
    layui.use('laydate', function(){
        laydate = layui.laydate
        laydate.render({
            elem: '#start' //指定元素
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#end' //指定元素
            ,type: 'datetime'
        });
    })
    function addMemer(that,uid) {
        var text = $(that).val();
        var data = [];
        data['0'] = [];
        data['0'].push(text);
        data['0'].push(uid);
        $.post('<?php echo mvc::$cfg['SELF_URL'];?>/seller/submitnewUid',{'allUid':data,'isAjax':1},function(res){
            if(res.status){
                layer.msg("保存成功");
            } else {
                layer.msg(res.data)
            }
        },'json');
    }
        //设置会员等级
    function setRegisterMem(){
        var ids = new Array();
        $(".inner_container").find("tbody").find("input[type='checkbox']").each(function(index,i){
            if(i.checked){
                ids.push($(i).val());
            }
        });
        if(ids.length==0){
            layer.msg('未选择会员！')
            return false;
        }

        layer.open({
            type:1,
            title:'设置会员等级',
            area:['300px','180px'],
            content:$("#setLevelModel"),
            success:function(layero,index){
                //取消
                $("#closeSetLevel").click(function(){
                    layer.close(index);
                })

                // 监听提交
                $("#submitSetLevel").bind('click',function(){
                    var level = $("#editlevels").val();
                    if(level==""){
                        $("#editlevels").focus();
                        return false;
                    } 
                    layer.close(index);
                    $.ajax({
                        url:SELF_URL+'seller/setRegisterMem?isAjax=1',
                        data:{'ids':ids.toString(),'level':level},
                        dataType:'json',
                        type:'post',
                        success:function(res){
                            if(!AJAX.checkData(res)) return false;
                            layer.msg(res.data, {icon: 1,time: 2000 },function(){
                                location.reload();
                            });
                        }
                    });
                });
            }
        })
        
    }
</script>