123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298 |
- /**
- * 用户管理
- *
- */
- $.namespace("user.main");
- user.main.init = function() {
- //把form传入,构造翻页控件
- pageinfo($("#userform"));
- }
- user.main.search = function() {
- //console.log($("#userform").serialize());
- //console.log($("#currentpage").val());
- $("#currentpage").val(1);
- $("#userform").submit();
- }
- user.main.isNotBlank=function(value){
- if(typeof(value)!='undefined'){
- value=value+"";
- for(var i=0; i<value.length; i++) {
- var c = value.charAt(i);
- if ((c!=' ')&&(c!='\n')&&(c!='\t')) return true;
- }
- }
- return false;
- }
- user.main.deluser = function(data,logindata) {
- if(data==logindata){
- $.alert({
- title : '提示',
- content : '不能删除当前登录用户',
- confirm : function() {
- }
- });
- }else{
- $.confirm({
- title : '确认框',
- content : '删除会导致其分配的角色也会删除,确认删除吗',
- confirm : function() {
- $.post($.app + "/user/deluser.html", {
- id : data
- }, function(data) {
-
- var message="";
- var success=false;
- if(data&&data.jsonInfo){
- console.log(data.jsonInfo);
- if(data.jsonInfo.isfail||data.jsonInfo.userIdisNull){
- message="提交参数错误";
- }else if(!data.jsonInfo.userexist){
- message="用户不存在";
- }else{
- for(var n in data){
- if(n=='jsonInfo'){
- continue;
- }
-
- var d=data[n];
- if(typeof(d.success)=="boolean"&&!d.success&&user.main.isNotBlank(d.sysname)){
- message=message+d.sysname+"、";
- }
- }
-
- if(!user.main.isNotBlank(message)){
- success=true;
- message="同步成功";
- }else{
- message=message.substring(0, message.length-1)+"同步失败"
- }
- }
- }
- $.alert({
- title : '提示',
- content : message,
- confirm : function() {
- /*
- if (data.success) {
- location.href = $.app + "/user/querylist.html";
- }
- */
- if(success){
- location.href = $.app + "/user/querylist.html";
- }
-
- }
- });
-
-
- /*
- if (data.success) {
- $.alert({
- title : '提示',
- content : '删除成功',
- confirm : function() {
- location.href = $.app + "/user/querylist.html";
- }
- });
- } else {
- $.alert({
- title : '提示',
- content : data.message,
- confirm : function() {
- }
- });
- }*/
- }, "json");
- },
- cancel : function() {
- }
- });
- }
- }
- user.main.edit = function(data) {
- $("#adduserName").attr("disabled",true);
- $.post(basePath + "/user/edit.html", {
- id : data
- }, function(data) {
- $("#htitle").html('用户修改');
- if (data) {
- for ( var a in data) {
- if ($("#add" + a)) {
- $("#add" + a).val(data[a]);
- }
- }
- }
- }, "json");
- }
- //增加用户
- user.main.adduser = function() {
- var id=$("#addid").val();
- var adduname=$("#adduname").val();
- if(adduname==''){
- $.alert({
- title : '提示',
- content : '姓名不能为空'
- });
- return;
- }
- var adduserName=$("#adduserName").val();
- if(adduserName==''){
- $.alert({
- title : '提示',
- content : '登录名不能为空'
- });
- return;
- }
- if(id!=null&&id!=""){
- //alert($("#addform").serialize())
- $.ajax({
- url : $.app + "/user/saveuser.html",
- data : $("#addform").serialize(),
- dataType : "json",
- type : "post",
- dataType : "json",
- success : function(data) {//ajax返回的数据
- if (data.success) {
- $.confirm({
- title : '提示',
- content : '修改成功,是否分配角色',
- confirm : function() {
- location.href = $.app + "/user/userrole.html?id="+data.attrs.id;
- },
- cancel : function() {
- location.href = $.app + "/user/querylist.html";
- }
- });
- } else {
- $.alert({
- title : '提示',
- content : data.message,
- confirm : function() {
- }
- });
- }
- }
- });
- }else{
- $.ajax({
- url : $.app + "/user/saveuser.html",
- data : $("#addform").serialize(),
- dataType : "json",
- type : "post",
- dataType : "json",
- success : function(data) {//ajax返回的数据
- if (data.success) {
- $.alert({
- title : '提示',
- content : '保存成功,请分配角色!',
- confirm : function() {
- location.href = $.app + "/user/userrole.html?id="+data.attrs.id;
- }
- });
- } else {
- $.alert({
- title : '提示',
- content : data.message,
- confirm : function() {
- }
- });
- }
- }
- });
-
- }
- };
- user.main.repsw = function(data) {
- $.confirm({
- title : '确认框',
- content : '确认重置密码吗',
- confirm : function() {
- $.post(basePath + "/user/repsw.html", {
- id : data
- }, function(data) {
-
- var message="";
- var success=false;
- if(data&&data.jsonInfo){
- console.log(data.jsonInfo);
- if(data.jsonInfo.isfail||data.jsonInfo.userIdisNull){
- message="提交参数错误";
- }else if(data.jsonInfo.passWordisNull){
- message="密码不能为空";
- }else if(!data.jsonInfo.userexist){
- message="用户不存在";
- }else{
- for(var n in data){
- if(n=='jsonInfo'){
- continue;
- }
-
- var d=data[n];
- if(typeof(d.success)=="boolean"&&!d.success&&user.main.isNotBlank(d.sysname)){
- message=message+d.sysname+"、";
- }
- }
-
- if(!user.main.isNotBlank(message)){
- success=true;
- message="同步成功";
- }else{
- message=message.substring(0, message.length-1)+"同步失败"
- }
- }
- }
- $.alert({
- title : '提示',
- content : message,
- confirm : function() {
-
- }
- });
-
- /*
- if (data.success) {
- $.alert({
- title : '提示',
- content : '重置成功',
- });
- } else {
- $.alert({
- title : '提示',
- content : data.message,
- confirm : function() {
- }
- });
- }*/
- }, "json");
- }
- });
- };
- user.main.clear = function() {
- $("#adduserName").attr("disabled",false);
- $("#htitle").html('用户新增');
- $("#adduname").val("");
- $("#adduserName").val("");
- }
- user.main.fprole = function(data) {
- location.href = $.app + "/user/userrole.html?id=" + data;
- }
|