Browse Source

再次登陆,刷新咨询列表功能

dell 8 years ago
parent
commit
ba5488afc6
2 changed files with 196 additions and 156 deletions
  1. 36 2
      app/js/consult.js
  2. 160 154
      app/js/login.js

+ 36 - 2
app/js/consult.js

@ -8,17 +8,41 @@ var otypeval = document.getElementById("typeval");//咨询类型
8 8
var ostateval = document.getElementById("stateval");//咨询状态
9 9
var osortval = document.getElementById("sortval");//时间排序
10 10
11
mui.plusReady(function() {
12
	var self = plus.webview.currentWebview();
13
	console.log('当前咨询列表页id==='+self.id);
14
})
15
11 16
12 17
mui.init({
13 18
    pullRefresh: {
14
        container: '#zixunpullrefresh',
19
    	container: '#zixunpullrefresh',
20
    	/*down: {
21
        	auto: true,
22
		    contentdown : "下拉可以刷新",
23
		    contentover : "释放立即刷新",
24
		    contentrefresh : "正在刷新...",
25
            callback: pulldownRefresh
26
       },*/
15 27
        up: {
16 28
            contentrefresh: '正在加载...',
17
           
18 29
            callback: pullupRefresh
19 30
        }
20 31
    }
21 32
});
33
 /**
34
 * 下拉刷新具体业务实现
35
 */
36
function pulldownRefresh() {
37
    pageIndex = 1;
38
    console.log('下拉刷新');
39
    //table.innerHTML = '';
40
    setTimeout(function() {
41
        getaData();
42
        mui('#zixunpullrefresh').pullRefresh().endPulldownToRefresh();
43
        mui('#zixunpullrefresh').pullRefresh().refresh(true);
44
    }, 1000);
45
}
22 46
23 47
//上拉加载具体业务实现
24 48
function pullupRefresh() {
@ -123,11 +147,21 @@ function getaData() {
123 147
            error: function(xhr, type, errerThrown) {
124 148
                mui.toast('网络异常,请稍候再试');
125 149
                plus.nativeUI.closeWaiting(); 
150
                mui('#zixunpullrefresh').pullRefresh().endPullupToRefresh(true);
126 151
            }
127 152
        });
128 153
    });
129 154
};
130 155
156
/*重新登陆,咨询列表数据刷新*/
157
window.addEventListener('relogin', function(event) {
158
//	alert('重新登陆')
159
	userId = event.detail.id;
160
	console.log(userId);
161
	initdata();
162
});
163
164
131 165
initdata();
132 166
/*第一次加载数据*/
133 167
function initdata() {

+ 160 - 154
app/js/login.js

@ -1,155 +1,161 @@
1
//登录
2
mui.ready(function() {
3

4
	/*定义全局变量*/
5
	var reg = document.getElementById("reg");
6
	var login = document.getElementById("login");
7
	var userName = document.getElementById("username");
8
	var userPassword = document.getElementById("password");
9
	var forgetPassword = document.getElementById("forgetPassword");
10

11
	mui.plusReady(function() {
12
		
13
        /*点击注册按钮*/
14
		reg.addEventListener("tap", function() {
15
			goRegFun();
16
		})
17
		
18
		/*点击忘记密码按钮*/
19
		forgetPassword.addEventListener("tap", function() {
20
			mui.openWindow({
21
				url: '../html/findpwd-phone.html',
22
				id: '../html/findpwd-phone.html',
23
				show: {
24
					aniShow: "slide-in-right"
25
				}
26
			});
27
		})
28

29
		/*校验登录按钮显示状态*/
30
		mui('.frmbox').on('keyup', "#username,#password", function() {
31
			hideButtn(userName,userPassword,login,"frmactiveok");
32
		});
33
		
34
		/*登录按钮*/
35
		login.addEventListener('tap', function() {
36
			userVal()
37
		})
38

39
		
40
		/*校验用户账号*/
41
		function userVal() {
42
			var gunf = /^\w+@\w+\.((cn)|(com)|(com\.cn))$/;
43
			var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
44
			if(hunPhone.test(userName.value)) {
45
				userRegisterOk();
46
			} else if(gunf.test(userName.value)) {
47
				userRegisterOk();
48
			} else {
49
				plus.nativeUI.toast("请输入正确的手机或邮箱", toastStyle)
50
				return;
51
			}
52
		}
53

54
		/*判断账号是否注册*/
55
		function userRegisterOk() {
56
			mui.ajax(baseUrl + '/ajax/isReg?key=' + userName.value, {
57
				dataType: 'json', //数据格式类型
58
				type: 'GET', //http请求类型
59
				timeout: 10000, //超时设置
60
				success: function(data) {
61
					console.log(data.data)
62
					if(data.data == true) {
63
						plus.nativeUI.toast("用户不存在请注册用户", toastStyle);
64
						return;
65
					} else {
66
						passwordVal()
67
					}
68
				},
69
				error: function() {
70
					plus.nativeUI.toast("服务器链接超时", toastStyle);
71
					return;
72
				}
73
			});
74
		}
75

76
		/*校验登录密码*/
77
		function passwordVal() {
78
			if(userPassword.value.length < 6) {
79
				plus.nativeUI.toast("密码不少于6位", toastStyle);
80
				return;
81
			} else {
82
				loginBut();
83
			}
84
		}
85

86
		/*提交登录*/
87
		function loginBut() {
88
			mui.ajax(baseUrl + '/ajax/login', {
89
				data: {
90
					"pw": userPassword.value,
91
					"lk": userName.value
92
				},
93
				dataType: 'json', //数据格式类型
94
				type: 'POST', //http请求类型
95
				timeout: 10000, //超时设置
96
				success: function(data) {
97
					console.log(data.data)
98
					if(data.data != "null" && data.data != null) {
99
						var userId = data.data.id;
100
						plus.storage.setItem('userid', userId);
101
						firstLogin();
102
					} else {
103
						plus.nativeUI.toast("登录账号和密码不匹配!", toastStyle);
104
						return;
105
					}
106
				},
107
				error: function() {
108
					plus.nativeUI.toast("服务器链接超时", toastStyle);
109
					return;
110
				}
111
			});
112
		}
113

114
		/*判断用户第一次登录,是否填写了个人信息*/
115
		function firstLogin() {
116
			var professorId = plus.storage.getItem('userid');
117
			//console.log(userId);
118
			mui.ajax(baseUrl + "/ajax/professor/" + professorId, {
119
				dataType: 'json', //数据格式类型
120
				type: 'GET', //http请求类型
121
				async: false,
122
				timeout: 10000, //超时设置
123
				success: function(data) {
124
					console.log(data.data)
125
					if(data.data != null) {
126
						//mui.currentWebview.close();
127
			        	mui.back();
128
				        var myaccountPage = plus.webview.getWebviewById('html/myaccount.html');
129
						mui.fire(myaccountPage, 'closeUser', {
130
							id: professorId
131
						});
132
					} else {
133
						var productView = mui.preload({
134
							url: '../html/fillinfo.html',
135
							id: '../html/fillinfo.html',
136
							show: {
137
								aniShow: "slide-in-right"
138
							},
139
							extras: {
140
								userid: professorId
141
							}
142
						});
143
						productView.show();
144
					}
145
				},
146
				error: function() {
147
					plus.nativeUI.toast("服务器链接超时", toastStyle);
148
					return;
149
				}
150
			});
151
		}
152

153
	});
154

1
//登录
2
mui.ready(function() {
3
4
	/*定义全局变量*/
5
	var reg = document.getElementById("reg");
6
	var login = document.getElementById("login");
7
	var userName = document.getElementById("username");
8
	var userPassword = document.getElementById("password");
9
	var forgetPassword = document.getElementById("forgetPassword");
10
11
	mui.plusReady(function() {
12
		
13
        /*点击注册按钮*/
14
		reg.addEventListener("tap", function() {
15
			goRegFun();
16
		})
17
		
18
		/*点击忘记密码按钮*/
19
		forgetPassword.addEventListener("tap", function() {
20
			mui.openWindow({
21
				url: '../html/findpwd-phone.html',
22
				id: '../html/findpwd-phone.html',
23
				show: {
24
					aniShow: "slide-in-right"
25
				}
26
			});
27
		})
28
29
		/*校验登录按钮显示状态*/
30
		mui('.frmbox').on('keyup', "#username,#password", function() {
31
			hideButtn(userName,userPassword,login,"frmactiveok");
32
		});
33
		
34
		/*登录按钮*/
35
		login.addEventListener('tap', function() {
36
			userVal()
37
		})
38
39
		
40
		/*校验用户账号*/
41
		function userVal() {
42
			var gunf = /^\w+@\w+\.((cn)|(com)|(com\.cn))$/;
43
			var hunPhone = /^1[3|4|5|7|8]\d{9}$/;
44
			if(hunPhone.test(userName.value)) {
45
				userRegisterOk();
46
			} else if(gunf.test(userName.value)) {
47
				userRegisterOk();
48
			} else {
49
				plus.nativeUI.toast("请输入正确的手机或邮箱", toastStyle)
50
				return;
51
			}
52
		}
53
54
		/*判断账号是否注册*/
55
		function userRegisterOk() {
56
			mui.ajax(baseUrl + '/ajax/isReg?key=' + userName.value, {
57
				dataType: 'json', //数据格式类型
58
				type: 'GET', //http请求类型
59
				timeout: 10000, //超时设置
60
				success: function(data) {
61
					console.log(data.data)
62
					if(data.data == true) {
63
						plus.nativeUI.toast("用户不存在请注册用户", toastStyle);
64
						return;
65
					} else {
66
						passwordVal()
67
					}
68
				},
69
				error: function() {
70
					plus.nativeUI.toast("服务器链接超时", toastStyle);
71
					return;
72
				}
73
			});
74
		}
75
76
		/*校验登录密码*/
77
		function passwordVal() {
78
			if(userPassword.value.length < 6) {
79
				plus.nativeUI.toast("密码不少于6位", toastStyle);
80
				return;
81
			} else {
82
				loginBut();
83
			}
84
		}
85
86
		/*提交登录*/
87
		function loginBut() {
88
			mui.ajax(baseUrl + '/ajax/login', {
89
				data: {
90
					"pw": userPassword.value,
91
					"lk": userName.value
92
				},
93
				dataType: 'json', //数据格式类型
94
				type: 'POST', //http请求类型
95
				timeout: 10000, //超时设置
96
				success: function(data) {
97
					console.log(data.data)
98
					if(data.data != "null" && data.data != null) {
99
						var userId = data.data.id;
100
						plus.storage.setItem('userid', userId);
101
						firstLogin();
102
						var consultPage = plus.webview.getWebviewById('html/consultlist.html');
103
						console.log("目前id=="+plus.storage.getItem('userid'))
104
						console.log(userId)
105
						mui.fire(consultPage, 'relogin', {
106
							id: plus.storage.getItem('userid')
107
						});
108
					} else {
109
						plus.nativeUI.toast("登录账号和密码不匹配!", toastStyle);
110
						return;
111
					}
112
				},
113
				error: function() {
114
					plus.nativeUI.toast("服务器链接超时", toastStyle);
115
					return;
116
				}
117
			});
118
		}
119
120
		/*判断用户第一次登录,是否填写了个人信息*/
121
		function firstLogin() {
122
			var professorId = plus.storage.getItem('userid');
123
			//console.log(userId);
124
			mui.ajax(baseUrl + "/ajax/professor/" + professorId, {
125
				dataType: 'json', //数据格式类型
126
				type: 'GET', //http请求类型
127
				async: false,
128
				timeout: 10000, //超时设置
129
				success: function(data) {
130
					console.log(data.data)
131
					if(data.data != null) {
132
						//mui.currentWebview.close();
133
			        	mui.back();
134
				        var myaccountPage = plus.webview.getWebviewById('html/myaccount.html');
135
						mui.fire(myaccountPage, 'closeUser', {
136
							id: professorId
137
						});
138
					} else {
139
						var productView = mui.preload({
140
							url: '../html/fillinfo.html',
141
							id: '../html/fillinfo.html',
142
							show: {
143
								aniShow: "slide-in-right"
144
							},
145
							extras: {
146
								userid: professorId
147
							}
148
						});
149
						productView.show();
150
					}
151
				},
152
				error: function() {
153
					plus.nativeUI.toast("服务器链接超时", toastStyle);
154
					return;
155
				}
156
			});
157
		}
158
159
	});
160
155 161
});