@extends('admin.layout')
<style type="text/css">
    .search-link {
        margin-top: 7px;
        font-size: 1.2em;
    }
</style>
@section('header')

@endsection

@section('content')
<div id="sg-main-container-sg">
    <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>{{ $model_name . '列表' }}</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>
                                <div class="col-sm-2 form-group">
                                    <select name="pay_status" class="form-control">
                                        <option value="0">全部</option>
                                        @foreach($model->getPayStatuses() as $value)
                                            <option value="{{ $value['key'] }}" {{ request('pay_status') == $value['key'] ? 'selected' : '' }}>{{ $value['value'] }}</option>
                                        @endforeach
                                    </select>
                                </div>
                                <div class="col-sm-2 form-group">
                                    <input type="text" name="keyword" class="form-control" value="{{ request('keyword') }}" placeholder="输入关键词">
                                </div>
                                <div class="col-sm-2 form-group">
                                    <input type="text" name="start_time" class="datepicker form-control" value="{{ request('start_time') }}" placeholder="开始时间" autocomplete="off">
                                </div>
                                <div class="col-sm-2 form-group">
                                    <input type="text" name="end_time" class="datepicker form-control" value="{{ request('end_time') }}" placeholder="截止时间" autocomplete="off">
                                </div>
                                <div class="col-sm-1 search-link">
                                    <a href="{{ $pre_uri . 'index?start_time=' . $seven_days_ago }}">近7天</a>
                                </div>
                                <div class="col-sm-1 search-link">
                                    <a href="{{ $pre_uri . 'index?start_time=' . $one_month_ago }}">近30天</a>
                                </div>
                                <div class="col-sm-2 form-group">
                                    <button class="btn btn-sm btn-primary" type="submit">搜素</button>
                                </div>
                            </form>
                        </div>
                        <table class="table table-striped table-bordered table-hover dataTables-example dataTable" id="sg-main-table">
                            <thead>
                                <tr>
                                    <th>购买信息</th>
                                    <th>金额</th>
                                    <th>订单状态</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                @if($list->count() <= 0)
                                    <tr>
                                        <td colspan="4" style="text-align: center;">暂无{{ $model_name }}</td>
                                    </tr>
                                @else
                                    @foreach($list as $item)
                                        <tr>
                                            <td colspan="4" style="text-align: left">
                                                {{ $item->created_at . ' 订单号：' . $item->out_trade_no }}
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>{{ $item->getPayPosition() }}</td>
                                            <td>{{ $item->getPayMoney() }}</td>
                                            <td>
                                                <div>付款状态：{!! $item->getPayStatusLabel() !!}</div>
                                                <div>支付方式：{!! $item->getPayMethodLabel() !!}</div>
                                            </td>
                                            <td>
                                                <div class="btn-group">
                                                    <a class="btn btn-sm btn-primary btn-detail" href="{{ $pre_uri . 'show?id=' . $item->id }}">详情</a>
                                                    <div class="btn btn-sm btn-info btn-remark" data-id="{{ $item->id }}">备注</div>
                                                    <div class="btn btn-sm btn-danger btn-delete" data-id="{{ $item->id }}">删除</div>
                                                </div>
                                            </td>
                                        </tr>
                                    @endforeach
                                @endif
                            </tbody>
                        </table>
                        <div class="row">
                            <div class="col-sm-12">{{ $list->links() }}</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="delete-modal" tabindex="-1" role="dialog" aria-labelledby="delete-label" aria-hidden="true">
    <div class="modal-dialog">
        <form id="delete-form" method="POST" action="{{ $pre_uri . 'delete' }}">
            {{ csrf_field() }}

            <input type="hidden" name="id" id="delete-input-id">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="delete-label">确定要删除吗？</h4>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button type="submit" class="btn btn-danger">删除</button>
                </div>
            </div>
        </form>
    </div>
</div>
@endsection

@section('footer')
<script type="text/javascript">
$(function () {
    $('#sg-main-table').on('click', '.btn-delete', function () {
        $('#delete-input-id').val($(this).attr('data-id'));
        $('#delete-modal').modal('show');
    }).on('click', '.btn-remark', function () {
        var id = $(this).attr('data-id');
        layer.open({
            type: 2,
            title: '更改备注',
            shadeClose: true,
            shade: 0.8,
            area: ['80%', '90%'],
            content: '{{ $pre_uri . "showRemarkForm?id=" }}' + id,
            btn: ['确定'],
            yes: function(index) {
                layer.close(index);
            }
        });
    });
})
</script>
@endsection