@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/tgoodManagement/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

                                <!-- 欄位：LINE POINT -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">LINE POINT</td>
                                    <td>
                                        <div class="col-lg-3 nopadding">
                                            @if ($operdata == "")
                                                <input name="lp" type="text" value="" maxlength="2" id="lp"
                                                       class="form-control">
                                            @else
                                                <input name="lp" type="text" value="{{ $operdata['lp'] }}"
                                                       maxlength="2" id="lp" class="form-control">
                                            @endif
                                            <label class="error" for="lp"></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="ratio" type="text" value="" maxlength="4" id="ratio"
                                                       class="form-control">
                                            @else
                                                <input name="ratio" type="text" value="{{ $operdata['ratio'] }}"
                                                       maxlength="4" id="ratio" class="form-control">
                                            @endif
                                            <label class="error" for="ratio"></label>
                                        </div>
                                    </td>
                                </tr>
                                <!-- 欄位：有效否 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">有效否</td>
                                    <td>
                                        @if ($operdata == "")
                                            <input id="active" type="checkbox" name="active" checked='checked'/>
                                        @else
                                            <input id="active" type="checkbox"
                                                   name="active" {{ ($operdata['active'] == \App\Http\Services\ConstDef\GeneralConst::ACTIVE_YES)?"checked='checked'":"" }} />
                                        @endif
                                    </td>
                                </tr>
                                <!-- 欄位：共可發數量 -->
                                <!-- ALL Mode -->
                                <tr>
                                    <td class="header-require col-lg-2">共可發數量</td>
                                    <td>
                                        <div class="col-lg-3 nopadding">
                                            @if ($operdata == "")
                                                <input name="totalQty" type="text" value="" maxlength="5" id="totalQty"
                                                       class="form-control">
                                            @else
                                                <input name="totalQty" type="text" value="{{ $operdata['totalQty'] }}"
                                                       maxlength="5" id="totalQty" class="form-control">
                                            @endif
                                            <label class="error" for="totalQty"></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="issuedQty" type="text" value="0" maxlength="5" id="issuedQty"
                                                       class="form-control" readonly>
                                            @else
                                                <input name="issuedQty" type="text" value="{{ $operdata['issuedQty'] }}"
                                                       maxlength="5" id="issuedQty" class="form-control" readonly>
                                            @endif
                                            <label class="error" for="issuedQty"></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/tgoodManagement') }}';
            });
            $("#btnBackTo2_foot").click(function () {
                // 下方的返回列表按鈕觸發
                location.href = '{{ url('backend/dataManagement/tgoodManagement') }}';
            });
            // 初始化需要偵錯的表格
            $('#EditForm').validate();
            // 正規表達驗證初始化
            $.validator.addMethod(
                "regex",
                function (value, element, regexp) {
                    var re = new RegExp(regexp);
                    return this.optional(element) || re.test(value);
                }
            );
            // 各欄位
            $('#lp').rules("add", {
                required: true,
                number: true,
                minlength: 1,
                maxlength: 2,
                min: 0,
                max: 10,
                messages: {
                    required: "LINE POINT length must between 1-2",
                    number: "LINE POINT must number",
                    minlength: "LINE POINT length must between 1-2",
                    maxlength: "LINE POINT length must between 1-2",
                    min: "LINE POINT must between 0-10",
                    max: "LINE POINT must between 0-10"
                }
            });
            $('#ratio').rules("add", {
                required: true,
                number: true,
                minlength: 1,
                maxlength: 4,
                messages: {
                    required: "機率 length must between 1-4",
                    number: "機率 must number",
                    minlength: "機率 length must between 1-4",
                    maxlength: "機率 length must between 1-4"
                }
            });
            $('#totalQty').rules("add", {
                required: true,
                number: true,
                minlength: 1,
                maxlength: 5,
                messages: {
                    required: "共可發數量 length must between 1-5",
                    number: "共可發數量 must number",
                    minlength: "共可發數量 length must between 1-5",
                    maxlength: "共可發數量 length must between 1-5"
                }
            });
        });

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

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

    </script>
@endsection
