function signalViewModel(account, name, personid, RYXZ, DbFactory) { var that = this; this.count = 0; //人员性质 this.RYXZ = RYXZ; //本地数据库对象 this.DbFactory = DbFactory; ///消息数 this.Notify = []; //账户 this.Account = account; //登录名 this.Name = name; //人员ID this.PersonId = personid; //登录的集成代理类 this.LoginProxy = $.connection.LoginHub; //初始化连接服务器成功后调用 //this.LoginProxy.client.connectedSuccess = function (connectId) { // ZLPMS.Msg('成功获取到在线用户信息'); //} //所有用户登录成功更新数量 this.LoginProxy.client.userLoginCallback = function (cnt) { $("#onlineUser").text(cnt); } //提示断线 $.connection.hub.disconnected(function () { alert("服务已断开连接,请刷新网页!") //if (that.count <= 3) { // debugger // setTimeout(function () { // that.count++ // that.register() // }, 2000); //} }) //尝试重连 //$.connection.hub.reconnecting(function () { // that.register() //}); //接收服务器新消息 this.LoginProxy.client.newMessage = function (msg) { that.showNotification(msg); layer.open({ offset: 'rb', title: false, area: '200px', shade: 0, type: 1, content: '
' + msg + '
', icon: 1, anim: 2 //btn: '知道了', //yes: function(index){ // layer.close(index); //} }); } //被踢下线 this.LoginProxy.client.offline = function () { alert('您的账号在其它客户端登录,被强制下线'); window.onbeforeunload = function (e) { }; ZLPMS.Loading3('正在退出...'); window.location.href = "/Account/Login"; //$.ajax({ // type: "post", // url: "/Admin/Permissions/LoginHandler.ashx?tag=Logout", // data: null, // dataType: "text", // success: function (data, textStatus) { // G_SYSTEM_EXIT = true; // window.location.href = "/Account/Login"; // }, // error: function (XMLHttpRequest, textStatus, errorThrown) { // //DuiFn.MsgAlert(XMLHttpRequest.statusText); // }, // complete: function (XHR, TS) { // G_SYSTEM_EXIT = true; // } //}); } //返回用户列表(json) this.LoginProxy.client.users = function (json) { var html = '' + n.UserName + '
'; }); html += "' + message + '
', icon: 1, anim: 2, id:'OpenMessage' }); } this.GetNotify = function () { DbFactory.get("Notify", function (data) { data = data.Value; that.Notify = data; for (var i in data) { var nof = data[i]; if (i < 5) $("#Notify").append("" + nof.Message + "
"); } if (data.length > 0) $("#NotifyCount").append("" + data.length + ""); }) } this.AddNotify = function (message, ProblemId,Type) { $("#Notify").empty(); $('#NotifyCount').find('.badge').remove(); var Img = that.GetIcon(Type); that.Notify.unshift({ rowId: that.GetId(4), Message: message, id: ProblemId, Img: Img }); for (var i in that.Notify) { var nof = that.Notify[i]; if(i<5) $("#Notify").append("" + nof.Message + "
"); } if (that.Notify.length > 0) $("#NotifyCount").append("" + that.Notify.length + ""); that.DbFactory.save({ id: "Notify", Value: that.Notify }) } this.RemovedNotify = function (rowId) { $("#Notify").empty(); $('#NotifyCount').find('.badge').remove(); for (var i in that.Notify) { if (that.Notify[i].rowId == rowId) { that.Notify.splice(i, 1); break; } } for (var i in that.Notify) { var nof = that.Notify[i]; if (i < 5) $("#Notify").append("" + nof.Message + "
"); } if (that.Notify.length > 0) $("#NotifyCount").append("" + that.Notify.length + ""); that.DbFactory.save({ id: "Notify", Value: that.Notify }) } //清除所有消息 $("#message-Clear").bind('click', function () { $("#Notify").empty(); $('#NotifyCount').find('.badge').remove(); that.Notify = []; }) this.GetIcon = function (Type) { var Icon; switch (Type) { case 0: Icon = "/Content/Images/Problem/xin.png"; break; case 1: Icon = "/Content/Images/Problem/zhipai.png"; break; case 2: Icon = "/Content/Images/Problem/jiejue.png"; break; case 3: Icon = "/Content/Images/Problem/huitui.png"; break; case 4: Icon = "/Content/Images/Problem/zhongzhi.png"; break; case 5: Icon = "/Content/Images/Problem/tijiao.png"; break; case 6: Icon = "/Content/Images/Problem/daishouli.png"; break; case 7: Icon = "/Content/Images/Problem/daichuli.png"; break; default: Icon = "/Content/Images/Problem/xin.png" } return Icon; } this.GetTime = function (Time) { var sdate = new Date(Time); var now = new Date(); var days = now.getTime() - sdate.getTime(); var day = parseInt(days / (1000 * 60 * 60)); if (day < 1) { day = parseInt(day * 60) + "分钟前"; } else if (day < 24) { day = day + "小时前"; } else if (48 > day > 24) { day = "昨天"; } else { day = parseInt(day / 24) + '天' + '前'; } return day; } this.GetId=function(n){ var res = ''; for (; res.length < n; res += Math.random().toString(36).substr(2).toUpperCase()) { } return res.substr(0, n); } //处理问题 this.DealProblem=function (showAtt, IsSupport,ProblemId) { //是否为技术支持处理 IsSupport = IsSupport || 0; //受理问题 var receiveProblem = function (title,HJID) { var index = top.ZLPMS.Loading3(2); //受理问题 $.ajax({ url: '/Support/ReceiveProblem', data: { id: ProblemId }, method: 'post', success: function (data) { top.ZLPMS.UnLoading(index); var url = "/Problem/ProductionPdeal?id=" + ProblemId + "&showAtt=" + showAtt + '&workflowid=' + HJID + '&IsSupport=' + IsSupport; //成功后调用 if (data.code == 200) { top.ZLPMS.OpenNewWindow("处理问题:" + title, url, '1000px', '640px', function () { //回调用刷新(只有确定后才刷新) }); } else {//显示具体原因,并提示是否强制处理 top.ZLPMS.Confirm('该问题已被他人受理,您确定要继续处理吗?', 3, function (idx) { top.ZLPMS.CloseWindow(idx); top.ZLPMS.OpenNewWindow("处理问题", url, '1000px', '640px'); }) } } }); }; $.post('/Problem/GetProblemById/' + ProblemId, function (data) { var row = data[0]; if (row) { /*已关闭的问题,已解决的问题,已受理的问题, 不需要处理*/ if (row.是否终止 == 1) { top.ZLPMS.Msg('已终止的问题不需要再处理!'); return; } if (row.是否解决 == 1) { top.ZLPMS.Msg('已解决的问题不需要再处理!'); return; } if (row.环节ID > 3 && that.RYXZ != '1') { top.ZLPMS.Msg('非本部人员不能处理技术支持与研发处理环节问题,仅能查阅!'); return; } if (row.环节ID == 3 && (that.RYXZ == '3' || that.RYXZ == '4' || that.RYXZ == '5')) {//客户,机构管理员,卫计委人员无法处理项目问题 top.ZLPMS.Msg('客户,机构管理员,卫计委人员无法处理项目问题,仅能查阅!'); return; } //打开处理窗口 receiveProblem(row.编号, row.环节ID); } else {//提醒用户没有选择问题记录 top.ZLPMS.Msg('没有选择需要处理的问题记录,请选择后再处理!'); } }) } //获取公告 this.LoginProxy.client.GetNotice = function () { $.get("/Notice/PanDuanIsShow", function (data) { if (data == "True") { //显示公告通知 top.ZLPMS.OpenNewWindow("公告通知", "/Notice/Notice_Window", "850px", "555px") } }) } //超时推送 this.OverTimePush = function () { //受理超时 $.post("/Problem/GetAcceptOverTime", function (data) { if (data && data.length > 0) { that.AddNotifyMuti("问题待受理已超时,请注意受理",data,6); } //处理超时 $.post("/Problem/GetDealOverTime", function (data2) { if (data2 && data2.length > 0) { that.AddNotifyMuti("问题处理已超时,请注意解决", data2, 7); } }); }) } this.AddNotifyMuti = function (message, ProblemIds, Type) { $("#Notify").empty(); $('#NotifyCount').find('.badge').remove(); var Img = that.GetIcon(Type); outer: for (var t in ProblemIds) { var Problem = ProblemIds[t].ID; var ProblemNum = ProblemIds[t].编号; //如果消息里面存在,则不添加 inter: for (var i in that.Notify) { if (that.Notify[i].id == Problem) { continue outer; } } that.Notify.unshift({ rowId: that.GetId(4), Message: "编号【" + ProblemNum + "】" + message, id: Problem, Img: Img }); } for (var i in that.Notify) { var nof = that.Notify[i]; if (i < 5) $("#Notify").append("" + nof.Message + "
"); } if (that.Notify.length > 0) $("#NotifyCount").append("" + that.Notify.length + ""); } }