@extends('admin.layout')
@section('header')

    <link href="{{ session()->get('is_we7')=='true'?'/addons/furnitureWe7/public':'' }}/base/css/fileinput.css" media="all" rel="stylesheet" type="text/css" />

    <script src="{{ session()->get('is_we7')=='true'?'/addons/furnitureWe7/public':'' }}/base/js/fileinput.js" type="text/javascript"></script>
    <script src="{{ session()->get('is_we7')=='true'?'/addons/furnitureWe7/public':'' }}/base/js/fileinput_locale_zh.js" type="text/javascript"></script>

@endsection
@section('content')

    <?php
    if (!isset($data)) $data = array();
    if (!$data && session("data")) {
        $data = session("data");
    }
    if (!$data && session('_old_input')) {
        $data = session("_old_input");
    }
    ?>
    <div class="wrapper wrapper-content animated fadeInRight">
        <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="row">
                            <div class="col-lg-10">
                                <form name="form_product" id="form-validation" action=""
                                      class="form-horizontal form-validation" accept-charset="UTF-8" method="post">



                                        <div class="form-group">

                                            <label class="control-label col-sm-3">厂家名称</label>

                                            <div class="col-sm-9">
                                                <input id="data_name" name="data[name]" class="form-control"
                                                       value="{{ $data['name'] or ''}}" required="" aria-required="true"
                                                       placeholder="">
                                            </div>

                                        </div>
                                        <div class="form-group">

                                            <label class="control-label col-sm-3">厂家头像</label>

                                            <div class="col-sm-9">
                                                {!!  widget('Tools.ImgUpload')->single('avatar',"data[avatar]", isset($data['avatar'])? $data['avatar'] : "") !!}

                                            </div>

                                        </div>

                                    <div class="form-group">
                                        <label class="control-label col-sm-3">个人二维码画报
                                            <br/>
                                            <small class="text-navy">(440像素 * 440像素)</small>
                                            </label>
                                        <div class="col-sm-9">
                                            {!!  widget('Tools.ImgUpload')->single2('/upload/circleOfFriends','circleOfFriends',"circleOfFriends",  isset($data['circleOfFriends'])? $data['circleOfFriends'] : '',array("sizex"=>440,"sizey"=>440)) !!}
                                        </div>
                                    </div>
                                    <div class="form-group">

                                        <label class="control-label col-sm-3">个人二维码介绍语</label>

                                        <div class="col-sm-9">
                                            <input id="data_introduce" name="data[introduce]" class="form-control"
                                                   value="{{ $data['introduce'] or ''}}" required="" aria-required="true"
                                                   placeholder="">
                                        </div>

                                    </div>

                                    <div class="form-group">

                                        <label class="control-label col-sm-3">厂家二维码
                                            <br/>
                                            <small class="text-navy">(430像素 * 430像素)</small>
                                            </label>
                                        <div class="col-sm-9">
                                            {!!  widget('Tools.ImgUpload')->single2('/upload/qrcode','qrcode',"qrcode",  isset($data['qrcode'])? $data['qrcode'] : '',array("sizex"=>430,"sizey"=>430)) !!}
                                        </div>

                                    </div>



                                        <div class="form-group">

                                            <label class="control-label col-sm-3">电话</label>

                                            <div class="col-sm-9">
                                                <input id="data_phone" name="data[phone]" class="form-control"
                                                       value="{{ $data['phone'] or ''}}" required=""
                                                       aria-required="true"
                                                       placeholder="">
                                            </div>

                                        </div>

                                        <!--引入高德地图API-->
                                        <script type="text/javascript"
                                                src="https://webapi.amap.com/maps?v=1.3&key=533117702a063eae1dc26c183a1ac7bb&plugin=AMap.Autocomplete"></script>
                                        <script type="text/javascript"
                                                src="https://cache.amap.com/lbs/static/addToolbar.js"></script>
                                        <div class="form-group">
                                            <label class="control-label col-sm-3">地址<span
                                                        style="color: red">*</span></label>
                                            <div class="col-sm-9">
                                                <input n name="data[address]" readonly="true"
                                                       value="{{$data['address'] or ''}}" class="form-control" id="add"
                                                       data-toggle="modal"
                                                       data-target="#myModal">
                                            </div>
                                        </div>

                                        <input type="hidden" name="lon" id="lon" value="{{$data['lon'] or ''}}">
                                        <input type="hidden" name="lat" id="lat" value="{{$data['lat'] or ''}}">


                                    <div class="form-group">
                                        <label class="control-label col-sm-3">经销商画报</label>
                                        <div class="col-sm-9">
                                            {{--     //{!! ueditor('') !!}--}}
                                            {!!  widget('Tools.ImgUpload')->multi2('/upload/agent_banner','agent_banner',"data[agent_banner]",  isset($data['agent_banner'])? $data['agent_banner'] : '') !!}
                                        </div>
                                    </div>

                                    <div class="form-group">

                                        <label class="control-label col-sm-3">厂家LOGO
                                            <br/>
                                            <small class="text-navy">(130像素 * 130像素)</small>
                                            </label>
                                        <div class="col-sm-9">
                                            {!!  widget('Tools.ImgUpload')->single2('/upload/logo','logo',"logo",  isset($data['logo'])? $data['logo'] : '',array("sizex"=>130,"sizey"=>130)) !!}
                                        </div>

                                    </div>

                                    <div class="form-group">

                                        <label class="control-label col-sm-3">开屏广告图</label>
                                        <div class="col-sm-9">
                                            {!!  widget('Tools.ImgUpload')->multi2('/upload/banner','banner',"data[banner]", isset($data['banner'])? $data['banner'] : '',[]) !!}
                                        </div>
                                    </div>



                                    <div class="form-group">

                                        <label class="control-label col-sm-3">分享画面
                                            <br/>
                                            <small class="text-navy">(1080像素 * 1080像素)</small>
                                        </label>
                                        <div class="col-sm-9">
                                            {{--{!!  widget('Tools.ImgUpload')->single2('/upload/cover_pic','cover_pic',"cover_pic",  isset($data['cover_pic'])? $data['cover_pic'] : '',array("sizex"=>662,"sizey"=>510)) !!}--}}
                                            {!!  widget('Tools.ImgUpload')->single2('/upload/share_image','share_image',"share_image",  isset($data['share_image'])? $data['share_image'] : '',array("sizex"=>1080,"sizey"=>1080)) !!}
                                            <button type="button" onclick="layer.open({type: 2,area: ['80%', '90%'],content: '{{ U('Album/Manufacturer/viewShare')}}'});"  class="btn btn-primary col-sm-offset-3">查看示例</button>
                                        </div>
                                    </div>
                                    <div class="form-group">

                                        <label class="control-label col-sm-3">分享标题</label>

                                        <div class="col-sm-9">
                                            <input id="data_introduce" name="data[share_title]" class="form-control" value="{{ $data['share_title'] or ''}}" required="" aria-required="true"  placeholder="">
                                        </div>

                                    </div>



                                    <div class="form-group">
                                        <label class="control-label col-sm-3">&nbsp;</label>
                                        <div class="col-sm-9">
                                            <input type="hidden" name="_referer"
                                                   value="<?php echo urlencode(request()->server('HTTP_REFERER'));?>"/>
                                            <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>"/>
                                            <input type="submit" class="btn btn-success" style="margin-right:20px;">
                                            <input type="reset" class="btn btn-default">
                                        </div>
                                    </div>

                                </form>
                            </div>
                            <!-- /.col-lg-10 -->
                        </div>
                        <!-- /.row -->
                    </div>
                </div>
            </div>
        </div>

        <div class="row">
            <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>视频列表</h5>
                    </div>
                    <div class="ibox-content">
                        <form enctype="multipart/form-data" method="post" action="{{ U('Album/Manufacturer/uploadVideo') }}">
                            <div class="form-group">
                                <input id="file-0b" class="file" type="file" name="video">
                            </div>
                            {{csrf_field()}}
                        </form>
                        <table class="table">
                            <thead>
                            <tr>
                                <th>#</th>
                                <th>链接</th>
                                <th>文件名</th>
                                <th>操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if(!empty($video))
                                <tr>
                                    <td>{{ $video['id'] }}</td>
                                    <td>{{ $video['name'] }}</td>
                                    <td>{{ $video['url'] }}</td>
                                    <td>
                                        <div class="pull-right">
                                            <a href="{{ U('Album/Manufacturer/videoDel',['id'=>$video['id']])}}" onclick="return confirm('你确定执行删除操作？');" class="btn btn-sm btn-danger pull-right">删除</a>
                                        </div>
                                    </td>
                                </tr>
                            @else
                                <tr>
                                    <td colspan="4">暂无文件</td>
                                </tr>
                            @endif

                            </tbody>
                        </table>

                    </div>
                </div>
            </div>
        </div>

        <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
             aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-dialog" style="min-width:60%;">
                <div class="modal-content">
                    <div class="modal-header">
                        <h4 class="modal-title" id="myModalLabel">
                            选择坐标
                        </h4>
                    </div>
                    <div class="modal-body">
                        <div id="container" style="width: 100%;min-height: 400px;"></div>
                        <div id="myPageTop">
                            <table>
                                <tr>
                                    <td>
                                        <label>按关键字搜索：</label>
                                    </td>
                                    <td>

                                    </td>

                                </tr>
                                <tr>
                                    <td>
                                        <input style="margin-right: 10px;min-width:300px"
                                               value="{{ isset($data['address'])?$data['address'] : "" }}" type="text"
                                               placeholder="请输入关键字进行搜索" id="tipinput">
                                    </td>
                                    <td>
                                        <div style="margin-right: 10px;" class="btn btn-sm btn-primary"
                                             id="confirm">显示搜索点
                                        </div>
                                    </td>
                                    <td class="column2">
                                        <input type="hidden" readonly="true" id="lnglat">
                                    </td>
                                </tr>
                            </table>
                            <br>
                            <button type="button" id="modal-close" class="btn btn-sm btn-primary text-center"
                                    data-dismiss="modal">确认位置信息
                            </button>
                        </div>
                        <div id="panel"></div>
                    </div>

                </div><!-- /.modal-content -->
            </div><!-- /.modal -->
        </div>
    </div>


    <script type="text/javascript">
        var map = new AMap.Map("container", {
            resizeEnable: true,
            zoom: 10
        });
        $("#confirm").click(function () {
            var val = $('#tipinput').val();
            AMap.service(["AMap.PlaceSearch"], function () {
                var placeSearch = new AMap.PlaceSearch({ //构造地点查询类
                    pageSize: 5,
                    pageIndex: 1,
                    map: map,
                    panel: "panel"
                });
                placeSearch.search(val);
            });
        });

        //为地图注册click事件获取鼠标点击出的经纬度坐标
        var clickEventListener = map.on('click', function (e) {
            document.getElementById("lnglat").value = e.lnglat.getLng() + ',' + e.lnglat.getLat();
        });

        AMap.plugin('AMap.Geocoder', function () {
            var geocoder = new AMap.Geocoder({});
            var marker = new AMap.Marker({
                map: map,
                bubble: true
            })
            map.on('click', function (e) {
                console.log(e);
                marker.setPosition(e.lnglat);
                $('#lon').val(e.lnglat.getLng());
                $('#lat').val(e.lnglat.getLat());
                geocoder.getAddress(e.lnglat, function (status, result) {
                    if (status == 'complete') {
                        console.log(result);
                        document.getElementById('tipinput').value = result.regeocode.formattedAddress
                    }
                })
            })

        });
        $("#modal-close").click(function () {
            var b = ($('#tipinput').val());
            console.log(b);
            $('#map').val(b);
            $('#add').val(b);
        });
        /*  $('.sg-datepicker').datepicker({
              format: 'yyyy-mm-dd',
              language: 'zh-CN'
          });*/
    </script>
@endsection