zoukankan      html  css  js  c++  java
  • 典型的js页面

    var myurl;
    var mydata;
    var postype = "POST";
    var getype = "GET";
    var jsontype = "json";
    var htmltype = "html";
    var contentype = "application/json; charset=utf-8";
    
    //----------------------------  初始化  ---------------------------------
    $(function () {
        //TODO:这个电场名称是?
        var dotype = getQueryString("dotype");
        var zhanbh = getQueryString("zhanbh");
        bindWarnType(); //绑定站告警类型select
        bindZhanMc(); //绑定站名称select
        bindZhanYxBh(dotype); //绑定桩运行编号select
        zhanname_onchanged(); //站名称和站运行编号联动
        setDateTime(dotype); //设置起始时间和结束时间(如果从当日实时告警点[更多]链接进来,开始、结束时间默认当日)
        realTimeWarnQuery(); //初始化datagrid
        //如果进入具体场站,仅显示当前场站告警信息(此时,场站名称不可选择)
        setDom(zhanbh);
        bindDoTypeAndQuery(dotype); //根据type绑定处理方式(如果从当日实时告警点[待灭警数量]链接进来,处理结果默认条件为“等待灭警”  )
    });
    /**
    * *设置datagrid对象
    **/
    var dgObj = {
        url: '../../WebService/WarnRecService.ashx',
        queryParams: { action: 'findbytelesignallingwarn2', warnType: '', zhanBh: '', yunXinBh: '', kssj: '', jssj: '', clfs: '' },
        fit: true,
        pagination: true,
        pageSize: 20,
        singleSelect: true,
        border: false,
        striped: true,
        toolbar: "#tb",
        columns: [[
            { field: 'Id', hidden: true },
            { field: 'CodeName', title: '类型', align: 'center',  100 },
            { field: 'OccurDt', title: '时间', align: 'center',  150 },
            { field: 'ZhanJc', title: '场站名称', align: 'center',  150 },
            { field: 'YunXing_Bh', title: '桩运行编号', align: 'center',  113 },
            { field: 'LogDesc', title: '内容', align: 'center',  340 },
            {
                field: 'ProcessFlag',
                title: '处理情况',
                 60,
                align: 'center',
                formatter: function (value, row, index) {
                    var str = "";
                    switch (row.ProcessFlag) {
                        case 0:
                            str = "<a href='#' onclick='OffPolice_click("" + row.Id + "")' class='easyui-linkbutton' plain='true' title='' iconcls='icon-cancel'></a>";
                            break;
                        case 1:
                        case 2:
                            str = "<a href='#' class='easyui-linkbutton' plain='true' title='' iconcls='icon-ok'></a>";
                            break;
                        default:
                    }
                    return str;
                }
            },
            {
                field: 'content',
                title: '处理方式',
                align: 'center',
                 100,
                formatter: function (value, row, index) {
                    var str = row.ProcessFlag;
                    switch (str) {
                        case 0:
                            str = "未处理";
                            break;
                        case 1:
                            str = "自动灭警";
                            break;
                        case 2:
                            str = "手动灭警";
                            break;
                        default:
                    }
                    return str;
                }
            }
        ]],
        onLoadSuccess: function () {
            $($('#dg').datagrid("getPanel")).find('a.easyui-linkbutton').linkbutton();
        }
    };
    
    //----------------------------  页面方法  ---------------------------------
    /*
    * *根据type绑定处理方式
    */
    function bindDoTypeAndQuery(type) {
        if (type == "0") {
            $("#sel-dotype").val(type);
            btn_query();
        } else if (type == "more") {
            btn_query();
        }
    }
    
    /*
    * *如果进入具体场站,仅显示当前场站告警信息(此时,场站名称不可选择)
    */
    function setDom(zhanbh) {
        if (zhanbh.length != 0) {
            $("#sel-zhanname").val(zhanbh);
            $("#sel-zhanname").attr("disabled", true);
            myurl = "../../WebService/WarnRecService.ashx";
            mydata = { action: 'getxunxingbh', zhanBh: zhanBh };
            ajaxData();
        }
    }
    
    /*
    * 获取url参数值
    */
    function getQueryString(name) {
        var url = location.href;
        var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
        var paraObj = {};
        for (var i = 0; j = paraString[i]; i++) {
            paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
        }
        var returnValue = paraObj[name.toLowerCase()];
        if (typeof (returnValue) == "undefined") {
            return "";
        } else {
            return returnValue;
        }
    }
    
    /**
    * *初始化datagrid
    **/
    function realTimeWarnQuery() {
        var kssj = $("#begintime").val();
        var jssj = $("#endtime").val();
        dgObj.queryParams.kssj = kssj;
        dgObj.queryParams.jssj = jssj;
        $('#dg').datagrid(dgObj);
    }
    
    /**
    * *设置起始时间和结束时间
    **/
    function setDateTime(type) {
        var date = new Date();
        var months = new Array("01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12");
        var year = date.getFullYear();
        var month = months[date.getMonth()];
        var day = "01";
        switch (type) {
            case "0":
                $("#begintime").val(year + "-" + month + "-" + day);
                day = date.getDate();
                $("#endtime").val(year + "-" + month + "-" + day);
                break;
            case "more":
                day = date.getDate();
                $("#begintime").val(year + "-" + month + "-" + day);
                $("#endtime").val(year + "-" + month + "-" + day);
                break;
            case "":
                $("#begintime").val(year + "-" + month + "-" + day);
                day = date.getDate();
                $("#endtime").val(year + "-" + month + "-" + day);
                break;
    
            default:
        }
    
    }
    
    /**
    * *绑定站告警类型select
    **/
    function bindWarnType() {
        myurl = "../../WebService/WarnRecService.ashx";
        mydata = { action: 'GetWarnType' };
        ajaxData();
    }
    
    /**
    * *绑定桩运行编号select
    **/
    function bindZhanYxBh(type) {
        $("#sel-yunxingbh").empty();
        $("#sel-yunxingbh").append("<option value=''>—请选择—</option>");
    }
    
    /**
    * *ajax成功返回
    * *绑定站告警类型select
    **/
    function ajaxSuccess_bindWarnType(data) {
        if (data.Rows.length <= 0 || data == null) {
            return false;
        }
        $("#sel-warntype").empty();
        var l = data.Rows.length;
        $("#sel-warntype").append("<option value=''>—请选择—</option>");
        for (var i = 0; i < l; i++) {
            $("#sel-warntype").append("<option value='" + data.Rows[i].Code + "'>" + data.Rows[i].Codename + "</option>");
        }
        return true;
    }
    
    /**
    * *绑定站名称select
    **/
    function bindZhanMc(zhanbh) {
        myurl = "../../WebService/WarnRecService.ashx";
        mydata = { action: 'getzhanmc' };
        ajaxData();
    }
    
    /**
    * *ajax成功返回
    * *绑定站名称select
    **/
    function ajaxSuccess_bindZhanMc(data) {
        if (data.Rows.length <= 0 || data == null) {
            return false;
        }
        $("#sel-zhanname").empty();
        var l = data.Rows.length;
        $("#sel-zhanname").append("<option value=''>—请选择—</option>");
        for (var i = 0; i < l; i++) {
            $("#sel-zhanname").append("<option value='" + data.Rows[i].Zhan_Bh + "'>" + data.Rows[i].Zhan_Jc + "</option>");
        }
        return true;
    }
    
    //----------------------------  页面事件  ---------------------------------
    
    /**
    * *保存告警处理界面
    **/
    function btn_ok() {
        var clcz = $("[name=r_gjcl]:checked").val();
        if (clcz == 1) {
            myurl = "../../WebService/WarnRecService.ashx";
            mydata = {
                action: "offPolice",
                warnid: $("#hidd_warnid").val()
            };
            ajaxData();
        }
        btn_close();
        return false;
    }
    
    /**
    * *告警处理ajax成功时调用的方法
    **/
    function ajaxSuccess_btn_ok(data) {
        switch (data.Status) {
            case 0:
                parent.messager("提示", data.Msg);
                break;
            case 1:
                $('#dg').datagrid("reload");
                break;
    
            default:
        }
    }
    
    /**
    * *关闭告警处理界面
    **/
    function btn_close() {
        $('#dlg').dialog('close');
    }
    
    
    /**
    * *打开告警处理界面
    **/
    function OffPolice_click(warnid) {
        $("#hidd_warnid").val("");
        $("#dlg").dialog("open");
        $("[name=r_gjcl]").eq(0).attr("checked", true);
        $("#hidd_warnid").val(warnid);
    }
    
    /**
    * *站名称和站运行编号联动
    **/
    function zhanname_onchanged() {
        $("#sel-zhanname").change(function () {
            var zhanBh = $("#sel-zhanname").val();
            if (zhanBh.length == 0) {
                bindZhanYxBh();
                return false;
            }
            myurl = "../../WebService/WarnRecService.ashx";
            mydata = { action: 'getxunxingbh', zhanBh: zhanBh };
            ajaxData();
            return true;
        });
    }
    
    /**
    * *ajax成功返回
    * *绑定运行编号select
    **/
    function ajaxSuccess_bindXunXinBh(data) {
        if (data.Rows.length <= 0 || data == null) {
            return false;
        }
        $("#sel-yunxingbh").empty();
        var l = data.Rows.length;
        $("#sel-yunxingbh").append("<option value=''>—请选择—</option>");
        for (var i = 0; i < l; i++) {
            if (data.Rows[i].YUNXING_BH == null) {
                continue;
            }
            $("#sel-yunxingbh").append("<option value='" + data.Rows[i].YUNXING_BH + "'>" + data.Rows[i].YUNXING_BH + "</option>");
        }
        return true;
    }
    
    /**
    * *点击查询
    **/
    function btn_query() {
        var warntype = $("#sel-warntype").val(); var zhanBh = $("#sel-zhanname").val(); var yunXinbh = $("#sel-yunxingbh").val();
        var kssj = $("#begintime").val(); var jssj = $("#endtime").val(); var clfs = $("#sel-dotype").val();
        dgObj.queryParams.warnType = warntype;
        dgObj.queryParams.zhanBh = zhanBh;
        dgObj.queryParams.yunXinBh = yunXinbh;
        dgObj.queryParams.kssj = kssj;
        dgObj.queryParams.jssj = jssj;
        dgObj.queryParams.clfs = clfs;
        $('#dg').datagrid(dgObj);
    }
    
    //----------------------------  ajax方法  ---------------------------------
    
    /**
    * *ajax增删改查方法
    **/
    function ajaxData() {
    
        $.ajax({
            url: myurl,
            type: postype,
            async: false,
            data: mydata,
            dataType: jsontype,
            success: serviceSuccess,
            error: serviceError
        });
    }
    
    /**
    * *ajax成功时返回resultObject是json数据
    **/
    function serviceSuccess(resultObject) {
        if (resultObject == null) {
            return true;
        }
        switch (resultObject.Status) {
            case 0:
            case 2:
                parent.messager("提示", resultObject.Msg);
                break;
            case 1:
                eval(resultObject.JsExecuteMethod + "(resultObject)");
                break;
            default:
        }
        return true;
    }
    
    /**
    * *ajax失败时返回
    **/
    function serviceError(result) {
        return false;
    }
  • 相关阅读:
    【JAVA基础&Python】静态方法与单例模式,以及应用场景
    【JAVA基础】static的定义
    【JAVA基础&Python】类与对象的继承
    MD的编辑器汇总
    Oracle 学习笔记(二)
    安装Jieba 库出现错误解总结
    (十五)-前端 -项目总结
    (八)-前端-DOM基础
    (十四)-前端-面试-项目相关
    (十三)- 前端-面试-REACT
  • 原文地址:https://www.cnblogs.com/zhangwei595806165/p/3325678.html
Copyright © 2011-2022 走看看