busequipmentalarmhandle.js 13.5 KB
let action = null;
let sendDataWhereTree = {
    projectKeys: null,
    projectName: null,
    projectCode: null
},
 ztreeProjectData = null;

layui.config({
    base: "/js/",
    version: 1
}).use(['system', 'ztree'], function () {
    var form = layui.form,
        $ = layui.jquery,
        element = layui.element,
        table = layui.table,
        system = layui.system,
        sysU = new system.u(),
        sendDataWhere = { handleUser: null },
        sendDataDescWhere = null,
        areaName = "equipment",
        controllerName = "BusEquipmentAlarmHandle",
        app = null;

    action = {
        addOptions: function () {
            var options = {
                fromId: "#modifyForm form",
                url: `/${areaName}/${controllerName}/Ins`,
                //sendDataWhere: null,
                //isAddWhereExtend: "arbitrarily",
                //mainTable: app.data.tableIns,
                submit: "submit(fromAdd)"
            }
            return options;
        },

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

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

        exportOptions: function () {
            var options = {
                fromId: "listForm",
                url: `/${areaName}/${controllerName}/Export`,
                isDefault: true,
                sendDataWhere: { handleUser: sendDataWhere.handleUser, projectName: sendDataWhereTree.projectName, ProjectCode: sendDataWhereTree.projectCode },
                excelCols: {
                    head: app.data.cols,
                    body: app.data.colsDesc
                }, ExcelExportFn: function (excelParm, result, toolbarId, callBackFn) {
                    debugger
                    callBackFn(excelParm, result, toolbarId);
                }
            }
            return options;
        },

        queryOptions: function () {
            var options = {
                resetFrom: "form[lay-filter=listForm]",
                fromId: "listForm",
                urlExport: `/${areaName}/${controllerName}/Export`,
                urlQuery: `/${areaName}/${controllerName}/Load`,
                sendDataWhere: { handleUser: sendDataWhere.handleUser },
                mainTable: app.data.tableIns
            }
            return options;
        },
        queryOptionsDesc: function () {
            var options = {
                resetFrom: "form[lay-filter=listFormDesc]",
                fromId: "listFormDesc",
                urlQuery: `/${areaName}/${controllerName}/LoadDesc`,
                sendDataWhere: { equipmentCode: sendDataDescWhere.equipmentCode },
                mainTable: app.data.tableInsDesc,
            }
            return options;
        },

        rowClickOptions: function () {
            var options = {
                //是否主子表
                isDefault: true,
                targetTableId: app.data.tableElem,
                tabfilter: "tableTabBody",
                tabId: 2,
                customFn: app.methods.initTableDesc
            }
            return options;
        },

        uploadOptions: function () {
            var options = {
                url: `/${areaName}/${controllerName}/Import`,
                fromFile: "#excelfile",
                content: $("#ImportData")
            }
            return options;
        },
        addBefore: function (callBack) {
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },
        editBefore: function (data, callBack) {
            //data.enable = data.enable.toString();
            form.val("modifyForm", data);
            if (callBack != null) callBack();
        },
        editSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },
        //处理人 选择
        handleUserFromEvent: function (data) {
            var val = data.text + `【${data.value}】`;
            if (val.indexOf("-请选择") > -1) val = "";
            sendDataWhere.handleUser = val;
        },
        checkboxMethod: function (obj) {
            var page = "".GetUrlParam("page"),
                xxx = "".GetUrlParam("xxx");
            if (page == "xxx") {
                var sendData = {
                    
                };
                var ajaxConfig = {
                    data: sendData,
                    url: `${areaName}/${controllerName}/xxx`,
                    success: function (result) {
                        if (sysU.successBefore(result)) return false;
                        layer.msg(result.Message);
                    }
                };
                sysU.ajax(ajaxConfig);
            }
        },
        //所有动作成功之后
        actionSuccess: (flag) => {
            var sendData = { ProjectCode: sendDataWhereTree.projectCode }
            if (flag.indexOf(sysU.config.descSuffix) > -1) {
                sendData = { equipmentCode: sendDataWhereTree.equipmentCode }
            }
            sysU.refreshTable(app, sysU, sendData, flag);
        },
        closeAfter: function (callBack) {
            if (callBack != null) callBack();
        }
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80, hide: true, title: "Id", hide: true, noExel: true },
                { field: "projectName", width: 220, title: "项目名称" },
                { field: "equipmentCode", width: 230, title: "设备编码" },
                { field: "equipmentName", width: 220, title: "设备名称" },
                { field: "countNum", width: 200, title: "已处理报警记录数量" },
            ]],
            colsDesc: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80, hide: true, title: "Id", hide: true, noExel: true },
                { field: "equipmentAlarmRecordId", width: 100, title: "报警记录编号", hide: true },
                { field: "equipmentCode", width: 150, title: "设备编号", hide: true },
                { field: "equipmentName", width: 150, title: "设备名称", hide: true },
                { field: "alarmMessage", width: 250, title: "报警信息" },
                { field: "faultType", width: 100, title: "故障分类" },

                { field: "createTime", width: 150, title: "报警发生时间" },
                { field: "handleInfo", width: 150, title: "处理记录" },
                { field: "handleUser", width: 150, title: "处理人" },
                { field: "UserHandleTime", width: 150, title: "处理时间" },
                { field: "reason", width: 100, title: "原因方" },

                { field: "createBy", width: 150, title: "createBy", hide: true },
                { field: "updateTime", width: 150, title: "updateTime", hide: true, noExel: true },
                { field: "updateBy", width: 150, title: "updateBy", hide: true, noExel: true },
            ]],

            tableIns: null,
            tableElem: "mainList",
            tableInsDesc: null,
            tableElemDesc: "mainListDesc",

            tree: $("#tree"),
            treeObj: null,
            setting: {
                view: { selectedMulti: false },
                async: {
                    enable: true,
                    url: `/equipment/DaqEquipmentAlarmRecord/GetTreeList`,
                    type: "get"
                },
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "keys",
                        pIdKey: "parentId",
                        rootPId: ""
                    }
                },
                callback: {
                    onClick: function (event, treeId, treeNode) {
                        sendDataWhereTree.projectKeys = treeNode.projectKeys;
                        sendDataWhereTree.projectCode = treeNode.keys;
                        sendDataWhereTree.projectName = treeNode.name;
                        app.methods.initTable(sendDataWhereTree);
                        element.tabChange(action.rowClickOptions().tabfilter, 1)
                        if (app.data.tableInsDesc != null) layui.table.reload(app.data.tableElemDesc, { url: '', data: [] })  
                        $("#eqMsgDetail").text(`设备报警处理记录`)
                    },
                    onAsyncSuccess: function (event, treeId, treeNode, msg) {
                        app.data.treeObj.expandAll(true);
                        $("#tree_2_a").click()
                        ztreeProjectData = JSON.parse(msg)
                    }
                }
            },

            //下拉框配置
            selectOption: {
                selectHandleUser: {
                    SelType: "FromDict",
                    SelFrom: "AlarmHandlePeople",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    isFirstSelected: false,
                    Dom: [$("[name='handleUser']")]
                },
                //返回的数据 用于后续操作
                selectData: {

                }
            },
        },
        methods: {
            initTable: function (opt) {
                var config = {};
                if (opt != undefined) $.extend(config, opt);
                let options = {
                    elem: "#" + app.data.tableElem,
                    url: `/${areaName}/${controllerName}/Load`,
                    cols: sysU.columnRecord(app.data.tableElem, app.data.cols),
                    toolbar: '#toolbarTable',
                    where: config, 
                    height: "full-50",//如果是主明细页签,列表主体高度要设置,否则分页导航不直观展示
                    doneExtend: function (res, obj) {
                        setTimeout(() => {
                            app.data.tree.height($("div.layui-table-view").height() - 8);
                        }, 50);
                    }
                }
                app.data.tableIns = sysU.initTable(options);
            },

            initTableDesc: function (obj) {
                //查询表单值
                sendDataDescWhere = form.val("listFormDesc");
                //主表附加设备值
                sendDataDescWhere["equipmentCode"] = obj.data.equipmentCode;
                let opt = {
                    cols: sysU.columnRecord(app.data.tableElemDesc, app.data.colsDesc),
                    elem: "#" + app.data.tableElemDesc,
                    url: `/${areaName}/${controllerName}/LoadDesc`,
                    height: 'full-50',
                    toolbar: '#toolbarTableDesc',
                    menuModule: controllerName,
                    areaMenus: 2,
                    where: sendDataDescWhere
                }
                app.data.tableInsDesc = sysU.initTable(opt);
                $("#eqMsgDetail").text(`【${obj.data.projectName}, ${obj.data.equipmentName}】设备报警处理记录`)
            },

            initSelectTable: function () {
              var opt1 = {
                    elem: ".productCode",
                    checkedKey: "productCode",
                    doneKey: {
                        key: "productCode",
                        lableValue: "productName"
                    },
                    searchKey: "productCode",
                    searchName: "产品编码"
                };
               sysU.initSelectProduct(opt1);
            },

            initTree: function () {
                app.data.treeObj = $.fn.zTree.init(app.data.tree, app.data.setting);
            },
            //树节点查询,目前树结构只有一级 所以不需要提供查询
            filterNodes: function (list, searchText) {
                var filterList = [];
                list.forEach((ele) => {
                    if (ele.name.indexOf(searchText) > -1) {
                        filterList.push(ele);
                    }
                });
                return filterList;
            },
            //项目树搜索
            queryProject(searchText) {
                let setting = "".copyObj2(app.data.setting)
                delete setting.async;
                var data = app.methods.filterNodes(ztreeProjectData, searchText)
                $.fn.zTree.init(app.data.tree, setting, data);
                if (data.length > 0) {
                    app.data.treeObj.expandAll(true);
                    var ele = "tree_1_a";
                    if (data.length == ztreeProjectData.length) ele = "tree_2_a";
                    $("#" + ele).click()
                }
            },

            initFrom() {
                sysU.initSelect(app.data.selectOption);
                sysU.tabClick("tableTabBody");
            }
        },
        registerEvent: function () {
            $("#queryProjectCode").bind('input propertychange', function () {
                if (app.data.treeObj == null) return;
                var searchText = $(this).val();
                app.methods.queryProject(searchText);
            })
        },
        init: function () {
            //var sendDataWhere = form.val("listForm")
            app.methods.initTree();
            app.methods.initFrom();
            app.registerEvent();
        }
    };
    app.init();
});