@extends('admin.master')

@section('content')
    <div class="row">
        <div class="col-lg-12">
            <!-- 指定新增的端點 -->
            <form id="EditForm" class="form-horizontal" method="post"
                  action="{{ url('/backend/dataManagement/activityManagement/store') }}">
                {{ csrf_field() }}
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <!-- 更改文案 -->
                        <h4 class="panel-title">{{ ($operdata == "") ? "Create " : "Modify " }}回合</h4>
                    </div>
                    <div class="panel-body">
                        <div>
                            <!-- 表格本體 -->
                            <table class="table" cellspacing="0" id="DetailsView1" style="border-collapse:collapse;">
                                <tbody>
                                <!-- 欄位：自增量 -->
                                @if ($operdata == "")
                                    <input type="hidden" name="mode" value="insert"/>
                                    <!-- Insert Mode -->
                                @else
                                    <!-- Edit Mode -->
                                    <tr>
                                        <td class="col-lg-2">自增量</td>
                                        <td>
                                            <input name="id" type="hidden" value="{{ $operdata['id'] }}" id="id"/>
                                            {{ $operdata['id'] }}
                                        </td>
                                    </tr>
                                @endif
                                <!-- 欄位：活動名稱 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">活動名稱</td>
                                    <td>
                                        <div class="col-lg-3 nopadding">
                                            @if ($operdata == "")
                                                <input name="activityName" type="text" value="" maxlength="20"
                                                       id="activityName"
                                                       class="form-control">
                                            @else
                                                <input name="activityName" type="text"
                                                       value="{{ $operdata['activityName'] }}"
                                                       maxlength="20" id="activityName" class="form-control">
                                            @endif
                                            <label class="error" for="activityName"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：登記發票時間起日 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">登記發票時間起日</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="reqTimeBegin" type="text"
                                                       value="" maxlength="10" id="reqTimeBegin">
                                            @else
                                                <input class="form-control input-sm" name="reqTimeBegin" type="text"
                                                       value="{{ $operdata['reqTimeBegin'] }}" id="reqTimeBegin">
                                            @endif
                                            <label class="error" for="reqTimeBegin"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：登記發票時間迄日 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">登記發票時間迄日</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="reqTimeFinal" type="text"
                                                       value="" maxlength="10" id="reqTimeFinal">
                                            @else
                                                <input class="form-control input-sm" name="reqTimeFinal" type="text"
                                                       value="{{ $operdata['reqTimeFinal'] }}" id="reqTimeFinal">
                                            @endif
                                            <label class="error" for="reqTimeFinal"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：開獎時間 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">開獎時間</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="drawTime" type="text"
                                                       value="" maxlength="10" id="drawTime">
                                            @else
                                                <input class="form-control input-sm" name="drawTime" type="text"
                                                       value="{{ $operdata['drawTime'] }}" id="drawTime">
                                            @endif
                                            <label class="error" for="drawTime"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：獎號 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">獎號</td>
                                    <td>
                                        <div class="col-lg-3 nopadding">
                                            @if ($operdata == "")
                                                <input name="drawNumbers" type="text" value="" maxlength="30"
                                                       id="drawNumbers"
                                                       class="form-control">
                                            @else
                                                <input name="drawNumbers" type="text"
                                                       value="{{ $operdata['drawNumbers'] }}"
                                                       maxlength="30" id="drawNumbers" class="form-control">
                                            @endif
                                            <label class="error" for="drawNumbers"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：登記領獎時間起日 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">登記領獎時間起日</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="redeemTimeBegin" type="text"
                                                       value="" maxlength="10" id="redeemTimeBegin">
                                            @else
                                                <input class="form-control input-sm" name="redeemTimeBegin" type="text"
                                                       value="{{ $operdata['redeemTimeBegin'] }}" id="redeemTimeBegin">
                                            @endif
                                            <label class="error" for="redeemTimeBegin"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：登記領獎時間迄日 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">登記領獎時間迄日</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="redeemTimeFinal" type="text"
                                                       value="" maxlength="10" id="redeemTimeFinal">
                                            @else
                                                <input class="form-control input-sm" name="redeemTimeFinal" type="text"
                                                       value="{{ $operdata['redeemTimeFinal'] }}" id="redeemTimeFinal">
                                            @endif
                                            <label class="error" for="redeemTimeFinal"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：資料驗證時間起日 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">資料驗證時間起日</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="checkTimeBegin" type="text"
                                                       value="" maxlength="10" id="checkTimeBegin">
                                            @else
                                                <input class="form-control input-sm" name="checkTimeBegin" type="text"
                                                       value="{{ $operdata['checkTimeBegin'] }}" id="checkTimeBegin">
                                            @endif
                                            <label class="error" for="checkTimeBegin"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：資料驗證時間迄日 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">資料驗證時間迄日</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="checkTimeFinal" type="text"
                                                       value="" maxlength="10" id="checkTimeFinal">
                                            @else
                                                <input class="form-control input-sm" name="checkTimeFinal" type="text"
                                                       value="{{ $operdata['checkTimeFinal'] }}" id="checkTimeFinal">
                                            @endif
                                            <label class="error" for="checkTimeFinal"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：獎金發放時間起日 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">獎金發放時間起日</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="getTimeBegin" type="text"
                                                       value="" maxlength="10" id="getTimeBegin">
                                            @else
                                                <input class="form-control input-sm" name="getTimeBegin" type="text"
                                                       value="{{ $operdata['getTimeBegin'] }}" id="getTimeBegin">
                                            @endif
                                            <label class="error" for="getTimeBegin"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：獎金發放時間迄日 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">獎金發放時間迄日</td>
                                    <td>
                                        <div class="col-lg-1 nopadding">
                                            @if ($operdata == "")
                                                <input class="form-control input-sm" name="getTimeFinal" type="text"
                                                       value="" maxlength="10" id="getTimeFinal">
                                            @else
                                                <input class="form-control input-sm" name="getTimeFinal" type="text"
                                                       value="{{ $operdata['getTimeFinal'] }}" id="getTimeFinal">
                                            @endif
                                            <label class="error" for="getTimeFinal"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：建立日期 -->
                                <!-- ALL Mode -->
                                @if ($operdata == "")
                                @else
                                    <tr>
                                        <td class="header-require col-lg-2">建立日期</td>
                                        <td>
                                            <div class="col-lg-3 nopadding">
                                                {{ $operdata['cdate'] }}
                                            </div>
                                        </td>
                                    </tr>
                                @endif
                                <!-- 欄位：最後修改日期 -->
                                <!-- ALL Mode -->
                                @if ($operdata == "")
                                @else
                                    <tr>
                                        <td class="header-require col-lg-2">最後修改日期</td>
                                        <td>
                                            <div class="col-lg-3 nopadding">
                                                {{ $operdata['mdate'] }}
                                            </div>
                                        </td>
                                    </tr>
                                @endif
                                <!-- 欄位：最後修改人 -->
                                <!-- ALL Mode -->
                                @if ($operdata == "")
                                @else
                                    <tr>
                                        <td class="header-require col-lg-2">最後修改人</td>
                                        <td>
                                            <div class="col-lg-3 nopadding">
                                                {{ $operdata['oid'] }}
                                            </div>
                                        </td>
                                    </tr>
                                @endif
                                <!-- 下控制按鈕 -->
                                <tr>
                                    <td>&nbsp;</td>
                                    <td>
                                        <div style="text-align: right">
                                        @if ($operdata == "")
                                            <!-- Insert Mode -->
                                                <input type="submit" name="btnUpdate_foot" value="Create"
                                                       id="btnUpdate_foot" class="btn btn-primary btn-xs"
                                                       onclick="submitForm();">
                                        @else
                                            <!-- Edit Mode -->
                                                <input type="submit" name="btnUpdate_foot" value="Modify"
                                                       id="btnUpdate_foot" class="btn btn-primary btn-xs"
                                                       onclick="submitForm();">
                                            @endif
                                            <input type="button" name="btnBackTo2_foot" value="Back"
                                                   id="btnBackTo2_foot" class="btn btn-default btn-xs">
                                        </div>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- panel-body -->
                </div>
            </form>
        </div>
    </div>
@endsection

@section('extjs')
    <script>
        $(document).ready(function () {
            $("#btnBackTo2").click(function () {
                // 上方的返回列表按鈕觸發
                location.href = '{{ url('backend/dataManagement/activityManagement') }}';
            });
            $("#btnBackTo2_foot").click(function () {
                // 下方的返回列表按鈕觸發
                location.href = '{{ url('backend/dataManagement/activityManagement') }}';
            });
            // 初始化需要偵錯的表格
            $('#EditForm').validate();
            // 正規表達驗證初始化
            $.validator.addMethod(
                "regex",
                function (value, element, regexp) {
                    var re = new RegExp(regexp);
                    return this.optional(element) || re.test(value);
                }
            );
            // 各欄位
            $('#activityName').rules("add", {
                required: true,
                minlength: 1,
                maxlength: 20,
                messages: {
                    required: "活動名稱 length must between 1-20",
                    minlength: "活動名稱 length must between 1-20",
                    maxlength: "活動名稱 length must between 1-20"
                }
            });
            $('#reqTimeBegin').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有登記發票時間起日",
                    minlength: "必須要有登記發票時間起日",
                    maxlength: "必須要有登記發票時間起日"
                }
            });
            $('#reqTimeFinal').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有登記發票時間迄日",
                    minlength: "必須要有登記發票時間迄日",
                    maxlength: "必須要有登記發票時間迄日"
                }
            });
            $('#drawTime').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有開獎時間",
                    minlength: "必須要有開獎時間",
                    maxlength: "必須要有開獎時間"
                }
            });
            $('#drawNumbers').rules("add", {
                required: false,
                regex: "^[0-9]{3}(,[0-9]{3}){0,3}$",
                messages: {
                    regex: "獎號格式為3碼數字用逗號區隔，最多4組獎號"
                }
            });
            $('#redeemTimeBegin').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有登記領獎時間起日",
                    minlength: "必須要有登記領獎時間起日",
                    maxlength: "必須要有登記領獎時間起日"
                }
            });
            $('#redeemTimeFinal').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有登記領獎時間迄日",
                    minlength: "必須要有登記領獎時間迄日",
                    maxlength: "必須要有登記領獎時間迄日"
                }
            });
            $('#checkTimeBegin').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有資料驗證時間起日",
                    minlength: "必須要有資料驗證時間起日",
                    maxlength: "必須要有資料驗證時間起日"
                }
            });
            $('#checkTimeFinal').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有資料驗證時間迄日",
                    minlength: "必須要有資料驗證時間迄日",
                    maxlength: "必須要有資料驗證時間迄日"
                }
            });
            $('#getTimeBegin').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有獎金發放時間起日",
                    minlength: "必須要有獎金發放時間起日",
                    maxlength: "必須要有獎金發放時間起日"
                }
            });
            $('#getTimeFinal').rules("add", {
                required: true,
                minlength: 10,
                maxlength: 10,
                messages: {
                    required: "必須要有獎金發放時間迄日",
                    minlength: "必須要有獎金發放時間迄日",
                    maxlength: "必須要有獎金發放時間迄日"
                }
            });
        });

        //提交與取消按鈕
        function submitForm() {
            if (!!($("#EditForm").valid()) === false) {
                return false;
            } else {
                $(document).ready(function () {
                    $.blockUI({
                        css: {
                            border: 'none',
                            padding: '15px',
                            backgactivityColor: '#000',
                            '-webkit-border-radius': '10px',
                            '-moz-border-radius': '10px',
                            opacity: .5,
                            color: '#FFF'
                        }
                    });
                });
            }
        }

        function cancelValidate() {
            $("#EditForm").validate().cancelSubmit = true;
        }

        // 日期選擇器
        $('#reqTimeBegin').datepicker({
            dateFormat: 'yy-mm-dd'
        });
        $('#reqTimeFinal').datepicker({
            dateFormat: 'yy-mm-dd'
        });
        $('#drawTime').datepicker({
            dateFormat: 'yy-mm-dd'
        });
        $('#redeemTimeBegin').datepicker({
            dateFormat: 'yy-mm-dd'
        });
        $('#redeemTimeFinal').datepicker({
            dateFormat: 'yy-mm-dd'
        });
        $('#checkTimeBegin').datepicker({
            dateFormat: 'yy-mm-dd'
        });
        $('#checkTimeFinal').datepicker({
            dateFormat: 'yy-mm-dd'
        });
        $('#getTimeBegin').datepicker({
            dateFormat: 'yy-mm-dd'
        });
        $('#getTimeFinal').datepicker({
            dateFormat: 'yy-mm-dd'
        });

    </script>
@endsection
