<?php /* D:\phpstudy\PHPTutorial\WWW\liangshan\resources\views/Admin/vip-level.blade.php */ ?>
<?php $__env->startSection('admin'); ?>
<!-- 新增 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <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>
      </div>
      <div class="modal-body">
                <form class="form-horizontal">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">等级名称</label>
                            <div class="col-sm-12">
                             <input type="text" class="form-control level_name" placeholder="等级名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">升级金额</label>
                            <div class="col-sm-12">
                                <input type="number" class="form-control level_price">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">赠送金额</label>
                            <div class="col-sm-12">
                                <input type="number" class="form-control send">
                            </div>
                        </div>

                </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" onclick="create()">添加</button>
      </div>
    </div>
  </div>
</div>
<!-- 修改 -->
<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModal2Label">
  <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>
      </div>
      <div class="modal-body">
                <form class="form-horizontal">
                <input type="hidden" class="user_id">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">等级名称</label>
                            <div class="col-sm-12">
                             <input type="text" class="form-control level_name2" placeholder="等级名称">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">升级金额</label>
                            <div class="col-sm-12">
                                <input type="number" class="form-control level_price2">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">赠送金额</label>
                            <div class="col-sm-12">
                                <input type="number" class="form-control send2">
                            </div>
                        </div>
                </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary" onclick="update()">修改</button>
      </div>
    </div>
  </div>
</div>
<!-- 莫泰结束 -->
<div class="content-wrapper" style="min-height: 810px;">
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h4>会员等级列表</h4>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/admin/index">首页</a></li>
              <li class="breadcrumb-item active">会员管理</li>
              <li class="breadcrumb-item active">会员等级列表</li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>
    <div class="col-xs-6">
        <a href="javascript:void(0)" class="btn btn-primary add" style="margin-left:17px;margin-bottom:15px"> 添加会员等级 +</a>
        <a href="javascript:window.location.href='/admin/vip/list'" class="btn btn-info" style="margin-left:17px;margin-bottom:15px"> 查看会员列表</a>
    </div>

    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12">

            <div class="card">
              <!-- /.card-header -->
              <div class="card-body p-0">
                <table class="table table-condensed">
                  <tbody>

                  <tr style="text-align:center">
                    <th>等级</th>
                    <th>金额(元)</th>
                    <th>赠送(元)</th>
                    <th>用户数</th>
                    <th>状态</th>
                    <th>操作</th>
                  </tr>
                <?php $__currentLoopData = $level; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                  <tr style="text-align:center">
                    <input type="hidden" value="<?php echo e($val -> id); ?>">
                    <td><?php echo e($val -> level_name); ?></td>
                    <td><?php echo e($val -> level_price); ?></td>
                    <td><?php echo e($val -> send); ?></td>
                    <td><?php echo e(DB::table('user') -> where('level',$val -> id) -> count()); ?></td>
                    <td>
                        <?php if($val -> status == 1): ?>
                        <a href="javascript:void(0)" onclick="status(<?php echo e($val -> id); ?>)"><span class="badge bg-success">上线中</span></a>
                        <?php else: ?>
                        <a href="javascript:void(0)" onclick="status(<?php echo e($val -> id); ?>)"><span class="badge bg-danger">未上线</span></a>
                        <?php endif; ?>
                    </td>
                    <td><a href="javascript:void(0)" class="btn btn-primary btn-sm" onclick='edit(<?php echo e($val -> id); ?>,"<?php echo e($val -> level_name); ?>",<?php echo e($val -> level_price); ?>,<?php echo e($val -> send); ?>)'> 调整</a></td>
                  </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </tbody></table>
              </div>
            </div>
          </div>
        </div>
    </section>
  </div>
<script src="/admin/plugins/jquery/jquery.min.js"></script>
<script src="/admin/layer-v3.1.1/layer/layer.js"></script>
<script>
    function status(id)
    {
        if(!id){
            layer.msg('参数错误');
            return false;
        }
        layer.confirm('确认操作吗？', {
            btn: ['确认','取消'] //按钮
            }, function(){
                $.get('/admin/vip/level_status',{id:id},function(res){
                    if(res.code == '1000'){
                        layer.msg(res.msg);
                        window.location.reload();
                    }else{
                        layer.msg(res.msg);
                    }
                })
        });  
    }
    //添加会员模态框
    $('.add').click(function(){
        $('#myModal').modal();
    })
    //添加会员模态框
    function edit(id,level_name,level_price,send)
    {
        if(!id || !level_name || !level_price){
            layer.alert('参数不全');
            return false;
        }
        $('.level_name2').val(level_name);
        $('.level_price2').val(level_price);
        $('.send2').val(send);
        $('.user_id').val(id);
        $('#myModal2').modal();
    }
    //添加会员等级
    function create()
    {
        var level_name = $('.level_name').val();
        var level_price = $('.level_price').val();
        var send = $('.send').val();
        if(!level_name || !level_price){
            layer.alert('请填写完整信息');
            return false;
        }
        $.get('/admin/vip/level_create',{level_name:level_name,level_price:level_price,send:send},function(res){
            if(res.code == '1000'){
                layer.msg(res.msg);
                window.location.reload();
            }else{
                layer.msg(res.msg);
            }
        })
    }
    //调整会员等级
    function update()
    {
        var level_name = $('.level_name2').val();
        var level_price = $('.level_price2').val();
        var send = $('.send2').val();
        var id = $('.user_id').val();
        if(!id || !level_name || !level_price){
            layer.alert('参数不全');
            return false;
        }
        $.get('/admin/vip/level_update',{id:id,level_name:level_name,level_price:level_price,send:send},function(res){
            if(res.code == '1000'){
                layer.msg(res.msg);
                window.location.reload();
            }else{
                layer.msg(res.msg);
            }
        })
    }
</script>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('title','会员等级列表'); ?>
<?php $__env->startSection('vip','menu-open'); ?>
<?php $__env->startSection('vip2','active'); ?>
<?php $__env->startSection('vip-level','active'); ?>
<?php echo $__env->make('Public.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>