app.js
5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/**
* 工具类
*/
/**
* 金额转成千分位格式
*
* @param decimals 小数位数
* @param decimal_sep
* @param thousands_sep 千分位分隔符
*/
Number.prototype.toMoney = function(decimals, decimal_sep, thousands_sep) {
var n = this, c = isNaN(decimals) ? 2 : Math.abs(decimals), d = decimal_sep
|| '.', t = (typeof thousands_sep === 'undefined') ? ','
: thousands_sep, sign = (n < 0) ? '-' : '', i = parseInt(n = Math
.abs(n).toFixed(c))
+ '', j = ((j = i.length) > 3) ? j % 3 : 0;
return sign + (j ? i.substr(0, j) + t : '')
+ i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t)
+ (c ? d + Math.abs(n - i).toFixed(c).slice(2) : '');
};
$.ajaxSetup({
complete : function(request, textStatus) {
// 通过XMLHttpRequest取得响应头,sessionstatus,
var sessionstatus = request.getResponseHeader("sessionstatus");
if (sessionstatus == 'timeout') {
changeCaptcha();
$('#loginModal').modal({
closeOnOverlayClick : false
}).open();
}
}
});
/**登录页验证码*/
function changeCaptcha() {
$('#imgCaptcha').attr('src', '/captcha-image?' + Math.random());
}
/**弹窗登录验证码*/
function changeCaptcha2() {
$('#imgCaptcha2').attr('src', '/captcha-image?' + Math.random());
}
$.extend({
/**
* 消息弹出框
*/
alert : function(content, width, height){
if (isNaN(width) || width< 300) {
width = 300;
}
if (isNaN(height) || height< 300) {
width = 300;
}
$("#alert").remove();
var popUp = $('<div class="easyDialog_wrapper entrust ensure" style="width:' +
width+'px;height:'+ height +'px;" id="alert"></div>')
.append('<div class="easyDialog_content" style="border-top: 3px solid #d81e31;"><div class="easyDialog_text" id="entrust_result">' +
content + '</div><div class="easyDialog_footer" ><button style="width: 40%;margin: 20px 30%;background: #d1131d;border: 0;" class="btn_highlight " id="closeBtn" >确定</button></div></div>');
$(document.body).append(popUp);
easyDialog.open({
container : 'alert'
});
}
});
/**
* 发送验证码
*/
var ValidCode = function($) {
return {
i : 60,
flag : false,
resultCode : null,
checkValia : function() { // that,vCode,phoneNum
var _this = this;
var _that = arguments[0];
if (arguments.length == 3) {
var vCode = arguments[1];
var phoneNum = arguments[2];
$.ajax({
url : "/checkValiaCode",
type : "POST",
dataType : "json",
data : {
valiadateCode : vCode,
randomNum : Math.random()
},
success : function(data) {
// var result=_this.sendSms(_that,vCode,phoneNum);
if (data.resultCode == "0") {
alert("验证码不正确");
changeCaptcha();
} else if (data.resultCode == "1") {
_this.sendSms(_that, vCode, phoneNum)
}
}
});
} else if (arguments.length == 1) {
_this.sendSms(_that);
}
},
checkPhoneNum : function(phoneNum) {
var reg = /^0?1[3|4|5|7|8][0-9]\d{8}$/;
if (!phoneNum || !reg.test(phoneNum)) {
return false;
} else {
return true;
}
},
/**给当前用户发送验证码*/
sendToCurrentUser : function(button, stype) {
ValidCode.countDown(button, 60);
$.get('/msg/sendValidCode?t=' + Math.random(), function(data) {
}, 'text');
},
/**发送提现短信*/
sendForKiting : function(button){
ValidCode.countDown(button, 60);
$.get('/msg/kiting?t=' + Math.random(), function(data) {
}, 'text');
},
/**
* 发送到指定号码
*/
sendToPhoneNo : function(mobile_tel, valiadateCode) {
$.ajax({
url : "/msg/sendMsg",
type : "POST",
dataType : 'json',
data : {
mobile_tel : mobile_tel,
valiadateCode : valiadateCode
},
success : function(data) {
var ret = data.resultCode;
return ret;
},
error : function() {
}
});
},
/**
* 倒计时
* @param button 按钮ID
* @param time 倒计时秒数
* @return setTimeout句柄
*/
countDown: function(button, time) {
var handler = null;
if (time > 0) {
$(button).val('再次发送(' + time + ')');
$(button).attr('disabled', true);
handler = setTimeout(function() {
ValidCode.countDown(button, --time);
}, 1000);
} else {
$(button).val('发送验证码');
$(button).attr('disabled', false);
}
return handler;
},
sendSms : function() {
var _this = this;
var _that = arguments[0];
if (arguments.length == 3) {
var vCode = arguments[1];
var phoneNum = arguments[2];
var checkpn = _this.checkPhoneNum(phoneNum);
if (!checkpn) {
$("#code_text").html("<span style='color:red;'>请填写有效手机号码。</span>");
}
}
if (_this.flag) {
$(_that).text("发送验证码");
_this.flag = false;
_this.i = 60;
return;
}
if (_this.i > 0) {
_this.i = _this.i - 1;
if (_this.i == 59) {
$(_that).attr('disabled', true);
if (arguments.length == 3) {
_this.resultCode = _this.sendMes(phoneNum, vCode);
} else {
_this.resultCode = _this.sendMes();
}
}
$(_that).html("再次发送(" + _this.i + ")");
setTimeout(function() {
_this.sendSms(_that);
}, 1000);
} else {
_this.i = 60;
$(_that).attr('disabled', false);
$(_that).text("发送验证码");
}
}
}
}(jQuery);