basesim.js 13.9 KB
//const { debug } = require("console");
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 = "base",
        controllerName = "BaseSim",
        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",
                //deleteCount:1
            }
            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;
        },

        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) {
            typeof data.field.isVirtual == "undefined" ? data.field["isVirtual"] = false : data.field["isVirtual"] = true;
            if (callBack != null) callBack();
        },
        editBefore: function (data, callBack) {
            //data.enable = data.enable.toString();
            app.methods.initSelectTable();
            form.val("modifyForm", data);
            $("input[name=accountNumber").attr("ts-selected", data.accountNumber);
            if (callBack != null) callBack();
        },
        editSaveBefore: function (data, callBack) {
            if (typeof data.field.isDelete == "undefined") data.field["isDelete"] = "0";
            typeof data.field.isVirtual == "undefined" ? data.field["isVirtual"] = false : data.field["isVirtual"] = true;
            if (callBack != null) callBack();
        },

        btnBindEquipment: function () {
            var checkStatus = table.checkStatus('mainList'),
                data = checkStatus.data;
            if (data.length != 1) {
                layer.msg(`请选择要关联设备的Sim卡!`);
                return;
            }

            var url = `/equipment/BaseEquipment/Index?menuFlag=-2&selectColKeyCustom=simNumber&page=BaseSim&simNumber=${data[0].simNumber}`;//menuFlag=-2 菜单隐藏
            sysU.openPage({
                title: "为SIM卡【" + data[0].simNumber + "】绑定设备<span style='color:red;'>(一张sim卡可绑定最多250台设备)</span>",
                area: ["1100px", "600px"],
                type: 2,
                content: url
            })
        },

        //领卡:补充SIM卡信息(领卡时间和调试时间、网关客户)
        btnUseSim: function (sU, toolbarId, obj) {
            $("#AddUseSimForm form")[0].reset();
            var checkStatus = table.checkStatus(toolbarId),
                data = checkStatus.data;
            if (data.length != 1) {
                layer.msg(`请选择要领用的一张SIM卡!`);
                return;
            }

            if (data.length == 1) {
                $('#getCardDate').val(data[0].getCardDate);
                $('#debugDate').val(data[0].debugDate);
                $('#gatewayClient').val(data[0].gatewayClient);
                $('#getCardUser').val(data[0].getCardUser);
                $('#gatewaySerialNumber').val(data[0].gatewaySerialNumber);
                $('#gatewayKey').val(data[0].gatewayKey);
                $('#vpnNumber').val(data[0].vpnNumber);
                $('#vpnKey').val(data[0].vpnKey);

            }
            layer.open({
                type: 1,
                title: `领卡<span style="color:red">(绑定网关、VPN,提供领卡、调试日期和网关客户信息)</span>`,
                content: $("#AddUseSimForm"),
                area: ['700px', '400px'],
                btn: ['保存', '关闭'],
                yes: function (index, layero) {

                    
                    // 获取所有带有 lay-verify="required" 属性的 input 控件
                    var requiredInputs = document.querySelectorAll('#AddUseSimForm input[lay-verify="required"]');
                    
                    // 遍历所有 required 输入框
                    for (var i = 0; i < requiredInputs.length; i++) {
                        var input = requiredInputs[i];

                        // 检查输入框的值是否为空
                        if (input.value.trim() === '') {
                            // 如果为空,可以执行相应的操作,例如:
                            //alert('请填写 ' + input.name + ' 字段!');
                            layer.msg("必填项不能为空", { icon: 2, shift: 6 });
                            input.focus(); // 将焦点设置到该输入框
                            return false; // 返回 false 阻止表单提交
                        }
                    }


                    var sendData = {
                        id: data[0].id,
                        simKey: data[0].simKey,
                        getCardDate: $('#getCardDate').val(),
                        getCardUser: $('#getCardUser').val(),
                        debugDate: $('#debugDate').val(),
                        gatewayClient: $('#gatewayClient').val(),
                        vpnKey: $('#vpnKey').val(),
                        gatewayKey:$('#gatewayKey').val()
                    };
                    var ajaxConfig = {
                        data: sendData,
                        url: `/${areaName}/${controllerName}/UseSim`,
                        success: function (result) {
                            if (sysU.successBefore(result)) return;
                            layer.close(index);
                            if (action["actionSuccess"] !== undefined) action["actionSuccess"].call(null, "xxx", toolbarId);
                        }
                    };
                    sysU.ajax(ajaxConfig);
                }
            });

        },

        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) => {
            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: "simId", width: 80, hide: true, title: "卡号" },
                { field: "simKey", width: 80, hide: true, title: "simKey" },
                { field: "simNumber", width: 180, title: "ICCID码" },
                { field: "simIP", width: 150, title: "IP地址" },

                { field: "suppliersInfo", width: 250, title: "供应商" },
                { field: "factoryDate", width: 150, title: "出厂日期" },
                { field: "isUse", width: 150, title: "是否领用", templet:"#isSysUseTemplet" },
                { field: "isDelete", width: 150, title: "状态", templet: "#isSysDeleteTemplet" },
                { field: "isVirtual", width: 150, title: "是否是虚拟卡", templet: "#isSysVirtualTemplet" },

                { field: "gatewayClient", width: 150, title: "网关客户" },
                { field: "getCardUser", width: 100, title: "领卡人" },
                { field: "getCardDate", width: 150, title: "领卡时间" },
                { field: "debugDate", width: 150, title: "调试时间" },
                { field: "simRemark", width: 150, title: "备注" },

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

            //下拉框配置
            selectOption: {
                //station: {
                //    SelType: "FromUrl",
                //    SelFrom: `/${areaName}/${controllerName}/StationLineSelect`,
                //    SelLabel: "workStationName",
                //    SelValue: "workStationCode",
                //    OptGroup: true,
                //    Dom: [$("[name='stationCode']")]
                //},
                //返回的数据 用于后续操作
                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-56",//如果是主明细页签,列表主体高度要设置,否则分页导航不直观展示
                    doneExtend: function (res, obj) {
                    }
                }
                app.data.tableIns = sysU.initTable(options);
            },

            initSelectTable: function () {

            },

            initFrom() {
                sysU.initSelect(app.data.selectOption);
                sysU.initSelecteByEnum(app.data.selectOptionEnum);
                //绑定VPN时,调用弹出VPN列表
                var opt1 = {
                    elem: "#vpnNumber",
                    checkedKey: "vpnNumber",
                    doneKey: {
                        key: "vpnNumber"
                    },
                    searchKey: "vpnNumber",
                    doneExtend: function (elem, data, $nowElem) {
                        var res = data.data;
                        if (res.length != 1) {
                            layer.msg("请选择一个要绑定的VPN账号");
                            $("#vpnNumber").val("")
                            return;
                        }
                        $("#vpnKey").val(res[0].vpnKey)
                    }
                };
                sysU.initVpnList(opt1);

                var opt2 = {
                    elem: "#gatewaySerialNumber",
                    checkedKey: "gatewaySerialNumber",
                    doneKey: {
                        key: "gatewaySerialNumber"
                    },
                    searchKey: "gatewaySerialNumber",
                    doneExtend: function (elem, data, $nowElem) {
                        var res = data.data;
                        if (res.length != 1) {
                            layer.msg("请选择一个要绑定的网关账号");
                            $("#gatewaySerialNumber").val("")
                            return;
                        }
                        $("#gatewayKey").val(res[0].gatewayKey)
                    }
                };
                sysU.initGatewayList(opt2);
            }
        },
        registerEvent: function () {

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