sysuser.js 6.49 KB

let action = null;
let app = null;
layui.config({
    base: "/js/",
    version: 33
}).use(['ztree', 'droptree', 'system' , "jqprint"], function () {
    var form = layui.form,
        $ = layui.jquery,
        system = layui.system,
        u = new system.u(),
        layuimini = layui,
        areaName = "",
        tableName = "SysUser";

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

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

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

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

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

        uploadOptions: function () {
            var options = {
                url: `/${tableName}/Import`
            }
            return options;
        },

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

        editSaveBefore: function (dataLayuiFrom, callBack) {
            dataLayuiFrom.field.Disable = dataLayuiFrom.field.Disable == "1" ? true : false;
            if (callBack != null) callBack();
        },

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

        addSaveBefore: function (data, callBack) {
            data.field.Disable = data.field.Disable == "1" ? true : false;
            if (callBack != null) callBack();
        },

        qcCodePrintOptions: () => {
            var options = {
                qrCodeValueKey: "UserCode",
                //【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].UserName}</label>
                                             </div>
                                             <div class="qcCode_lable">
                                                <label>电话:</label><label>${selectData[i].Phone}</label>
                                             </div>
                                          </div>`;
                        sysU.qRCodeWirtDom(parameter, qrcodeElem, qrcodeId, qcCodeValue);
                    }
                    return true;
                }
            }
            return options;
        },

        //所有动作成功之后
        actionSuccess: (falg, toolbarId) => {
            if (falg === "add" || falg === "edit" || falg === "delete" || falg === "upload") {
                //app.methods.initTable();
            } else if (falg === "refresh") {
                //app.data.tableIns.config.page.curr = 1;
                //app.data.tableIns.reload("mainList", {});
            }
        }
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "Id", width: 80, hide: true, title: "Id" },
                { field: "UserCode", width: 150, title: "账号" },
                { field: "UserName", width: 150, title: "用户名" },
                { field: "Phone", width: 150, title: "电话" },
                { field: "Disable", width: 150, title: "是否禁用", templet: (d) => { return "".GetState(window.top.EnumIsDisable, d.Disable) } },

                { field: 'Created', width: 150, title: '创建时间' },
                { field: "CreatedBy", width: 150, title: "创建人" },
                { field: "Updated", width: 150, title: "更新时间" },
                { field: "UpdatedBy", width: 150, title: "更新人" }
            ]],
            urlTable: `/${tableName}/Load`,
            tableIns: null,
            tableElem: "mainList"
        },
        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: app.data.urlTable,
                    toolbar: '#toolbarTable',
                    where: config,
                    menuModule: tableName
                }
                app.data.tableIns = u.initTable(opt);
            },
            initTree: function () {
                layuimini.droptree('/SysRole/GetAllRole', "#MenuRole", "#MenuRoles");
            }
        },
        registerEvent: function () {

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