@model string;
<html>
@{
    Layout = null;
}
<head>
    <link rel="stylesheet" href="~/WebConsole/css/licensing.css" />
    <link rel="stylesheet" href="~/WebConsole/css/modalBox.css">
</head>

<body class="container-main">
    <div class="container-item">
        <h1 class="h1">
            请输入验证码
        </h1>
        <div>
            <form class="login">
                <div class="container-form">
                    <input id="input_box" type="text" name="authCode" value="" placeholder="验证码" />
                    <input id="ok_button" class="submit"
                           type="button"
                           onclick="check(this.form)"
                           value="确 定" />
                </div>
            </form>
            <div class="serial-number">SN: @Model</div>
        </div>
    </div>

    <div id="code_error" class="modal">
        <p>验证码错误,请联系厂家获取!</p>
        <a href="#" rel="modal:close">关闭</a>
    </div>

    <div id="reboot_msg" class="modal">
        <p>验证通过,请重启设备!</p>
        <a href="#" rel="modal:close">关闭</a>
    </div>
    <script src="~/js/jquery-3.4.1.min.js"></script>
    <script>
        //will set ApiName as key,ProviderConfigName as value
        var currenthref = window.location.href;
        var currentPath = window.location.pathname;
        var currentHP = currenthref.slice(0, currenthref.indexOf(currentPath) + 1);
        var apis = new Map();
        $(document).ready(function () {
            var requestData = ["webapi", ["LicensingApp"]];
            var serviceUrl = currentHP+"u/?apitype=service&an=ShowMeApi&pn=ProcessorsDispatcher&en=Edge.Core.Processor.Dispatcher.DefaultDispatcher";
            $.ajax({
                url: serviceUrl,
                datatype: "application/json",
                type: 'post',
                contentType: "application/json;charset=utf-8;",
                data: JSON.stringify(requestData),
                beforeSend: function () {
                },
                success: function (data) {
                    console.log(data);
                    data.forEach(function (d) {
                        if (apis.has(d.ApiName)) {
                            apis.delete(d.ApiName);
                        }
                        apis.set(d.ApiName, d.Path);
                    });
                },
                error: function (err) {
                    console.log(err);
                }
            });
        });
        function saveLicense(license) {
            var path = apis.has("VerifyLicense") ? apis.get("VerifyLicense") : "";
            if (path === "") return;
            //var requestUrl = "http://localhost:8384/u/?apitype=service&an=VerifyLicense&pn=" + processorName
            //    + "&en=Application.LicensingApp.App";
            var requestUrl = currentHP.slice(0, currentHP.length-1) + path;
            $.ajax({
                url: requestUrl,
                datatype: "application/json",
                type: 'post',
                contentType: "application/json;charset=utf-8;",
                data: JSON.stringify(license),
                beforeSend: function () {
                },
                success: function (data) {
                    if (data == true) {
                        //window.location.href = '@Url.Action("SaveLicense", "Home")?license=' + license;
                        $("#reboot_msg").modal({
                            fadeDuration: 100
                        });
                        disableInputForm();
                    }
                    else {
                        $("#code_error").modal({
                            fadeDuration: 100
                        });
                    }
                },
                error: function (err) {
                    console.log(err);
                }
            });
        }

        function check(form) {
            if (form.authCode.value != "") {
                saveLicense(form.authCode.value);
            } else {
                $("#code_error").modal({
                    fadeDuration: 100
                });
            }
        }

        function disableInputForm() {
            document.getElementById("input_box").disabled  = true;
            document.getElementById("ok_button").disabled  = true;
        }
    </script>
    <script src="~/WebConsole/js/jQuery3.js"></script>
    <script src="~/WebConsole/js/modalBox.js"></script>
</body>
</html>