SysFile.js 7.34 KB
let action = null;
let app = null;
let sendData = {
    equipmentTypeName: null,
    keys: null,
    equipmentTypeId: null,
};
layui.config({
    base: "/js/",
    version: 1
}).use(['system', 'ztree'], function () {
    var form = layui.form,
        $ = layui.jquery,
        system = layui.system,
        u = new system.u(),
        table = layui.table,
        sendDataDesc = null,
        rowData = null,

        areaName = "Base",
        controller = "SysFile";

    action = {

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

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

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

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

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

        uploadOptions: function () {
            var options = {
                area: ["600px", "500px"],
                url: `/${areaName}/${controller}/Import`,
                fromFile: "#File",
                content: $("#ImportData")
            }
            return options;
        },
        //内部不支持异步
        uploadBefore: function (checkStatus, parm) {
            var editFlagElement = $("#EditFlag");
            editFlagElement.val("false");
            //“True”代表编辑,反之新增
            if (checkStatus.data.length == 1) {
                form.val(parm.content[0].id, checkStatus.data[0]);
                editFlagElement.val("true");
            }
            $("#ImportData [name='EquipmentTypeId']").val(sendData.equipmentTypeId);
            $("#ImportData [name='EquipmentTypeName']").val(sendData.equipmentTypeName);
            return true;
        },
        uploadSaveBefore: function (formData, selectRow, callBack) {
            var fromValue = form.val(formData.parm.content[0].id);
            delete fromValue.File;
            var keys = Object.keys(fromValue);
            for (var item in keys) {
                if (!Object.prototype.hasOwnProperty.call(keys, item)) continue;
                var closName = keys[item],
                    val = fromValue[closName];
                formData.formFile.append(closName, val);
            }

            if (callBack != null) callBack();
        },

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

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "fileId", width: 100, title: "编码", hide: true },
                { field: 'fileName', width: 200, title: '文档名称' },
                /*{ field: 'Version', width: 100, title: '版本' },*/
                { field: 'size', width: 120, title: '文档大小' },
                { field: 'targetId', title: '适用的设备Id', hide: true },
                { field: 'EquipmentTypeName', width: 120, title: '适用的设备' },
                { field: 'suffix', width: 100, title: '文档类型' },
                { field: 'remark', width: 120, title: '备注' },
                { field: 'url', width: 120, title: '文件下载', },// templet: '#DownLoad'

                { field: 'createTime', width: 150, title: '创建时间' },
                { field: 'createdBy', width: 100, title: '创建人' },
                //{ field: 'Updated', width: 150, title: '更新时间' },
                //{ field: 'UpdatedBy', width: 100, title: '更新人' }
            ]],
            urlTable: `/${areaName}/${controller}/Load`,
            tableIns: null,
            tableInsDesc: null,

            tableElem: "mainList",

            tree: $("#tree"),
            treeObj: null,
            setting: {
                view: { selectedMulti: false },
                async: {
                    enable: true,
                    url: `/${areaName}/${controller}/GetTreeList`,
                    type: "get"
                },
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "keys",
                        pIdKey: "parentId",
                        rootPId: ""
                    }
                },
                callback: {
                    onClick: function (event, treeId, treeNode) {
                        sendData.equipmentTypeId = treeNode.id;
                        sendData.equipmentTypeName = treeNode.name;
                        app.methods.initTable({ targetId: sendData.equipmentTypeId });
                        app.methods.initTable({ EquipmentTypeName: sendData.equipmentTypeName });
                    },
                    onAsyncSuccess: function (event, treeId, treeNode, msg) {
                        app.data.treeObj.expandAll(true);
                    }
                }
            },
            selectOption: {
                //返回的数据 用于后续操作
                selectData: {
                    targetTableName:"api_feeding_list"
                }
            }
        },
        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,
                    height: 'full-0',
                    toolbar: '#toolbarTable',
                    where: config,
                    menuModule: controller
                }
                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);
            },
            initFrom() {
                u.initSelect(app.data.selectOption);
            },
        },
        registerEvent: function () {

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