Merge branch 'feature/installment2a' of git.yoho.cn:fe/yohobuywap-node into feature/installment2a
Showing
2 changed files
with
112 additions
and
22 deletions
1 | var $ = require('yoho-jquery'); | 1 | var $ = require('yoho-jquery'); |
2 | var tip = require('../plugin/tip'); | 2 | var tip = require('../plugin/tip'); |
3 | +var yohoApp = require('../yoho-app'); | ||
3 | 4 | ||
4 | var Timer = function() { | 5 | var Timer = function() { |
5 | this.counter = 0; | 6 | this.counter = 0; |
@@ -35,7 +36,9 @@ var validateForm = function() { | @@ -35,7 +36,9 @@ var validateForm = function() { | ||
35 | formModel.mobile && | 36 | formModel.mobile && |
36 | formModel.snsCheckCode && | 37 | formModel.snsCheckCode && |
37 | formModel.agreements === 'on') { | 38 | formModel.agreements === 'on') { |
38 | - applyButton.removeClass('disabled'); | 39 | + if (!applyButton.data('running')) { |
40 | + applyButton.removeClass('disabled'); | ||
41 | + } | ||
39 | ret = true; | 42 | ret = true; |
40 | } else { | 43 | } else { |
41 | applyButton.addClass('disabled'); | 44 | applyButton.addClass('disabled'); |
@@ -54,7 +57,7 @@ var validateForm = function() { | @@ -54,7 +57,7 @@ var validateForm = function() { | ||
54 | 57 | ||
55 | var checkCard = require('./bind-card-check'); | 58 | var checkCard = require('./bind-card-check'); |
56 | 59 | ||
57 | -const clearVerifyCode = function() { | 60 | +var clearVerifyCode = function() { |
58 | formModel.snsCheckCode = ''; | 61 | formModel.snsCheckCode = ''; |
59 | $('#sns-check-code').val(''); | 62 | $('#sns-check-code').val(''); |
60 | }; | 63 | }; |
@@ -162,18 +165,18 @@ $('#send-sms').click(function() { | @@ -162,18 +165,18 @@ $('#send-sms').click(function() { | ||
162 | 165 | ||
163 | // 输入框改变时同时更新模型 | 166 | // 输入框改变时同时更新模型 |
164 | /* | 167 | /* |
165 | -$('input').on('change', function() { | ||
166 | - var name = $(this).attr('name'); | 168 | + $('input').on('change', function() { |
169 | + var name = $(this).attr('name'); | ||
167 | 170 | ||
168 | - if ($(this).is(':checkbox')) { | ||
169 | - formModel[name] = $(this).is(':checked') ? $(this).val() : null; | ||
170 | - } else { | ||
171 | - formModel[name] = $(this).val(); | ||
172 | - } | 171 | + if ($(this).is(':checkbox')) { |
172 | + formModel[name] = $(this).is(':checked') ? $(this).val() : null; | ||
173 | + } else { | ||
174 | + formModel[name] = $(this).val(); | ||
175 | + } | ||
173 | 176 | ||
174 | - validateForm(); | ||
175 | -}); | ||
176 | -*/ | 177 | + validateForm(); |
178 | + }); | ||
179 | + */ | ||
177 | 180 | ||
178 | // validateForm(); | 181 | // validateForm(); |
179 | 182 | ||
@@ -198,14 +201,17 @@ setInterval(function() { | @@ -198,14 +201,17 @@ setInterval(function() { | ||
198 | $('#apply-button').click(function() { | 201 | $('#apply-button').click(function() { |
199 | var ret = false; | 202 | var ret = false; |
200 | var that = $(this); | 203 | var that = $(this); |
204 | + var asyncMode = yohoApp.isiOS; | ||
201 | 205 | ||
202 | if ($(this).hasClass('disabled') || !validateForm()) { | 206 | if ($(this).hasClass('disabled') || !validateForm()) { |
203 | return false; | 207 | return false; |
208 | + } else { | ||
209 | + $(this).addClass('disabled').text('处理中...').data('running', true); | ||
204 | } | 210 | } |
205 | 211 | ||
206 | $.ajax({ | 212 | $.ajax({ |
207 | method: 'get', | 213 | method: 'get', |
208 | - async: false, | 214 | + async: asyncMode, |
209 | url: '/home/installment/starting-service/check-verify-code', | 215 | url: '/home/installment/starting-service/check-verify-code', |
210 | data: { | 216 | data: { |
211 | mobile: formModel.mobile, | 217 | mobile: formModel.mobile, |
@@ -217,7 +223,7 @@ $('#apply-button').click(function() { | @@ -217,7 +223,7 @@ $('#apply-button').click(function() { | ||
217 | method: 'post', | 223 | method: 'post', |
218 | url: '/home/installment/activate-service', | 224 | url: '/home/installment/activate-service', |
219 | data: formModel, | 225 | data: formModel, |
220 | - async: false | 226 | + async: asyncMode |
221 | }); | 227 | }); |
222 | } else { | 228 | } else { |
223 | clearVerifyCode(); | 229 | clearVerifyCode(); |
@@ -226,12 +232,10 @@ $('#apply-button').click(function() { | @@ -226,12 +232,10 @@ $('#apply-button').click(function() { | ||
226 | }).then(function(result) { | 232 | }).then(function(result) { |
227 | var params; | 233 | var params; |
228 | 234 | ||
229 | - if (!result) { | ||
230 | - // return; | 235 | + that.removeClass('disabled').text('下一步').data('running', false); |
231 | 236 | ||
232 | - result = { | ||
233 | - code: 500 | ||
234 | - }; | 237 | + if (!result) { |
238 | + return; | ||
235 | } | 239 | } |
236 | 240 | ||
237 | params = { | 241 | params = { |
@@ -242,12 +246,21 @@ $('#apply-button').click(function() { | @@ -242,12 +246,21 @@ $('#apply-button').click(function() { | ||
242 | }; | 246 | }; |
243 | 247 | ||
244 | if (result.code === 200 && result.data) { | 248 | if (result.code === 200 && result.data) { |
245 | - that.attr('href', location.pathname + '?openby:yohobuy=' + encodeURIComponent(JSON.stringify(params))); | 249 | + if (asyncMode) { |
250 | + yohoApp.invokeMethod('go.instalmentActivated', params.params); | ||
251 | + } else { | ||
252 | + that.attr('href', location.pathname + '?openby:yohobuy=' + encodeURIComponent(JSON.stringify(params))); | ||
253 | + } | ||
254 | + | ||
246 | ret = true; | 255 | ret = true; |
247 | } else if (result.code === 500) { | 256 | } else if (result.code === 500) { |
248 | // 接口可能超时返回审核中 by 孟令阶 | 257 | // 接口可能超时返回审核中 by 孟令阶 |
249 | params.params.status = '1'; | 258 | params.params.status = '1'; |
250 | - that.attr('href', location.pathname + '?openby:yohobuy=' + encodeURIComponent(JSON.stringify(params))); | 259 | + if (asyncMode) { |
260 | + yohoApp.invokeMethod('go.instalmentActivated', params.params); | ||
261 | + } else { | ||
262 | + that.attr('href', location.pathname + '?openby:yohobuy=' + encodeURIComponent(JSON.stringify(params))); | ||
263 | + } | ||
251 | ret = true; | 264 | ret = true; |
252 | } else { | 265 | } else { |
253 | tip.show(result.message); | 266 | tip.show(result.message); |
@@ -268,7 +281,7 @@ $('input[maxlength]').keyup(function() { | @@ -268,7 +281,7 @@ $('input[maxlength]').keyup(function() { | ||
268 | }); | 281 | }); |
269 | 282 | ||
270 | $('#agreements').click(function() { | 283 | $('#agreements').click(function() { |
271 | - const params = { | 284 | + var params = { |
272 | action: 'go.instalmentProtocol', | 285 | action: 'go.instalmentProtocol', |
273 | params: { | 286 | params: { |
274 | protocolUrl: location.protocol + '//' + location.hostname + location.port + $(this).data('href') | 287 | protocolUrl: location.protocol + '//' + location.hostname + location.port + $(this).data('href') |
public/js/yoho-app.js
0 → 100644
1 | +/** | ||
2 | + * YOHO-SDK | ||
3 | + * | ||
4 | + * 与原生 APP 交互的代码 | ||
5 | + * 所有函数要做降级处理 | ||
6 | + * 假如不是 YOHO App,在浏览器实现对应的功能 | ||
7 | + * 浏览器不支持的功能,给出提示,控制台不能报错,不影响后续代码执行 | ||
8 | + * | ||
9 | + * 希望能与 微信 JS-SDK 一样方便 | ||
10 | + */ | ||
11 | +var tip = require('./plugin/tip'); | ||
12 | + | ||
13 | +/* 空方法 */ | ||
14 | +var emptyFn = function() {}; | ||
15 | + | ||
16 | +/* 提示信息 */ | ||
17 | +var tipInfo = '暂不支持,请在YOHO!BUY应用中打开'; | ||
18 | + | ||
19 | +var yoho = { | ||
20 | + /** | ||
21 | + * 判断是否是 APP | ||
22 | + */ | ||
23 | + isApp: /YohoBuy/i.test(navigator.userAgent || ''), | ||
24 | + isiOS: /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(navigator.userAgent || ''), | ||
25 | + isAndroid: /Android/i.test(navigator.userAgent || ''), | ||
26 | + | ||
27 | + /** | ||
28 | + * JS 与 APP 共享的对象 | ||
29 | + */ | ||
30 | + data: window.yohoInterfaceData, | ||
31 | + | ||
32 | + ready: function(callback) { | ||
33 | + if (this.isApp) { | ||
34 | + document.addEventListener('deviceready', callback); | ||
35 | + } else { | ||
36 | + return callback(); | ||
37 | + } | ||
38 | + }, | ||
39 | + | ||
40 | + /** | ||
41 | + * 调用APP原生方法 | ||
42 | + * @param method 方法名称 | ||
43 | + * @param args 传递给 APP 的参数 {"index":tab_index} | ||
44 | + * @param success 调用成功的回调方法 | ||
45 | + * @param fail 调用失败的回调方法 | ||
46 | + */ | ||
47 | + invokeMethod: function(method, args, success, fail) { | ||
48 | + var appInterface = window.yohoInterface; | ||
49 | + | ||
50 | + if (this.isApp && appInterface) { | ||
51 | + appInterface.triggerEvent(success || emptyFn, fail || emptyFn, { | ||
52 | + method: method, | ||
53 | + arguments: args | ||
54 | + }); | ||
55 | + } else { | ||
56 | + tip.show(tipInfo); | ||
57 | + } | ||
58 | + }, | ||
59 | + | ||
60 | + /** | ||
61 | + * 原生调用 JS 方法 | ||
62 | + * @param name 方法名 | ||
63 | + * @param callback 回调 | ||
64 | + */ | ||
65 | + addNativeMethod: function(name, callback) { | ||
66 | + var appInterface = window.yohoInterface; | ||
67 | + | ||
68 | + // 延迟 500ms 注入 | ||
69 | + setTimeout(function() { | ||
70 | + if (appInterface) { | ||
71 | + appInterface[name] = callback; | ||
72 | + } | ||
73 | + }, 500); | ||
74 | + } | ||
75 | +}; | ||
76 | + | ||
77 | +module.exports = yoho; |
-
Please register or login to post a comment