PalletIn.js 11.1 KB
layui.config({
    base: "/js/"
}).use(['form', 'element', 'vue', 'layer', 'laydate', 'jquery','hhweb', 'table', 'utils', 'Universal'], function () {
    var form = layui.form,
        layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        $ = layui.jquery,
        table = layui.table,
        Universal = layui.Universal;

    var AreaName = 'task';
    var TableName = 'TaskDetail';

    var vm = new Vue({
        el: '#PalletForm'
    });

    var PalletIn = new Vue({
        data: {}
    });


    var mainList = {
        //NoData: function () {
        //    return "<div id='background' style='width:100%;height:100%;background-image:url(../../images/NoData.png);background-repeat:no-repeat;background-size:cover;'>.</div>"
        //},
        mainList: function (vm) {
            console.log(vm);
            table.reload('mainList', {
                url: "/" + "task" + "/" + "Task" + "/StationToInventory"
                , where: { stationCode: vm }
                , method: "post"
                , text: { none: "暂无数据,请扫码容器编号!" }
               // , text: { none: this.NoData() }
            });
        }
    };

    var selector = {
        'TaskType': {
            SelType: "FromDict",
            SelFrom: "taskType",
            SelModel: "TaskType",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='TaskType']")]
        },
        'ContainerStatus': {
            SelType: "FromDict",
            SelFrom: "containerStatus",
            SelModel: "ContainerStatus",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='ContainerStatus']")]
        },
        'Type': {
            SelType: "FromDict",
            SelFrom: "containerType",
            SelModel: "Type",
            SelLabel: "DictLabel",
            SelValue: "DictValue",
            Dom: [$("[name='Type']")]
        }
    };

    var vml = new Array({
        vm: vm,
    });

    Universal.BindSelector($, form, vml, selector);


    //空栈板请求
    $(document).on("click", "#btnEmpty", function () {
        var str = $('[name = "IsShou"]:checked').val();
        console.log(str);
        if (str == undefined) {
            layer.alert("请选择站台", { icon: 5, shadeClose: true, title: "错误信息" });
        } else {
            var type = "p_1";
            $.ajax({
                async: false,
                type: "post",
                url: "/task/Task/EmptyPalletOut",
                data: { station: str, type: type },
                dataType: "json",
                success: function (result) {
                    if (result.Code == 200) {
                        layer.msg("呼叫空栈板成功", { icon: 6, shade: 0.4, time: 1000 });
                    }
                    else {
                        layer.alert("失败:" + result.Message, { icon: 5, shadeClose: true, title: "错误信息" });
                    }
                },
                error: function (errorThrown) {
                    layer.alert(errorThrown, { icon: 2, title: '提示' });
                }
            })
        }
    });

    //空板回库
    $(document).on("click", "#btnEmptyBack", function () {
        var b = $('[name = "IsShou"]:checked').val();
        if (b == undefined) {
            layer.alert("请选择站台", { icon: 5, shadeClose: true, title: "错误信息" });
        } else {
            layer.open({
                title: '空板回库',
                area: ["400px", "350px"],
                type: 1,
                content: $('#PalletEmptyIn'),
                btn: ['提交', '关闭'],
                yes: function (index) {
                    if ($('[name = "Type"]').val() != '') {
                        layer.close(index);
                        $.ajax({
                            async: false,
                            url: "/" + "task" + "/" + "Task" + "/BulidEmptyContainerBack",
                            type: "post",
                            data: { station: $('[name = "IsShou"]:checked').val(), containerCode: $('[name = "ContainerId"]')[0].value, type: $('[name = "Type"]').val() },
                            dataType: "json",
                            success: function (result) {
                                if (result.code == 200) {
                                    layer.msg("空托回库成功", { icon: 6, shade: 0.4, time: 1000 });
                                }
                                else {
                                    layer.alert("失败:" + result.msg, { icon: 5, shadeClose: true, title: "错误信息" });
                                }
                            },
                            error: function (errorThrown) {
                                layer.alert(errorThrown, { icon: 2, title: '提示' });
                            }
                        })
                    } else {
                        layer.alert("请选择托盘类型", { icon: 5, shadeClose: true, title: "错误信息" });
                    }
                },
                btn2: function (index) {
                    layer.close(index);
                }
            });
        }
    });

    //站台选择
    $(document).on("click", "#btnstation", function () {
        layer.open({
            title: '站台选择',
            //area: ["800px", "400px"],
            type: 1,
            content: $('#station'),
            btn: ['确认'],
            yes: function (index) {
                $('#btnstation').text($('[name = "IsShou"]:checked').parent().text());
                layer.close(index);
            }
        });
    });

    //物料添加
    $(document).on("click", "#btnInventory", function () {
        AddInventory();
    });

    //托盘入库
    $(document).on("click", "#btnPalletIn", function () {
        var b = $('[name = "IsShou"]:checked').val();
        if (b == undefined) {
            layer.alert("请选择站台", { icon: 5, shadeClose: true, title: "错误信息" });
        } else {
            $.ajax({
                async: false,
                url: "/" + "task" + "/" + "Task" + "/HandTaskIn",
                type: "post",
                data: { containerCode: "", station: b },
                dataType: "json",
                success: function (result) {
                    if (result.code == 200) {
                        layer.msg("入库成功", { icon: 6, shade: 0.4, time: 1000 });
                        $('[name = "Num"]').val("");
                        $('[name = "MaterialCode"]').val("");
                        $('[name = "SourceCode"]').val("");
                        $('[name = "Batch"]').val("");
                        $('[name = "ContainerId"]').val("");
                        //mainList.mainList("#");
                    }
                    else {
                        layer.alert("失败:" + result.msg, { icon: 5, shadeClose: true, title: "错误信息" });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert(errorThrown, { icon: 2, title: '提示' });
                }
            });
        }
        
    });


    //打开页面聚焦“容器管理”
    $(document).ready(function () {
        $('[name = "ContainerId"]').focus();
    });

    //“容器编号”回车监听
    $('[name = "ContainerId"]').bind("keydown", function (e) {
        if (e.which == 13) {
            AddInventory();
            e.preventDefault(); //Skip default behavior of the enter key
            //if ($(this).val() != "") {
            //    FindFirstTask();
            //    //改变焦点
            //    $('[name = "Num"]').focus();
            //}
            //else {
            //    $(this).focus();
            //}
        }
    });

    //根据站台请求物料信息
    function AddInventory() {
        var b = $('[name = "IsShou"]:checked').val();
        if (b == undefined) {
            layer.alert("请选择站台", { icon: 5, shadeClose: true, title: "错误信息" });
        } else {
            var str = $('[name = "ContainerId"]').val();
            var strs = str.split('%');
            if (strs.length > 3) {
                $('[name = "Num"]').val(strs[3]);
                console.log($('[name = "Num"]').val());
                $('[name = "MaterialCode"]').val(strs[0]);
                $('[name = "SourceCode"]').val(strs[1]);
                $('[name = "Batch"]').val(strs[2]);
            }
            $.ajax({
                async: false,
                url: "/" + "task" + "/" + "Task" + "/AddInventory",
                type: "post",
                data: { containerCode: '', material: $('[name = "MaterialCode"]').val(), batch: $('[name = "Batch"]').val(), station: b, num: $('[name = "Num"]').val(), sourceCode: $('[name = "SourceCode"]').val() },
                dataType: "json",
                success: function (result) {
                    if (result.code == 200) {
                        if (strs.length < 3) {
                            $('[name = "Num"]').val("");
                            $('[name = "MaterialCode"]').val("");
                            $('[name = "SourceCode"]').val("");
                            $('[name = "Batch"]').val("");
                        } else {
                            $('[name = "ContainerId"]').val("");
                        }

                        layer.msg("入库成功", { icon: 6, shade: 0.4, time: 1000 });
                    }
                    else {
                        layer.alert("失败:" + result.msg, { icon: 5, shadeClose: true, title: "错误信息" });
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert(errorThrown, { icon: 2, title: '提示' });
                }
            });
            //mainList.mainList(b);
        }
    }

   //根据站台请求物料信息
    function FindInventory(station) {
        table.reload('listForm', {
            url: "/" + "task" + "/" + "Task" + "/StationToInventory"
            , where: station
            , method: "post"
            , text: { none: "暂无数据,请扫码容器编号!" }
            // , text: { none: this.NoData() }
        });
        //$.ajax({
        //    async: false,
        //    url: "/" + "task" + "/" + "Task" + "/StationToInventory",
        //    type: "post",
        //    data: { stationCode: station },
        //    dataType: "json",
        //    success: function (result) {
        //        console.log(result)
        //        if (result.code == 200) {
        //            PalletIn.$set('$data', result.data);
        //            mainList.mainList(PalletIn);
        //        }
        //        else if (result.code == 0) {
                   
                 
        //        }
        //        else {
        //            layer.alert("失败:" + result.msg, { icon: 5, shadeClose: true, title: "错误信息" });
        //        }
        //    },
        //    error: function (XMLHttpRequest, textStatus, errorThrown) {
        //        layer.alert(errorThrown, { icon: 2, title: '提示' });
        //    }
        //});
    }
});