@extends('admin.master')

@section('top')
  <div class="top-breadcrumb pull-left">
    <h5>订单管理</h5>
  </div>
@endsection

@section('ordersearch')
<div class="nav-tabs-box">
  <ul class="nav nav-tabs" role="tablist">
    @foreach (config('system.status') as $key => $value)
      <li role="presentation" class="@if($key == $status)active @endif">
        <a href="{{ url('admin/order?status='.$key) }}">{{ $value }}</a>
      </li>
    @endforeach
  </ul>
</div>
    
@endsection

@section('content')
  <div class="order-search mb-10">
    {!! Form::model($where, ['method'=>'get', 'class'=>'form-inline']) !!}
    {!! Form::hidden('status', null) !!}
    <div class="form-group pr-10">
      <label class="control-label">用户名：</label>
      {!! Form::text('username', null, ['class'=>'form-control len wd-search', 'id'=>'kw', 'placeholder'=>'请输入用户名']) !!}
    </div>
    <div class="form-group pr-10">
      <label class="control-label">订单号：</label>
      {!! Form::text('orderid', null, ['class'=>'form-control len wd-search', 'id'=>'kw', 'placeholder'=>'请输入订单号']) !!}
    </div>
    <button type="submit" class="btn btn-primary">查询</button>
    {!! Form::close() !!}
  </div>
  {!! Form::open(['route' => 'admin.product.index', 'method' => 'post', 'class'=>'form-ajax']) !!}
  <table class="table table-hover">
    <thead>
    <tr>
      <th width="60" class="text-center">
        <div class="pretty p-default p-smooth">
          <input name="chkAll" type="checkbox" id="chkAll" onclick="checkAll(this, 'id[]')" value="checkbox">
          <div class="state p-success"><label></label></div>
        </div>
      </th>
      <th>用户名</th>
      <th>订单号</th>
      <th>订单信息</th>
      <th>订单状态</th>
      <th>下单时间</th>
      <th>联系人</th>
      <th>联系电话</th>
      <th>收获地址</th>
      <th>付款金额</th>
      <th class="text-center">操作</th>
    </tr>
    </thead>
    <tbody>
    @if(!$data->isEmpty())
      @foreach ($data as $value)
        <tr>
          <td align="center">
            <div class="pretty p-default p-smooth">
              <input name="id[]" class="id" type="checkbox" value="{{ $value['id'] }}" onclick="checkItem(this, 'chkAll')">
              <div class="state p-success"><label></label></div>
            </div>
          </td>
          <td>
            {{ $value->member->username }}
          </td>
          <td>
            {{ $value->order_id }}
          </td>
          <td>
            @foreach ($value->list as $val)
              <p style="line-height: 40px;">
                <a href="{{ url('product/'.$val->product->slug.'.html') }}" target="_blank"><img src="{{ url($val->img) }}" width="30" class="mr-5">{{ $val->title }}</a>
                <span class="pl-10">￥{{ $val->price }} x {{ $val->num }}</span>
              </p>
            @endforeach
          </td>
          <td>
            @if ($value->order_status == 1)
              <span class="changeblue">货到付款</span>
            @else
              @if ($value->status == 0)
                <span class="changegray">未付款</span>
              @else
                <span class="changegreen">已付款</span>
              @endif
            @endif
          </td>
          <td>
            {{ $value->created_at->format('Y-m-d') }}
          </td>
          <td>
            {{ $value->receive_name }}
          </td>
          <td>
            {{ $value->receive_phone }}
          </td>
          <td>
            {{ $value->receive_address }}
          </td>
          <td align="center">
            ￥<span class="text-warning pl-5">{{ $value->total_fee }}</span>
          </td>
          <td>
            <div class="toolbar">
              <a href="{{ route('admin.order.edit', $value->id) }}" class="btn-link">查看</a>
              <span class="text-explode ">|</span>
              <a href="javascript:void(0);" class="btn-link delete-item" data-id="{{ $value->id }}">删除</a>
            </div>
          </td>
        </tr>
      @endforeach
      <tr class="footer">
        <td align="center">
          <div class="pretty p-default p-smooth">
            <input name="chkAll" type="checkbox" id="chkAll" onclick="checkAll(this, 'id[]')" value="checkbox">
            <div class="state p-success"><label></label></div>
          </div>
        </td>
        <td class="text-left" colspan="10">
          <div class="foot-wrap">
            <input name="btn_del" type="button" value="删 除" class="btn btn-default delet-select">
            @if(!empty($data->render()))
              <div class="pull-right">
                <div class="pagination-info">共有{{ $data->total() }}条， 每页显示：{!! $data->perPage() !!}条</div>
                {!! $data->appends($where)->render() !!}
              </div>
            @endif
          </div>
        </td>
      </tr>
    @endif
    </tbody>
  </table>
  @if($data->isEmpty())
    <div class="nodata-wrap">
      <div class="notice-null"><span class="inline-block">暂无数据</span></div>
    </div>
  @endif

  {!! Form::close() !!}
@endsection

@section('notice')
  <!-- Modal -->
  <div class="modal fade" id="dialog" tabindex="-1" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="true"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body clearfix">
          <div class='col-sm-1 text-center'><i class='iconfont icon-zhuyi'></i></div>
          <div class='col-sm-11 breakall'><p>删除后您将无法恢复，请谨慎操作</p><p class='text-muted'>您确认要删除吗？</p></div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary btn-modal-ok">确定</button>
          <button class="btn btn-default btn-modal-cancel btn-modal-close" data-dismiss="modal">取消</button>
        </div>
      </div>
    </div>
  </div>
  <!-- Modal End -->
  <!-- Modal -->
  <div class="modal fade" id="dialog-tip" tabindex="-1" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="true"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body clearfix">
          <div class='col-sm-1 text-center'><i class='fa fa-times-circle text-size-32 text-warning'></i></div>
          <div class='col-sm-11 breakall'><p class="delete-error">删除失败！</p></div>
        </div>
        <div class="modal-footer">
          <button class="btn btn-primary btn-modal-close" data-dismiss="modal">确定</button>
        </div>
      </div>
    </div>
  </div>
  <!-- Modal End -->
  <!-- Modal -->
  <div class="modal fade" id="dialog-common" tabindex="-1" role="dialog">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="true"><span aria-hidden="true">&times;</span></button>
          <h4 class="modal-title">提示</h4>
        </div>
        <div class="modal-body clearfix">
          <div class='col-sm-1 text-center'><i class='iconfont icon-zhuyi'></i></div>
          <div class='col-sm-11 breakall'><p class="common">请选择要删除的内容!</p></div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary btn-modal-common">确定</button>
        </div>
      </div>
    </div>
  </div>
  <!-- Modal End -->
@endsection

@section('foot')
  <script type="text/javascript">
      //批量删除
      $('.delet-select').on('click', function(){
          var ids = [];
          $('.id:checked').each(function(){
              ids.push(this.value);
          });
          ids = ids.join('-');

          if (!ids) {
              $('.common').text('请选择要删除的内容!');
              $('#dialog-common').modal('show');
              return false;
          }
          url = location.pathname + '/' + ids;

          $('#dialog').modal('show');
          return false;
      });

      //批量更新排序

      $('body').on('click', '.btn-modal-common', function(){
          $(this).parents('#dialog-common').modal('hide');
      });

      // 删除
      $('.delete-item').on('click', function(e) {
          var deleteAction = location.pathname;
          var id = $(this).data('id');
          url = deleteAction + '/' + id;

          $('#dialog').modal('show');
          return false;
      });

      $('body').on('click', '.btn-modal-ok', function() {
          $(this).parents('#dialog').modal('hide');
          $.ajax({
              type: "DELETE",
              url: url,
              success: function(data) {
                  if (data.status == 'success') {
                      swal({
                          title: "",
                          text: "信息删除成功！",
                          type: "success",
                          showConfirmButton: false,
                          timer: 1200,
                      });
                      setTimeout("location.reload()", 1200);
                  } else {
                      $('.delete-error').html('删除失败！');
                      $('#dialog-tip').modal('show');
                  }
              }
          });
      });
  </script>
@endsection