{{include file="public/header" /}}

<!-- header nav -->
{{include file="public/header_nav" /}}

<!-- conntent start  -->
<div class="am-g inside create">
    <h2>数据库信息</h2>
    <div class="am-alert am-radius" data-am-alert>
        <button type="button" class="am-close">&times;</button>
        <p class="am-text-xs">温馨提示</p>
        <p class="am-text-xs">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;建议采用utf8mb4编码、MySQL版本5.6或5.7</p>
        {{if !empty($charset_type_list)}}
            {{foreach $charset_type_list as $v}}
                <p class="am-text-xs">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{{$v.charset}}编码、MySQL版本需 {{$v.version}} 及以上版本 （{{$v.collate}}）</p>
            {{/foreach}}
        {{/if}}
    </div>
    <form class="am-form am-form-horizontal form-validation" method="post" action="{{:MyUrl('install/index/confirm')}}" request-type="ajax-fun" request-value="FormBackConfirm" timeout="60000">
        <div class="am-form-group">
            <label class="am-u-sm-2 am-form-label">数据库类型</label>
            <div class="am-u-sm-10">
                <input type="text" name="DB_TYPE" placeholder="数据库类型" value="mysql" class="am-radius am-input-sm" readonly data-validation-message="请选择数据库类型" required />
            </div>
        </div>

        <div class="am-form-group am-form-select">
            <label class="am-u-sm-2 am-form-label">数据库编码</label>
            <div class="am-u-sm-10">
                <select class="am-input-sm am-radius chosen-select" name="DB_CHARSET" data-validation-message="请选择数据编码" required>
                    {{if !empty($charset_type_list)}}
                        {{foreach $charset_type_list as $v}}
                            <option value="{{$v.charset}}">{{$v.charset}} - {{$v.collate}} （mysql版本>={{$v.version}}）</option>
                        {{/foreach}}
                    {{/if}}
                </select>
            </div>
        </div>

        <div class="am-form-group">
            <label class="am-u-sm-2 am-form-label">数据库服务器</label>
            <div class="am-u-sm-10">
                <input type="text" name="DB_HOST" placeholder="数据库服务器" value="127.0.0.1" class="am-radius am-input-sm" data-validation-message="请填写数据库服务器地址" required />
            </div>
        </div>

        <div class="am-form-group">
            <label class="am-u-sm-2 am-form-label">数据库端口</label>
            <div class="am-u-sm-10">
                <input type="number" name="DB_PORT" placeholder="数据库端口" value="3306" class="am-radius am-input-sm" data-validation-message="请填写数据库端口" required />
            </div>
        </div>

        <div class="am-form-group">
            <label class="am-u-sm-2 am-form-label">数据库名</label>
            <div class="am-u-sm-10">
                <input type="text" name="DB_NAME" placeholder="数据库名" value="shopxo" class="am-radius am-input-sm" data-validation-message="请填写数据库名" required />
            </div>
        </div>

        <div class="am-form-group">
            <label class="am-u-sm-2 am-form-label">数据库用户名</label>
            <div class="am-u-sm-10">
                <input type="text" name="DB_USER" placeholder="数据库用户名" value="" class="am-radius am-input-sm" data-validation-message="请填写数据库用户名" required />
            </div>
        </div>

        <div class="am-form-group">
            <label class="am-u-sm-2 am-form-label">数据库密码</label>
            <div class="am-u-sm-10">
                <input type="text" name="DB_PWD" placeholder="数据库密码" value="" class="am-radius am-input-sm" data-validation-message="请填写数据库密码" required />
            </div>
        </div>

        <div class="am-form-group">
            <label class="am-u-sm-2 am-form-label">数据表前缀</label>
            <div class="am-u-sm-10">
                <input type="text" name="DB_PREFIX" placeholder="数据表前缀" value="sxo_" class="am-radius am-input-sm" data-validation-message="请填写数据表前缀" required />
            </div>
        </div>

        <div class="agree ongoing-button">
            <a href="{{:MyUrl('install/index/check')}}" class="am-btn am-btn-secondary am-radius am-btn-xs">上一步</a>
            <button type="submit" class="am-btn am-btn-success am-radius am-btn-xs btn-loading-example" data-am-loading="{spinner:'circle-o-notch', loadingText:'安装中...'}">确认</button>
        </div>
    </form>
</div>
<!-- conntent end  -->

{{include file="public/footer" /}}
<script type="text/javascript">
function FormBackConfirm(e)
{
    console.log(e)
    var $button = $('form.form-validation button[type="submit"]');
    if(e.code == 0)
    {
        $.AMUI.progress.start();
        $.ajax({
            url: "{{:MyUrl('install/index/add')}}",
            type: 'POST',
            dataType: "json",
            timeout: 60000,
            data: GetFormVal('form.form-validation', true),
            success: function(res)
            {
                $.AMUI.progress.done();
                if(res.code == 0)
                {
                    Prompt(res.msg, 'success');
                    setTimeout(function()
                    {
                        window.location.href = "{{:MyUrl('install/index/successful')}}";
                    }, 1500);
                } else {
                    Prompt(res.msg);
                    $button.button('reset');
                }
            },
            error: function(xhr, type)
            {
                $button.button('reset');
                $.AMUI.progress.done();
                Prompt(HtmlToString(xhr.responseText) || '异常错误', null, 30);
            }
        });
    } else {
        $button.button('reset');
        Prompt(e.msg)
    }
}
</script>