Inventory.js 10.5 KB

let action = null,
    aopTable = null,
    app = null;

layui.config({
    base: "/js/",
    version: 128
}).use(['system', "jqprint"], function () {
    var form = layui.form,
        $ = layui.jquery,
        table = layui.table,
        layer = layui.layer,
        system = layui.system,
        u = new system.u(),
        sendData = null,
        tableEdit = layui.tableEdit,
        isFirstQuery = false,
        areaName = 'warehous',
        tableName = 'Inventory';

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

        editOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${tableName}/Upd`,
                submit: "submit(fromUpdate)"
            }
            return options;
        },

        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/DelByIds`,
                keyId: "id"
            }
            return options;
        },
             
        exportOptions: function () {
            var options = {
                fromId: "listForm",
                url: `/${areaName}/${tableName}/Export`,
                isDefault: false,
                excelCols: {
                    head: app.data.cols
                }
            }
            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`,
                fromFile: "#excelfile",
                content: $("#ImportData")
            }
            return options;
        },
        addBefore: function (callBack) {
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },
        editBefore: function (data, callBack) {
            debugger
            form.val("modifyForm", data);
            if (callBack != null) callBack();
        },

        editAfter: function (callBack) {

            if (callBack != null) callBack();
        },

        addSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },

        btnSendNesting: function (sU, toolbarId, obj) {
           
            $.ajax({
                url: `/${areaName}/${tableName}/SendNesting`,
                type: "POST",
                data: null,
                dataType: "json",
                success: function (data) {
                    //  alert(data.Message);                                                                                   
                    layer.alert(data.Message, { icon: 6, shade: 0.4, time: sU.config.msgOpenTime });
                },
                error: function () {
                    //失败处理
                }
            });
        },

        //所有动作成功之后
        actionSuccess: (falg) => {
            u.refreshTable(app, u, null, falg);
        }
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                {
                    field: "id", width: 60, sort: true, fixed: true, hide: true, title: "ID",
                    verifyConfig: {
                        empty: "req", msg: "盘点数据【ID】不能为空!,ID:", type: "number"
                    }
                },
                { field: "lineCode", width: 150, sort: true, fixed: false, title: "产线" },
                { field: "materialCode", width: 150, sort: true, fixed: false, title: "物料编码" },
                {
                    field: "pipeLength", width: 100, sort: true, fixed: false, title: "管材长度", edit: "text",
                    verifyConfig: {
                        empty: "req", msg: "盘点数据【管材长度】不能为空!,ID:", type: "number"
                    }
                },
                {
                    field: "qty", width: 80, sort: true, fixed: false, title: "数量", edit: "text",
                    verifyConfig: {
                        empty: "req", msg: "盘点数据【数量】不能为空!,ID:", type: "number"
                    }
                },
                { field: "materialName", width: 200, sort: true, fixed: false, title: "物料名称" },
                { field: "diameter", width: 150, sort: true, fixed: false, title: "管径" },
                { field: "thickness", width: 150, sort: true, fixed: false, title: "壁厚" },
                { field: "useState", width: 150, sort: true, fixed: false, title: "物料状态", templet: (d) => { return "".GetState(window.top.InventoryUseState, d.useState) } },
                {
                    field: "pipeSN", width: 150, sort: true, fixed: false, title: "管材SN",
                    edit: "text",
                    verifyConfig: {
                        empty: "req", msg: "盘点数据【管材SN】不能为空!,ID:", type: "string"
                    }
                },
                { field: "createTime", width: 150, sort: true, fixed: false, title: "入库日期" },
            ]],
            tableIns: null,
            tableElem: "mainList",
            //下拉框配置
            selectOption: {
                lineCode: {
                    SelType: "FromUrl",
                    SelFrom: "/HomeRedis/GetBaseInfoByKey?key=base_line",
                    SelLabel: "LineName",
                    SelValue: "LineCode",
                    Dom: [$("[name='lineCode']")]
                },
                locationCode: {
                    SelType: "FromUrl",
                    SelFrom: "/HomeRedis/GetBaseInfoByKey?key=base_location",
                    SelLabel: "locationName",
                    SelValue: "locationCode",
                    Dom: [$("[name='locationCode']")]
                },
                inventoryStatus: {
                    SelType: "FromDict",
                    SelFrom: "inventoryStatus",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                },
                zoneCode: {
                    SelType: "FromDict",
                    SelFrom: "zoneCode",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='zoneCode']")]
                },
                warehouseCode: {
                    SelType: "FromUrl",
                    SelFrom: "/warehous/Warehouse/Load",
                    SelLabel: "name",
                    SelValue: "code",
                    Dom: [$("[name='warehouseCode']")]
                },
                //返回的数据 用于后续操作
                selectData: {

                }
            }
        },
        methods: {
            initTable: function (opts) {
                var config = {};
                if (opts != undefined) $.extend(config, opts);
                let options = {
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${tableName}/Load`,
                    cols: u.columnRecord(app.data.tableElem, app.data.cols),
                    toolbar: '#toolbarTable',
                    where: config,
                    doneExtend: function () {
                        setTimeout(function () {
                            app.methods.setColsEditConfig();
                            app.methods.initAopTable();
                        }, 2000);
                    }
                }
                if ("".GetUrlParam("menuFlag") === -2) options["height"] = 'full-55';
                app.data.tableIns = u.initTable(options);
            },


            setColsEditConfig: function () {
                for (var i = 0; i < app.data.cols[0].length; i++) {
                    if (typeof app.data.cols[0][i].field == "undefined") continue;
                    if (app.data.cols[0][i].field == "locationCode") {
                        var locationCodeConfigData = [];
                        app.data.selectOption.selectData["locationCode"].forEach(x => {
                            locationCodeConfigData.push({ name: x.id, value: x.locationCode });
                        });
                        app.data.cols[0][i]["config"] = { type: 'select', data: locationCodeConfigData }
                    }
                }
            },

            initAopTable: function () {
                aopTable = tableEdit.aopObj(app.data.cols);
                aopTable.on(`tool(${app.data.tableElem})`, function (obj) {
                    debugger
                    var field = obj.field; //单元格字段
                    var value = obj.value; //修改后的值
                    var data = obj.data; //当前行旧数据
                    var event = obj.event; //当前单元格事件属性值
                    var update = {};
                    update[field] = value;
                    obj.update(update);
                });
            },

            initFrom() {
                u.initSelect(app.data.selectOption);

                var opt1 = {
                    elem: "#materialCode",
                    checkedKey: "MaterialCode",
                    doneKey: {
                        key: "MaterialCode",
                        lableValue: "MaterialName"
                    },
                    searchKey: "MaterialCode",
                    searchName: "物料编码",
                    doneExtend: function (elem, data, $nowElem) {
                        debugger
                        var rootFrom = $("#modifyForm");
                        rootFrom.find("[name=materialCode]").val(data.data[0].materialCode);
                        rootFrom.find("[name=materialName]").val(data.data[0].materialName);
                    }
                };
                u.initSelectMaterialFeed1(opt1);
            }
        },
        registerEvent: function () {

        },
        init: function () {
            var inventoryId = "".GetUrlParam("InventoryId");
            sendData = { id: inventoryId == null ? 0 : inventoryId }
            app.methods.initFrom();
            app.methods.initTable(sendData);
            app.registerEvent();
        }
    };
    app.init();
});