@extends('admin.layout')

@section('content')
    <link href="/css/time/jquery.datetimepicker.css" rel="stylesheet">
    <link href="/css/time/jquery-ui-1.10.1.css" rel="stylesheet">
    <?php
    if (!isset($data)) $data = array();
    if (!$data && session("data")) {
        $data = session("data");
    }
    if (!$data && session('_old_input')) {
        $data = session("_old_input");
    }
    ?>
    <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">
                    @if(role('Coupon/Info/index'))
                        <div class="row">
                            <div class="col-sm-3 pull-right">
                                <a href="{{ U('Coupon/Info/index')}}" class="btn btn-sm btn-primary pull-right">返回列表</a>
                            </div>
                        </div>
                    @endif

                    <div class="row">
                        <div class="col-lg-10">
                            <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-9">
                                        <input id="data_name" name="data[name]" class="form-control"
                                               value="{{ $data['name'] or ''}}" required="" aria-required="true"
                                               placeholder="">
                                    </div>

                                </div>


                                <div class="form-group">

                                    <label class="control-label col-sm-3">优惠券类型：</label>

                                    <div class="col-sm-9">
                                        <select id="data_type" class="form-control" name="data[type]" required>

                                            <option value="0"
                                                    @if(isset($data['type']) && $data['type'] == 0) selected @endif>
                                                固定金额
                                            </option>
                                            <option value="1"
                                                    @if(isset($data['type']) && $data['type'] == 1) selected @endif>
                                                折扣
                                            </option>

                                        </select>
                                    </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"  id="data_discount">

                                    <label class="control-label col-sm-3">折扣</label>

                                    <div class="col-sm-9">
                                        <input  name="data[discount]" class="form-control"
                                               value="{{ $data['discount'] or ''}}"
                                               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[discount_price]" class="form-control"
                                               value="{{ $data['discount_price'] or ''}}" placeholder="">
                                    </div>

                                </div>

                                <div class="form-group">

                                    <label class="control-label col-sm-3">可用产品</label>
                                    <div class="col-md-6 col-sm-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 id="data_count" name="data[count]" class="form-control"
                                               value="{{ $data['count'] or ''}}" required="" aria-required="true"
                                               placeholder="">
                                    </div>

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

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

                                    <div class="col-sm-3">
                                        <input id="end_time" name="data[end_time]" class="form-control"
                                               value="{{ $data['end_time'] or ''}}" required="" aria-required="true"
                                               placeholder="">
                                    </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>
                        <!-- /.col-lg-10 -->
                    </div>
                    <!-- /.row -->
                </div>
            </div>
        </div>
    </div>

@endsection

@section('footer')
    {{--时间插件--}}
    <script src="/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']);

            $("#end_time").datepicker({
                inline: true,
                showOtherMonths: true
            })
                .datepicker('widget').wrap('<div class=" ll-skin-lugo" />');

        });

    </script>
    <script type="text/javascript">
        $(function () {
            $('#product-select').multiSelect();
            var product_ids = "{{ $product_ids }}";
            product_ids = product_ids.split(',');
            $('#product-select').multiSelect('select', product_ids);
        });


        if($('#data_type').val() ==1 ){
            $('#data_discount').show();
            $('#data_discount_price').hide()
        }else {
            $('#data_discount').hide();
            $('#data_discount_price').show()
        }

        $('#data_type').change(function () {
            if($(this).val() ==1 ){
                $('#data_discount').show();
                $('#data_discount_price').hide()
            }else {
                $('#data_discount').hide();
                $('#data_discount_price').show()
            }
        })

    </script>
@endsection