BusEquipmentMaintainRule.js 11.5 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 = null,
        areaName = "equipment",
        controllerName = "BusEquipmentMaintainRule",
        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;
        },
        addOptionsDesc: function () {
            var options = {
                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) {
            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) {
            form.val("modifyFormDesc", data);
            //callBack是回调函数,如果editBefore有ajax 放在成功之后
            if (callBack != null) callBack();
        },

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

        //所有动作成功之后
        actionSuccess: (flag) => {
           sysU.refreshTable(app, sysU, null, 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: 150, title: "保养规则名称" },
                { field: "equipmentTypeCode", width: 150, title: "设备类型编码", hide: true },
                { field: "remark", width: 150, 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: "price", width: 150, title: "保养费用" },
                { field: "indicator", width: 150, title: "保养周期" },
                { field: "indicatorType", width: 150, title: "保养周期类型" },
                { field: "warning", width: 150, title: "异常信息警告" },
                { field: "maintenanceContent", width: 150, title: "维保内容" },
                { field: "isDefault", width: 150, title: "是否系统默认" },

                { 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: {
                selectEquipmentTypeCode: {
                    SelType: "FromUrl",
                    SelFrom: `/${areaName}/BaseEquipmentType/Load`,
                    //SelModel:"EquipmentTypeName",
                    SelLabel: "name",
                    SelValue: "code",
                    Dom: [$("[name='equipmentTypeCode']")],
                    isFirstSelected: false
                },
                //返回的数据 用于后续操作
                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;
                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);
            },

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

            initFrom() {
                sysU.initSelect(app.data.selectOption);

                //sysU.initSelecteByEnum(app.data.selectOptionEnum);
            }
        },
        registerEvent: function () {

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