BusEquipmentMaintainNotice.js 15.7 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 = null,
        sendDataDescWhere = null,
        areaName = "equipment",
        controllerName = "BusEquipmentMaintainNotice",
        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;
        },


        editOptionsDesc: function () {
            var options = {
                title: ",处理报警",
                fromId: "#modifyFormDesc form",
                url: `/${areaName}/${controllerName}/Upd`,
                content: $("#modifyFormDesc"),
                submit: "submit(fromUpdateDesc)"
            }
            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: { ProjectCode: sendDataWhereTree.projectCode, projectName: sendDataWhereTree.projectName },
                excelCols: {
                    head: app.data.cols,
                    body: app.data.colsDesc
                },
                ExcelExportFn: function (excelParm, result, toolbarId, callBackFn) {
                    debugger
                    result.Result.body.forEach(x => {
                        if (x.UserHandleTime == "0001-01-01 00:00:00") x.UserHandleTime = "";
                        x.errorduration = "".convertSecondsToTime(x.errorduration);
                        x.alarmMessage = x.alarmMessage + ";" + (x.remark == null ? "" : x.remark);

                        x.isHandled = x.isHandled ? "已处理" : "未处理";
                        x.isEnd = x.isEnd ? "已结束" : "未结束";
                    })
                    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: { ProjectCode: sendDataWhereTree.projectCode },
                mainTable: app.data.tableIns
            }
            return options;
        },
        queryOptionsDesc: function () {
            var options = {
                resetFrom: "form[lay-filter=listFormDesc]",
                fromId: "listFormDesc",
                urlQuery: `/${areaName}/${controllerName}/LoadDesc`,
                sendDataWhere: { topKeys: sendDataDescWhere.keys },
                mainTable: app.data.tableInsDesc,
            }
            return options;
        },
        //内部不支持异步
        uploadBeforeDesc: function (checkStatus, parm) {
            debugger
            if (checkStatus.data.length === 0) {
                layer.alert(`请选择一条数据后,再确认保养。当前选择的行数【${checkStatus.data.length}】条!`, { icon: sysU.config.iconoError, shadeClose: true, title: "错误信息" });
                return false;
            }
            form.val(parm.content[0].id, checkStatus.data[0]);
            return checkStatus.data[0] != undefined;
        },

        uploadOptionsDesc: function () {
            var options = {
                title: "保养确认 <span style=\"color:red;font-weight: bold;\">(上传附件时间可能比较久,请耐心等待...)</span>",
                area: ["500px", "350px"],
                url: `/${areaName}/${controllerName}/Import`,
                fromFile: "#excelfile",
                content: $("#ImportData")
            }
            return options;
        },
        uploadSaveBeforeDesc: function (dataObj,selectRow,callBack) {
            debugger
            var maintainTime = dataObj.formFile.get("maintainTime");
            if (maintainTime == "") {
                layer.close(dataObj.closeIndex);
                layer.alert(`确认保养:保养时间不能为空!`, { icon: sysU.config.iconoError, shadeClose: true, title: "错误信息" });
                return false
            }
            var maintainer = dataObj.formFile.get("maintainer");
            if (maintainer == "") {
                layer.close(dataObj.closeIndex);
                layer.alert(`确认保养:保养人不能为空!`, { icon: sysU.config.iconoError, shadeClose: true, title: "错误信息" });
                return false
            }
            if (callBack != null) callBack();
        },
        addBefore: function (callBack) {
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        addSaveBefore: function (data, callBack) {
            if (callBack != null) callBack();
        },
        editBeforeDesc: function (data, callBack) {
            form.val("modifyFormDesc", data);
            if (callBack != null) callBack();
        },
        editSaveBeforeDesc: function (data, callBack) {
            if (callBack != null) callBack();
        },

        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);
            }
        },
        rowClickOptions: function () {
            var options = {
                isDefault: true,
                targetTableId: app.data.tableElem,
                tabfilter: "tableTabBody",
                tabId: 2,
                customFn: app.methods.initTableDesc
            }
            return options;
        },

        //当前行表格双击事件处理
        customTableRowClick: function (obj, tableId) {
            if (tableId == app.data.tableElem) {
                rowData = obj.data;
            }
        },
        customTableCelClick: function (obj, tableId) {
            console.log(obj, tableId)
        },

        //所有动作成功之后
        actionSuccess: (flag) => {
            var sendData = { ProjectCode: sendDataWhereTree.projectCode }
            if (flag.indexOf(sysU.config.descSuffix) > -1) {
                sendData = { topKeys: sendDataDescWhere.keys }
            }
            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", noExel: true },
                { field: "keys", width: 80, hide: true, title: "keys", noExel: true },
                { field: "projectName", width: 210, title: "项目" },
                { field: "factoryName", width: 150, title: "厂房", noExel: true },
                { field: "equipmentCode", width: 240, title: "设备编号" },
                { field: "equipmentName", width: 220, title: "设备名称" },
                {
                    field: "count", width: 150, title: "待保养部件数", templet: function (d) {
                        if (d.count > 0) {
                            return `<span style='color:red;'>${d.count}</span>`
                        }
                        return d.count;
                    }
                },
            ]],
            colsDesc: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80, hide: true, title: "Id", noExel: true },
                { field: "topKeys", width: 80, hide: true, title: "topKeys", noExel: true },
                { field: "headKeys", width: 80, hide: true, title: "headKeys", noExel: true },
                { field: "equipmentCode", width: 200, title: "设备编号", hide: true },
                { field: "equipmentName", width: 200, title: "设备名称" },
                { field: "partCode", width: 100, title: "部件编码", hide: true },
                { field: "partName", width: 250, title: "部件名称" },
                { field: "lastMaintainTime", title: "上次保养时间", width: 200 },
                { field: "nextMaintainTime", title: "下次保养时间", width: 200},
                { field: "status", title: "保养状态", templet: '#MaintainStatus', width: 100 },
            ]],
            tableIns: null,
            tableElem: "mainList",
            tableInsDesc: null,
            tableElemDesc: "mainListDesc",

            tree: $("#tree"),
            treeObj: null,
            setting: {
                view: { selectedMulti: false },
                async: {
                    enable: true,
                    url: `/${areaName}/${controllerName}/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)

                        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: {
                selectFaultType: {
                    SelType: "FromDict",
                    SelFrom: `FaultType`,
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='FaultType']")]
                },
                selectHandling: {
                    SelType: "FromDict",
                    SelFrom: "Handling",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='Handling']")]
                },
                selectReason: {
                    SelType: "FromDict",
                    SelFrom: "Reason",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='Reason']")]
                },
                //返回的数据 用于后续操作
                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["topKeys"] = obj.data.keys;
                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.equipmentName}】设备部件列表`)
            },

            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.initFrom();
            app.methods.initTree();
            app.registerEvent();
        }
    };
    app.init();
});