Factory.js 4.36 KB
let action = null;

layui.config({
    base: "/js/",
    version: 111
}).use(['system'], function () {
    var form = layui.form,
        $ = layui.jquery,
        system = layui.system,
        u = new system.u(),
        areaName = 'configure',
        tableName = 'Factory';

    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:"factoryKey"
            }
            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`,
                fromFile: "#excelfile",
                content: $("#ImportData")
            }
            return options;
        },

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

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

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

        //所有动作成功之后
        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: 'factoryKey', width: 80,  hide: true, title: 'factoryKey' },
                
                { field: 'factoryCode', width: 120,  title: '工厂代号', noExel: true },
                { field: 'factoryName', width: 200, title: '工厂名称' },
                { field: 'otherCode', width: 120, title: '外部编码' },

                { field: 'name', width: 200,  title: '集团名称', noExel: true },
                { field: 'address', width: 250,  title: '地址' },
                { field: 'telephone', width: 120,  title: '电话' },

                { field: 'companyGroup', width: 10,  hide: true, title: '集团' },
                { field: 'createTime', width: 150,  title: '建立时间' },
                { field: 'createBy', width: 100,  title: '建立者' },
                { field: 'updateTime', width: 150,  title: '更新时间' },
                { field: 'updateBy', width: 100,  title: '更新者' }
            ]],
            tableIns: null,
            tableElem:"mainList"
        },
        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);
            }
        },
        registerEvent: function () {

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