<style>
    .login-box {
        margin-top: -10rem;
        padding: 5px;
    }
    .login-card-body {
        padding: 1.5rem 1.8rem 1.6rem;
    }
    .card, .card-body {
        border-radius: .25rem
    }
    .login-btn {
        padding-left: 2rem!important;;
        padding-right: 1.5rem!important;
    }
    .content {
        overflow-x: hidden;
    }
    .form-group .control-label {
        text-align: left;
    }
</style>

<div class="login-page bg-40">
    <div class="login-box">
        <div class="login-logo mb-2">
            订货会
        </div>
        <div class="card">
            <div class="card-body login-card-body shadow-100">
                <p class="login-box-msg mt-1 mb-1"></p>

                <form id="login-form" method="POST" action="{{ route('login') }}">

                    <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                    <fieldset class="form-label-group form-group position-relative has-icon-left">
                        <select
                            id="khdm"
                            type="text"
                            class="form-control select2 {{ $errors->has('kh') ? 'is-invalid' : '' }}"
                            name="khdm"
                            required
                            autofocus
                        >
                            <option value=0>请选择客户</option>
                            @foreach($kus as $ku)
                                <option value={{ $ku->KHDM }}>{{ $ku->KHDM }}-{{ $ku->KHMC }}
                                </option>
                            @endforeach
                        </select>

                        <div class="form-control-position">
{{--                            <i class="fa fa-fw fa-angle-double-down"></i>--}}
                        </div>

                        <div class="help-block with-errors"></div>
                        @if($errors->has('kh'))
                            <span class="invalid-feedback text-danger" role="alert">
                                            @foreach($errors->get('kh') as $message)
                                    <span class="control-label" for="inputError"><i class="feather icon-x-circle"></i> {{$message}}</span><br>
                                @endforeach
                                        </span>
                        @endif
                    </fieldset>
                    <fieldset class="form-label-group form-group position-relative has-icon-left">
                        <input
                            id="password"
                            type="password"
                            class="form-control {{ $errors->has('password') ? 'is-invalid' : '' }}"
                            name="password"
                            placeholder="密码"
                            required
                            autocomplete="current-password"
                        >

                        <div class="form-control-position">
                            <i class="fa fa-key"></i>
                        </div>
                        <label for="phone">密码</label>

                        <div class="help-block with-errors"></div>
                        @if($errors->has('password'))
                            <span class="invalid-feedback text-danger" role="alert">
                                            @foreach($errors->get('password') as $message)
                                    <span class="control-label" for="inputError"><i class="feather icon-x-circle"></i> {{$message}}</span><br>
                                @endforeach
                                            </span>
                        @endif

                    </fieldset>
                    <button type="submit" class="btn btn-primary float-right login-btn">

                        登录
                        &nbsp;
                        <i class="feather icon-arrow-right"></i>
                    </button>
                </form>

            </div>
        </div>
    </div>
</div>
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.1.0-beta.0/css/select2.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.1.0-beta.0/js/select2.min.js"></script>

<script>
    $(document).ready(function($) {
        $('.select2').select2({
            placeholder: "输入客户名称搜索",
            allowClear: true,
            language: "zh-CN",
            width: '100%'
        });
    });
    Dcat.ready(function () {
        $('#login-form').form({
            validate: true, // 启用前端验证
            success: function (response) {
                if (response.status) {
                    window.location.href = response.redirect; // 自定义跳转路径
                } else {
                    Dcat.error(response.message || '提交失败'); // 错误提示
                }
            },
            error: function (response) {
                // console.error('提交异常:', c);
                Dcat.error(response.message || '提交失败'); // 错误提示
            }
        });
    });
</script>
