SysCompany.js 4.43 KB
let action = null;

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

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

        uploadOptions: function () {
            var options = {
                url: `/${areaName}/${tableName}/Import`,
                fromFile: "#excelfile",
                selectRow:"true",
                content: $("#ImportData")
            }
            return options;
        },
 
        queryOptions: function () {
            var options = {
                resetFrom:"form[lay-filter=listForm]",
                fromId: "listForm",
                urlQuery: `/${areaName}/${tableName}/Load`,
                mainTable: app.data.tableIns
            }
            return options;
        },

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

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

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

        uploadBefore: function (formData, callBack) {

        },
        uploadSaveBefore: function (formData, selectRow, callBack) {
            debugger
            formData.append("position", $("#position").val());
            formData.append("targetId", selectRow.data[0].companyId);
            if (callBack != null) callBack();
        },
        

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

    var app = {
        data: {
            cols:[[
                { checkbox: true, fixed: true },
                { field: 'companyId', width: 80,  hide: true, title: 'companyId' },
                { field: 'name', width: 320,  title: '公司名称', noExel: true },
                { field: 'telephone', width: 180,  title: '联系电话', noExel: true },
                { field: 'ver', width: 150,  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',
                    doneExtend: function (res) {
                        var addBtn = $("a[lay-event=btnAdd]");
                        var deleteBtn = $("a[lay-event=btnDelete]");
                        if (res.code === 0 || res.Result.length > 0) {
                            addBtn.hide();
                            deleteBtn.hide();
                        } else {
                            addBtn.show();
                            deleteBtn.show();
                        }
                    }
                } 
                app.data.tableIns = u.initTable(options);
            }
        },
        registerEvent: function () {

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