Container.js 9.84 KB

let action = null;

layui.config({
    base: "/js/",
    version: 11
}).use(["system", "jqprint"], function () {
    var form = layui.form,
        $ = layui.jquery,
        table = layui.table,
        layer = layui.layer,
        system = layui.system,
        u = new system.u(),

        areaName = "warehous",
        tableName = "Container";

    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: "containerCode"
            }
            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 = {
                containerId: `#printContainer`,
                customFn: (sysU, parameter) => {
                    sentData.page = 1;
                    sentData.isPage = true;
                    var data = form.val(parameter.fromId);
                    if (data.start != "" && data.end != "") {
                        if (new Date(data.start) > new Date(data.end)) {
                            layer.alert(sysU.config.titleTime, { icon: sysU.config.iconoError, shadeClose: true });
                            return "0";
                        }
                    }
                    app.methods.initGantt(data);
                }
            }
            return options;
        },


        qcCodePrintOptions: () => {
            var options = {
                qrCodeValueKey: "containerCode",
                //【qrcodeElem】 是要修改的内容其他的不要变 id 的变量值不需要变
                customFn: (sysU, parameter, selectData) => {
                    for (var i = 0; i < selectData.length; i++) {
                        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_lable">
                                                <label>编码:</label><label>${qcCodeValue}</label>
                                             </div>
                                             <div class="qcCode_lable">
                                                <label>容器类型:</label><label>${selectData[i].typeName}</label>
                                             </div>
                                          </div>`;
                        sysU.qRCodeWirtDom(parameter, qrcodeElem, qrcodeId, qcCodeValue);
                    }
                    return true;
                }
            }
            return options;
        },

        addBefore: function (callBack) {
            debugger
            u.initSelect(app.data.selectOption, callBack);
        },

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

        editBefore: function (data, callBack) {
            debugger
            var fn = () => {
                callBack();
                form.val("modifyForm", data);
            }
            u.initSelect(app.data.selectOption, fn);
        },


        BatchCreateLocation: function () {
            var formElem = "BtchForm";
            document.getElementById(formElem).reset();
            var temp = {
                containerType: {
                    SelType: "FromDict",
                    SelFrom: "containerType",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='containerType']")]
                },
                //返回的数据 用于后续操作
                selectData: {

                }
            };
            u.initSelect(temp);
            layer.open({
                type: 1,
                moveType: 1,
                title: "批量创建", 
                area: ["550px", "450px"], 
                content: $('#BtchAdd'),
                btn: ['创建', '关闭'],
                yes: function (index, layero) {
                    var valueObj= form.val(formElem);
                    if (valueObj.type == "") {
                        layer.alert("容器类型不能为空!", { icon: sysU.config.iconoError, shadeClose: true, title: "错误信息" });
                        return null;
                    }
                    if (valueObj.Num == "") {
                        layer.alert("总数不能为空!", { icon: sysU.config.iconoError, shadeClose: true, title: "错误信息" });
                        return null;
                    }
                    var ajaxConfig = {
                        data: { type: valueObj.type, containerNum: valueObj.Num},
                        url: `/${areaName}/${tableName}/BtchAdd`,
                        success: function (result) {
                            if (u.successBefore(result)) return false;
                            layer.close(index);
                            layer.msg(result.Message);
                            action.actionSuccess();
                        }
                    };
                    u.ajax(ajaxConfig);
                }
            });
        },
        //所有动作成功之后
        actionSuccess: (falg) => {
            u.refreshTable(app, u, null, falg);
        }
    }

    var app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80,  hide: true, title: "Id" },
                { field: "containerCode", width: 180,  title: "容器编码" },

                { field: "containerType", width: 20,  hide: true, title: "容器类型" },
                { field: "typeName", width: 100,  title: "容器类型" },
                { field: "IsLock", width: 20,  hide: true, title: "IsLock" },
                { field: "isLockName", width: 100,  title: "IsLock" },

                { field: "warehouseCode", width: 150,  title: "仓库编码" },
                { field: "locationCode", width: 150,   title: "库位编码" },
                { field: "paint", width: 100,  title: "油漆系统" },

                { field: "status", width: 100,  hide: true, title: "status" },
                { field: "statusName", width: 100,  title: "状态" },

                { field: "printCount", width: 100,  title: "打印次数" },

                { field: "createTime", width: 150,  title: "建立时间" },
                { field: "createBy", width: 150,  title: "建立者" },
                { field: "updateTime", width: 150,  title: "更新时间" },
                { field: "updateBy", width: 150,  title: "更新者" }
            ]],
            tableIns: null,
            tableElem: "mainList",
            //下拉框配置
            selectOption: {
                status: {
                    SelType: "FromDict",
                    SelFrom: "containerStatus",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='status']")]
                },
                type: {
                    SelType: "FromDict",
                    SelFrom: "containerType",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='containerType']")]
                },
                IsLock: {
                    SelType: "FromDict",
                    SelFrom: "IsLock",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='IsLock']")]
                },
                locationCode: {
                    SelType: "FromUrl",
                    SelFrom: "/warehous/Location/Load",
                    SelModel: "locationCode",
                    SelLabel: "locationCode",
                    SelValue: "locationCode",
                    Dom: [$("[name='locationCode']")]
                },
                //返回的数据 用于后续操作
                selectData: {

                }
            }
        },
        methods: {
            initTable: function () {
                let options = {
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${tableName}/Load`,
                    cols: u.columnRecord(app.data.tableElem, app.data.cols),
                    toolbar: "#toolbarTable"
                }
                app.data.tableIns = u.initTable(options);
            },

            initFrom() {

            }
        },
        registerEvent: function () {

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