pay.min.js
29.1 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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
(function() {
localStorage.setItem('auto', false);
// 加载页面内容到body下
init_data();
function init_data(response) {
// 注册页面所有模块
if (response) {
$(response).appendTo($('body .mask'));
}
/**
* 首页模块
*/
var Home = function(modId) {
Module.call(this, modId);
}
Core.inherit(Home, Module);
Home.prototype.bind = function() {
var that = this;
that.$c.on('click', 'input[type=button]', function(e) {
// 更新要兑换的元宝
e.preventDefault();
Core.Data.current_pay_channel = null;
Core.Data.game_amount = parseInt($(e.target).attr('data'));
var youai_star_need = Core.Data.game_amount / Core.Data.exchange_rate;
if (Core.Data.total_amount >= youai_star_need) {
// 用户游爱星足够兑换,进入兑换模块
Core.Data.youai_star = youai_star_need;
Core.Data.money = Core.Data.youai_star / Core.Data.rate;
Core.updateMod('exchange');
} else {
// 用户游爱星不足够兑换,进入充值渠道列表
Core.Data.money = youai_star_need / Core.Data.rate;
Core.Data.youai_star = youai_star_need;
Core.updateMod('channel_list');
}
return false;
});
}
Core.registerMod('home', Home);
/**
* 兑换和发起代付的回调方法
*/
var payconfirm_cb = function(data) {
var code = data.code;
var msg = data.msg;
if ('object' != typeof (msg)) {
Core.showTips(msg, false);
return;
}
var $cur_mod = $('#' + Core.cur_mod);
var ele_pay_user = $cur_mod.find('input[name="pay_user"]');
if (ele_pay_user.length == 0) {
tpl = '成功使用<span class="text-info">{{=it.youai_star}}</span>个游爱星兑换<span class="text-info">{{=it.game_amount}}</span>{{=it.game_unit}}{{=it.game_unit_name}},{{=it.game_unit_name}}将会很快充入您的账户,请留意游戏提示.';
} else {
tpl = '已向<span class="text-info">'
+ ele_pay_user.val()
+ '</span>发送代付<span class="text-info">{{=it.youai_star}}</span>个游爱星兑换<span class="text-info">{{=it.game_amount}}</span>{{=it.game_unit}}{{=it.game_unit_name}}.';
}
var doTpl = doT.template(tpl);
var success_msg = doTpl({
"youai_star" : msg.youai_star,
"amount" : msg.amount,
"game_unit_name" : Core.Data.game_unit_name,
"game_amount" : msg.game_amount,
"game_unit" : Core.Data.game_unit
});
Core.Data.success_msg = success_msg;
Core.Data.trade_id = msg.trade_id;
Core.showTips('成功提交!', true, 2000);
Core.updateMod('pay_result');
}
/**
* 兑换模块
*/
var Exchange = function(modId) {
Module.call(this, modId);
}
Core.inherit(Exchange, Module);
Exchange.prototype.bind = function() {
var that = this;
that.$c.on('click', 'input[type=submit]', function(e) {
e.preventDefault();
Core.ajax_do(that.$c.find('.ajax'), payconfirm_cb, that);
return false;
});
// that.$c.on('click', '#change_vc1', function(e) {
// e.preventDefault();
// var num = new Date().getTime();
// var rand = Math.round(Math.random() * 10000);
// num = num + rand;
// if ($("#vdimgck1")[0]) {
// $("#vdimgck1")[0].src = "/validate_code/?tag=" + num;
// }
// return false;
// });
}
Core.registerMod('exchange', Exchange);
/**
* 发起代付模块
*/
var Pay_for = function(modId) {
Module.call(this, modId);
}
Core.inherit(Pay_for, Module);
Pay_for.prototype.bind = function() {
var that = this;
that.$c.on('click', 'input[type=submit]', function(e) {
e.preventDefault();
Core.ajax_do(that.$c.find('.ajax'), payconfirm_cb, that);
return false;
});
}
Core.registerMod('pay_for', Pay_for);
/**
* 显示结果模块
*/
var Pay_result = function(modId) {
Module.call(this, modId);
}
Core.inherit(Pay_result, Module);
Core.registerMod('pay_result', Pay_result);
/**
* 充值方式列表模块
*/
var Channel_list = function(modId) {
this.myScroll = null;
Module.call(this, modId);
}
Core.inherit(Channel_list, Module);
Channel_list.prototype.bind = function() {
var that = this;
that.$c.on('click', '.channel_list a.channel', function(e) {
e.preventDefault();
var reload = false;
var list = Core.Data.game_pay_channel_list;
var $c = $(e.target);
var id = $c.attr('data-id');
for ( var index in list) {
var item = list[index];
if (id == item.id) {
if (Core.Data.current_pay_channel != item) {
reload = true;
}
Core.Data.current_pay_channel = item;
// Core.Data.game_amount =
// null;
break;
}
}
if (reload) {
Core.updateMod('pay');
} else {
Core.showMod('pay');
}
return false;
});
}
Channel_list.prototype.refresh = function() {
this.myScroll.refresh();
}
Channel_list.prototype.show_after = function() {
Core.auto_click = true
if (!this.myScroll){
this.myScroll = new iScroll('channel_list_wrapper');
}
Core.Data.frame_src = ''
}
Core.registerMod('channel_list', Channel_list);
/**
* 充值模块
*/
var Pay = function(modId) {
this.myScroll = null;
Module.call(this, modId);
}
Core.inherit(Pay, Module);
Pay.prototype.bind = function() {
var that = this;
that.$c.on('click', 'input[type=submit]', function(e) {
e.preventDefault();
var isText = that.$c.find('.require_input input[type=text]').length > 0;
if (isText && that.check()) {
Core.ajax_do(that.$c.find('.ajax'),
that.paycomfirm_cb, that);
} else if (!isText) {
Core.ajax_do(that.$c.find('.ajax'),
that.paycomfirm_cb, that);
}
return false;
});
that.$c.on('change', '.card_amount', function(e){
var value = parseInt($(e.target).val());
if(value > Core.Data.money){
//显示出余额提示
var m = value - Core.Data.money;
that.$c.find('.select-info').html('注:充值剩余的' + m + '元将保存为账户的游爱星.');
}
});
}
Pay.prototype.show_after = function(){
var that = this;
if (Core.auto_click){
that.$c.find("input[type='submit'].zhifubaoBtn").click();
Core.auto_click = false
}
$('#alert').hide();
if (!this.myScroll){
this.myScroll = new iScroll('pay_panel_wrapper');
}
}
Pay.prototype.check = function() {
var check = true, that = this;
that.$c.find(".require_input input").each(
function() {
var value = $(this).val();
if ('' == value) {
Core.showTips("请输入" + $(this).attr('title'), false,
2000);
check = false;
return false;
} else {
var format = $(this).attr('format');
if (format) {
var re = RegExp(format, 'g')
if ('' != value.replace(re, "")) {
Core.showTips($(this).attr('title')
+ "输入格式不正确"
+ $(this).attr('placeholder'),
false, 2000);
check = false;
return false;
}
}
}
});
if (!check)
return false;
var money = $(".require_input .card_amount").val();
money = parseFloat(money);
if (money == null || money == NaN || isNaN(money)) {
Core.showTips("请选择金额", false, 2000);
return false;
}
Core.Data.post_data = {};
that.$c
.find(
"input[type='hidden'],input[type='text'],input[type='password'],select")
.each(function() {
var name = $(this).attr('name');
var value = $(this).val();
Core.Data.post_data[name] = value;
});
// 更新当前金钱状态
Core.Data.money = money;
$("#pay_form input[name=money]").val(money);
console.log(Core.Data.post_data);
return true;
}
Pay.prototype.refresh = function() {
this.myScroll.refresh();
}
Pay.prototype.paycomfirm_cb = function(data) {
var code = data.code;
var msg = data.msg;
if ('object' != typeof (msg)) {
Core.showTips(msg, false);
return;
}
var pay_param = msg.pay_param;
if (pay_param) {
if (pay_param.next_url && pay_param.next_url != "") {
Core.showTips('正在跳转请稍等...', true, 1000);
Core.Data.frame_title = "充值";
Core.Data.frame_src = pay_param.next_url;
Core.updateMod('frame');
return;
} else if (pay_param.action_url && pay_param.action_url != "") {
var action_url = pay_param.action_url;
var method = pay_param.method;
var params = "";
if (action_url.indexOf("?") != -1) {
params = action_url.split("?")[1];
action_url = action_url.split("?")[0];
}
var go_form = $("<form></form>");
if (!method)
method = 'get';
go_form.attr("method", method);
go_form.attr("action", action_url);
params = params.split("&");
for ( var i in params) {
var item = params[i]
go_form.append('<input type="hidden" name="'
+ item.split("=")[0] + '" value="'
+ unescape(item.split("=")[1]) + '"/>');
}
Core.showTips('<h3>正在跳转请稍等...</h3>');
go_form.submit();
return;
}
}
var pay_channel_name = '', tpl = "";
if (Core.Data.current_pay_channel) {
tpl = Core.Data.current_pay_channel.success_msg;
pay_channel_name = Core.Data.current_pay_channel.name
} else {
var ele_pay_user = $('input[name="pay_user"]');
if (ele_pay_user.length == 0) {
tpl = '使用{{=it.youai_star}}颗游爱星兑换{{=it.game_unit_name}}{{=it.game_amount}}{{=it.game_unit}}成功,{{=it.game_unit_name}}将会很快充入您的账户,请留意游戏提示.';
} else {
tpl = '已向'
+ ele_pay_user.val()
+ '发送代付{{=it.youai_star}}颗游爱星兑换{{=it.game_unit_name}}{{=it.game_amount}}{{=it.game_unit}}.';
}
}
var doTpl = doT.template(tpl);
var success_msg = doTpl({
"pay_channel_name" : pay_channel_name,
"youai_star" : msg.youai_star,
"amount" : msg.amount,
"game_unit_name" : Core.Data.game_unit_name,
"game_amount" : msg.game_amount,
"game_unit" : Core.Data.game_unit
});
Core.Data.success_msg = success_msg;
Core.Data.trade_id = msg.trade_id;
Core.showTips('成功提交!', true, 2000);
Core.updateMod('pay_result');
}
Core.registerMod('pay', Pay);
// /**
// * 确认付款(提交表单)模块
// */
// var Pay_confirm = function(modId){
// Module.call(this, modId);
// }
// Core.inherit(Pay_confirm, Module);
// Pay_confirm.prototype.bind = function(){
// var that = this;
// that.$c.on('click', '[type=submit]', function(e) {
// e.preventDefault();
// Core.ajax_do(that.$c.find('.ajax'),
// that.paycomfirm_cb, that);
// return false;
// });
// that.$c.on('click', '#change_vc', function(e){
// e.preventDefault();
// var num = new Date().getTime();
// var rand = Math.round(Math.random() * 10000);
// num = num + rand;
// if ($("#vdimgck")[0]) {
// $("#vdimgck")[0].src = "/validate_code/?tag=" + num;
// }
// return false;
// });
// that.$c.on('click', '.checkbox', function(e){
// var chked = e.target.checked;
// var proxy_pay = that.$c.find("div.proxy_pay");
// var txt_pay_user =
// that.$c.find("input[data-key='pay_user']");
// if (chked){
// txt_pay_user.attr('name', 'pay_user');
// txt_pay_user.attr('required', 'required');
// proxy_pay.show();
// }else{
// txt_pay_user.removeAttr('name');
// txt_pay_user.removeAttr('required');
// proxy_pay.hide();
// }
// });
// }
//
// Pay_confirm.prototype.paycomfirm_cb = function(data){
// var code = data.code;
// var msg = data.msg;
// if ('object' != typeof(msg)){
// Core.showTips(msg, false);
// return;
// }
//
// var pay_param = msg.pay_param;
// if (pay_param){
// if (pay_param.next_url && pay_param.next_url!=""){
// Core.showTips('<h3>正在跳转请稍等...</h3>');
// document.location = pay_param.next_url;
// return;
// }else if(pay_param.action_url &&
// pay_param.action_url!=""){
// var action_url = pay_param.action_url;
// var method = pay_param.method;
// var params = "";
// if(action_url.indexOf("?")!=-1){
// params = action_url.split("?")[1];
// action_url = action_url.split("?")[0];
// }
// var go_form = $("<form></form>");
// if (!method)
// method = 'get';
//
// go_form.attr("method", method);
// go_form.attr("action", action_url);
// params = params.split("&");
// for(var item in params){
// go_form.appendChild('<input type="hidden"
// name="'+item.split("=")[0]+'"
// value="'+escape(item.split("=")[1])+'"/>');
// }
//
// Core.showTips('<h3>正在跳转请稍等...</h3>');
// go_form.submit();
// return;
// }
// }
// var pay_channel_name = '', tpl = "";
// if (Core.Data.current_pay_channel){
// tpl = Core.Data.current_pay_channel.success_msg;
// pay_channel_name = current_pay_channel.name
// }else{
// var ele_pay_user = $('input[name="pay_user"]');
// if(ele_pay_user.length == 0){
// tpl =
// '使用{{=it.youai_star}}颗游爱星兑换{{=it.game_unit_name}}{{=it.game_amount}}{{=it.game_unit}}成功,{{=it.game_unit_name}}将会很快充入您的账户,请留意游戏提示.';
// }else{
// tpl =
// '已向'+ele_pay_user.val()+'发送代付{{=it.youai_star}}颗游爱星兑换{{=it.game_unit_name}}{{=it.game_amount}}{{=it.game_unit}}.';
// }
// }
// var doTpl = doT.template(tpl);
// var success_msg =
// doTpl({"pay_channel_name":pay_channel_name,
// "youai_star":msg.youai_star, "amount":msg.amount,
// "game_unit_name":Core.Data.game_unit_name,
// "game_amount":msg.game_amount,
// "game_unit":Core.Data.game_unit});
// Core.Data.success_msg = success_msg;
// Core.Data.trade_id = msg.trade_id;
// Core.showTips('成功提交!', true, 2000);
// Core.updateMod('pay_result');
// }
// Core.registerMod('pay_confirm', Pay_confirm);
/**
* 代付操作模块
*/
var Pay_proxy = function(modId) {
Module.call(this, modId);
}
Core.inherit(Pay_proxy, Module);
Pay_proxy.prototype.bind = function() {
var that = this;
that.$c.on('click', '.btn-payfor', function(e) {
e.preventDefault();
Core.ajax_do(that.$c.find('form.ajax'), that.payproxy_cb,
that);
return false;
});
that.$c.on('click', '.btn-undo', function(e) {
e.preventDefault();
Core.ajax_do(that.$c.find('a.ajax'), that.payproxy_cb,
that);
return false;
});
}
Pay_proxy.prototype.payproxy_cb = function(data) {
var code = data.code;
var msg = data.msg;
Core.showTips(msg, true, 3000);
if (code == 0) {
// 操作导致代付列表发生变化,需要更新列表
$('#proxy_scroller .trade-list').empty();
setTimeout(function() {
Core.showMod('proxy_record');
}, 2000);
}
}
Core.registerMod('pay_proxy', Pay_proxy);
var Pay_feedback = function(modId){
Module.call(this, modId);
}
Core.inherit(Pay_feedback, Module);
Pay_feedback.prototype.bind = function(){
var that = this;
that.$c.on('click', '.submit', function(e){
e.preventDefault();
if (that.$c.find('textarea').val().length > 150) {
Core.showTips('问题描述超出了150个字符!', false);
return false;
}
Core.ajax_do(that.$c.find('.ajax'), that.sq_cb, that);
return false;
})
}
Pay_feedback.prototype.sq_cb = function(data) {
Core.showTips(data.msg, true, 2000);
this.isValid = false;
this.$c.find('textarea').val('');
Core.showMod('pay');
}
Core.registerMod('pay_feedback', Pay_feedback);
/**
* 兑换记录模块
*/
var Trade_record = function(modId) {
this.myScroll = null;
Module.call(this, modId);
}
Core.inherit(Trade_record, Module);
Trade_record.prototype.bind = function() {
var that = this;
that.$c.on('click', 'li.more a', function(e) {
e.preventDefault();
Core.load_html($(e.target), that.refresh, that);
return false;
});
}
Trade_record.prototype.refresh = function() {
this.myScroll.refresh();
}
Trade_record.prototype.show_after = function() {
if (this.$c.find('.trade-list').children().length == 0) {
Core.load_html(this.$c.find('.trade-list'), this.tr_cb,
this);
}
var _des = Core.last_mod ? Core.last_mod : 'home';
this.$c.find('a.btn.pull-left').attr('href', '#'+_des);
}
Trade_record.prototype.tr_cb = function(data) {
if (!this.myScroll){
this.myScroll = new iScroll('wrapper');
}
}
Core.registerMod('trade_record', Trade_record);
/**
* 代付记录模块
*/
var Proxy_record = function(modId) {
this.myScroll = null;
Module.call(this, modId);
}
Core.inherit(Proxy_record, Module);
Proxy_record.prototype.bind = function() {
var that = this;
that.$c.on('click', '.op-payfor', function(e) {
e.preventDefault();
var $e = $(e.target);
var id = $e.attr('data-id');
$e.data('path', '/pay/proxy/pay/?id=' + id + '&format=json');
Core.load_json($e, function(data){
Core.Data.temp = data;
Core.showTips('加载完成!', true, 2000);
Core.updateMod('pay_proxy');
}, that);
return false;
});
that.$c.on('click', 'li.more a', function(e) {
e.preventDefault();
Core.load_html($(e.target), that.refresh, that);
return false;
});
}
Proxy_record.prototype.refresh = function() {
this.myScroll.refresh();
}
Proxy_record.prototype.show_after = function() {
if (this.$c.find('.trade-list').children().length == 0) {
Core.load_html(this.$c.find('.trade-list'), this.pr_cb,
this);
}
if(Core.last_mod == 'pay_proxy') return;
var _des = Core.last_mod ? Core.last_mod : 'home';
this.$c.find('a.btn.pull-left').attr('href', '#'+_des);
}
Proxy_record.prototype.pr_cb = function(data) {
if (!this.myScroll){
this.myScroll = new iScroll('proxy_wrapper');
}
}
Core.registerMod('proxy_record', Proxy_record);
/**
* 邀请好友模块
*/
var Invite_friend = function(modId) {
Module.call(this, modId);
}
Core.inherit(Invite_friend, Module);
Invite_friend.prototype.bind = function() {
var that = this;
that.$c.on('click', '#share a', function(e){
e.preventDefault();
var $e = $(e.target);
var params = [];
var head = $e.attr('title');
var url = $e.attr('href');
var pic = Core.Data.game_icon;
var targetUrl = Core.Data.invite_url;//'http://www.9133.com/game/' + Core.Data.app_id + '.html';
var title = 'title=' + encodeURIComponent('我在玩' + Core.Data.game_name + ',游戏很棒,一起来玩吧!');
targetUrl = 'url=' + encodeURIComponent(targetUrl);
if($e.hasClass('s_tqq')){
params.push('c=share');
params.push('a=index');
}
if($e.hasClass('s_qzone')){
pic = 'pics=' + encodeURIComponent(pic);
} else {
pic = 'pic=' + encodeURIComponent(pic);
}
params.push(pic);
params.push(targetUrl);
params.push(title);
var appkey = $e.attr('data-appkey');
if(appkey){
appkey = 'appkey=' + appkey;
params.push(appkey);
}
url = url + '?' + params.join('&');
Core.Data.frame_title = head + '分享';
Core.Data.frame_src = url;
Core.updateMod('frame');
});
}
Invite_friend.prototype.if_cb = function(data) {
Core.showTips(data.msg, data.code == 0 ? true : false);
this.$c.find('input[type=email]').val('');
}
Invite_friend.prototype.show_after = function(){
var that = this;
if(Core.isWeixin){
that.$c.find('#share_weixin').show();
that.$c.find('#share').hide();
}else{
that.$c.find('#share_weixin').hide();
that.$c.find('#share').show();
}
}
Core.registerMod('invite_friend', Invite_friend);
/**
* 其他充值方式模块
*/
var Other = function(modId) {
this.myScroll = null;
Module.call(this, modId);
}
Core.inherit(Other, Module);
Other.prototype.bind = function() {
var that = this;
that.$c.on('click', 'ol.other-pay li a', function(e) {
e.preventDefault();
var $e = $(e.target);
while (!$e.is('a'))
$e = $e.parent();
var href = $e.attr('href');
window.open(href);
});
}
Core.registerMod('other', Other);
var Frame = function(modId) {
Module.call(this, modId);
}
Core.inherit(Frame, Module);
Frame.prototype.bind = function(){
var that = this;
that.$c.on('click', '.scroll-btn', function(e){
e.preventDefault();
e.stopPropagation();
var $frame = that.$c.find('iframe');
var h1 = $frame.height();
var h2 = that.$c.find('.ios_scroll').height();
var top = parseInt($frame.css('margin-top'));
if($(e.currentTarget).hasClass('scroll-down')){
if(Math.abs(top) + 20>(h1-h2)) return;
$frame.css('margin-top', top-50);
} else {
if(top>=0) return;
$frame.css('margin-top', top+50);
}
});
}
Frame.prototype.show_after = function() {
var that = this;
var _des = Core.last_mod ? Core.last_mod : 'home';
var $frame = that.$c.find('iframe');
var $div = that.$c.find('.ios_scroll');
var isFix = false;
this.$c.find('a.btn.pull-left').attr('href', '#' + _des);
var i = 0;
$frame[0].onload = function() {
that.$c.find('#loading_frame').hide();
$('#alert').hide();
if(Core.isAndroid && !isFix){
var h1 = $frame.height();
var h2 = $div.height();
if(h1>h2){
//android 低版本浏览器,需要提供手动滚动iframe
that.$c.addClass('fix');
isFix = true;
} else {
that.$c.addClass('nofix');
}
}
}
}
Core.registerMod('frame', Frame);
/**
* 客服问题列表模块
*/
var Kefu_list = function(modId) {
this.myScroll = null;
this.cur_id = null;
Module.call(this, modId);
}
Core.inherit(Kefu_list, Module);
Kefu_list.prototype.bind = function() {
var that = this;
that.$c.on('click', 'li>a.item', function(e) {
e.preventDefault();
e.stopPropagation();
/*
* @todo-list bug fixed in android,the click event fired twice!
*/
if (Core.cur_mod == 'question_detail')
return;
var $e = $(e.target);
while (!$e.is('a'))
$e = $e.parent();
var id = $e.attr('data-id');
if (id == that.cur_id) {
Core.Data.question_update = false;
Core.showMod('question_detail');
return false;
}
that.cur_id = id;
Core.Data.question_update = true;
$e.data('path', '/user/question/view?id=' + id + '&format=json');
Core.load_json($e, function(data){
Core.Data.question_detail = data;
Core.showTips('加载完成!', true, 2000);
Core.updateMod('question_detail');
}, that);
// Core.showTips('加载中...', true, 5000);
// $.getJSON('/user/question/view?id=' + id + '&format=json',
// function(data) {
// Core.Data.question_detail = data;
// Core.showTips('加载完成!', true, 2000);
// Core.updateMod('question_detail');
// });
return false;
});
that.$c.on('click', 'li.more a', function(e) {
e.preventDefault();
Core.load_html($(e.target), that.refresh, that);
return false;
});
}
Kefu_list.prototype.refresh = function() {
this.myScroll.refresh();
}
Kefu_list.prototype.show_after = function() {
if (this.$c.find('.kefu-list').children().length == 0) {
$ol = this.$c.find('.kefu-list');
if($ol.attr('data-params-url').indexOf('undefined') == -1)
Core.load_html(this.$c.find('.kefu-list'), this.act_cb,
this);
}
this.isValid = false;
}
Kefu_list.prototype.act_cb = function(data) {
if (!this.myScroll){
this.myScroll = new iScroll('kefu_wrapper');
}
}
Core.registerMod('kefu_list', Kefu_list);
var Modify_pwd = function(modId) {
Module.call(this, modId);
}
Core.inherit(Modify_pwd, Module);
Modify_pwd.prototype.bind = function() {
var that = this;
that.$c.on('click', '[type=submit]', function(e) {
e.preventDefault();
Core.ajax_do(that.$c.find('.ajax'), that.modify_cb, that);
return false;
});
}
Modify_pwd.prototype.modify_cb = function(data) {
var status_code = data.code;
var msg = data.msg;
if (status_code == 0) {
if(Core.Data.is_guest == 1){
//游客帐号转正
localStorage.removeItem('guest_n');
Core.showTips('账号升级成功, 请记住登录名和新密码。', true);
}
if (!Core.user_names) Core.user_names = {}
Core.user_names[msg.username] = this.$c.find('input[name=newpwd]').val();
localStorage.setItem('user_names', JSON.stringify(Core.user_names));
Core.Data.is_guest = msg.is_guest;
Core.Data.username = msg.username;
Core.Data.nickname = msg.nickname;
// 强制更新显示home模块,模块自刷新
this.isValid = false;
Core.updateMod('home');
} else {
Core.showTips(msg, false);
}
}
Core.registerMod('modify_pwd', Modify_pwd);
/**
* 客服问题详细模块
*/
var Question_detail = function(modId) {
this.myScroll = null;
this.$score = null;
Module.call(this, modId);
}
Core.inherit(Question_detail, Module);
Question_detail.prototype.bind = function() {
var that = this;
that.$c.on('click', 'li.more a', function(e) {
e.preventDefault();
Core.load_html($(e.target), that.refresh, that);
return false;
});
that.$c.on('click', 'li p > a', function(e) {
e.preventDefault();
that.$score = $(e.target);
Core.ajax_do($(e.target), that.jude_cb, that);
return false;
})
}
Question_detail.prototype.jude_cb = function(data) {
Core.showTips(data.msg);
if (data.code == 0) {
var score = this.$score.html();
this.$score.parent().empty().html(
'您的评价: <span class="btn">' + score
+ '</span>');
}
}
Question_detail.prototype.refresh = function() {
var that = this;
setTimeout(function() {
that.myScroll.refresh();
}, 300);
}
Question_detail.prototype.show_after = function() {
if (Core.Data.question_update) {
if (this.myScroll){
this.myScroll.destory();
}else{
this.myScroll = new iScroll('question_detail_scroller');
}
}
}
Core.registerMod('question_detail', Question_detail);
/**
* enter_game_amount 进入sdk的要购买的游戏币
* enter_amount 进入sdk要购买的游戏币转为平台币数量(换算)
* total_amount 用户所拥有的平台币
* game_amount 本次支付需要购买的游戏币
* youai_star 本次支付需要支付的平台币(换算)
* money 本次支付需要支付的人民币(换算)
*/
function pay_init() {
if (Core.Data.enter_game_amount > 0) {
Core.Data.enter_amount = Core.Data.enter_game_amount / Core.Data.exchange_rate;
Core.Data.pay_again = 0;
}
if (Core.Data.enter_game_amount > 0
&& Core.Data.enter_amount <= Core.Data.total_amount) {
// 需要进入兑换页面
Core.start_page = "exchange";
Core.Data.game_amount = Core.Data.enter_game_amount;
Core.Data.youai_star = Core.Data.enter_amount;
Core.Data.money = Core.Data.youai_star / Core.Data.rate;
} else if (Core.Data.enter_game_amount > 0) {
// 需要进入渠道充值页面
Core.start_page = "channel_list";
Core.Data.game_amount = Core.Data.enter_game_amount;
Core.Data.youai_star = Core.Data.enter_amount;
Core.Data.money = Core.Data.youai_star / Core.Data.rate;
} else {
// 没有输入充值数量,进入选择数量的界面
}
}
function onBridgeReady() {
var mainImgUrl = Core.Data.game_icon;
var mainURL = Core.Data.invite_url;//'http://www.9133.com/game/' + Core.Data.app_id + '.html';
var mainTitle= '一起玩' + Core.Data.game_name;
var mainDesc = '我在玩' + Core.Data.game_name + ',游戏很棒,一起来玩吧!';
try{
WeixinJSBridge.on("menu:share:timeline", function(e) {
var data = {
appid:'wx1d2b5cd6b11aaf3d',
img_url:mainImgUrl,
img_width: "120",
img_height: "120",
link: mainURL,
desc: mainDesc,
title: mainTitle
};
alert('shareTimeline');
WeixinJSBridge.invoke("shareTimeline", data, function(res) {
WeixinJSBridge.log(res.err_msg);
});
});
WeixinJSBridge.on("menu:share:weibo", function() {
WeixinJSBridge.invoke("shareWeibo", {
"content": mainDesc,
"url": mainURL
}, function(res) {
//alert(res.err_msg);
//WeixinJSBridge.log(res.err_msg);
});
});
WeixinJSBridge.on('menu:share:appmessage', function(argv) {
WeixinJSBridge.invoke("sendAppMessage", {
appid:'wx1d2b5cd6b11aaf3d',
img_url: mainImgUrl,
img_width: "120",
img_height: "120",
link: mainURL,
desc: mainDesc,
title: mainTitle
}, function(res) {
//alert(res.err_msg);
//WeixinJSBridge.log(res.err_msg)
});
});
} catch(error){alert(error);}
};
if (typeof WeixinJSBridge == "undefined"){
if( document.addEventListener ){
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
}else if (document.attachEvent){
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
}
}else{
onBridgeReady();
}
if (window.isGetData == 1) {
// 兼容旧版本sdk
pay_init();
$('#loading').hide();
Core.init();
} else {
window.isGetData = 1;
window.initFunc = pay_init;
}
}
})();