@extends('admin.layout')

@section('content')
    <link href="/base/css/time/jquery.datetimepicker.css" rel="stylesheet">
    <link href="/base/css/time/jquery-ui-1.10.1.css" rel="stylesheet">
    <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">
                           {{-- <form method="GET" action="" accept-charset="UTF-8">
                                <div class="col-sm-6" style="margin: auto;float: none">
                                    <div class="input-group">
                                        <input type="text" value="{{Request::get('keyword')}}" placeholder="搜索全部订单"
                                               name="keyword" class="input-sm form-control">
                                        <span class="input-group-btn">
									<button type="submit" class="btn btn-sm btn-success">搜索</button>
								</span>
                                    </div>
                                </div>
                            </form>--}}
                            @if(role('Album/Order/create'))
                                <div class="col-sm-3 pull-right">
                                    <a href="{{ U('Album/Order/create')}}"
                                       class="btn btn-sm btn-primary pull-right">添加</a>
                                </div>
                            @endif
                        </div>
                        <div class="row">
                            <form method="GET" action="" accept-charset="UTF-8">

                                <div class="col-sm-8">
                                    <div class="input-group">
                                        <div class="col-sm-5" style="padding-left: 0">
                                            <input type="text" value="{{Request::get('keyword')}}"
                                                   placeholder="订单号/分类/型号/姓名/电话/地址"
                                                   name="keyword" class="input-sm form-control">
                                            <input type="hidden" name="status" value="{{Request::get('status')}}">
                                            <input type="hidden" name="expected" value="{{Request::get('expected')}}">

                                        </div>
                                        <div class="col-sm-3">
                                            <input id="start" name="start"
                                                   value="{{Request::get('start') ? : date('Y-m-d',time())}}"
                                                   class="input-sm form-control"/>
                                        </div>
                                        <div class="col-sm-3">
                                            <input id="end" name="end"
                                                   value="{{Request::get('end') ? : date('Y-m-d',time())}}"
                                                   class="input-sm form-control"/>
                                        </div>

                                        <span class="input-group-btn col-sm-2">
                                            <button type="submit" class="btn btn-sm btn-primary">搜索</button>
                                        </span>
                                    </div>
                                </div>
                            </form>

                        </div>

                        <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
                            <thead>
                            <tr>
                                <th class="sorting" data-sort="sno"> 订单编号</th>
                                <th class="sorting" data-sort="picture"> 图片</th>
                                <th class="sorting" data-sort="qrcode"> 订单信息</th>
                                <th class="sorting" data-sort="status">订单状态</th>
                                @if(Request::get('expected'))
                                    <th class="sorting" data-sort="status">逾期备注</th>@endif
                                <th width="22%">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if(isset($list))
                                @foreach($list as $key => $item)
                                    <tr>
                                        <td>{{ $item->sno }}</td>
                                        <td>
                                            @if(role('Album/Order/getpic'))<span style="cursor: pointer"
                                                  onclick="layer.open({type: 2,area: ['80%', '90%'],title:'图片',content: '{{ U('Album/Order/picture',['id'=>$item->id])}}'});"
                                                  class="label label-default">查看图片</span>
                                            @else
                                                <span style="cursor: pointer">暂无权限</span>
                                            @endif
                                        </td>
                                        <td>
                                            产品分类：{{ $item->category }}<br/>
                                            型 号：{{ $item->type }}<br/>
                                            颜 色：{{ $item->color}}<br/>
                                            问题描述：{{ mb_substr($item->question,0,10).'...' }}
                                        </td>
                                        <td>{{ $item->status() }}</td>
                                        @if(Request::get('expected'))
                                            <td>@if($item->expected_comment){{$item->expected_comment}}@else
                                                    @if(role('Album/Order/addecomment'))
                                                    <button class="btn btn-warning myModal1" data-toggle="modal"
                                                            data-id="{{ $item->id }}" data-target="#myModal">添加备注
                                                    </button>
                                                    @endif
                                                @endif
                                            </td>
                                        @endif
                                        <td>
                                            <div class="btn-group">
                                                @if($item->status == 0)
                                                    @if(role('Album/Order/status'))
                                                        <button class="btn btn-success myModal" data-toggle="modal"
                                                                data-id="{{ $item->id }}" data-target="#myModal2">通过审核
                                                        </button>
                                                    @endif
                                                @else
                                                    @if(role('Album/Order/check'))
                                                        <button onclick="layer.open({type: 2,area: ['80%', '90%'],content: '{{ U('Album/Order/check',['id'=>$item->id])}}'});"
                                                                class="btn btn-success ">打印
                                                        </button>
                                                    @endif
                                                @endif
                                            </div>
                                            @if(role('Album/Order/view'))
                                                <button onclick="layer.open({type: 2,area: ['80%', '90%'],content: '{{ U('Album/Order/view',['id'=>$item->id])}}'});"
                                                        class="btn btn-primary ">查看详情
                                                </button>
                                            @endif
                                            @if(role('Album/Order/destroy'))
                                              <a class="btn btn-danger" href="{{ U('Album/Order/destroy',['id'=>$item->id])}}"
                                                       onclick="return confirm('你确定关闭该订单？');">关闭订单</a>
                                            @endif
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="6">
                                            收货地址:{{ $item->customer_address }} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            姓名:{{ $item->customer_name }} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            联系方式:{{ $item->customer_phone }} &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                            下单时间:{{ $item->created_at }}
                                        </td>
                                    </tr>
                                @endforeach
                            @endif

                            </tbody>
                        </table>
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="dataTables_info" id="DataTables_Table_0_info"
                                     role="alert" aria-live="polite" aria-relevant="all">每页{{ $list->count() }}
                                    条，共{{ $list->lastPage() }}页，总{{ $list->total() }}条。
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
                                    {!! $list->setPath('')->appends(Request::all())->render() !!}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="modal inmodal" id="myModal" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                                class="sr-only">Close</span></button>
                    <h4 class="modal-title">添加备注</h4></div>
                <small class="font-bold">
                    <div class="modal-body">
                        <div class="ibox float-e-margins">
                            <div class="ibox-content">

                                <form name="form_product" id="form-validation-1" 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">
                                            <textarea id="expected_comment" name="expected_comment" class="form-control"
                                                      cols="20" rows="10"></textarea>
                                        </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>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    </div>
                </small>
            </div>
            <small class="font-bold">
            </small>
        </div>
        <small class="font-bold">
        </small>
    </div>
    <div class="modal inmodal" id="myModal2" tabindex="-1" role="dialog" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content animated flipInY">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">×</span><span
                                class="sr-only">Close</span></button>
                    <h4 class="modal-title">通过审核</h4></div>
                <small class="font-bold">
                    <div class="modal-body">
                        <div class="ibox float-e-margins">
                            <div class="ibox-content">

                                <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-3">
                                            <input id="expected_time" name="expected_time"
                                                   value="{{Request::get('expected_time') ? : date('Y-m-d',time())}}"
                                                   class="input-sm form-control"/>
                                        </div>

                                    </div>

                                    <div class="form-group">

                                        <label class="control-label col-sm-3">修理费</label>

                                        <div class="col-sm-3">
                                            <input id="price" name="price" class="form-control" required=""
                                                   aria-required="true" placeholder="">
                                        </div>
                                        <div class="col-sm-6" id="order-pic">

                                        </div>

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

                                        <label class="control-label col-sm-3">配件清单</label>

                                        <div class="col-sm-3">
                                            <input name="name[]" class="form-control" placeholder="" value="">
                                        </div>

                                        <label class="control-label col-sm-1">数量</label>

                                        <div class="col-sm-3">
                                            <input name="count[]" class="form-control" placeholder="" value="">
                                        </div>

                                        <button type="button" class="btn btn-outline btn-success" id="add_parts">添加
                                        </button>

                                    </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>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                    </div>
                </small>
            </div>
            <small class="font-bold">
            </small>
        </div>
        <small class="font-bold">
        </small>
    </div>
    {{--时间插件--}}
    <script src="/base/js/time/jquery-ui-1.10.1.min.js"></script>
    <script>
        //        时间选择js
        $(function () {
            $.datepicker.regional['zh-CN'] = {
                clearText: '清除',
                clearStatus: '清除已选日期',
                closeText: '关闭',
                closeStatus: '不改变当前选择',
                prevText: '<上月',
                prevStatus: '显示上月',
                prevBigText: '<<',
                prevBigStatus: '显示上一年',
                nextText: '下月>',
                nextStatus: '显示下月',
                nextBigText: '>>',
                nextBigStatus: '显示下一年',
                currentText: '今天',
                currentStatus: '显示本月',
                monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
                monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
                monthStatus: '选择月份',
                yearStatus: '选择年份',
                weekHeader: '周',
                weekStatus: '年内周次',
                dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
                dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
                dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
                dayStatus: '设置 DD 为一周起始',
                dateStatus: '选择 m月 d日, DD',
                dateFormat: 'yy-mm-dd',
                firstDay: 1,
                initStatus: '请选择日期',
                isRTL: false
            };
            $.datepicker.setDefaults($.datepicker.regional['zh-CN']);

            $("#start").datepicker({
                inline: true,
                showOtherMonths: true
            });
            $("#end").datepicker({
                inline: true,
                showOtherMonths: true
            });
            $("#expected_time").datepicker({
                inline: true,
                showOtherMonths: true
            })

                .datepicker('widget').wrap('<div class=" ll-skin-lugo" />');

        });

        $('#add_parts').click(function () {
            $('#products_parts').after("<div class=\"form-group\">\n" +
                "                                        <label class=\"control-label col-sm-3\"></label>\n" +
                "\n" +
                "                                        <div class=\"col-sm-3\">\n" +
                "                                            <input  name=\"name[]\" class=\"form-control\" required=\"\" aria-required=\"true\"  placeholder=\"\" value=\"1\">\n" +
                "                                        </div>\n" +
                "\n" +
                "                                        <label class=\"control-label col-sm-1\"></label>\n" +
                "                                        <div class=\"col-sm-3\">\n" +
                "                                            <input  name=\"count[]\" class=\"form-control\" required=\"\" aria-required=\"true\"  placeholder=\"\" value=\"1\">\n" +
                "                                        </div>\n" +
                "\n" +
                "\n" +
                "                                    </div>")
        })

        $('.myModal').click(function () {
            var order = $(this).attr('data-id');
            $('#form-validation').attr('action', "/admin/Album/Order/status?id=" + order + "&status=1")
            $.ajax({
                type: "get",
                url: "/admin/Album/Order/getpic",
                data: {id: order},
                dataType: "json",
                success: function (data) {
                    console.log(order)
                    for (i in data) {
                        $('#order-pic').html("<img style='height: 60px' src=" + data[i] + ">")
                    }
                }
            });
        })
        $('.myModal1').click(function () {
            var order = $(this).attr('data-id');
            $('#form-validation-1').attr('action', "/admin/Album/Order/addecomment?id=" + order)
            console.log(order)
        })


    </script>
@endsection

