@extends('Merchant::layouts.app')

@section('title', '核销统计')

@section('css')
    <link rel="stylesheet" href="{{ asset('assets/merchant/css/plugins/datapicker/datepicker3.css') }}"/>
@endsection

@push('script')
    <script type="text/javascript"
            src="{{ asset('assets/merchant/js/plugins/datapicker/bootstrap-datepicker.js') }}"></script>
    <script type="text/javascript">
        $("#time-interval .input-daterange").datepicker({
            autoclose: true, //自动关闭
            beforeShowDay: $.noop,    //在显示日期之前调用的函数
            clearBtn: true,          //显示清除按钮
            forceParse: true,         //是否强制转换不符合格式的字符串
            format: 'yyyy-mm',     //日期格式
            language: 'cn',           //语言
            minViewMode: 1,   // 最小精度选择
            startView: 1,             //开始显示
            WeekHighlighted: true,      // 本周高亮
            endDate: new Date()
        });

        $("button").click(function () {
            var $this = $(this);
            var $form = $this.parents('form');
            $("input[name='action']").val($this.data('action'));
            $form.submit();
        });

    </script>
@endpush

@section('content')
    <div class="ibox">
        <div class="row">
            <div class="col-sm-12 m-b">
                <form action="{{ route('merchant.census')}}" class="form-inline pull-right" method="get"
                      accept-charset="utf-8">
                    <div class="form-group" id="time-interval">
                        <div class="input-daterange input-group">
                            <input type="text" class="input-sm form-control" placeholder="核销月份" readonly name="month"
                                   value="{{ Request::input('month')??now()->format('Y-m') }}"/>
                        </div>
                    </div>

                    <div class="input-group">
                    <span class="input-group-btn">
                        <input type="hidden" name="action" value="search">
                        <button type="button" class="btn btn-sm btn-primary" data-action="search"><i
                                    class="fa fa-check"></i>&nbsp;刷新</button>
                        <button type="button" class="btn btn-sm btn-warning confirm" tip='确认要导出当前条件内容？'
                                data-action="excel"><i class="fa fa-paste"></i>&nbsp;导出</button>
                    </span>
                    </div>
                </form>
            </div>
        </div>
        <div class="ibox-content">
            <div class="table-responsive">
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th>日期</th>
                        @foreach ($rules as $rule)
                            <th>{{ $rule->rule->title }}</th>
                        @endforeach
                        <th></th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach ($coupons as $coupon)
                        <tr>
                            <td> {{ $coupon['day'] }} </td>
                            @foreach ($rules as $rule)
                                <th>{{ $coupon[$rule->code] ??'' }}</th>
                            @endforeach
                            <td>
                                <a href="{{ route('merchant.coupons',['start'=>$coupon['day'],'end'=>$coupon['day']]) }}">查看</a>
                            </td>

                        </tr>
                    @endforeach
                    <tr style="color: #f8ac59">
                        <td> 全部</td>
                        @foreach ($rules as $rule)
                            <th>{{ $all[$rule->code] ??'' }}</th>
                        @endforeach

                    </tr>
                    </tbody>
                </table>
            </div>

        </div>
    </div>
@endsection
