Receipt.js 8.87 KB
let action = null;
layui.config({
    base: "/js/",
    version: 2
}).use(['system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        element = layui.element,
        table = layui.table,
        system = layui.system,
        sysU = new system.u(),
        sendData = null,
        areaName = "wo",
        controllerName = "WorkOrder",
        tableEdit = layui.tableEdit,
        app = null,
        aopTable = null;

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

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

        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${controllerName}/DelByIds`,
                keyId: "id"
            }
            return options;
        },

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

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

        uploadOptions: function () {
            var options = {
                url: `/${areaName}/${controllerName}/Import`,
                fromFile: "#excelfile",
                content: $("#ImportData")
            }
            return options;
        },

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

        btnSaveReceipt: function (sU, 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++) {
                //isEdit 是修改源码table.js新增的标记
                if (typeof allData[i].isEdit == "undefined") continue;
                var tempVal = {};
                for (var k = 0; k < validCosName.length; k++) {
                    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;
                        }
                    }
                    tempVal[field] = vaCos;
                    tempVal["id"] = allData[i]["id"];
                    tempVal["quantityRequired"] = allData[i]["quantityRequired"];
                    tempVal["qty"] = allData[i]["qty"];
                    tempVal["consumedQuantity"] = allData[i]["consumedQuantity"];
                }
                setData.push(tempVal);
            }

            if (setData.length == 0) {
                layer.alert("请编辑修改[收货数量]后在提交保存!", { icon: sysU.config.iconoError, shadeClose: true });
                return;
            }
            var ajaxConfig = {
                data: {
                    model: setData
                },
                url: `/${areaName}/${controllerName}/UpdReceipt`,
                success: function (result) {
                    if (sysU.successBefore(result)) return;
                    layer.msg(result.Message, { icon: sysU.config.iconoOk, shade: 0.4, time: sysU.config.msgOpenTimeLong });
                    table.reload(toolbarId);
                }
            };
            sysU.ajax(ajaxConfig);
        },

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

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true, hide: true, },
                { field: "id", width: 80, title: "Id" },
                { field: "workOrderCode", width: 150, title: "工单编码", totalRowText: '合计:' },
                { field: "oprSequenceCode", width: 150, title: "工序编码" },
                { field: "materialCode", width: 150, title: "物料编码" },
                { field: "materialName", width: 150, title: "物料名称" },
                { field: "quantityRequired", width: 80, title: "需求数量", totalRow: true, templet: '<span>{{ d.quantityRequired }}</span>' },
                {
                    field: "quantityReceived", width: 80, title: "收货数量", edit: "text", totalRow: true, templet: '<span>{{ d.quantityReceived }}</span>',
                    verifyConfig: {
                        empty: "req", msg: "列【收货数量】不能为空且只能是数字!,ID:", type: "number",
                    }
                },
                { field: "consumedQuantity", width: 80, title: "消耗数量", totalRow: true, templet: '<span>{{ d.consumedQuantity }}</span>' },
                { field: "qty", width: 80, title: "库存数量", totalRow: true, templet: '<span>{{ d.qty }}</span>' },
                { field: "whCode", width: 60, 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: {
                //station: {
                //    SelType: "FromUrl",
                //    SelFrom: `/${areaName}/${controllerName}/StationLineSelect`,
                //    SelLabel: "workStationName",
                //    SelValue: "workStationCode",
                //    OptGroup: true,
                //    Dom: [$("[name='stationCode']")]
                //},
                //返回的数据 用于后续操作
                selectData: {

                }
            }
        },
        methods: {
            initTable: function () {
                let options = {
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${controllerName}/LoadReceipt`,
                    cols: sysU.columnRecord(app.data.tableElem, app.data.cols),
                    toolbar: '#toolbarTable',
                    totalRow: true,
                    doneExtend: function () {
                        setTimeout(function () {
                            app.methods.initAopTable();
                        }, 1000);
                    }
                }
                app.data.tableIns = sysU.initTable(options);
            },

            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);
                });
            },

            initSelectTable: function () {

            },

            initFrom() {
                sysU.initSelect(app.data.selectOption);
            }
        },
        registerEvent: function () {

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