ManualMaterialLoading.js 11.1 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 = "ManualMaterialLoading",
        app = null;

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

        setData: function (locationCode, locationName, askingStatus) {
            app.data.currentCode = locationCode;
            app.methods.initWorkOrderCodeSelect();
            app.methods.initProductCodeSelect();
            form.val("modifyForm", { orderingPoint: locationName, locationCode: locationCode });

            if (askingStatus == 10 || askingStatus == 20) {
                app.data.selectOption.endPosition.Where = { "locationCode": locationCode };


                //$("#modifyForm input[name=startPosition]").val(locationCode[0]);
                sysU.initSelect(app.data.selectOption, () => {
                    debugger
                    form.val("modifyForm", { startPosition: app.data.selectOption.selectData.endPosition[0].value });
                });

                sysU.openAddOrEdit({
                    title: "设置装料数据",
                    area: ["800px", "400px"],
                    content: $("#modifyForm"),
                    fromId: "#modifyForm form",
                    btnOpenYes: "button[name=fromAdd]",
                    submitEvent: function (index, layero) {

                        if ($("#modifyForm [name=startPosition]").val() == null) {
                            layer.msg("请选择装料点!", { icon: sysU.config.iconoError, shade: 0.4, time: sysU.config.msgOpenTime });
                            return;
                        }

                        var verify = sysU.VerifyForm("modifyForm form");
                        if (!verify) return;
                        layer.close(index);
                        console.log("完成");

                        var model = {
                            endPosition: locationCode,
                            workOrderCode: $("#modifyForm input[name=planCode]").val(),
                            productCode: $("#modifyForm input[name=productCode]").val(),
                            workpieceNo: $("#modifyForm input[name=workpieceNo]").val(),
                            loadQty: $("#modifyForm input[name=loadQty]").val(),
                            startPosition: $("#modifyForm [name=startPosition]").val()
                        }

                        app.methods.setData(model, askingStatus);
                    },
                    success: function (layero, index) { }
                });
            }
        }
    }

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

            endPointList: [],

            currentIndex: "",
            currentCode: "",

            selectOption: {
                endPosition: {
                    SelType: "FromUrl",
                    SelFrom: `/${areaName}/${tableName}/GetLocationRelData`,
                    SelLabel: "key",
                    SelValue: "value",
                    Where: {},
                    Dom: [$("[name='startPosition']")]
                },
                //返回的数据 用于后续操作 app.data.selectData.endPosition[0]
                selectData: {

                }
            }
        },
        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 = [];
                strElementList.push("<table style='width:100%'><tr><td style='display: flex;width:100%'>");
                for (var index = 0; index < list.length; index++) {
                    var color = "green";
                    var status = "未装料";
                    switch (list[index].askingStatus) {
                        case 10://未叫料
                            color = "green";
                            status = "未装料";
                            break;
                        case 20://已叫料
                            color = "green";
                            status = "已叫料";
                            break;
                        case 25://已装料
                            color = "cadetblue";
                            status = "已装料一次";
                            break;
                        case 30://已装料
                            color = "darkgray";
                            status = "已装料";
                            break;
                        case 40://已送料
                            color = "darkgray";
                            status = "已送料";
                            break;
                    }
                    if (index == 6) {
                        strElementList.push("</td></tr><tr><td style='display: flex;width:100%'>");
                    }
                    var str = `<div class="${list[index].askingStatus != 10 ?
                        'element-item-disable' : 'element-item'} ${color}" 
                            onclick="action.setData('${list[index].locationCode}', 
                            '${list[index].locationName}', ${list[index].askingStatus})">
                            <div class="element-title">${status}</div>
                            <div>${list[index].locationName}</div>
                        </div>`;
                    strElementList.push(str);
                }
                strElementList.push("</td></tr></table>");
                var result = strElementList.join(" ");
                dom.html("");
                dom.append(result);
            },
            //设置状态
            setData: function (model, askingStatus) {
                var ajaxConfig = {
                    data: { model: model, askingStatus: askingStatus },
                    loading: false,
                    type: "post",
                    url: `/${areaName}/${tableName}/LoadingCharge`,
                    success: function (result) {
                        if (sysU.successBefore(result)) return;
                        console.log(result);
                    }
                };
                sysU.ajax(ajaxConfig);
            },
            initWorkOrderCodeSelect() {
                var opt = {
                    elem: ".planCode",
                    checkedKey: "planCode",
                    doneKey: {
                        key: "planCode",
                        lableValue: "planCode"
                    },
                    searchKey: "planCode",
                    searchName: "生产计划号",
                    doneExtend: function (elem, data, $nowElem) {

                        debugger;
                        if (data.data.length > 0) {
                            $("#modifyForm input[name=productCode]").val(data.data[0].productHeaderCode);
                            $("#modifyForm input[name=workpieceNo]").val(data.data[0].wcsProductType);
                        }
                    }
                };
                sysU.initSelectWorkOrderList(opt);
            },
            initProductCodeSelect() {
                var opt = {
                    elem: ".productCode",
                    checkedKey: "productCode",
                    doneKey: {
                        key: "productCode",
                        lableValue: "productCode"
                    },
                    searchKey: "productCode",
                    searchName: "产品编码",
                    doneExtend: function (elem, data, $nowElem) {
                        debugger;
                        if (data.data.length > 0) {
                            $("#modifyForm input[name=planCode]").val("");
                            $("#modifyForm input[name=workpieceNo]").val(data.data[0].wcsProductType);
                        }
                    }
                };
                sysU.initSelectProductList(opt);
            },
            initFrom() {

            }
        },
        registerEvent: function () {

        },

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