@extends('admin.layout')

@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="row">
                        <form method="GET" action="" accept-charset="UTF-8">

                            <div class="col-sm-4">
                                <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-primary">搜索</button>
								</span>
                                </div>
                            </div>
                        </form>
                        @if(role('Card/Info/create'))
                            <div class="col-sm-1 pull-right">
                                <button class="btn btn-sm btn-info" data-toggle="modal" data-target="#myModal2">生成
                                </button>
                            </div>
                        @endif
                    </div>

                    <table class="table table-striped table-bordered table-hover dataTables-example dataTable">
                        <thead>
                        <tr>
                            <th class="sorting" data-sort="card_no"> 优惠卡编号</th>
                            <th class="sorting" data-sort="qrcode"> 二维码</th>
                            <th class="sorting" data-sort="price"> 金额</th>
                            <th class="sorting" data-sort="min_price">最低使用价格</th>
                            <th class="sorting" data-sort="end_time">有效期</th>
                            <th class="sorting" data-sort="status"> 状态</th>
                            <th class="sorting" data-sort="remark"> 备注</th>
                            <th class="sorting" data-sort="created_at"> 创建时间</th>
                            <th width="22%">相关操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        @if(isset($list))
                            @foreach($list as $key => $item)
                                <tr>
                                    <td>{{ $item->card_no }}</td>
                                    <td><img src="{{$item->qrcode}}" style="height: 80px" alt=""></td>
                                    <td>{{ $item->price }}</td>
                                    <td>{{ $item->min_price }}</td>
                                    <td>{{ $item->end_time }}</td>
                                    <td>{{ $item->status() }}</td>
                                    <td>{{ $item->remark }}</td>
                                    <td>{{ $item->created_at }}</td>
                                    <td>
                                        <div class="btn-group">




                                                @if(role('Card/Info/update') && $item->status <2 )
                                                    <button onclick="window.location.href='{{ U('Card/Info/update',['id'=>$item->id])}}'"
                                                            class="btn btn-warning">核销
                                                    </button>
                                                @endif

                                        </div>
                                        @if(role('Card/Info/view'))
                                            <button onclick="layer.open({type: 2,area: ['80%', '90%'],content: '{{ U('Card/Info/view',['id'=>$item->id])}}'});"
                                                    class="btn btn-primary ">查看
                                            </button>
                                        @endif
                                    </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 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="{{ U('Card/Info/store') }}"
                                          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_count" name="count" class="form-control"
                                                       value="" required=""
                                                       aria-required="true"
                                                       placeholder="">
                                            </div>

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

                                            <label class="control-label col-sm-3">优惠金额</label>

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

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

                                            <label class="control-label col-sm-3">最低使用价格</label>

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

                                        </div>

                                        <div class="form-group">

                                            <label class="control-label col-sm-3">可用产品</label>
                                            <div class="col-md-6">
                                                <select name="product_id[]" multiple="multiple" id="product-select"
                                                        class="form-control">
                                                    @foreach($product as $item)
                                                        <option value="{{$item->id}}">
                                                            {{$item->name}}
                                                        </option>
                                                    @endforeach
                                                </select>
                                            </div>

                                        </div>

                                        <div class="form-group">

                                            <label class="control-label col-sm-3">有限期</label>

                                            <div class="col-sm-9">

                                                <input class="form-control layer-date" id="data_time"
                                                       name="data[end_time]" placeholder="YYYY-MM-DD hh:mm:ss"
                                                       onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})"
                                                       value="{{ $data['time'] or ''}}">
                                            </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>
@endsection
@section('footer')
    <script type="text/javascript">
        $(function () {
            $('#product-select').multiSelect();
        });

    </script>
@endsection