TTaskSimulation.js 5.12 KB
layui.config({
    base: "/js/"
}).use(['form', 'I18nPage', 'element', 'vue', 'layer', 'jquery', 'hhweb'], function () {
    var form = layui.form,
        layer = layui.layer,
        element = layui.element,
        $ = layui.jquery,
        hhweb = layui.hhweb,
        I18nPage = layui.I18nPage;

    var AreaName = 'task';
    var TableName = 'TTaskSimulation';

    var Lang = I18nPage.GetLang();
    var MessageContainer = {};
    I18nPage.GetI18nMessage({
        Type: "PM",
        Code: "TTaskSimulation",
        Container: MessageContainer,
    });

    I18nPage.GetI18nText({
        Type: "LP",
        Code: "TTaskSimulation",
    });

    if (Lang == "cn") {
        $($(':radio[name="action"]')[0]).attr("title","前进");
        $($(':radio[name="action"]')[1]).attr("title","后退");
        $($(':radio[name="action"]')[2]).attr("title", "左转");
        $($(':radio[name="action"]')[3]).attr("title", "右转");
        $($(':radio[name="action"]')[4]).attr("title", "上升");
        $($(':radio[name="action"]')[5]).attr("title", "下降");
        $($(':radio[name="action"]')[6]).attr("title", "转盘左转");
        $($(':radio[name="action"]')[7]).attr("title", "转盘右转");
    }
    else {
        $($(':radio[name="action"]')[0]).attr("title","Forward");
        $($(':radio[name="action"]')[1]).attr("title","Back off");
        $($(':radio[name="action"]')[2]).attr("title", "Turn Left");
        $($(':radio[name="action"]')[3]).attr("title", "Turn Right");
        $($(':radio[name="action"]')[4]).attr("title", "Rise");
        $($(':radio[name="action"]')[5]).attr("title", "Decline");
        $($(':radio[name="action"]')[6]).attr("title", "Turntable Left");
        $($(':radio[name="action"]')[7]).attr("title", "Turntable Right");
    }
    form.render()

    var link = false;
    $("#LinkAgv").on('click', function () {
        var agvNo = $("#agvNo").val();
        if (agvNo == undefined || agvNo == "") {
            layer.alert(MessageContainer["AgvNoNotInput"], { icon: 5, shadeClose: true, title: MessageContainer["ErrorInfo"] });
            return;
        }
        var index = layer.load();
        $.ajax({
            url: "/" + AreaName + "/" + TableName + "/LinkAgv",
            type: "post",
            data: { agvNo: agvNo, link: !link },
            dataType: "json",
            success: function (result) {
                layer.close(index);
                Log("Agv:【" + agvNo + "】,Link:【" + link + "】, Message: 【" + result.Message + "】");
                if (result.Code == 200 && result.Status) {
                    link = !link;
                    if (link) {
                        $("[name='LP_LinkAgv']").html(MessageContainer["CloseLink"]);
                        $("#DivAction").show();
                    }
                    else {
                        $("[name='LP_LinkAgv']").html(MessageContainer["Connect"]);
                        $("#DivAction").hide();
                    }
                }
                else {
                    layer.alert(result.Message, { icon: 5, shadeClose: true, title: MessageContainer["ErrorInfo"] });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.close(index);
                layer.alert(errorThrown, { icon: 2, shadeClose: true, title: MessageContainer["ErrorInfo"] });
            }
        });
    });

    $("#btnSend").mousedown(function () {
        SendTask();
    })

    $("#btnSend").mouseup(function () {
        StopTask();
    })

    $("#btnClear").on("click", function () {
        $("#Msg").val("");
    })

    function Log(msg) {
        $("#Msg").val(msg + "\r\n" + $("#Msg").val());
    }

    function SendTask() {
        var agvNo = $("#agvNo").val();
        
        var action = $(':radio[name="action"]:checked').val();
        console.info(action);
        $.ajax({
            url: "/" + AreaName + "/" + TableName + "/ControlAgv",
            type: "post",
            data: { agvNo: agvNo, action: action },
            dataType: "json",
            success: function (result) {
                Log("Agv:【" + agvNo + "】,Task Send:【" + $(':radio[name="action"]:checked')[0].title + "】, Message: 【" + result.Message + "】");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.close(index);
                layer.alert(errorThrown, { icon: 2, shadeClose: true, title: MessageContainer["ErrorInfo"] });
            }
        });
    }

    function StopTask() {
        var agvNo = $("#agvNo").val();
        $.ajax({
            url: "/" + AreaName + "/" + TableName + "/ControlAgv",
            type: "post",
            data: { agvNo: agvNo, action: 0 },
            dataType: "json",
            success: function (result) {
                Log("Agv:【" + agvNo + "】,Task Send:【Stop】, Message: 【" + result.Message + "】");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.close(index);
                layer.alert(errorThrown, { icon: 2, shadeClose: true, title: MessageContainer["ErrorInfo"] });
            }
        });
    }
});