var UserList = function () { this.OpenStatus = null; this.CloseStatus = null; this.DeleteUser = null; this.userSearch = null; this.selRoleCat = null; this.PageController = null; } //初始化方法 UserList.prototype.init = function () { var _this = this, _d = this.d; this.OpenStatus = this.$("OpenStatus"); this.CloseStatus = this.$("CloseStatus"); this.DeleteUser = this.$("DeleteUser"); this.userSearch = this.$("userSearch"); this.selRoleCat = this.$("selRoleCat"); this.bindEvent(_d); this.PageController = new Pager(); this.PageController.init(); this.PageController.BindGoPageEvent(function (pageIndex) { window.location.href = "/BackEnd/UserMgr/List/" + pageIndex + "" }); //在table绑定链接 $("#DataList").click(function (e) { if (e.target.tagName == "A" && e.target.getAttribute('name') == "OpenStatus") { var p = e.target; if (p != null) { var f = p.getAttribute('aID'); _this.OpenState(f); } } }); //在table绑定链接 $("#DataList").click(function (e) { if (e.target.tagName == "A" && e.target.getAttribute('name') == "CloseStatus") { var p = e.target; if (p != null) { var f = p.getAttribute('aID'); _this.CloseState(f); } } }); } UserList.prototype.bindEvent = function (d) { var _this = this; //执行删除 _this.DeleteUser.click(function (e) { var p = e.target.parentNode.parentNode; if (p != null) { if (confirm("您确定要删除此产品吗??")) { _this.DoDelete(p.getAttribute('id')); } } }); } //启用该用户 UserList.prototype.OpenState = function (tt) { var _this = this; var aj = 1; var postData = {}; postData["state"] = 0; postData["userID"] = tt; if (aj == 1) { aj = 0; $.ajax({ type: "post", url: "/UserMgr/ModifyUserState", dataType: 'json', data: postData, success: function (x) { if (x) { if (x.code) { if ("ok" === x.code || "OK" === x.code) { alert(x.msg); $("#DataList td[icq=/'" + tt + "/']").html("启用"); $("#DataList td[itt=/'" + tt + "/']").html(" <a name=CloseStatus href=JavaScript:void() aID=" + tt + ">禁用</a>"); return false; } else { alert(x.msg); return false; } } } }, complete: function () { aj = 1; } }); return false; } } //彻底删除该用户 UserList.prototype.DoDelete = function (dto) { var _this = this; var aj = 1; var postData = {}; postData["userID"] = dto if (aj == 1) { aj = 0; $.ajax({ type: "post", url: "/UserMgr/DeleteCurrentUser", dataType: 'json', data: postData, success: function (x) { if (x) { if (x.code) { if ("ok" === x.code || "OK" === x.code) { $("#DataList tr[id=/'" + dto + "/']").remove(); return false; } else { alert(x.msg); return false; } } } }, complete: function () { aj = 1; } }); return false; } } //禁用该用户 UserList.prototype.CloseState = function (tt) { var _this = this; var aj = 1; var postData = {}; postData["userID"] = tt; postData["state"] = 1; if (aj == 1) { aj = 0; $.ajax({ type: "post", url: "/UserMgr/ModifyUserState", dataType: 'json', data: postData, success: function (x) { if (x) { if (x.code) { if ("ok" === x.code || "OK" === x.code) { alert(x.msg); $("#DataList td[icq=/'" + tt + "/']").html("禁用"); $("#DataList td[itt=/'" + tt + "/']").html(" <a name='OpenStatus' href='JavaScript:void()' aID=" + tt + ">启用</a>"); return false; } else { alert(x.msg); return false; } } } }, complete: function () { aj = 1; } }); return false; } } //获得控件对象 UserList.prototype.$ = function (componentName) { return $('[name="' + componentName + '"]') } var userList = new UserList(); userList.init();