WeldTechnology.js 15.3 KB

let action = null;
layui.config({
    base: "/js/",
    version: 1222
}).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 = "configure",
        tableName = "WeldTechnology",
        app = null;

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

        addOptionsDesc: function () {
            var options = {
                fromId: "#modifyFormDesc form",
                url: `/${areaName}/${tableName}/InsDesc`,
                content: $('#modifyFormDesc'),
                submit: "submit(fromAddDesc)"
            }

            return options;
        },

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

        editOptionsDesc: function () {
            var options = {
                fromId: "#modifyFormDesc form",
                url: `/${areaName}/${tableName}/UpdDesc`,
                content: $('#modifyFormDesc'),
                submit: "submit(fromUpdateDesc)"
            }
            return options;
        },

        deleteOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/DelByIds`,
                keyId: "id",
                titleConfirmDelete:"确定要删除所选信息吗(对应的明细数据也会删除)?"
            }
            return options;
        },

        deleteOptionsDesc: function () {
            var options = {
                url: `/${areaName}/${tableName}/DelByIdsDesc`,
                keyId: "id"
            }
            return options;
        },

        exportOptions: function () {
            var options = {
                fromId: "listForm",
                url: `/${areaName}/${tableName}/Export`,
                isDefault: true,
                excelCols: {
                    head: app.data.cols,
                    body: app.data.colsDesc
                }
            }
            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;
        },

        rowClickOptions: function () {
            var options = {
                isDefault: true,
                targetTableId: app.data.tableElem,
                tabfilter: "tableTabBody",
                tabId: 2,
                customFn: app.methods.initTableDesc
            }
            return options;
        },

        editBefore: function (data, callBack) {
            app.data.weldTechFileShow.attr("src", data.url),
            form.val("modifyForm", data);
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        editSaveBefore: function (data, callBack) {
            debugger;
            var formFile = new FormData();
            formFile.append("excelfile", app.data.weldTechFile[0].files[0]); 
            for (var key in data.field) {
                if (!Object.prototype.hasOwnProperty.call(data.field, key)) continue;
                formFile.append(key, data.field[key]); //加入文件对象
            }
            //图片是否修改
            formFile.append("isFileChange", app.data.isFileChange);
            var parm = action.editOptions();
            var ajaxConfig = {
                data: formFile,
                url: parm.url,
                cache: false,//上传文件无需缓存
                processData: false,//用于对data参数进行序列化处理 这里必须false
                contentType: false, //必须
                success: function (result) {
                    if (sysU.successBefore(result)) return;
                    layer.msg(result.Message, { icon: 6, shade: 0.4, time: 1500 });
                    if (action["actionSuccess"] !== undefined) action["actionSuccess"].call(null, "mainList");
                    setTimeout(() => { layer.closeAll(); }, 800);
                }
            };
            setTimeout(() => {
                sysU.ajax(ajaxConfig);
            }, 500);
            return false;
        },

        editBeforeDesc: function (data, callBack) {
            form.val("modifyFormDesc", data);
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addBefore: function (callBack) {
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addBeforeDesc: function (callBack) {
            $("input[name=TechnologyHeadId]").val(sendData.id);
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addSaveBefore: function (data, callBack) {
            debugger;
            var formFile = new FormData();
            formFile.append("excelfile", app.data.weldTechFile[0].files[0]); 
            for (var key in data.field) {
                if (Object.prototype.hasOwnProperty.call(data.field, key)) {
                    formFile.append(key, data.field[key]); //加入文件对象
                }
            }
            //图片是否修改
            formFile.append("isFileChange", app.data.isFileChange);
            var parm = action.addOptions();
            var ajaxConfig = {
                data: formFile,
                url: parm.url,
                cache: false,//上传文件无需缓存
                processData: false,//用于对data参数进行序列化处理 这里必须false
                contentType: false, //必须
                success: function (result) {
                    if (sysU.successBefore(result)) return;
                    layer.msg(result.Message, { icon: 6, shade: 0.4, time: 1500 });
                    if (action["actionSuccess"] !== undefined) action["actionSuccess"].call(null, "mainList");
                    setTimeout(() => { layer.closeAll(); }, 800);
                }
            };
            setTimeout(() => {
                sysU.ajax(ajaxConfig);
            }, 500);
            return false;
        },

        //所有动作成功之后
        actionSuccess: (flag) => {
            if ((flag == "delete" || flag == "deleteDesc") && sendData!=null) {
                app.data.tableInsDesc.config.where = sendData;
                app.data.tableInsDesc.config.page.curr = 1;
                app.data.tableInsDesc.reload("mainListDesc", {});

                app.data.tableIns.config.where = {};
                app.data.tableIns.config.page.curr = 1;
                app.data.tableIns.reload("mainList", {});
            } else if (flag.indexOf("Desc") > -1 && sendData != null) {
                app.data.tableInsDesc.config.where = sendData;
                app.data.tableInsDesc.config.page.curr = 1;
                app.data.tableInsDesc.reload("mainListDesc", {});
            } else {
                app.data.tableIns.config.where = {};
                app.data.tableIns.config.page.curr = 1;
                app.data.tableIns.reload("mainList", {});
            }
        }
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80,   title: "Id" },
                {
                    field: "center", width: 80, align: 'center',  title: "打印", templet: function (d)
                    {
                        var url = `/${areaName}/${tableName}/PrintView?id=` + d.id;
                        return `<a  href="${url}" data-href="${url}"  target="_blank" style="line-height: 21px;" class='layui-btn layui-btn-sm layui-btn-normal'>打印 </a>`;
                } },
                { field: "MaterialCode", width: 100,   title: "母材" },
                { field: "WeldingWire", width: 120,   title: "焊丝" },
                { field: "Diameter", width: 150,   title: "管径" },

                { field: "Thickness", width: 150,   title: "壁厚" },
                { field: "GrooveAngle", width: 150,   title: "坡口角度" },
                { field: "RootFace", width: 150,   title: "钝边" },
                { field: "Interval", width: 150,   title: "间隙" },
                { field: "ErrorVariable", width: 150,   title: "错边量" },

                { field: "PreheatingTemperature", width: 150,   title: "工件温度" },
                { field: "PreheatingTime", width: 150,   title: "工件工件时间" },
                { field: "InterlaminarTemperature", width: 150,   title: "层间温度" },
                { field: "TreatmentTemperature", width: 150,   title: "焊后热处理温度" },
                { field: "ProcessingTime", width: 150,   title: "焊后热处理时间" },

                { field: "ToolingSystem", width: 150,   title: "工装系统" },
                { field: "ToolingShapeAndSize", width: 150,   title: "工件外形及尺寸" },
                { field: "WeldingPowerSource", width: 150,   title: "焊接电源" },
                { field: "WeldingGunModel", width: 150,   title: "焊接型号" },
                { field: "WeldingBrand", width: 150,   title: "焊丝型牌号" },

                { field: "WeldingSpecs", width: 150,   title: "焊丝规格" },
                { field: "WeldingGas", width: 150,   title: "焊接气体" },
                { field: "WeldingPosition", width: 150,   title: "焊接位置" },
                { field: "WeldingDirection", width: 150,   title: "焊接方向" },
                { field: "WeldingStroke", width: 150,   title: "焊接行程" },

                { field: "ElectricCurrentForm", width: 150,   title: "电流形式" },
                { field: "CutputPolarity", width: 150,   title: "输出极性" },
                { field: "Remark", width: 150,   title: "备注" },
                { field: "Recorder", width: 150,   title: "记录员" },
                { field: "RecordingTime", width: 150,   title: "记录时间" },

                { field: "AuditBy", width: 150,   title: "校核" },
                { field: "AuditTime", width: 150,   title: "校核时间" },
                {
                    field: "fileName", width: 150, sort: true, event: 'fileEvent', fixed: false,  title: "图片", templet: function (d) {
                        if (d.url == "" || d.url == null) return "";
                        return `<a data-type="file" href="#" data-href="${d.url}" style="color: cornflowerblue;text-decoration: underline"> ${d.fileName}</a>`;
                    }
                },

                { field: "createTime", width: 150,   title: "建立时间" },
                { field: "createBy", width: 150,   title: "建立者" },
                { field: "updateTime", width: 150,   title: "更新时间" },
                { field: "updateBy", width: 150,   title: "更新者" }
            ]],
            colsDesc: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80,  hide: true, title: "Id" },
                { field: "TechnologyHeadId", width: 120,   title: "焊接工艺头ID" },
                { field: "Floor", width: 100,   title: "层道数" },
                { field: "ElectricCurrent", width: 120,   title: "电流" },
                { field: "WireFeederSpeed", width: 150,   title: "送丝速度" },
                { field: "Voltage", width: 150,   title: "电压" },

                { field: "WeldingSpeed", width: 150,   title: "焊接速度" },
                { field: "SwingSpeed", width: 150,   title: "摆动速度" },
                { field: "SwingWidth", width: 150,   title: "摆动宽度" },
                { field: "StopTime", width: 150,   title: "停留时间" },

                { field: "createTime", width: 150,  hide: true, title: "建立时间" },
                { field: "createBy", width: 150,  hide: true, title: "建立者" },
                { field: "updateTime", width: 150,  hide: true, title: "更新时间" },
                { field: "updateBy", width: 150,  hide: true, title: "更新者" }
            ]],
            urlTable: `/${areaName}/${tableName}/Load`,
            tableIns: null,
            tableInsDesc: null,
            tableElem: "mainList",
            tableElemDesc: "mainListDesc",
            weldTechFile: $("#weldTechFile"),
            weldTechFileShow: $("#weldTechFileShow"),
            isFileChange: false,

            selectOption: {
                //返回的数据 用于后续操作
                selectData: {

                }
            }
        },
        methods: {
            initTable: function (options) {
                var config = {};
                if (options != undefined) $.extend(config, options);
                let opt = {
                    cols: sysU.columnRecord(app.data.tableElem, app.data.cols),
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${tableName}/Load`,
                    toolbar: '#toolbarTable',
                    height: 'full-55',
                    where: config
                }
                app.data.tableIns = sysU.initTable(opt);
            },
            initTableDesc: function (obj) {
                sendData = { id: obj.data.id };
                let opt = {
                    cols: sysU.columnRecord(app.data.tableElemDesc, app.data.colsDesc),
                    elem: "#" + app.data.tableElemDesc,
                    url: `/${areaName}/${tableName}/LoadDesc`,
                    height: 'full-55',
                    toolbar: '#toolbarTableDesc',
                    limit: 0,
                    where: sendData
                }
                app.data.tableInsDesc = sysU.initTable(opt);
            },
            initFrom: function () {
                sysU.initSelect(app.data.selectOption);
            }
        },
        registerEvent: function () {

            //附件预览
            app.data.weldTechFile.on('change', function () {
                var filePath = $(this).val(),
                    fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase(),
                    src = window.URL.createObjectURL(this.files[0]); //转成可以在本地预览的格式
                if (!fileFormat.match(/.png|.jpg|.jpeg/)) {
                    error_prompt_alert('上传错误,文件格式必须为:png/jpg/jpeg');
                    return;
                } else {
                    app.data.weldTechFileShow.attr('src', src);
                }
                app.data.isFileChange = true;
            });
        },
        init: function () {
            app.methods.initTable();
            app.registerEvent();
            app.methods.initFrom();
        }
    };
    app.init();
})