ManualMaterialRequest.js 8.21 KB
let action = null;
layui.config({
    base: "/js/",
    version: 6222
}).use(['system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        element = layui.element,
        table = layui.table,
        system = layui.system,
        sysU = new system.u(),
        areaName = "distribution",
        tableName = "ManualMaterialRequest",
        app = null;

    action = {
        loadData: function (param) {
            app.data.currentIndex = param;
            app.methods.initData();
        },

        setData: function (locationCode, askingStatus, callType) {
            debugger;

            app.data.currentCode = locationCode;
            if (askingStatus == 20) {
                layer.confirm("确定取消叫料?", { icon: 3 }, function (index) {
                    app.methods.EscLoadingAsking(locationCode);
                    layer.close(index);
                });
            } else if (askingStatus == 10) {
                if (callType == 10) {
                    layer.confirm("确定叫料?", { icon: 3 }, function (index) {
                        app.methods.LoadingAsking(locationCode);
                        layer.close(index);
                    });
                }
                else {
                    layer.alert("当前料点是自动料点,由设备呼叫,不能人工呼叫!", { icon: sysU.config.iconoError, shade: 0.4 });
                }
            }
            //else if (askingStatus == 20) {
            //    layer.alert("已装料的不能取消!", { icon: sysU.config.iconoError, shade: 0.4 });
            //} else if (askingStatus == 30) {
            //    layer.alert("已送料的不能取消!", { icon: sysU.config.iconoError, shade: 0.4 });
            //}
        }
    }

    app = {
        data: {
            startPointEle: $("#startPointEle"),
            endPointEle: $("#endPointEle"),

            endPointList: [],

            currentIndex: "",
            currentCode: '',
        },
        methods: {
            //调用头接口
            initHead: function () {
                var ajaxConfig = {
                    data: {},
                    loading: false,
                    type: "post",
                    url: `/${areaName}/${tableName}/LoadHead`,
                    success: function (result) {
                        if (sysU.successBefore(result)) return;
                        console.log(result);
                        app.methods.initElementHead(result.Result);
                    }
                };
                sysU.ajax(ajaxConfig);
            },
            //调用数据接口
            initData: function () {
                var ajaxConfig = {
                    data: { keys: app.data.currentIndex },
                    loading: false,
                    type: "post",
                    url: `/${areaName}/${tableName}/LoadData`,
                    success: function (result) {
                        if (sysU.successBefore(result)) return;
                        console.log(result);

                        app.methods.initElement($("#" + app.data.currentIndex), result.Result);
                    }
                };
                sysU.ajax(ajaxConfig);
            },
            //初始头元素
            initElementHead: function (list) {
                var startElementList = [];
                var endElementList = [];
                app.data.endPointList = [];
                var key = "";
                for (var index = 0; index < list.length; index++) {
                    if (index == 0) {
                        key = list[index].key;
                    }
                    var str = `<li ${index == 0 ? "class='layui-this'" : ""} 
                            lay-id="${index + 1}" onclick="action.loadData('${list[index].key}')">${list[index].value}
                    </li>`;
                    startElementList.push(str);

                    str = `<div class="layui-tab-item ${index == 0 ? "layui-show" : ""}"> 
                            <div class="endPoint-div" id="${list[index].key}"></div>
                        </div>`;
                    app.data.endPointList.push(list[index].key);
                    endElementList.push(str);
                }
                var result = startElementList.join(" ");
                app.data.startPointEle.html("");
                app.data.startPointEle.append(result);

                result = endElementList.join(" ");
                app.data.endPointEle.html("");
                app.data.endPointEle.append(result);

                if (key != "") {
                    app.data.currentIndex = key;
                    app.methods.initData();
                }
            },
            //初始元素
            initElement: function (dom, list) {
                var strElementList = [];
                for (var index = 0; index < list.length; index++) {
                    var color = "green";
                    var status = "未叫料";
                    switch (list[index].askingStatus) {
                        case 10://未叫料
                            color = "green";
                            status = "未叫料";
                            //if (list[index].callType == 20) {
                            //    color = "gray";
                            //}                                
                            break;
                        case 20://已叫料
                            color = "gray";
                            status = "已叫料";
                            break;
                        case 30://已装料
                            color = "darkgray";
                            status = "已装料";
                            break;
                        case 40://已送料
                            color = "darkgray";
                            status = "已送料";
                            break;
                    }
                    var str = `<div class="${list[index].askingStatus != 10 && list[index].askingStatus != 20?
                        'element-item-disable' : 'element-item'}
                            ${color}" onclick="action.setData('${list[index].locationCode}', 
                            ${list[index].askingStatus},
                            ${list[index].callType})">
                            <div class="element-title">${status}</div>
                            <div>${list[index].locationName}</div>
                        </div>`;
                    strElementList.push(str);
                }
                var result = strElementList.join(" ");
                dom.html("");
                dom.append(result);
            },
            //叫料操作
            LoadingAsking: function (locationCode) {
                var ajaxConfig = {
                    data: { locationCode: locationCode },
                    loading: false,
                    type: "post",
                    url: `/${areaName}/${tableName}/LoadingAsking`,
                    success: function (result) {
                        
                        if (sysU.successBefore(result)) return;
                        console.log(result);

                        //app.methods.initElement($("#" + app.data.currentIndex), result.Result);
                    }
                };
                sysU.ajax(ajaxConfig);
            },
            //取消叫料操作
            EscLoadingAsking: function (locationCode) {
                var ajaxConfig = {
                    data: { locationCode: locationCode },
                    loading: false,
                    type: "post",
                    url: `/${areaName}/${tableName}/EscLoadingAsking`,
                    success: function (result) {
                        
                        if (sysU.successBefore(result)) return;
                        console.log(result);

                        //app.methods.initElement($("#" + app.data.currentIndex), result.Result);
                    }
                };
                sysU.ajax(ajaxConfig);
            }
        },
        registerEvent: function () {

        },

        init: function () {
            app.methods.initHead();
            app.registerEvent();
            setInterval(function () {
                app.methods.initData();
            }, 1000);
        }
    };
    app.init();
});