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

    action = {
        addOptions: function () {
            var options = {
                title: "【设备类型数据来源设备类型列表】",
                fromId: "#modifyForm form",
                url: `/${areaName}/${controllerName}/Ins`,
                //sendDataWhere: null,
                //isAddWhereExtend: "arbitrarily",
                //mainTable: app.data.tableIns,
                submit: "submit(fromAdd)"
            }
            return options;
        },
        addOptionsDesc: function () {
            var options = {
                title:"【设备部件数据来源设备部件信息】",
                fromId: "#modifyFormDesc form",
                url: `/${areaName}/${controllerName}/InsDesc`,
                content: $('#modifyFormDesc'),
                submit: "submit(fromAddDesc)"
            }
            return options;
        },

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

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

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

        queryOptions: function () {
            var options = {
                resetFrom: "form[lay-filter=listForm]",
                fromId: "listForm",
                urlExport: `/${areaName}/${controllerName}/Export`,
                urlQuery: `/${areaName}/${controllerName}/Load`,
                sendDataWhere:{},
                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();
        },
        addBeforeDesc: function (callBack) {
            $("#modifyFormDesc input[name=headKeys]").val(sendDataDescWhere.headKeys); 
            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();
        },
        editBeforeDesc: function (data, callBack) {
            if (data.isSystemDefault) {
                layer.alert("设备保养规则是系统默认规则的禁止编辑(可以删除后再新增操作)!", { icon: sysU.config.iconoError, shade: 0.4, time: sysU.config.errorTime });
                return false;
            }
            form.val("modifyFormDesc", data);
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

        editSaveBefore: function (data, callBack) {
            if (typeof data.field.isDefault == "undefined") data.field["isDefault"] = 'false';
            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);
            }
        },
        equipmentTypeCodeFromEvent: function (data) {
            let equipmentRuleName = $("#modifyForm input[name=equipmentRuleName]")
            if (equipmentRuleName.val() == "") {
                equipmentRuleName.val(data.text)
            }
        },

        //所有动作成功之后
        actionSuccess: (flag) => {
            var data  = null;
            if (flag.includes("Desc")) {
                data = sendDataDescWhere;
            }
            sysU.refreshTable(app, sysU, data, flag);
        },
        closeAfter: function (callBack) {
            if (callBack != null) callBack();
        }
    }

    app = {
        data: {
            cols: [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80, hide: true, title: "Id" },
                { field: "keys", width: 80, hide: true, title: "Keys" },
                { field: "equipmentRuleCode", width: 150, title: "保养规则编码", hide: true },
                { field: "equipmentRuleName", width: 200, title: "保养规则名称" },
                { field: "equipmentTypeCode", width: 150, title: "设备类型编码", hide: true },
                { field: "remark", width: 252, title: "备注" },

                { field: "createTime", width: 150, title: "创建时间" },
                { field: "createBy", width: 150, title: "创建人" },
                { field: "updateTime", width: 150, title: "修改时间" },
                { field: "updateBy", width: 150, title: "修改人" },
            ]],
            colsDesc:  [[
                { checkbox: true, fixed: true },
                { field: "id", width: 80, hide: true, title: "Id" },
                { field: "headKeys", width: 150, title: "主表keys", hide: true,},
                { field: "equipmentPartCode", width: 150, title: "设备部件编码", hide: true, },
                { field: "indicatorType", width: 150, title: "保养周期类型", hide: true },
                { field: "indicatorTypeName", width: 150, title: "保养类型名称", templet: function (d) { return GetDicLabel('indicatorType', 'DictValue', 'DictLabel', d.indicatorType) } },
                { field: "indicator", width: 150, title: "保养周期" },

                { field: "price", width: 150, title: "保养费用(元)" },

                { field: "warning", width: 300, title: "异常信息警告" },
                { field: "maintenanceContent", width: 300, title: "维保内容" },
                { field: "isSystemDefault", width: 150, title: "是否系统默认规则", templet: '#isSystemDefault' },

                { field: "createTime", width: 150, title: "创建时间" },
                { field: "createBy", width: 150, title: "创建人" },
                { field: "updateTime", width: 150, title: "修改时间" },
                { field: "updateBy", width: 150, title: "修改人" },
            ]], 
            tableIns: null,
            tableElem: "mainList",
            tableInsDesc: null,
            tableElemDesc: "mainListDesc",

            //下拉框配置
            selectOption: {
                 //设备部件
                equipmentPartCode: {
                    SelType: "FromUrl",
                    SelFrom: `/${areaName}/BaseEquipmentPart/Load`,
                    Where: { equipmentTypeCode: null, page: 1, limit: 200 },
                    SelLabel: "partName",
                    SelValue: "partCode",
                    Dom: [$("[name='equipmentPartCode']")],
                },
                //保养类型
                indicatorType: {
                    SelType: "FromDict",
                    SelFrom: "IndicatorType",
                    SelLabel: "DictLabel",
                    SelValue: "DictValue",
                    Dom: [$("[name='indicatorType']")]
                },
                //返回的数据 用于后续操作
                selectData: {

                }
            },

            //下拉框配置
            selectOptionHead: {
                //设备类型
                equipmentTypeCode: {
                    SelType: "FromUrl",
                    SelFrom: `/${areaName}/BaseEquipmentType/Load`,
                    Where: { page: 1, limit: 200 },
                    SelLabel: "name",
                    SelValue: "code",
                    Dom: [$("[name='equipmentTypeCode']")]
                },
                //返回的数据 用于后续操作
                selectData: {

                }
            },

            //下拉框配置枚举
            selectOptionEnum: {
                 type: {
                    SelValue: "value",     //key or value
                    SelFrom: "dataSource", //固定
                    Dom: [$("select[name='xxx']")],
                    dataSource: window.top.Enumxxx,
                },
                //返回的数据 用于后续操作
                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-46',
                    doneExtend: function (res, obj) {
                    
                    }
                }
                app.data.tableIns = sysU.initTable(options);
            },

            initTableDesc: function (obj) {
                //查询表单值
                sendDataDescWhere = form.val("listFormDesc");
                //主表附加设备值
                sendDataDescWhere["headKeys"] = obj.data.keys;  
                app.data.selectOption.equipmentPartCode.Where.equipmentTypeCode = obj.data.equipmentTypeCode;
                sysU.initSelect(app.data.selectOption);

                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);
                $("#tabMainListDesc").text(`明细【${obj.data.equipmentRuleName}】`);
            },


            initFrom() {
                //sysU.initSelecteByEnum(app.data.selectOptionEnum);

                sysU.initSelect(app.data.selectOptionHead);
            }
        },
        registerEvent: function () {

        },
        init: function () {
            //var sendDataWhere = form.val("listForm")
            app.methods.initTable();
            app.methods.initFrom();
            app.registerEvent();
        }
    };
    app.init();
});