@extends('admin.layouts.app')
@section('header')
    <style>
        .company-info {
            border: 1px solid #eee;
            padding: 10px 0;
            margin: 10px;
            border-radius: 5px
        }

        .company-info p {
            margin-bottom: 0;
            font-size: 14px
        }

        .company-info p label {
            color: #aaa;
            font-weight: 400
        }

        .company-info p span {
            margin-right: 20px;
            color: #111
        }

        .ibox-content {
            background-color: #f5f9fc;
        }

        #company-list {
            background-color: #ffffff;
        }

        #filter_table {
            background-color: #ffffff;
            margin: 0 auto 20px auto;
            padding: 30px 5px;
            border-radius: 5px

        }
        .bootstrap-tagsinput{
            width: 80%;
        }
    </style>
@endsection

@section('content')
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>挖掘线索</h5>

                    <div class="ibox-tools">
                        <a class="collapse-link"> <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">

                    <div class="col-xl-9 col-lg-10" id="filter_table">
                        <form method="GET" action="" accept-charset="UTF-8" id="filter_company">
                            {{ csrf_field() }}
                            <div class="row" style="margin-bottom: 20px">
                                <div class="col-sm-10 col-sm-offset-2" style="margin: auto">
                                    <input class="tagsinput form-control" type="text"
                                           name="company_name" style="display: none;width: 100%"
                                           placeholder="请输入企业名称关键字" value="{{Request::get('company_name')}}">

                                         <span class="btn btn-default" style="margin: 5px 6px" onclick="filter_company()">搜索</span>


                                </div>

                            </div>
                            <div class="row">
                                <div class="col-sm-2">
                                    <select name="district" class="form-control" onchange="filter_company()">
                                        <option value="">所在地区</option>
                                        @foreach($fields['district'] as $district)
                                            <option value="{{$district['value']}}"
                                                    @if($district['value'] == Request::get('district')) selected @endif>{{$district['name']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <select name="industry[]" data-placeholder="所属行业" class="form-control chosen-select"
                                            onchange="filter_company()" multiple="" tabindex="-1">
                                        <option value="">所属行业</option>
                                        @foreach($fields['industry'] as $industry)
                                            <option value="{{$industry['value']}}"
                                                    @if(Request::get('industry') &&  in_array($industry['value'],Request::get('industry')) ) selected @endif>{{$industry['name']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <select name="reg_capital" class="form-control" onchange="filter_company()">
                                        <option value="">注册资本</option>
                                        @foreach($fields['reg_capital'] as $reg_capital)
                                            <option value="{{$reg_capital['value']}}"
                                                    @if($reg_capital['value']== Request::get('reg_capital')) selected @endif>{{$reg_capital['name']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <select name="start_date" class="form-control" onchange="filter_company()">
                                        <option value="">成立年限</option>
                                        @foreach($fields['start_date'] as $start_date)
                                            <option value="{{$start_date['value']}}"
                                                    @if($start_date['value']== Request::get('start_date')) selected @endif>{{$start_date['name']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <select name="ent_type" class="form-control" onchange="filter_company()">
                                        <option value="">企业类型</option>
                                        @foreach($fields['ent_type'] as $ent_type)
                                            <option value="{{$ent_type['value']}}"
                                                    @if($ent_type['value']== Request::get('ent_type')) selected @endif>{{$ent_type['name']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="col-sm-2">
                                    <select name="open_status" class="form-control" onchange="filter_company()">
                                        <option value="">企业状态</option>
                                        @foreach($fields['open_status'] as $open_status)
                                            <option value="{{$open_status['value']}}"
                                                    @if($open_status['value']== Request::get('open_status')) selected @endif>{{$open_status['name']}}</option>
                                        @endforeach
                                    </select>
                                </div>

                            </div>
                        </form>

                    </div>

                    <div id="company-list" class="col-xl-9 col-lg-10" style="margin: auto">
                        @include('admin.company.info.data')
                    </div>

                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
    <script type="text/javascript">
        /*对字段进行过滤*/
        function filter_company() {
            data = $('#filter_company').serialize();
            $.ajax({
                type: 'get',
                data: data,
            }).done(function (data) {
                $('#company-list').html(data.html)
            })
        }

        /*保存公海*/
        function save_collection() {
            hasCollection = "{{$hasCollection}}";
            if (hasCollection) {
                layer.confirm('你已经创建过公海，确定要替换吗？替换后不可撤销!', {
                    btn: ['确定', '取消']//按钮
                }, function (index) {
                    layer.close(index);
                    ajax_collection_save()
                });
            } else {
                ajax_collection_save()
            }

        }

        function ajax_collection_save() {
            data = $('#filter_company').serialize();
            $.ajax({
                url: '{{ U('Company/Collection/create') }}',
                type: 'post',
                data: data,
                success: function (data) {
                    if (data == 200) {
                        layer.msg('保存公海成功！',
                            {icon: 1},
                            function () {
                                window.location.href = '{{ U('Company/Collection/index') }}'
                            }
                        )
                    }
                }

            })
        }

        /*Ajax分页*/
        $('body').on('click', '.pagination a', function (e) {
            e.preventDefault();
            if ($(this).attr('href') != '#') {
                data = $('#filter_company').serialize();
                $.ajax({
                    url: $(this).attr('href'),
                    type: 'get',
                    data: data,
                }).done(function (data) {
                    $('#company-list').html(data.html)
                })
            }

        });

        $('body').on('change', '#company-import', function (e) {
            file = $('#company-import').val();
            if (file) {
                $('.company-import').show()
            } else {
                $('.company-import').hide()
            }
        })
        $('body').on('click', '.company-import', function (e) {
            layer.load(1)
        })


    </script>
@endsection