materialdistributeloaddata.js 15.2 KB
let action = null;
layui.config({
    base: "/js/",
    version: 1222
}).use(['system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        element = layui.element,
        table = layui.table,
        system = layui.system,
        sysU = new system.u(),
        newAction = null,
        sendDataDesc = null,
        sendDataEndPosition = null,
        areaName = "distribution",
        tableName = "MaterialDistributeLoadData",
        app = null;

    action = {
        addOptions: function () {
            newAction = "add";
            $("#divAdd").show();
            $("#divEdit").hide();
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${tableName}/Ins`,
                submit: "submit(fromAdd)"
            }
            return options;
        },

        addOptionsDesc: function () {
            var options = {
                fromId: "#modifyFormDesc form",
                url: `/${areaName}/${tableName}/InsDesc`,
                content: $('#modifyFormDesc'),
                submit: "submit(fromAddDesc)"
            }

            return options;
        },

        editOptions: function () {
            newAction = "edit";
            $("#divAdd").hide();
            $("#divEdit").show();
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${tableName}/Upd`,
                submit: "submit(fromUpdate)"
            }
            return options;
        },

        editOptionsDesc: function () {
            var options = {
                fromId: "#modifyFormDesc form",
                url: `/${areaName}/${tableName}/UpdDesc`,
                content: $('#modifyFormDesc'),
                submit: "submit(fromUpdateDesc)"
            }
            return options;
        },

        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/DelByIds`,
                keyId: "keys",
                titleConfirmDelete: "确定要删除所选信息吗(对应的明细数据也会删除)?"
            }
            return options;
        },

        deleteOptionsDesc: function () {
            var options = {
                url: `/${areaName}/${tableName}/DelByIdsDesc`,
                keyId: "id"
            }
            return options;
        },

        exportOptions: function () {
            var options = {
                fromId: "listForm",
                url: `/${areaName}/${tableName}/Export`,
                isDefault: true,
                excelCols: {
                    head: app.data.cols,
                    body: app.data.colsDesc
                }
            }
            return options;
        },

        queryOptions: function () {
            var options = {
                resetFrom: "form[lay-filter=listForm]",
                fromId: "listForm",
                urlExport: `/${areaName}/${tableName}/Export`,
                urlQuery: `/${areaName}/${tableName}/Load`,
                mainTable: app.data.tableIns
            }
            return options;
        },

        uploadOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/Import`
            }
            return options;
        },

        rowClickOptions: function () {
            var options = {
                isDefault: true,
                targetTableId: app.data.tableElem,
                tabfilter: "tableTabBody",
                tabId: 2,
                customFn: app.methods.initTableDesc
            }
            return options;
        },

        editBefore: function (data, callBack) {
            if (data.status !== window.top.EnumLoadData.已装料) {
                layer.alert("装料模板数据状态是【已装料】才能编辑!", { icon: sysU.config.iconoError, shade: 0.4 });
                return;
            }
            app.methods.initProductCodeSelect();
            var whereData = { entity: { "productCode": data.productCode, flag: "edit", "keys": data.keys, containerCode: data.containerCode} }
            app.methods.initTableLoadTemplateTable(whereData);

            setTimeout(()=> {
                form.val("modifyForm", data);
                $("#endPositionEdit").val(data.endPosition);
            },500);
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        editSaveBefore: function (data, callBack) {
            data.field["table"] = sysU.getTableAllData("LoadTemplateTable");
            data.field["endPosition"] = $("#endPositionEdit").val();
            if (callBack != null) callBack();
        },

        editBeforeDesc: function (data, callBack) {
            form.val("modifyFormDesc", data);
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },
        editSaveBeforeDesc: function (data, callBack) {
            if (callBack != null) callBack();
        },

        addBefore: function (callBack) {
            app.methods.initProductCodeSelect();
            debugger
            if (table.cache.LoadTemplateTable != "undefined") {
                var whereData = { entity: { "productCode": "-1" } }
                app.methods.initTableLoadTemplateTable(whereData);
            }
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addBeforeDesc: function (callBack) {
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addSaveBefore: function (data, callBack) {
            debugger
            data.field["table"] = sysU.getTableAllData("LoadTemplateTable");
            data.field["endPosition"] = $("#endPositionAdd").val();
            if (callBack != null) callBack();
        },

        btnEndMaterialDistributeLoad: function (data, toolbarId) {
            layer.confirm("确定结束任务?", { icon: 3 }, function (index) {
                var checkStatus = table.checkStatus(toolbarId);
                if (checkStatus.data.length !== 1) {
                    layer.alert(data.config.titleSelectOne, { icon: data.config.iconoError, shadeClose: true, title: data.config.titleSelectOneRowData });
                    return false;
                }
                var key = checkStatus.data[0].keys;
                var ajaxConfig = {
                    data: { keys: key },
                    url: `/${areaName}/${tableName}/HandlerMaterialDistributeLoadEnd`,
                    success: function (result) {
                        if (sysU.successBefore(result)) return;
                        layer.msg(sysU.config.titleActionSuccess, { icon: sysU.config.iconoOk, shade: 0.4, time: sysU.config.msgOpenTime });
                        if (action["actionSuccess"] !== undefined) action["actionSuccess"].call(null, "");
                    }
                };
                sysU.ajax(ajaxConfig);
            });
        },
        //所有动作成功之后
        actionSuccess: (falg, toolbarId) => {
            sysU.refreshTable(app, sysU, sendDataDesc, falg);
        }
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 70, title: "Id" },
                { field: "keys", width: 120, hide: true, title: "keys" },
                { field: "productCode", width: 120, title: "产品编码" },
                { field: "wcsProductType", width: 150, title: "产品WCS编码" },

                { field: "startPosition", width: 150, title: "人工装料点" },
                { field: "endPosition", width: 150, title: "组队上料点" },
                { field: "needStation", width: 150, title: "需求工位" },
                { field: "containerCode", width: 150, title: "容器编码" },

                { field: "loadQty", width: 150, title: "装料套数" },
                { field: "useQty", width: 150, title: "使用套数" },
                {
                    field: "status", width: 150, title: "状态", templet: function (obj) {
                        return "".GetState(window.top.EnumLoadData, obj.status);
                    }
                },

                { field: "createTime", width: 150, title: "建立时间" },
                { field: "createBy", width: 150, title: "建立者" },
                { field: "updateTime", width: 150, title: "更新时间" },
                { field: "updateBy", width: 150, title: "更新者" }
            ]],
            colsDesc: [[
                { field: "id", width: 70, title: "Id", hide: true, },
                { field: "headKeys", width: 120, hide: true, title: "headKeys" },
                { field: "bodyKeys", width: 120, hide: true, title: "bodyKeys" },
                { field: "sequence", width: 150, title: "顺序" },

                { field: "materialCode", width: 150, title: "物料编码" },
                {
                    field: "MaterialName", width: 150, sort: true, fixed: false, title: "物料名称", templet: (d) => {
                        return "".GetMaterialName(window.top.material, "MaterialCode", "MaterialName", d.materialCode);
                    }
                },
                { field: "containerType", width: 150, title: "容器类型" },
                { field: "row", width: 150, title: "行" },
                { field: "line", width: 150, title: "列" },
                { field: "layer", width: 150, title: "层" },
                { field: "qty", width: 150, title: "数量" },

                { field: "createTime", width: 150, title: "建立时间" },
                { field: "createBy", width: 150, title: "建立者" },
                { field: "updateTime", width: 150, title: "更新时间" },
                { field: "updateBy", width: 150, title: "更新者" }

            ]],
            colsLoadTemplate: [[
                { field: 'sequence', width: 70, title: '序号' },
                { field: "materialCode", width: 250, title: '物料名称', templet: function (d) {
                        return "".GetMaterialName(window.top.material, "MaterialCode", "MaterialName", d.materialCode);
                } },

                { field: "row", width: 100, edit: true, title: '行' },
                { field: "line", width: 100, edit: true, title: '列' },
                { field: "layer", width: 100,  edit: true, title: '层' },
                { field: "qty", width: 100, edit: true,  title: '数量' }
            ]],

            urlTable: `/${areaName}/${tableName}/Load`,
            tableIns: null,
            tableInsDesc: null,
            tableElem: "mainList",
            tableElemDesc: "mainListDesc",

            selectOption: {
                endPosition: {
                    SelType: "FromUrl",
                    SelFrom: "",
                    SelLabel: "locationName",
                    SelValue: "locationCode",
                    Dom: [$("#modifyForm [name='endPositionAdd']")]
                },
                //返回的数据 用于后续操作
                selectData: {

                }
            }
        },
        methods: {
            initTable: function (options) {
                var config = {  };
                if (options != undefined) $.extend(config, options);
                let opt = {
                    cols: sysU.columnRecord(app.data.tableElem, app.data.cols),
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${tableName}/Load`,
                    toolbar: '#toolbarTable',
                    height: 'full-55',
                    where: config
                }
                app.data.tableIns = sysU.initTable(opt);
            },
            initTableDesc: function (obj) {
               sendDataDesc = {
                    headKeys: obj.data.keys
                }
                let opt = {
                    cols: sysU.columnRecord(app.data.tableElemDesc, app.data.colsDesc),
                    elem: "#" + app.data.tableElemDesc,
                    url: `/${areaName}/${tableName}/LoadDesc`,
                    height: 'full-55',
                    toolbar: '#toolbarTableDesc',
                    limit: 0,
                    page: false,
                    where:sendDataDesc
                }
                app.data.tableInsDesc = sysU.initTable(opt);
            },

            //新增编辑
            initTableLoadTemplateTable: function (where) {
                var config = {};
                if (where != undefined) $.extend(config, where);
                let opt = {
                    cols: app.data.colsLoadTemplate,
                    elem: "#LoadTemplateTable",
                    url: `/${areaName}/${tableName}/GetLoadDataTemplateByProductCode`,
                    height: 'full-360',
                    limit: 0,
                    page: false,
                    where: config
                }
                sysU.initTable(opt);
            },
            initFrom: function () {
            
            },

            initProductCodeSelect() {
                var opt = {
                    elem: ".productCode",
                    checkedKey: "productCode",
                    doneKey: {
                        key: "productCode",
                        lableValue: "productCode"
                    },
                    searchKey: "productCode",
                    searchName: "产品编码",
                    doneExtend: function (elem, data, $nowElem) {
                        var val = $("#modifyForm input[name=containerCode]").val();
                        if (val == null || val == "") {
                            layer.alert("请扫描或者输入料框条码后,选择产品编码!", { icon: sysU.config.iconoError, shade: 0.4, time: sysU.config.msgOpenTimeLong });
                            return false;
                        }
                        if (newAction == "edit") {
                            layer.alert("编辑的时候,不能更换装料模板,如果录入错误,请删除装料数据后,再新增!", { icon: sysU.config.iconoError, shade: 0.4, time: sysU.config.msgOpenTimeLong });
                            return false;
                        }
                        $("#modifyForm input[name=loadQty]").val(data.data[0].loadQty);
                        $("#modifyForm input[name=wcsProductType]").val(data.data[0].wcsProductType);
                        var whereData = { entity: { productCode: data.data[0].productCode, containerCode: val} }
                        app.methods.initTableLoadTemplateTable(whereData);

                        sendDataEndPosition = { productCode: data.data[0].productCode, containerCode: val }
                        app.data.selectOption.endPosition.SelFrom = `/${areaName}/${tableName}/GetLoadMaterialLocation?productCode=${sendDataEndPosition.productCode}&containerCode=${sendDataEndPosition.containerCode}`;
                        sysU.initSelect(app.data.selectOption);
                    }
                };
                sysU.initLoadDataTemplate(opt);
            }
        },
        registerEvent: function () {

        },

        init: function () {
            app.methods.initTable();
            app.registerEvent();
            app.methods.initFrom();
        }
    };
    app.init();
});