Jamcuk
2017-12-27 3996156e8e022dce953986acd91c3045272a4adb
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
998
999
1000
1001
1002
1003
1004
1005
1006
//获取应用实例
 
const app = getApp();
const com = require("../../utils/common.js");
const dowx = require("../../utils/DOWX.js");
var th = null;
 
// 上传域名
const uphttp = "https://bn.izbsq.com/";
 
Page({
 
    // 页面数据
    data: {
        // 需要获取的数据
        openid: null, //我的openid
        videoid: null, //该视频编号
        typenum: null, //该视频归属种
        // 领取概要
        had_lingqu: 0, //已经被领取的个数
        max_lingqu: 0, //红包共有的个数
        max_dashang: 0, //总的打赏人数
        // 视频文件信息
        process: null, //视频生成进度
        src_videoimg: null, //视频封面图片
        url_video: null, // 后台的视频地址
        // 录音格式
        time_luyinmin: 2, // 录音最短长度限制
        time_luyinmax: 10, // 录音最长长度限制
        // 弹幕的组
        zu_danmu: [], //弹幕的列表组
        // 领取的红包
        tf_hadlingqu: false, //是否已经领取过钱,控制是否弹出红包领取框
        bao_toux: null, //红包发起者的头像
        bao_nickname: '发起者昵称', //发起者昵称
        bao_jine: 0, //领取到的金额数值      
        
 
        // 使用中获取的变量
        show_video: true, //video组件是否可以显示
        show_ly: false, // 录音提示是否显示
        // 当前进行的步骤数
        bushu: 1,
        // video使用
        src_video: null, //video播放时的src
        tf_animt_cover: false, //是否允许弹幕滚动,用于重置弹幕
        // 录音
        zu_wificlass: ['luyinbo_wifi', 'luyinbo_wifi', 'luyinbo_wifi'], //录音播放的wifi样式
        file_luyin: null, // 录音文件
        time_luyin: 0,  // 录音时长
        time_show: '00' // 录音时提示的时间
    },
 
    // 数据请求
    getdata: {
        working1: false, //获取视频进度中?
        working2: false, //获取语音录制的格式要求中?
        working3: false, //获取视频红包的详情信息中?
        working4: false, //获取弹幕组中?
        working5: false, //获取视频链接中?
        // 获取视频生成进度
        timeout_process: null,
        process: function (callback) 
        {
            if (callback == null) { callback = function () { }; }
            if (th.getdata.working1 == true) { return false; } //已经在工作中了,那么直接退出
            th.getdata.working1 = true; //进入工作标识
            
            // 数据准备
            var mydata = {
                openid: th.data.openid,
                id: th.data.videoid
            };
            var myurl = com.getWholeUrl('bainian/api/client/video/getdrawprocess', mydata);
            // 数据请求
            dowx.AjaxPost(myurl, {}, function (res) 
            {
                th.getdata.working1 = false;
                dowx.AjaxStop([th.getdata.working1, th.getdata.working2, th.getdata.working3, th.getdata.working4, th.getdata.working5]);
 
                if (res.code == 0) 
                {
                    // 保存生成进度
                    th.setData({ process: res.data.process });
                    // 如果进度不为100,那么5s再次请求
                    if (th.data.process == 100) { callback(); }
                    else { 
                        th.getdata.timeout_process = setTimeout(function(){
                            console.log("timeout:请求生成进度");
                            th.getdata.process(callback);
                        },5000); 
                    }
                }
                else {
                    wx.showToast({
                        title: '进度' + res.msg,
                        image: '/img/zdo_error.png',
                        duration: 2500,
                    });
                }
            });
        },
        // 请求语音录制的格式要求
        luyingeshi: function ()
        {
            if (th.getdata.working2 == true) { return false; } // 如果已经在工作,那么直接退出函数
            th.getdata.working2 = true; //进入工作标识
 
            // 数据准备
            var mydata = { openid: th.data.openid };
            var myurl = com.getWholeUrl("bainian/api/client/config/getvideoconfig", mydata);
            // 请求数据
            dowx.AjaxPost(myurl, {}, function (res) 
            {
                th.getdata.working2 = false;
                dowx.AjaxStop([th.getdata.working1, th.getdata.working2, th.getdata.working3, th.getdata.working4, th.getdata.working5]);
 
                if (res.code == 0) 
                {
                    th.setData({ 
                        time_luyinmin: res.data.minVoiceTime, 
                        time_luyinmax: res.data.maxVoiceTime 
                    });
                }
                else {
                    wx.showToast({
                        title: '录音格式' + res.msg,
                        image: '/img/zdo_error.png',
                        duration: 2500,
                    });
                }
            });
        },
        // 请求视频红包的详情信息
        videoxiangqin: function (callback) 
        {
            if (callback == null) { callback = function () { }; }
            if (th.getdata.working3 == true) { return false; } //已经在工作中了,那么直接退出
            th.getdata.working3 = true; //进入工作标识
 
            // 数据准备
            var mydata = {
                id: th.data.videoid,
                openid: th.data.openid
            };
            var myurl = null;
            if (th.data.typenum == 1) { myurl = com.getWholeUrl('bainian/api/client/video/hb/getdetail', mydata); }
            else if (th.data.typenum == 2) { myurl = com.getWholeUrl('bainian/api/client/video/ysq/getdetail', mydata); }
            // 数据请求
            dowx.AjaxPost(myurl, {}, function(res)
            {
                th.getdata.working3 = false;
                dowx.AjaxStop([th.getdata.working1, th.getdata.working2, th.getdata.working3, th.getdata.working4, th.getdata.working5]);
 
                if (res.code == 0) 
                {
                    // 共同信息赋值
                    th.setData({
                        src_videoimg: res.data.videoGameInfo.postPicture, //视频封面图片
                        url_video: res.data.videoGameInfo.video.finalVideoUrl, //后台的视频地址
                        bao_toux: res.data.videoGameInfo.user.portrait, //红包发起者的头像
                        bao_nickname: res.data.videoGameInfo.user.nickName, //发起者昵称
                        shareimg: res.data.videoGameInfo.shareImg //朋友圈分享图
                    });
                    // 私有信息赋值
                    if (th.data.typenum == 1) 
                    {
                        th.setData({
                            had_lingqu: res.data.recieveCount,//已经被领取的个数
                            max_lingqu: res.data.moneyCount,//红包共有的个数
                            tf_hadlingqu: res.data.received, //是否已经领取过红包
                        });
                    }
                    else if (th.data.typenum == 2) 
                    {
                        th.setData({
                            max_dashang: res.data.totalCount,//总打赏人数
                        });
                    }
                    callback();
                }
                else {
                    wx.showToast({
                        title: res.msg,
                        image: '/img/zdo_error.png',
                        duration: 2500,
                    });
                }
            });
        },
        // 请求视频地址
        videourl: function ()
        {
            if (th.getdata.working5 == true) { return false; } //已经在工作中了,那么直接退出
            th.getdata.working5 = true; //进入工作标识
 
            // 数据准备
            var mydata = { openid: th.data.openid, id: th.data.videoid };
            var myurl = com.getWholeUrl("bainian/api/client/video/getplayurl", mydata);
            // 请求数据
            dowx.AjaxPost(myurl, {}, function (res) 
            {
                th.getdata.working5 = false;
                dowx.AjaxStop([th.getdata.working1, th.getdata.working2, th.getdata.working3, th.getdata.working4, th.getdata.working5]);
 
                if (res.code == 0) {
                    th.setData({ src_video: res.data.playUrl });
                }
                else {
                    wx.showToast({
                        title: res.msg,
                        image: '/img/zdo_error.png',
                        duration: 2500,
                    });
                }
            });
        },
        // 请求弹幕组
        danmu: function (callback) 
        {
            if (callback == null) { callback = function () {}; }
            if (th.getdata.working4 == true) { return false; } //已经在工作中了,那么直接退出
            th.getdata.working4 = true; //进入工作标识
 
            // 数据准备,一次请求200条数据,即全部请求
            var mydata = {
                id: th.data.videoid,
                openid: th.data.openid,
                page: 1,
                pagesize: 200
            };
            var myurl = null;
            if (th.data.typenum == 1) { myurl = com.getWholeUrl('bainian/api/client/video/hb/getmoneyjoinlist', mydata); }
            else if (th.data.typenum == 2) { myurl = com.getWholeUrl('bainian/api/client/video/ysq/getjoinlist', mydata); }
            // 发起请求
            dowx.AjaxPost(myurl, {}, function(res)
            {
                th.getdata.working4 = false;
                dowx.AjaxStop([th.getdata.working1, th.getdata.working2, th.getdata.working3, th.getdata.working4, th.getdata.working5]);
 
                if (res.code != 0) { 
                    wx.showToast({
                        title: res.msg,
                        image: '/img/zdo_error.png',
                        duration: 2500,
                    });
                }
                else
                {
                    if (th.data.typenum == 1) 
                    {
                        // 查看是否已经上传过录音
                        if (res.data.voice.length != 0) { th.setData({ file_luyin: res.data.voice }); }
                        else { th.setData({ file_luyin: null }); }
                    }
 
                    var zu_mo = [];//保存临时数据的组
                    // 通过循环将临时组的元素补全
                    for (var i = 0; i < res.data.data.length; i++) 
                    {
                        var yuan = {
                            userid: res.data.data[i].user.id, //用户id
                            userimg: res.data.data[i].user.portrait, //用户头像
                            time_luyin: res.data.data[i].voiceTime, //录音时长
                            show_danmu: false, // 是否显示该条弹幕
                            hadtime: 0 // 已经显示的时间
                        };
                        if (th.data.typenum == 1) {
                            yuan.money = res.data.data[i].money; //领取金额
                        }
                        else if (th.data.typenum == 2) {
                            yuan.money = res.data.data[i].money; //打赏金额
                        }
                        zu_mo.push(yuan);
                    }
                    // 弹幕组赋值
                    th.setData({ zu_danmu: zu_mo });
 
                    // 清除弹幕定时器
                    th.getdata.clear_danmu();
                    // 弹幕滚动
                    th.getdata.setinval_danmu();
                    
                    callback();
                }
            });
        },
        // 弹幕循环计时器方法, inval_danmu为null才可执行
        inval_danmu: null,
        timeout_danmu: null,
        setinval_danmu: function ()
        {
            // 如果弹幕条数为0,那么直接退出
            if (th.data.zu_danmu.length <= 0) { return false; } 
            // 如果已经存在计时器,那么不操作,直接退出
            if (th.getdata.inval_danmu != null) { return false; }
 
            // 对弹幕组出场进行配置:
            var length_zu = th.data.zu_danmu.length; // 弹幕组的长度
            var index_danmu = -1; //当前操作的弹幕组元素下标
            // 进行弹幕计时循环
            th.getdata.inval_danmu = setInterval(function () 
            {
                // 将处理的元素下标+1
                index_danmu = index_danmu + 1;
                // 下标超标则退出定时器
                if (index_danmu >= length_zu) 
                {
                    // 清除定时器
                    clearInterval(th.getdata.inval_danmu); th.getdata.inval_danmu = null;
 
                    // 重头滚动弹幕
                    th.getdata.timeout_danmu = setTimeout(function()
                    {
                        console.log("timeout:弹幕将马上重头再来");
                        // 初始化清除弹幕
                        th.getdata.clear_danmu();
                        // 递归本函数
                        th.getdata.setinval_danmu();
                    },6500);
                }
                // 未超出则依次显示
                else
                {
                    console.log("interval:新弹幕马上进入");
                    // 让当前下标元素变为show
                    var mo_zu = th.data.zu_danmu;
                    mo_zu[index_danmu].show_danmu = true;
                    th.setData({ zu_danmu: mo_zu });
                    // show为true的元素显示时间全部+1
                    for (var i=0; i<=index_danmu; i++)
                    {
                        if(mo_zu[i].show_danmu == true)
                        {
                            mo_zu[i].hadtime = mo_zu[i].hadtime + 2.5;
                            th.setData({ zu_danmu: mo_zu });
                            mo_zu = th.data.zu_danmu;
                            // 弹幕滚动出局检测
                            if (mo_zu[i].hadtime > 11) 
                            {
                                // 将这个元素show设为false
                                mo_zu[i].show_danmu = false;
                                th.setData({ zu_danmu: mo_zu });
                            }
                        }
                    }
                }
 
            }, 2500);
        },
        // 停止弹幕且归零
        clear_danmu: function ()
        {
            // 清除定时器
            if (th.getdata.inval_danmu != null) { clearInterval(th.getdata.inval_danmu); th.getdata.inval_danmu = null; }
            if (th.getdata.timeout_danmu != null) { clearTimeout(th.getdata.timeout_danmu); th.getdata.timeout_danmu = null; }
            // 将弹幕元素的show设为false, time设为0
            var mo_zu = th.data.zu_danmu;
            for (var i = 0; i < mo_zu.length; i++) 
            {
                if (mo_zu[i].hadtime != 0) 
                {
                    mo_zu[i].hadtime = 0;
                    mo_zu[i].show_danmu = false;
                }
            }
            th.setData({ zu_danmu: mo_zu });
        }
    },
 
    // 获取超链接传递的视频编号等信息,获取一次视频生成进度
    onLoad: function (options) 
    {
        // 对th赋值
        th = this;
        // 是否传递有视频编号
        if ( options.videoid ) 
        {   
            // 得到且保存 当前视频id,视频type
            th.setData({ 
                videoid: options.videoid, 
                typenum: options.type 
            });
            // 获取视频文件信息
            app.Get_info(function (info2) 
            {
                th.setData({ openid: info2.info2.openid });
                // 预先获取:该视频红包的相关信息
                th.getdata.videoxiangqin();
                // 获取生成进度
                th.getdata.process(function()
                {
                    // 请求录音录制格式
                    th.getdata.luyingeshi();
                    // 请求视频地址
                    th.getdata.videourl();
                    // 获取弹幕组
                    th.getdata.danmu();
                });
            });
        }
        // 通过二维码获取
        else if ( decodeURIComponent(options.scene) != "undefined" ) 
        {
            var scene = decodeURIComponent(options.scene);
            scene = JSON.parse(scene);
            console.log(scene);
            // 得到且保存 当前视频id,视频type
            th.setData({ 
                videoid: options.videoid, 
                typenum: options.type 
            });
            // 获取视频文件信息
            app.Get_info(function (info2) 
            {
                th.setData({ openid: info2.info2.openid });
                // 预先获取:该视频红包的相关信息
                th.getdata.videoxiangqin();
                // 获取生成进度
                th.getdata.process(function () 
                {
                    // 请求录音录制格式
                    th.getdata.luyingeshi();
                    // 请求视频地址
                    th.getdata.videourl();
                    // 获取弹幕组
                    th.getdata.danmu();
                });
            });
        }
        // 未能获取
        else { dowx.Showred(th,'未能获取视频id'); }
    },
    
    // 获取录音权限,获取视频信息
    onShow: function()
    {
        // 获取录音权限
        dowx.Authorize_record();
        // 当视频处理好后通过
        if (th.data.process == 100)
        {
            // 请求录音录制格式
            th.getdata.luyingeshi();
            // 获取该视频红包的相关信息
            th.getdata.videoxiangqin();
            // 获取弹幕组
            th.getdata.danmu();
        }
    },
 
    onPullDownRefresh: function () 
    {
        setTimeout(function () { wx.stopPullDownRefresh(); },300); 
        if (th.data.process == 100) 
        {
            // 请求录音录制格式
            th.getdata.luyingeshi();
            // 获取该视频红包的相关信息
            th.getdata.videoxiangqin();
            // 获取弹幕组
            th.getdata.danmu();
        }
    },
 
    onShareAppMessage: function () 
    {
        // 分享的标题设置
        var title = "";
        if (th.data.typenum == 1) { title = th.data.bao_nickname + "-发福利啦"; }
        else if (th.data.typenum == 2) { title = th.data.bao_nickname + "-来拜年了"; }
        return {
            title: title,
            path: '/pages/lingqu/lingqu?videoid=' + th.data.videoid + '&type=' + th.data.typenum,
            imageUrl: th.data.src_videoimg
        }
    },
 
    onUnload: function ()
    {
        // 清除弹幕定时器
        th.getdata.clear_danmu();
        // 清除5s请求的定时器
        if (th.getdata.timeout_process != null) { clearTimeout(th.getdata.timeout_process); th.getdata.timeout_process = null; }
    },
 
 
    // 红包隐藏框 事件 ----------------------------------------------------------------------------------------
    // 
    // 边缘图层 点击
    Click_bian: function()
    { 
       
        th.setData({ yc_bao: false }); // 红包框隐藏
        th.setData({ yc_baobushu: 1 }); //回到红包最初界面
        th.myvideo.show(); // video显示
    },
    // 立即开抢 点击
    Click_kaiqiang: function()
    {
        // 有录音文件时:录音后领取
        if (th.data.file_luyin!=null)
        {
            // 数据准备
            var mydata = {
                appid: 'wx4dbc1f6c7cf71b68',
                id: th.data.videoid,
                openid: th.data.openid,
                time: th.data.time_luyin
            };
            var myurl = uphttp + 'bainian/api/client/video/hb/recievehb';
            // 发送数据
            wx.showLoading({ title: '' });//loading框展示
            wx.uploadFile({
                url: myurl,
                filePath: th.data.file_luyin,
                name: 'voice',
                formData: mydata,
                fail: function (res) { 
                    wx.hideLoading();
                    wx.showToast({
                        title: '上传录音→fail',
                        image: '/img/zdo_error.png',
                        duration: 2500,
                    });
                },
                success: function (res) 
                {
                    wx.hideLoading();
                    res = JSON.parse(res.data);
                    if (res.code == 0) {
                        // 保存金额
                        th.setData({ bao_jine: res.data.money });
                        // 进入到红包第2步
                        th.setData({ yc_baobushu: 2 });
                        // 清除刚才的录音
                        th.setData({ time_luyin: 0, file_luyin: null });
                        // 页面进入第1步
                        th.setData({ bushu: 1 });
                        // 获取该视频红包的相关信息
                        th.getdata.videoxiangqin();
                        // 获取弹幕组
                        th.getdata.danmu();
                    }
                    else {
                        wx.showToast({
                            title: res.msg,
                            image: '/img/zdo_error.png',
                            duration: 2500,
                        });
                        // 清除刚才的录音
                        th.setData({ time_luyin: 0, file_luyin: null });
                        // 页面进入第1步
                        th.setData({ bushu: 1 });
                        // 获取该视频红包的相关信息
                        th.getdata.videoxiangqin();
                        // 获取弹幕组
                        th.getdata.danmu(function(){
                            // 弹框取消
                            th.Click_bian();
                        });
                    }
                }
            });
        }
        // 无录音文件时:看完视频就领
        else
        {
            // 数据准备
            var mydata = {
                appid: 'wx4dbc1f6c7cf71b68',
                id: th.data.videoid,
                openid: th.data.openid
            };
            var myurl = com.getWholeUrl('bainian/api/client/video/hb/recievehb',mydata);
            // 发送数据
            wx.showLoading({ title: '' });//loading框展示
            dowx.AjaxPost( myurl,{},function (res) 
            {
                wx.hideLoading();
                dowx.AjaxStop();
 
                if (res.code == 0) {
                    // 保存金额
                    th.setData({ bao_jine: res.data.money });
                    // 进入到红包第2步
                    th.setData({ yc_baobushu: 2 });
                    // 获取该视频红包的相关信息
                    th.getdata.videoxiangqin();
                    // 获取弹幕组
                    th.getdata.danmu();
                }
                else {
                    wx.showToast({
                        title: res.msg,
                        image: '/img/zdo_error.png',
                        duration: 2500,
                    });
                    // 获取该视频红包的相关信息
                    th.getdata.videoxiangqin();
                    // 获取弹幕组
                    th.getdata.danmu(function(){
                        // 弹框取消
                        th.Click_bian();
                    });
                }
            });
        }
    },
    // 查看详情 点击
    Click_xiangq: function() 
    { 
        th.myvideo.pause(); // 视频暂停
        wx.navigateTo({ url: '/pages/lingqulist/lingqulist?videoid='+th.data.videoid+'&type='+th.data.typenum }); 
    },
 
    // 分享隐藏框 事件 ----------------------------------------------------------------------------------------
    // 
    // 蒙层 点击
    Click_yc: function () { 
        th.setData({ yc_if2: false }); // 分享选择框隐藏
        th.myvideo.show(); // video显示
    },
    // 取消冒泡传递
    Click_yc2: function () {},
    // 朋友圈分享图 点击
    Click_sharepyq: function () {
        // 打开图片预览
        wx.previewImage({
            urls: [th.data.shareimg],
            fail: function (res) { dowx.Showred(th, '打开分享图→fail'); }
        });
    },
 
 
    // 按键 事件 ----------------------------------------------------------------------------------------
    // 
    // 主页按钮
    Click_paishe: function () { wx.reLaunch({ url: '/pages/index/index' }); },
 
    // 分享按钮
    Click_share: function () 
    {
        // 视频是否已经生成
        if (th.data.process != 100) {
            // 弹框表示正在生成中
            dowx.Showgreen(th, '正在生成中');
            return false;
        }
        // 暂停video播放
        th.myvideo.pause();
        // 隐藏video
        th.myvideo.hide();
        // 停止播放录音文件
        th.myaudio.stopben(); //本地播
        th.myaudio.stopwang(); //网络播
        // 显示分享选项弹框
        th.setData({ yc_if2: true });
    },
 
    // 录制录音按钮 按下
    working_record: false,
    An_luzhi: function () 
    {
        // 视频是否已经生成
        if (th.data.process != 100) {
            // 弹框表示正在生成中
            dowx.Showgreen(th, '正在生成中');
            return false;
        }
        if (th.working_record == true) { return false; }
        th.working_record = true;
        // 暂停video播放
        th.myvideo.pause();
        // 录音提示显示
        th.setData({ show_ly: true, time_show: '00' });
        // 启动录音
        dowx.Record_start(th, th.data.time_luyinmax, function (res) 
        {
            // 这里是录音文件回调
            if (res.time < th.data.time_luyinmin) 
            {
                wx.showToast({
                    title: '最少需要' + th.data.time_luyinmin + 's',
                    image: '/img/zdo_error.png',
                    duration: 2500,
                });
                th.setData({ file_luyin: null, time_luyin: 0 }); //消除录音文件
            }
            else if (res.time >= th.data.time_luyinmin) {
                // 录音提示隐藏
                th.setData({ show_ly: false });
                // 录音信息赋值
                th.setData({ file_luyin: res.tempFilePath, time_luyin: res.time });
                // 进入第2步
                th.setData({ bushu: 2 });
            }
            th.working_record = false;
        }, 
        function(timeD)
        {  
            var mo_timed = '00';
            if (timeD < 10) { mo_timed = '0' + timeD; }
            else if (timeD >= 10) { mo_timed = timeD; }
            th.setData({ time_show: mo_timed });
        });
    },
    // 录制录音按钮 松开
    Out_luzhi: function () 
    {
        // 视频是否已经生成
        if (th.data.process != 100) { return false; }
        // 录音提示隐藏
        th.setData({ show_ly: false });
        // 停止录音
        dowx.Record_stop(th);
    },
 
    // 重录按钮
    Click_chonglu: function () 
    {
        th.myaudio.stopben(); //录音播放停止
        th.tf_baibo = false; //录音播放停止
        th.setData({ file_luyin: null, time_luyin: 0 }); //消除录音文件 
        th.setData({ bushu: 1 }); //步数回到第1步    
    },
 
    // 播放本地录音按钮
    Click_luyinbo: function () 
    {
        // 语音未在播放则进行播放
        if (th.tf_baibo != true) 
        {
            // 暂停video播放
            th.myvideo.pause();
            // 播放录音文件
            th.myaudio.playben();
            th.tf_baibo = true;
        }
        // 语音在播放则暂停
        else{
            //停止播放录音文件
            th.myaudio.stopben();
            th.tf_baibo = false;
        }
    },
    // 播放后台录音按钮
    Click_luyinbo1: function () 
    {
        // 语音未在播放则进行播放
        if (th.tf_baibo != true) 
        {
            // 暂停video播放
            th.myvideo.pause();
            //播放录音文件
            th.myaudio.playwang();
            th.tf_baibo = true;
        }
        // 语音在播放则暂停
        else{
            //停止播放录音文件
            th.myaudio.stopwang();
            th.tf_baibo = false;
        }
    },
 
    // 上传录音按钮
    Click_queren: function () 
    {
        // 据情况弹出红包框,未领取过钱且红包还有剩余便可弹出
        if (th.data.tf_hadlingqu == false && th.data.had_lingqu < th.data.max_lingqu) 
        { 
            th.myvideo.pause(); // 暂停video
            th.myvideo.hide(); // 隐藏video
            th.setData({ yc_bao: true }); // 红包显示
        }
        // 不然只上传录音
        else {
            // 数据准备
            var mydata = {
                appid: 'wx4dbc1f6c7cf71b68',
                id: th.data.videoid,
                openid: th.data.openid,
                time: th.data.time_luyin
            };
            var myurl = uphttp + 'bainian/api/client/video/hb/recievehb';
            // 发送数据
            wx.showLoading({ title: '' });//loading框展示
            wx.uploadFile({
                url: myurl,
                filePath: th.data.file_luyin,
                name: 'voice',
                formData: mydata,
                fail: function () { 
                    wx.hideLoading(); 
                    wx.showToast({
                        title: '录音上传→fail',
                        image: '/img/zdo_error.png',
                        duration: 2500,
                    });
                },
                success: function (res) 
                {
                    wx.hideLoading();
                    res = JSON.parse(res.data);
                    if (res.code == 0) {
                        // 弹框提示
                        dowx.Showgreen(th, '上传成功');
                        // 清除刚才的录音
                        th.setData({ time_luyin: 0, file_luyin: null });
                        // 回到步数1
                        th.setData({ bushu: 1 });
                        // 获取该视频红包的相关信息
                        th.getdata.videoxiangqin();
                        // 获取弹幕组
                        th.getdata.danmu();
                    }
                    else {
                        wx.showToast({
                            title: res,msg,
                            image: '/img/zdo_error.png',
                            duration: 2500,
                        });
                        // 清除刚才的录音
                        th.setData({ time_luyin: 0, file_luyin: null });
                        // 回到步数1
                        th.setData({ bushu: 1 });
                        // 获取该视频红包的相关信息
                        th.getdata.videoxiangqin();
                        // 获取弹幕组
                        th.getdata.danmu();
                    }
                }
            });
        }
    },
 
    // 打赏按钮
    Click_dashang: function () 
    {
        // 视频是否已经生成
        if (th.data.process != 100) {
            // 弹框表示正在生成中
            dowx.Showgreen(th, '正在生成中');
            return false;
        }
        th.myvideo.pause(); // 视频暂停
        wx.navigateTo({ url: '/pages/dashang/dashang?videoid=' + th.data.videoid });
    },
 
    // 弹幕点击
    Click_danmudan: function (ev) 
    {
        // 获取点钱点击的弹幕的下标index
        var index = ev.currentTarget.id;
        th.myvideo.pause(); // 视频暂停
        wx.navigateTo({
            url: '/pages/lingqulist/lingqulist?videoid=' + th.data.videoid + '&type=' + th.data.typenum + '&index=' + index
        });
    },
 
 
 
    // 组件对象 -----------------------------------------------------------------------------------------------
    // 
    // 视频组件
    myvideo: {
        obj: null, // 组件对象
        id: 'myvideo', // 组件id
        uploadpath: null, // 下载的视频本地地址
        // video组件显示
        show: function () { 
            // 设置显示
            th.setData({ show_video: true }); 
            // 弹幕滚动
            th.getdata.setinval_danmu(); 
        },
        // video组件隐藏
        hide: function () { 
            // 清除弹幕定时器
            th.getdata.clear_danmu();
            // 设置隐藏
            th.setData({ show_video: false }); 
        },
        // 暂停视频
        pause: function () 
        {
            if (th.myvideo.obj == null) { th.myvideo.obj = wx.createVideoContext(th.myvideo.id); }
            th.myvideo.obj.pause();
            // 清除弹幕定时器
            th.getdata.clear_danmu();
        },
        // 下载视频
        uploadvideo: function () 
        {
            //未下载完成时通过
            if (th.myvideo.uploadpath == null) 
            {
                // 未在工作中状态才可以下载
                if (th.tf_working_upload != true) 
                {
                    th.tf_working_upload = true; //正在下载工作中
                    // 视频下载
                    wx.downloadFile({
                        url: th.data.url_video,
                        fail: function () { console.log('视频下载失败'); },
                        success: function (res) 
                        {
                            console.log("视频下载完成");
                            //路径赋值
                            th.myvideo.uploadpath = res.tempFilePath;
                            th.tf_working_upload = false; //未在下载工作中
                        }
                    });
                    // 标题图下载
                    wx.downloadFile({
                        url: th.data.src_videoimg,
                        fail: function () { console.log('标题图下载失败'); },
                        success: function (res) { th.setData({ src_videoimg: res.tempFilePath }); }
                    });
                }
            }
        },
        // 播放完毕后,重置src,让封面图显示
        endplay: function () 
        {
            // 初始化src
            th.setData({ src_video: null });
            // 下载完成时
            if (th.myvideo.uploadpath != null) { th.setData({ src_video: th.myvideo.uploadpath }); }
            // 没有下载完成时
            else { th.setData({ src_video: th.data.url_video }); }
            // 据情况弹出抢红包框
            if (th.data.tf_hadlingqu == false && th.data.had_lingqu < th.data.max_lingqu) 
            { 
                th.myvideo.pause(); // 暂停
                th.myvideo.hide(); // 隐藏
                th.setData({ yc_bao: true }); // 红包框出现
            }
        }
    },
 
    // 当video开始播放时触发  
    Bindplay: function () {
        // 视频下载
        th.myvideo.uploadvideo();
        // 弹幕滚动
        th.getdata.setinval_danmu(); 
    },
    // 视频播放完毕触发
    Over_video: function () { th.myvideo.endplay(); },
 
    // 音频组件
    myaudio: {
        obj: null, // 组件对象
        id: 'myaudio', // 组件id
        // 开始本地录音播放
        playben: function ()
        {
            // wifi图标变化
            dowx.Play_wifi(th, 'luyinbo_wifi');
            wx.playVoice({
                filePath: th.data.file_luyin,
                fail: function () { 
                    wx.showToast({
                        title: '录音播放→fail',
                        image: '/img/zdo_error.png',
                        duration: 2500,
                    });
                },
                success: function () {
                    th.myaudio.stopben();
                },
            });
        },
        // 停止本地录音播放
        stopben: function() 
        { 
            //wifi动画停止
            dowx.Stop_wifi(th, 'luyinbo_wifi');
            wx.stopVoice(); 
        },
        // 开始网络音频播放
        playwang: function () 
        { 
            if (th.myaudio.obj == null) { th.myaudio.obj = wx.createAudioContext(th.myaudio.id); }
            th.myaudio.obj.setSrc(th.data.file_luyin);
            th.myaudio.obj.play(); 
            // wifi图标变化
            dowx.Play_wifi(th, 'luyinbo_wifi');
        },
        // 停止网络音频播放
        stopwang: function() 
        {
            if (th.myaudio.obj == null) { th.myaudio.obj = wx.createAudioContext(th.myaudio.id); }
            th.myaudio.obj.seek(0);
            th.myaudio.obj.pause();
            //wifi动画停止
            dowx.Stop_wifi(th, 'luyinbo_wifi');
        },
    },
 
    // 网络音频播放完毕
    audioend: function () { dowx.Stop_wifi(th, 'luyinbo_wifi'); th.tf_baibo = false; },
    
})