@extends('Public.index')
@section('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">
                                <div class="checkbox" onclick="hot()">
                                    <label for="aaa">
                                        <input type="checkbox" id='aaa' value="">　点左边框框进行 全选/反选
                                    </label>
                                </div>
                            @foreach($goods_all as $key => $val)
                                <div class="checkbox">
                                    <label style="margin-left:20px">
                                        <input type="checkbox" name="hot" value="{{ $val['id'] }}">　销量:{{ $val['xiaoliang'] }}; {{ $val['goods_name'] }}
                                    </label>
                                </div>
                            @endforeach
                        </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="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>
    </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" id="md">
                        @foreach($md as $key => $val)
                        <option value="{{ $val -> id }}" @if($md_id == $val -> id) selected @endif> {{ $val -> md_name }}</option>
                        @endforeach
                    </select>
                </div>
        </div>

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

            <div class="card">
              <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>
                @foreach($hot as $key => $val)
                  <tr style="text-align:center">
                    <td><img style="height:100px;width:100px" src="/{{ $val -> goods_images }}" alt="{{ $val -> goods_name }}"></td>
                    <td>{{ $val -> goods_name }}</td>
                    <td onclick="orders({{ $val -> id }},{{ $val -> orders }})">{{ $val -> orders }}</td>
                    <td>
                        <a href="javascript:void(0)" onclick="del({{ $val -> id }})"><i class="fa fa-trash" style="font-size: 16px;" title="删除"></i></a>
                    </td>
                  </tr>
                @endforeach
                </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>
    $('#md').change(function(){
        var id = $('#md option:selected').val();
        window.location.href=" /admin/goodscate/goodshot?id="+id;
    })
    function hot()
    {
        $('input[name="hot"]').each(function () {
            let a = !$(this).prop("checked");
            $(this).prop("checked", a);
        });
    }

    function orders(id,orders)
    {
        layer.prompt({ value:orders,title:'输入排序序号', formType: 3}, function(text, index){
            if(!id){
                layer.msg('参数错误');
                return false;
            }
            $.get('/admin/goodscate/goodsOrders',{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);
        });
    }
    //全屏页面加载
    $('.add').click(function(){
        var index = layer.open({
            type: 2,
            content: '/admin/goodscate/goodsAdd',
            area: ['100%', '100%'],
            maxmin: true
            });
        layer.full(index);
    })
    function create()
    {
        obj = document.getElementsByName("hot");
        check_val = [];
        for(k in obj){
            if(obj[k].checked)
                check_val.push(obj[k].value);
        }
        if(check_val.length <= 0) {
            layer.alert('请选择至少一个商品');
            return false;
        }
        $.get('/admin/goodscate/goodshotAdd',{check_val:check_val},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/goodshotDelete',{id:id},function(res){
                    if(res.code == '1000'){
                        layer.msg(res.msg);
                        window.location.reload();
                    }else{
                        layer.msg(res.msg);
                    }
                })
        });
    }
    function update()
    {
        var name = $('.goodsname2').val();
        var orders = $('.goodsorders2').val();
        var id = $('.id2').val();
        if(!name || !orders || !id) {
            layer.msg('参数不全');
            return false;
        }
        $.get('/admin/goodscate/goodsUpdate',{id:id,name:name,orders:orders},function(res){
            if(res.code == '1000'){
                layer.msg(res.msg);
                window.location.reload();
            }else{
                layer.msg(res.msg);
            }
        }) 
    }
</script>
@endsection
@section('title','商品分类')
@section('goods','menu-open')
@section('goods2','active')
@section('hot','active')