<?php /* D:\phpStudy\PHPTutorial\WWW\liangshan\resources\views/Admin/goodscate.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 for="inputEmail3" class="col-sm-3 control-label"><span style="color:red">*</span> 分类名称</label>
                            <div class="col-sm-12">
                            <input type="text" class="form-control goodsname" id="inputEmail3" placeholder="分类名称">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="name" class="col-sm-4 control-label"><span style="color:red">*</span> 门店选择</label>
                                <div class="col-sm-12">
                                    <select class="form-control" id="md">
                                        <?php $__currentLoopData = $md; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($val -> id); ?>"> <?php echo e($val -> md_name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                        </div>

                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-3 control-label"> 排序</label>
                            <div class="col-sm-12">
                            <input type="number" class="form-control goodsorders" id="inputPassword3" placeholder="排序" value="1">
                            </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">
                        <div class="form-group">
                            <label for="inputEmail3" class="col-sm-3 control-label">分类名称</label>
                            <div class="col-sm-12">
                            <input type="hidden" class="id2" value="">
                            <input type="text" class="form-control goodsname2" id="inputEmail3" placeholder="分类名称">
                            </div>
                        </div>

                        <div class="form-group">
                            <label for="name" class="col-sm-4 control-label"><span style="color:red">*</span> 门店选择</label>
                                <div class="col-sm-12">
                                    <select class="form-control" id="md2">
                                        <?php $__currentLoopData = $md; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <option value="<?php echo e($val -> id); ?>"> <?php echo e($val -> md_name); ?></option>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    </select>
                                </div>
                        </div>
                        
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-3 control-label">排序</label>
                            <div class="col-sm-12">
                            <input type="number" class="form-control goodsorders2" id="inputPassword3" placeholder="排序" value="2">
                            </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-3">
        <button class="btn btn-primary" data-toggle="modal" data-target="#myModal" style="margin-left:17px;margin-bottom:15px">添加分类</button>
    </div>
    
    <div class="form-group col-md-12">
            <label for="name" class="col-sm-2 control-label"> 选择门店</label>
                <div class="col-sm-3">
                    <select class="form-control" onchange="pid(this)" id="cate">
                        <option value="0" <?php if(!$md_id): ?> selected <?php endif; ?>> 全部</option>
                        <?php $__currentLoopData = $md; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <option value="<?php echo e($val -> id); ?>" <?php if($md_id == $val -> id): ?> selected <?php endif; ?>> <?php echo e($val -> md_name); ?></option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
        </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 style="width: 100px">操作</th>
                  </tr>
                <?php $__currentLoopData = $goods_cate; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $val): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                  <tr style="text-align:center">
                    <td><?php echo e($val -> cate_name); ?></td>
                    <td onclick="orders(<?php echo e($val -> id); ?>,<?php echo e($val -> orders); ?>)"><?php echo e($val -> orders); ?></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)" onclick="edit(<?php echo e($val -> id); ?>)"><i class="fa fa-edit" style="font-size: 16px;" title="编辑"></i></a>
                        <a href="javascript:void(0)" onclick="del(<?php echo e($val -> id); ?>)"><i class="fa fa-trash" style="font-size: 16px;" title="删除"></i></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>
    $('#cate').change(function(){
        var id = $('#cate option:selected').val();
        window.location.href="/admin/goodscate?id="+id;
    })

    function status(id)
    {
        if(!id){
            layer.msg('参数错误');
            return false;
        }
        layer.confirm('确认操作吗？该分类下所有商品都将同步改变状态', {
            btn: ['确认','取消'] //按钮
            }, function(){
                $.get('/admin/goodscate/status',{id:id},function(res){
                    if(res.code == '1000'){
                        layer.msg(res.msg);
                        window.location.reload();
                    }else{
                        layer.msg(res.msg);
                    }
                })
        });

       
        
    }
    function orders(id,orders)
    {
        layer.prompt({ value:orders,title:'输入排序序号', formType: 3}, function(text, index){
            if(!id){
                layer.msg('参数错误');
                return false;
            }
            $.get('/admin/goodscate/orders',{id:id,text:text},function(res){
                if(res.code == '1000'){
                    layer.msg(res.msg);
                    window.location.reload();
                }else{
                    layer.msg(res.msg);
                }
            })
            layer.close(index);
        });
    }
    function create()
    {
        var goodsName = $('.goodsname').val();
        var goodsOrders = $('.goodsorders').val();
        var md = $('#md').val();
        if(!goodsName || !goodsOrders || !md) {
            layer.msg('参数不全');
            return false;
        }
        $.get('/admin/goodscate/create',{goodsName:goodsName,goodsOrders:goodsOrders,md:md},function(res){
            if(res.code == '1000'){
                layer.msg(res.msg);
                window.location.reload();
            }else{
                layer.msg(res.msg);
            }
        })
    }
    function del(id)
    {
        if(!id) {
            layer.msg('参数不全');
            return false;
        }
        layer.confirm('确认删除分类吗? 不会删除该分类下面的商品', {
            btn: ['确认','取消'] //按钮
            }, function(){
                $.get('/admin/goodscate/delete',{id:id},function(res){
                    if(res.code == '1000'){
                        layer.msg(res.msg);
                        window.location.reload();
                    }else{
                        layer.msg(res.msg);
                    }
                })
        });
    }
    function edit(id)
    {
        if(!id) {
            layer.msg('参数不全');
            return false;
        }
        $.get('/admin/goodscate/edit',{id:id},function(res){
            if(res){
                var result = JSON.parse(res);
                console.log(result);
                $('.goodsname2').val(result.cate_name);
                $('.goodsorders2').val(result.orders);
                $('.id2').val(result.id);
                $('#md2').val(result.md_id);
                $('#myModal2').modal();
            }else{
                layer.msg('查询失败');
            }
        }) 
    }
    function update()
    {
        var name = $('.goodsname2').val();
        var orders = $('.goodsorders2').val();
        var md = $('#md2').val();
        var id = $('.id2').val();
        if(!name || !orders || !id) {
            layer.msg('参数不全');
            return false;
        }
        $.get('/admin/goodscate/update',{id:id,name:name,orders:orders,md:md},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('goods','menu-open'); ?>
<?php $__env->startSection('goods2','active'); ?>
<?php $__env->startSection('cate','active'); ?>
<?php echo $__env->make('Public.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>