Warehouse.js 8.3 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(),

        lineSelectOption = {
            LineCode: {
                SelType: "FromUrl",
                SelFrom: "/configure/Line/Load",
                SelLabel: "lineName",
                SelValue: "lineCode",
                Where: {},
                Dom: [$("[name='lineCode']")]
            },
            //返回的数据 用于后续操作
            selectData: {

            }
        },
        sendData = {
            editData: null
        },
        areaName = "warehous",
        tableName = "Warehouse";

    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: "code"
            }
            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`
            }
            return options;
        },

        addBefore: function (callBack) {
            sendData.editData = null;
            if (callBack != null) callBack();
        },

        addSaveBefore: function (data, callBack) {
            data.field.workshopId = lineSelectOption.LineCode.Where["workshopId"];
            data.field.lineId = lineSelectOption.selectData.LineCode.GetArrValue("lineCode", data.field.lineCode, "id");
            if (callBack != null) callBack();
        },

        editBefore: function (data, callBack) {
            sendData.editData = data;
            lineSelectOption.LineCode.Where["workshopId"] = data.workshopId;

            var fn = ()=> {
                callBack();
                form.val("modifyForm", sendData.editData);
            }
            u.initSelect(lineSelectOption, fn);
        },

        editAfter: function (callBack) {
            if (callBack != null) callBack();
        },
       
        editSaveBefore: function (data, callBack) {
            data.field.workshopId = lineSelectOption.LineCode.Where["workshopId"];
            data.field.lineId = lineSelectOption.selectData.LineCode.GetArrValue("lineCode", data.field.lineCode, "id");
            if (callBack != null) callBack();
        },

        //车间选择 加载线体
        workshopCodeFromEvent: function (data) {
            debugger
            if (data.value == "") {
                lineSelectOption.LineCode.Dom[0].empty();
                form.render("select");
                return false;
            }
            lineSelectOption.LineCode.Where["workShopCode"] = app.data.selectOption.selectData.workshop.GetArrValue("workShopCode", data.value, "workShopCode");
            if (lineSelectOption.LineCode.Where["workShopCode"] == "") {
                layer.msg("选择的车间值错误", { icon: 6, shade: 0.4, time: u.config.errorTime });
                return false;
            }
            u.initSelect(lineSelectOption);
        },
        qcCodePrintOptions: () => {
            var options = {
                qrCodeValueKey: "code",
                //【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].name}</label>
                                             </div>
                                             <div class="qcCode_lable">
                                                <label>产线:</label><label>${selectData[i].lineName}</label>
                                             </div>
                                          </div>`;
                        sysU.qRCodeWirtDom(parameter, qrcodeElem, qrcodeId, qcCodeValue);
                    }
                    return true;
                }
            }
            return options;
        },
        //所有动作成功之后
        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: "code", width: 150,   title: "仓库编号" },
                { field: "name", width: 150,  title: "仓库名称" },

                { field: "workshopCode", width: 100,  title: "车间编码" },
                { field: "workshopname", width: 180,  title: "车间名称" },

                { field: "lineCode", width: 100,  title: "线体编码" },
                { field: "lineName", width: 180,  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: {
                workshop: {
                    SelType: "FromUrl",
                    SelFrom: "/HomeRedis/GetBaseInfoByKey?key=base_workshop",
                    SelLabel: "workShopName",
                    SelValue: "workShopCode",
                    Dom: [$("[name='workshopCode']")]
                },
                //返回的数据 用于后续操作
                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);
            },

            initSelectTable: function () {
              
            },

            initFrom() {
                u.initSelect(app.data.selectOption);
            }
        },
        registerEvent: function () {
            
        },
        init: function () {
            app.methods.initTable();
            app.methods.initFrom();
            app.registerEvent();
        }
    };
    app.init();
});