Line.js 9.12 KB

let action = null;
layui.config({
    base: "/js/",
    version: 55
}).use(['ztree', 'system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        table = layui.table,
        system = layui.system,
        u = new system.u(),
        sendData = {
            isok: null,
            workshopCode: null,
            workshopKey: null
        },
        areaName = "configure",
        tableName = "Line";

    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`,
                sendData: {
                    workshopCode: sendData.workshopCode == null ? 0 : sendData.workshopCode
                },
                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;
        },

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

        addBefore: function (callBack) {
            if (sendData.isok !== "true") {
                layer.alert("请选择车间节点新增线体", { icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
                return;
            }
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },
        addSaveBefore: function (data, callBack) {
            debugger
            if (sendData.isok !=="true") {
                layer.alert("请选择车间节点新增线体", { icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
                return;
            }
            if (sendData.workshopKey == "" || sendData.workshopKey == null) {
                layer.alert("线体新增:车间key不能为空!", { icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
                return;
            }
            if (sendData.workshopCode == "") {
                layer.alert("线体新增:车间编码不能为空!", { icon: u.config.iconoError, shade: 0.4, time: u.config.errorTime });
                return;
            }
            data.field.workshopCode = sendData.workshopCode;
            data.field.workshopKey = sendData.workshopKey;
            if (callBack != null) callBack();
        },
        qcCodePrintOptions: () => {
            var options = {
                qrCodeValueKey: "lineCode",
                //【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].lineName}</label>
                                             </div>
                                             <div class="qcCode_lable">
                                                <label>车间名称:</label><label>${selectData[i].workshopName}</label>
                                             </div>
                                          </div>`;
                        sysU.qRCodeWirtDom(parameter, qrcodeElem, qrcodeId, qcCodeValue);
                    }
                    return true;
                }
            }
            return options;
        },
        //所有动作成功之后
        actionSuccess: (falg) => {
            debugger
            u.refreshTable(app, u, null, falg, function () {
                app.methods.initTable({ workshopCode: sendData.workshopCode });
            });
        }
    }

    var app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80,  hide: true, title: "id" },
                { field: "workshopName", width: 160, sort: false, fixed: false,  title: "车间名称", noExel: true },
                { field: "lineCode", width: 100,   title: "线体代号" },
                { field: "lineName", width: 200,   title: "线体名称" },
                { field: 'otherCode', width: 120, title: '外部编码' },

                { field: "workshopId", width: 150,  hide: true, title: "车间id" },
                { field: "workshopKey", width: 150,  hide: true, title: "车间key" },
                { field: "lineKey", width: 150,  hide: true, title: "线体key" },
                { field: "createTime", width: 150,   title: "建立时间" },
                { field: "createBy", width: 150,   title: "建立者" },
                { field: "updateTime", width: 150,   title: "更新时间" },
                { field: "updateBy", width: 150,   title: "更新者" }
            ]],
            urlTable: `/${areaName}/${tableName}/Load`,
            tableIns: null,
            tableElem: "mainList",

            tree: $("#tree"),
            treeObj: null,
            setting: {
                view: { selectedMulti: false },
                async: {
                    enable: true,
                    url: `/${areaName}/${tableName}/GetTreeList`,
                    type: "get"
                },
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "keys",
                        pIdKey: "parentId",
                        rootPId: ""
                    }
                },
                callback: {
                    onClick: function (event, treeId, treeNode) {
                        debugger
                        sendData.isok = treeNode.isok;
                        sendData.workshopCode = treeNode.workShopCode;
                        sendData.workshopKey = treeNode.keys;
                        if (sendData.isok === "true") {
                            app.methods.initTable({ workshopCode: sendData.workshopCode });
                        }
                    },
                    onAsyncSuccess: function (event, treeId, treeNode, msg) {
                        app.data.treeObj.expandAll(true);
                    }
                }
            }
        },
        methods: {
            initTable: function (options) {
                var config = {};
                if (options != undefined) $.extend(config, options);
                let opt = {
                    cols: u.columnRecord(app.data.tableElem, app.data.cols),
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${tableName}/Load`,
                    toolbar: '#toolbarTable',
                    where: config
                }
                app.data.tableIns = u.initTable(opt);
            },
            initTree: function () {
                setTimeout(()=> {
                    app.data.treeObj = $.fn.zTree.init(app.data.tree, app.data.setting);
                    app.data.tree.height($("div.layui-table-view").height() - 20);
                }, 50);
            }
        },
        registerEvent: function () {
        },
        init: function () {
            app.methods.initTable();
            app.methods.initTree();
            app.registerEvent();
        }
    };
    app.init();
})