Inventory.js 15.2 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) {
            if (callBack != null) callBack();
            setTimeout(() => {
                $("#materialCode").val("");
            });
        },

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

        editBefore: function (data, callBack) {
            form.val("modifyForm", data);
            if (callBack != null) callBack();
        },

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

        editSaveBefore: function (data, callBack) {

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

        queryBefore: (sysU, toolbarId) => {
            if (!isFirstQuery) u.initSelect(app.data.selectOption);
            setTimeout(() => { isFirstQuery = true; });
        },

        qcCodePrintOptions: () => {
            var options = {
                qrCodeValueKey: "pipeSN",
                //【qrcodeElem】 是要修改的内容其他的不要变 id 的变量值不需要变 
                customFn: (sysU, parameter, selectData) => {
                    for (var i = 0; i < selectData.length; i++) {
                        debugger
                        var qcCodeValue = selectData[i][parameter.qrCodeValueKey],
                            qrcodeId = "qrcode" + i,
                            qrcodeHeadId = "qrcodeHead" + i,
                            qrcodeElem = `<div  id="${qrcodeHeadId}"  class="qcCode" >
                                             <div id="${qrcodeId}" ></div>
                                             <div class="qcCode_div">
                                                <label>管材SN:</label><label>${qcCodeValue}</label>
                                            </div>
                                             <div class="qcCode_div">
                                                <label>物料名称:</label><label class="qcCode_div_lable">${selectData[i].materialName}</label>
                                             </div>
                                             <div class="qcCode_div">
                                                <label>管径:</label><label class="qcCode_div_lable">${selectData[i].diameter}</label>
                                             </div>
                                             <div class="qcCode_div">
                                                <label>壁厚:</label><label class="qcCode_div_lable">${selectData[i].thickness}</label>
                                             </div>
                                             <div class="qcCode_div">
                                                <label>管材长度:</label><label>${selectData[i].pipeLength}</label>
                                             </div>
                                          </div>`;
                        parameter.qcCodeBody.append(qrcodeElem);
                        var qrcodeObj = new QRCode(document.getElementById(qrcodeId), {
                            width: 100,
                            height: 100
                        });
                        qrcodeObj.makeCode(qcCodeValue);
                    }
                    return true;
                }
            }
            return options;
        },

        //库存盘点 保存
        btnInventoryCheck: function (sysU, toolbarId, obj) {
            var allData = sysU.getTableAllData(toolbarId),
                allCos = obj.config.cols[0],
                validCosName = [],
                setData = [];
            for (var j = 0; j < allCos.length; j++) {
                if (typeof allCos[j].verifyConfig == "undefined") continue;
                validCosName.push({
                    field: allCos[j]["field"],
                    verifyConfig: allCos[j].verifyConfig
                });
            }

            for (var i = 0; i < allData.length; i++) {
                if (typeof allData[i].LAY_CHECKED == "undefined") continue;

                var tempVal = {};
                for (var k = 0; k < validCosName.length; k++) {
                    debugger
                    let field = validCosName[k].field;
                    var vaCos = allData[i][field];
                    if (validCosName[k].verifyConfig.empty == "req" && validCosName[k].verifyConfig.type == "number") {
                        let isVal = "".isNumber(vaCos);
                        if (!isVal) {
                            layer.alert(validCosName[k].verifyConfig.msg + allData[i].id, { icon: sysU.config.iconoError, shade: 0.4 });
                            return;
                        }
                    }
                    else if (validCosName[k].verifyConfig.empty == "req" && validCosName[k].verifyConfig.type == "string") {
                        let isVal;
                        if (field == "locationCode") {
                            if (vaCos != null && typeof vaCos.value != "undefined") vaCos = vaCos.value;
                        }
                        isVal = "".isEmpty(vaCos);
                        if (isVal) {
                            layer.alert(validCosName[k].verifyConfig.msg + allData[i].id, { icon: sysU.config.iconoError, shade: 0.4 });
                            return;
                        }
                    }
                    tempVal[field] = vaCos;
                }
                setData.push(tempVal);
            }

            if (setData.length == 0) {
                layer.alert("请编辑修改后在盘点保存!", { icon: sysU.config.iconoError, shadeClose: true });
                return;
            }
            var ajaxConfig = {
                data: {
                    model: setData
                },
                url: `/${areaName}/${tableName}/InventoryCheck`,
                success: function (result) {
                    if (sysU.successBefore(result)) return;
                    layer.msg(result.Message, { icon: sysU.config.iconoOk, shade: 0.4, time: sysU.config.errorTime });
                    action.actionSuccess("mainList", app.data.tableIns.config.page.curr);
                }
            };
            sysU.ajax(ajaxConfig);
        },

        //所有动作成功之后
        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: "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: 150, 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"
                    }
                }
            ]],
            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();
});