Program.js 45.5 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
//分类详情
var Common = require('Common');
var Network = require('Network');
var TVFocus = require('TVFocus');
var FocusInfo = require('FocusInfo');
var TVCanvas = require('TVCanvas');
var TVScrollParameter = require('TVScrollParameter');
var BusinessParameter = require('BusinessParameter');
var Utils = require('Utils');

cc.Class({
    extends: TVCanvas,

    properties: {
        _iCurrentNaviNumLoc: 1,
        _iNaviNumTotal: 0,
        _iMediaId: 0,
        _iBookMarkEpisodeId: 0,
        _iFavId: 0,  //校验收藏id
        _bCollected: false,  //是否收藏
        _bScore: false,//是否评分
        _bIsNaviDataInit: false, //是否初始化Navi
        _oEpisode: null,

        _iEpisodeNum: 1,         //恢复记录中的集数
        _strMediaName: '',       //记录中的集数名称
        _strMediaCode: '',       //记录的code值
        _strPlayUrl: '',

        videoPlay: cc.VideoPlayer,
        spriteScore: cc.Sprite,
        spriteCollect: cc.Sprite,
        homeBtnSprite:cc.Sprite,
        PFB_NAVI: {
            default: null,
            type: cc.Prefab,
        },
        PFB_EPISODE: {
            default: null,
            type: cc.Prefab,
        },
    },

    onLoad: function () {
        this._super();
        this._oImg = {};
        this.spriteCollect.spriteFrame.setRect(cc.rect(0, 0, this.spriteCollect.node.width, this.spriteCollect.node.height));
        this.spriteScore.spriteFrame.setRect(cc.rect(0, 0, this.spriteScore.node.width, this.spriteScore.node.height));
        this.homeBtnSprite.spriteFrame.setRect(cc.rect(0, 0, this.homeBtnSprite.node.width, this.homeBtnSprite.node.height));

        //-----------上下文及参数相关处理------------
        let oSceneParameter = this._cApplication.getTopSceneParameter();
        if (oSceneParameter) {
            this._strAppId = oSceneParameter.appId;//应用id
            this._iMediaId = oSceneParameter.id;
        }
        //恢复上下文
        // if (this._cApplication.getBackStatus()) {
        //     this._oSceneContext = this._cApplication.popSceneContext();
        //     this._cApplication.setBackStatus(false);
        // } else {
            this._oSceneContext = {};
            this._oSceneContext.currentPage = 1;
            this._oSceneContext.requestedStart = 0;
            this._oSceneContext._nodeGatherNumListX = 0;
            // this._oSceneContext.elderTypeId = oSceneParameter.typeId || 37;    //从上级拿过来的二级父Id
        // }

        this._strAppId = this._strAppId || "tda7e47f868313d9f5";  //测试
        this._iMediaId = this._iMediaId || 3050;
        //---------上下文及参数相关处理结束-----------

        this._graphicsLine = cc.find('EpisodeArea/GraphicsLine', this.node).getComponent(cc.Graphics);

        //剧集分类
        this._nodeNaviListWrapper = cc.find("NaviArea/NaviListWrapper", this.node);
        this._nodeNaviList = cc.find('NaviList', this._nodeNaviListWrapper);
        this._nodeNaviList.addComponent(TVScrollParameter);
        //剧集分类
        this._nodeEpisodeListWrapper = cc.find("EpisodeArea/EpisodeListWrapper", this.node);
        this._nodeEpisodeList = cc.find("EpisodeList", this._nodeEpisodeListWrapper);

        this.initPrefab();
        this.getPageBgTest(this, 'background');
        this.addHomeIcon(this);
        // this.getLastPlayRecord();   //获取播放记录
        this.checkPfbReadyAndInitPage();    //获取节目详情
        this.getAndCheckCollect();


        //VideoPlayer
        // this.videoPlay = cc.find("PlayBg/VideoView", this.node).getComponent(cc.VideoPlayer);
        this.videoPlay.remoteURL = "http://vjs.zencdn.net/v/oceans.mp4"; //测试播放器
        // this.videoPlay.node.on('ready-to-play', function (event) {
        //     this.videoPlay.play();
        // }, this);
    },

    onVideoPlayerEvent(sender, event) {
        // this.statusLabel.string = 'Status: ' + getStatus(event);
        if (event === cc.VideoPlayer.EventType.CLICKED) {
            if (this.videoPlay.isPlaying()) {
                this.videoPlay.pause();
            } else {
                this.videoPlay.play();
            }
        }

        else if (event === cc.VideoPlayer.EventType.COMPLETED) {    //相同视频源可能造成重复播放失败
            cc.log("play-complete---------->" + this._strPlayUrl);
            // this.videoPlay.remoteURL = "http://139.196.37.202:8080/sparrow.lab/80sTest_hd.mp4"; //测试播放器
            // this.videoPlay.remoteURL = this._strPlayUrl;
            // this.videoPlay.play();
        }
    },

    getPageBgTest: function (context, kind, spriteBg) {
        let oRankingRequestParameters = {
            "view": "json",
            "token": Common.TEST_API_TOKEN,
        };
        Network.ajax('GET', Common.TOPDRAW_API_SERVER2 + 'ArrangeHut/GetWallPaperFrame', null, oRankingRequestParameters,
            function (strResponse) {
                // cc.log("Success When Get Ranking..."+strResponse);
                try {
                    var oJSONResult = JSON.parse(strResponse);
                    if (oJSONResult.businessCode == 'success') {
                        if (oJSONResult.resultSet.length > 0) {
                            let nodeLeftRecommendPic = cc.find('Mask/Bg', context.node);
                            let normal = oJSONResult.resultSet[0].images.map.normal[0];
                            let background = oJSONResult.resultSet[0].images.map.background[0];
                            var strUrl = "";
                            if (kind == 'background') {
                                strUrl = Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[0].images.list[background].fileUrl;
                            } else if (kind == 'normal') {
                                strUrl = Common.TOPDRAW_IMAGE_SERVER + oJSONResult.resultSet[0].images.list[normal].fileUrl;
                            }
                            if (spriteBg) {   //新增骚操作
                                cc.loader.load(strUrl, function (err, texture) {
                                    spriteBg.spriteFrame = new cc.SpriteFrame(texture);
                                });
                                return;
                            }
                            if (strUrl) {
                                cc.loader.load(strUrl, function (err, texture) {
                                    nodeLeftRecommendPic.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
                                });
                            }
                        } else {
                            cc.log("Nothing...");
                        }
                    } else {
                        cc.log("Error When Get WallPaper..." + oJSONResult.description);
                    }
                } catch (error) {
                    cc.log("Exception When Get WallPaper..." + error);
                }
            },
            function (strResponse) {
                cc.log("Error When Get WallPaper..." + strResponse);
            }, this, "uuid");
    },

    initPrefab: function () {
        for (let i = 0; i < 4; i++) {
            let nodeEpisodeCell = cc.instantiate(this.PFB_EPISODE);
            nodeEpisodeCell.x = nodeEpisodeCell.width / 2 + (i) * (nodeEpisodeCell.width + 20);
            this._nodeEpisodeList.addChild(nodeEpisodeCell, 10, "EpisodeListCell" + i);
            let fiEpisodeBlock = nodeEpisodeCell.addComponent(FocusInfo);
            fiEpisodeBlock.init('{"click": [{"action": "ChangeScene","parameters": {"sceneName":"sceneProgramPlayerFullScreen"}}]}'
                , true, null, null, 1.0);
            this._aFocusTargets[0]['episode_list_cell_' + i] = nodeEpisodeCell;

            // let borderX = nodeEpisodeCell.x - nodeEpisodeCell.width / 2;     //搞边框
            // let borderY = nodeEpisodeCell.y - nodeEpisodeCell.height / 2;
            // this._graphicsLine.roundRect(borderX, borderY, 278, 175, 20);//圆角矩形路径
            // this._graphicsLine.stroke(); //绘制路径
        }
    },

    //校验收藏
    getAndCheckCollect: function () {
        var oCheckParams = {
            'view': 'json',
            'token': Common.TEST_API_TOKEN_EDU,
            // 'appId': this._strAppId
        };
        Network.ajax("GET", Common.TOPDRAW_API_SERVER_EDU + "User/GetDefaultCollection", null, oCheckParams,
            function (strResponse) {
                try {
                    var oJSONResult = JSON.parse(strResponse);
                    if (oJSONResult.businessCode == 'success') {
                        this._iFavId = oJSONResult.resultSet[0].id;
                        this.checkFav();
                        cc.log("Business Success:Get CheckCollect...");
                    } else {
                        cc.log("Business Error:Get CheckCollect..." + oJSONResult.description);
                    }
                } catch (error) {
                    cc.log("Business Exception:Get CheckCollect..." + error);
                }
            },
            function (strResponse) {
                cc.log("Business Error:Get CheckCollect..." + strResponse);
            }, this, "uuid");
    },

    //校验收藏
    checkFav: function () {
        var oCheckParams = {
            'view': 'json',
            'token': Common.TEST_API_TOKEN,
            'appId': this._strAppId,
            'collectionId': this._iFavId,
            'mediaIds': this._iMediaId,
            'start': 0,
            'limit': 1,
        };
        Network.ajax("GET", Common.TOPDRAW_API_SERVER + "User/ListMediaByCollection", null, oCheckParams,
            function (strResponse) {
                try {
                    var oJSONResult = JSON.parse(strResponse);
                    var self = this;
                    if (oJSONResult.businessCode == 'success') {
                        if (1 == oJSONResult.resultSet.length) {    //已收藏
                            this._bCollected = true;
                            cc.loader.loadRes('button/be_collected', cc.Texture2D, function (err, texture) {
                                self.spriteCollect.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 114, 106));
                            });
                        } else {    //未收藏
                            this._bCollected = false;
                            cc.loader.loadRes('button/not_collected', cc.Texture2D, function (err, texture) {
                                self.spriteCollect.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 114, 106));
                            });
                        }
                        cc.log("Business Success:Get CheckCollect...");
                    } else {
                        cc.log("Business Error:Get CheckCollect..." + oJSONResult.description);
                    }
                } catch (error) {
                    cc.log("Business Exception:Get CheckCollect..." + error);
                }
            },
            function (strResponse) {
                cc.log("Business Error:Get CheckCollect..." + strResponse);
            }, this, "uuid");
    },

    //获取播放历史
    getLastPlayRecord: function () {
        var oBookMarkParams = {
            'view': 'json',
            'start': 0,
            'limit': 150,
            'token': Common.TEST_API_TOKEN,
            'appId': this._strAppId
        };
        Network.ajax("GET", Common.TOPDRAW_API_SERVER + "User/ListBookmark", null, oBookMarkParams,
            function (strResponse) {
                try {
                    var oJSONResult = JSON.parse(strResponse);
                    if (oJSONResult.businessCode == 'success') {
                        let bIsBookMark = false;
                        for (let i = 0; i < oJSONResult.resultSet.length; i++) {
                            if (this._iMediaId == oJSONResult.resultSet[i].media_id && oJSONResult.resultSet[i].episode_id) {
                                this._iBookMarkEpisodeId = oJSONResult.resultSet[i].episode_id;
                                bIsBookMark = true;
                                this.getOneEpisode();
                            }
                        }

                        if (!bIsBookMark) {     //以前没播放过,默认播放第一集
                            if (this._oEpisode.resultSet[0].id) {
                                this._iBookMarkEpisodeId = this._oEpisode.resultSet[0].id;
                                this.getOneEpisode();
                            }
                        }
                        cc.log("Business Success:Get Play Record...");
                    } else {
                        cc.log("Business Error:Get Play Record..." + oJSONResult.description);
                    }
                } catch (error) {
                    cc.log("Business Exception:Get Play Record..." + error);
                }
            },
            function (strResponse) {
                cc.log("Business Error:Get Play Record..." + strResponse);
            }, this, "uuid");
    },
    //播放记录
    getOneEpisode: function () {
        cc.log("getOneEpisode-------------------------------->");
        if (Utils.isMobile()) {
            cc.log("getOneEpisode isMobile-------------------------------->");
            jsb.reflection.callStaticMethod("org/cocos2dx/javascript/ReflectActivity", "getPlayURL", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", this._iMediaId, this._iBookMarkEpisodeId, this._strAppId, "getPlayUrlForProgram");//获取播放器地址
            cc.log("getOneEpisode getStrPlayUrl-------------------------------->" + strPlayUrl);
        }
    },

    //由Android原生回调回来
    getPlayUrlForProgram: function (playUrl) {
        cc.log("getPlayUrlForProgram------------------------>" + playUrl);
        this._strPlayUrl = playUrl;
        this.videoPlay.remoteURL = playUrl; //
        this.videoPlay.node.on('ready-to-play', function (event) {
            cc.log("ready-to-play---------------------------->test");
            this.videoPlay.play();
        }, this);
    },

    //获取节目详情
    checkPfbReadyAndInitPage: function () {
        //根据Id获取详情
        let oGatherDetailRequestParameter = {
            "view": "json",
            "ids": this._iMediaId,
            "start": 0,
            "limit": 1,
            // "appId": this._strAppId,
            "token": Common.TEST_API_TOKEN_EDU
        };
        Network.ajax("GET", Common.TOPDRAW_API_SERVER_EDU + "Media/List", null, oGatherDetailRequestParameter,
            function (strResponse) {
                try {
                    var oJSONResult = JSON.parse(strResponse);
                    if (oJSONResult.businessCode == 'success') {
                        cc.find("HomeIcon/Text", this.node).getComponent(cc.Label).string = oJSONResult.resultSet[0].name;//标题
                        //这里给描述做拦截,防止字数多超出栏目
                        var description = oJSONResult.resultSet[0].description;
                        if (description.length > 83) {
                            description = description.substring(0, 83) + "...";
                        }
                        cc.find("IntroductionArea/Text", this.node).getComponent(cc.Label).string = description;
                        if (oJSONResult.resultSet[0].score) {
                            cc.find("IntroductionArea/Score", this.node).getComponent(cc.Label).string = parseInt(oJSONResult.resultSet[0].score * 10) / 10 + "分";
                        }

                        if (oJSONResult.resultSet[0].images && oJSONResult.resultSet[0].images.list.length > 0) {
                            var map;
                            if (this._strAppId == BusinessParameter.CARTOON_APPID) {
                                map = oJSONResult.resultSet[0].images.map.background ? oJSONResult.resultSet[0].images.map.background[0] : 0;
                            } else {
                                map = oJSONResult.resultSet[0].images.map.normal ? oJSONResult.resultSet[0].images.map.normal[0] : 0;
                            }
                        }
                        this._strEpisodeImg = oJSONResult.resultSet[0].images.list[map].fileUrl;

                        // this.getDefaultPromotion(); //获取默认明星推荐
                        this.getGatherDetailList(); //获取剧集列表
                    } else {
                        cc.log("Business Error:Get MediaDetail..." + oJSONResult.description);
                    }
                } catch (error) {
                    cc.log("Business Exception:Get MediaDetail..." + error);
                }
            },
            function (error) {
                cc.log("Business Exception:Get MediaDetail..." + error);
            }, this, "uuid");
    },

    getGatherDetailList: function () {
        let oGatherNumRequestParameter = {
            "view": "json",
            "start": this._oSceneContext.requestedStart,
            "limit": 20,
            "mediaId": this._iMediaId,
            "sortField": "index",
            "sortDirection": "asc",
            // "appId": this._strAppId,
            "token": Common.TEST_API_TOKEN_EDU
        };
        Network.ajax("GET", Common.TOPDRAW_API_SERVER_EDU + "Episode/ListByMedia", null, oGatherNumRequestParameter,
            function (strResponse) {
                try {
                    var oJSONResult = JSON.parse(strResponse);
                    this._oEpisode = oJSONResult;
                    if (oJSONResult.businessCode == 'success') {
                        for (let i = 0; i < 4; i++) {
                            let nodeEpisodeListCell = this._nodeEpisodeList.getChildByName("EpisodeListCell" + i);
                            if (i >= oJSONResult.resultSet.length) {//数据较少时隐藏其他多余预制体
                                nodeEpisodeListCell.active = false;  //
                                continue;
                            }
                            nodeEpisodeListCell.active = true;  //恢复预制可见及可点击
                            cc.find("EpisodeNum/Text", nodeEpisodeListCell).getComponent(cc.Label).string = oJSONResult.resultSet[i].name;
                            if (this._strEpisodeImg) {
                                Network.loadImageInNativeRuntime(
                                    Common.TOPDRAW_IMAGE_SERVER_EDU_RIGHT + this._strEpisodeImg,
                                    function (texture) {
                                        nodeEpisodeListCell.getChildByName("Bg").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
                                    }, null, this
                                );
                            }
                            // cc.find("TopArea/Name/NormalName/MidName", nodeGatherDetailListCell).getComponent(cc.Label).string = oJSONResult.resultSet[i].name;
                            // cc.find("TopArea/Name/ActiveName/NameContainer/NameText/NameText1", nodeGatherDetailListCell).getComponent(cc.Label).string = oJSONResult.resultSet[i].name;
                            // cc.find("TopArea/Name/ActiveName/NameContainer/NameText/NameText2", nodeGatherDetailListCell).getComponent(cc.Label).string = oJSONResult.resultSet[i].name;
                            // cc.find("TopArea/Name/ActiveName/NameContainer/NameText/NameText1", nodeGatherDetailListCell).getComponent(cc.Label)._updateRenderData(true);
                            // cc.find("TopArea/Name/ActiveName/NameContainer/NameText/NameText2", nodeGatherDetailListCell).getComponent(cc.Label)._updateRenderData(true);
                            let fiBlock = nodeEpisodeListCell.getComponent(FocusInfo);
                            fiBlock.setTVLink(
                                '{"click":[{"action":"ChangeScene","parameters":{"sceneName":"sceneProgramPlayerFullScreen",\
                                "appId":"' + this._strAppId + '","id":"' + this._iMediaId + '","episodeNum":"' + oJSONResult.resultSet[i].index + '",\
                                "mediaCode":"'+ oJSONResult.resultSet[i].code + '","name":"' + oJSONResult.resultSet[i].name + '"}}]}'
                            );
                        }

                        if (!this._bIsNaviDataInit) {
                            this.initNaviList();    //初始化Navi
                        }
                    }

                    this.getLastPlayRecord();   //获取播放记录

                    this.checkDataReadyAndInitFocus();
                } catch (error) {
                    cc.log("Exception When Get GatherNum List..." + error);
                }
            },
            function (strResponse) {
                cc.log("Error When Get GatherNum List..." + strResponse);
            }, this, "uuid");
    },

    initNaviList: function () {
        //剧集分类
        let sum = this._oEpisode.count / 20;
        this._iNaviNumTotal = Math.ceil(sum);
        this._oSceneContext.requestedLimit = 20;
        for (let i = 1; i <= Math.ceil(sum); i++) {
            let nodeNaviListCell = cc.find("NaviListCell" + i, this._nodeNaviList);
            if (nodeNaviListCell) {
                continue;
            }
            nodeNaviListCell = cc.instantiate(this.PFB_NAVI);
            nodeNaviListCell.x = nodeNaviListCell.width / 2 + (i - 1) * (nodeNaviListCell.width + 23);
            i == Math.ceil(sum) ? nodeNaviListCell.getChildByName('Text').getComponent(cc.Label).string = (20 * i - 19) + "-" + this._oEpisode.count
                : nodeNaviListCell.getChildByName('Text').getComponent(cc.Label).string = (20 * i - 19) + "-" + 20 * i;//TODO:最后显示应该是41-52而不是41-60
            this._nodeNaviList.addChild(nodeNaviListCell, 10, "NaviListCell" + i);
            cc.loader.loadRes('button/navi_bg', cc.Texture2D, function (err, texture) {
                let spriteFrame = new cc.SpriteFrame();
                if (i == 1) {
                    cc.find('Text', nodeNaviListCell).color = new cc.Color(112, 69, 61);
                    spriteFrame.setTexture(texture, cc.rect(0, 42, 110, 42));
                } else {
                    spriteFrame.setTexture(texture, cc.rect(0, 0, 110, 42));
                }
                nodeNaviListCell.getChildByName('Bg').getComponent(cc.Sprite).spriteFrame = spriteFrame;
                spriteFrame._calculateUV();
            });
            //准备焦点坐标
            let fiNaviBlock = nodeNaviListCell.addComponent(FocusInfo);
            fiNaviBlock.init('', true, null, null, 1.0);
            this._aFocusTargets[0]['navi_list_cell_' + i] = nodeNaviListCell;

            this._bIsNaviDataInit = true;
        }
    },

    //添加收藏
    addMedia2Collection: function () {
        var oAddMedia = {
            'view': 'json',
            'collectionId': this._iFavId,
            'mediaId': this._iMediaId,
            'token': Common.TEST_API_TOKEN_EDU,
            // 'appId': this._strAppId
        };
        Network.ajax("GET", Common.TOPDRAW_API_SERVER_EDU + "User/AddMedia2Collection", null, oAddMedia,
            function (strResponse) {
                try {
                    var oJSONResult = JSON.parse(strResponse);
                    if (oJSONResult.businessCode == 'success') {
                        var self = this;
                        this._bCollected = true;
                        cc.loader.loadRes('button/be_collected', cc.Texture2D, function (err, texture) {
                            cc.find('IntroductionArea/BtnPicCollect', self.node).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 106, 114, 106));
                        });
                        cc.log("Business Success:Get AddMedia...");
                    } else {
                        cc.log("Business Error:Get AddMedia..." + oJSONResult.description);
                    }
                } catch (error) {
                    cc.log("Business Exception:Get AddMedia..." + error);
                }
            },
            function (strResponse) {
                cc.log("Business Error:Get AddMedia..." + strResponse);
            }, this, "uuid");
    },

    //移除收藏
    removeMediaFromCollection: function () {
        var oAddMedia = {
            'view': 'json',
            'collectionId': this._iFavId,
            'mediaId': this._iMediaId,
            'token': Common.TEST_API_TOKEN_EDU,
            // 'appId': this._strAppId
        };
        Network.ajax("GET", Common.TOPDRAW_API_SERVER_EDU + "User/RemoveMediaFromCollection", null, oAddMedia,
            function (strResponse) {
                try {
                    var oJSONResult = JSON.parse(strResponse);
                    if (oJSONResult.businessCode == 'success') {
                        var self = this;
                        this._bCollected = false;
                        cc.loader.loadRes('button/not_collected', cc.Texture2D, function (err, texture) {
                            cc.find('IntroductionArea/BtnPicCollect', self.node).getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0,106, 114, 106));
                        });
                        cc.log("Business Success:Get AddMedia...");
                    } else {
                        cc.log("Business Error:Get AddMedia..." + oJSONResult.description);
                    }
                } catch (error) {
                    cc.log("Business Exception:Get AddMedia..." + error);
                }
            },
            function (strResponse) {
                cc.log("Business Error:Get AddMedia..." + strResponse);
            }, this, "uuid");
    },

    checkDataReadyAndInitFocus: function () {
        if (!this._bIsFocusInit) {
            this.initFocus();
            this._bIsFocusInit = true;
        }
    },

    initFocus: function () {

        let fiVideoView = cc.find('PlayBg/VideoView', this.node).addComponent(FocusInfo);    //
        fiVideoView.init('{"click": [{"action": "ChangeScene","parameters": {"sceneName":"sceneProgramPlayerFullScreen"}}]}', true, null, null, 1.0);
        this._aFocusTargets[0]['video_view'] = cc.find('PlayBg/VideoView', this.node);

        let fiScore = cc.find('IntroductionArea/BtnPicScore', this.node).addComponent(FocusInfo);    //
        fiScore.init('', true, null, null, 1.0);
        this._aFocusTargets[0]['btn_score'] = cc.find('IntroductionArea/BtnPicScore', this.node);

        let fiCollect = cc.find('IntroductionArea/BtnPicCollect', this.node).addComponent(FocusInfo);    //
        fiCollect.init('', true, null, null, 1.0);
        this._aFocusTargets[0]['btn_collect'] = cc.find('IntroductionArea/BtnPicCollect', this.node);

        let fiHomeBtn = cc.find('HomeBtn', this.node).addComponent(FocusInfo);    //
        // fiHomeBtn.init('', true, null, null, 1.0);
        fiHomeBtn.init('{"click": [{"action": "ChangeScene","parameters": {"sceneName":"sceneRecommend"}}]}', true);
        this._aFocusTargets[0]['btn_home'] = cc.find('HomeBtn', this.node);

        var nodeInitFocus = cc.find('PlayBg/VideoView', this.node);
        var nodeFocus = new cc.Node('nodeFocus');
        this.node.addChild(nodeFocus, 10);
        this._cFocus = this.node.getChildByName('nodeFocus').addComponent(TVFocus);
        this._cFocus.init('focusContainer', this,
            nodeInitFocus.getComponent(FocusInfo),
            Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, 2, 6, null);
    },

    keyDownDirection: function (Direct) {
        var fiFocusTarget = null;
        var fiCurrentFocus = this._fiCurrentFocus;
        var oScrollParameter = null;
        let aCheckResult;
        fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, this._iSceneStatus, Direct);
        //搜索到的目标节点有误,禁止它跳转
        if (Direct == Common.MOVE_DIRECTION_RIGHT && 0 == this._fiCurrentFocus.node.name.indexOf("EpisodeListCell3")) {
            return;
        }
        if (Direct == Common.MOVE_DIRECTION_LEFT && 0 == this._fiCurrentFocus.node.name.indexOf("EpisodeListCell0")) {
            return;
        }
        if (!fiFocusTarget) { return; }
        aCheckResult = this.checkFocusTarget(fiFocusTarget);
        fiFocusTarget = aCheckResult[0];
        oScrollParameter = aCheckResult[1];
        this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
    },

    checkFocusTarget: function (fiFocusTarget, oScrollParameter) {
        // if (this._bScore && 0 != fiFocusTarget.node.name.indexOf("Score")) {  //评分状态下屏蔽其他焦点
        //     return [null, oScrollParameter];
        // }
        if (fiFocusTarget && 0 == fiFocusTarget.node.name.indexOf("NaviListCell")) {
            if (0 != this._fiCurrentFocus.node.name.indexOf("NaviListCell")) {
                fiFocusTarget = cc.find("NaviListCell" + this._iCurrentNaviNumLoc, this._nodeNaviList).getComponent(FocusInfo);
            }
            let iIndex = fiFocusTarget.node.name.replace("NaviListCell", '');
            if (fiFocusTarget.node.x - fiFocusTarget.node.width / 2 + this._nodeNaviList.x >= this._nodeNaviListWrapper.width) {
                oScrollParameter = this._nodeNaviList.getComponent(TVScrollParameter);
                oScrollParameter.setHasRelation(true);
                oScrollParameter.setStep((fiFocusTarget.node.x + fiFocusTarget.node.width / 2 + this._nodeNaviList.x) - this._nodeNaviListWrapper.width);
                oScrollParameter.setTargetPosition(this._nodeNaviList.x - oScrollParameter.getStep());
                this._oSceneContext._nodeNaviListX = this._nodeNaviList.x - oScrollParameter.getStep();
            }
            if (fiFocusTarget.node.x + this._nodeNaviList.x < 0) {
                oScrollParameter = this._nodeNaviList.getComponent(TVScrollParameter);
                oScrollParameter.setHasRelation(true);
                oScrollParameter.setStep(-fiFocusTarget.node.x + fiFocusTarget.node.width / 2 - this._nodeNaviList.x);
                oScrollParameter.setTargetPosition(this._nodeNaviList.x + oScrollParameter.getStep())
                this._oSceneContext._nodeNaviListX = this._nodeNaviList.x + oScrollParameter.getStep();
            }
        }
        return [fiFocusTarget, oScrollParameter];
    },

    onKeyDown: function (event) {
        this._super(event);
        switch (event.keyCode) {
            case cc.macro.KEY.up:
            case Common.ANDROID_KEY.up:
                this.keyDownDirection(Common.MOVE_DIRECTION_UP);
                break;
            case cc.macro.KEY.right:
            case Common.ANDROID_KEY.right:
                let index = this._fiCurrentFocus.node.name.replace('EpisodeListCell', '');
                if (0 == this._fiCurrentFocus.node.name.indexOf('EpisodeListCell') && index == 3 && this._oSceneContext.currentPage * 4 < this._oEpisode.resultSet.length) {
                    this._oSceneContext.currentPage++;
                    this.moveEpisode();
                }
                this.keyDownDirection(Common.MOVE_DIRECTION_RIGHT);
                break;
            case cc.macro.KEY.down:
            case Common.ANDROID_KEY.down:
                this.keyDownDirection(Common.MOVE_DIRECTION_DOWN);
                break;
            case cc.macro.KEY.left:
            case Common.ANDROID_KEY.left:
                let index2 = this._fiCurrentFocus.node.name.replace('EpisodeListCell', '');
                if (0 == this._fiCurrentFocus.node.name.indexOf('EpisodeListCell') && index2 == 0 && this._oSceneContext.currentPage > 1) {
                    this._oSceneContext.currentPage--;
                    this.moveEpisode();
                }
                this.keyDownDirection(Common.MOVE_DIRECTION_LEFT);
                break;
            case cc.macro.KEY.enter:
            case cc.macro.KEY.space:
            case Common.ANDROID_KEY.enter:
                if (0 == this._fiCurrentFocus.node.name.indexOf('BtnPicCollect')) {
                    if (this._bCollected) {   //已收藏
                        this.removeMediaFromCollection();
                    } else {
                        this.addMedia2Collection();
                    }
                    return;
                } else if (0 == this._fiCurrentFocus.node.name.indexOf('BtnPicScore')) {//已经是加入课堂了
                    //敬请期待
                    this.commonTip("敬请期待",1);
                    // if (!this._bScore) {
                    //     this._bScore = !this._bScore;
                    //     this._iSceneStatus = 1;
                    //     cc.find('GradeMask', this.node).active = true;
                    //     let fiFocusTarget = cc.find('GradeMask/Pic/Score10', this.node).addComponent(FocusInfo);
                    //     this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Common.MOVE_DIRECTION_RIGHT, null, null);
                    // }
                    // return;
                } else if (this._bScore && 0 == this._fiCurrentFocus.node.name.indexOf('Score')) {   //已经是加入课堂了
                    // this.submitScore();
                    return;
                }
                // else if(0 == this._fiCurrentFocus.node.name.indexOf('HomeBtn')){
                //     cc.log("返回首页");
                //     return;
                // }
                this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
                break;
            case cc.macro.KEY.backspace:
            case Common.ANDROID_KEY.back:
                this.backAScene();
                break;
        }
    },

    //移动剧集
    moveEpisode: function () {
        let index = (this._oSceneContext.currentPage - 1) * 4;
        for (let i = index; i < index + 4; i++) {
            let nodeEpisodeListCell = this._nodeEpisodeList.getChildByName("EpisodeListCell" + i % 4);
            // if (i >= this._oEpisode.resultSet.length) {//数据较少时隐藏其他多余预制体
            //     nodeEpisodeListCell.active = false;  //
            //     continue;
            // }
            nodeEpisodeListCell.active = true;  //恢复预制可见及可点击
            if (this._oEpisode.resultSet[i]) {
                cc.find("EpisodeNum/Text", nodeEpisodeListCell).getComponent(cc.Label).string = this._oEpisode.resultSet[i].name;
                if (this._strEpisodeImg) {
                    Network.loadImageInNativeRuntime(
                        Common.TOPDRAW_IMAGE_SERVER_EDU_RIGHT + this._strEpisodeImg,
                        function (texture) {
                            nodeEpisodeListCell.getChildByName("Bg").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture);
                        }, null, this
                    );
                }
            } else {
                nodeEpisodeListCell.active = false;
            }
            this._cFocus.hide();
            this.scheduleOnce(() => {           //指定0让回调函数在下一帧立即执行
                this._cFocus.flyFocus(this._fiCurrentFocus, this._nodeEpisodeList.getChildByName("EpisodeListCell0").getComponent(FocusInfo), Common.MOVE_DIRECTION_LEFT, 1.0, null);
            }, 0);
            setTimeout(function () {    //在隐藏1.2秒焦点,
                this._cFocus.show();
            }.bind(this), 400);

            // cc.find("TopArea/Name/NormalName/MidName", nodeGatherDetailListCell).getComponent(cc.Label).string = oJSONResult.resultSet[i].name;
            // cc.find("TopArea/Name/ActiveName/NameContainer/NameText/NameText1", nodeGatherDetailListCell).getComponent(cc.Label).string = oJSONResult.resultSet[i].name;
            // cc.find("TopArea/Name/ActiveName/NameContainer/NameText/NameText2", nodeGatherDetailListCell).getComponent(cc.Label).string = oJSONResult.resultSet[i].name;
            // cc.find("TopArea/Name/ActiveName/NameContainer/NameText/NameText1", nodeGatherDetailListCell).getComponent(cc.Label)._updateRenderData(true);
            // cc.find("TopArea/Name/ActiveName/NameContainer/NameText/NameText2", nodeGatherDetailListCell).getComponent(cc.Label)._updateRenderData(true);
            // let fiBlock = nodeEpisodeListCell.getComponent(FocusInfo);
            // fiBlock.setTVLink(
            //     '{"click":[{"action":"ChangeScene","parameters":{"sceneName":"scenePlayerFullScreen",\
            //     "appId":"' + this._strAppId + '","id":"' + this._iMediaId + '","episodeNum":"'+oJSONResult.resultSet[i].index+'",\
            //     "mediaCode":"'+oJSONResult.resultSet[i].code+'","name":"'+oJSONResult.resultSet[i].name+'"}}]}'
            // );
        }
    },

    onBeforeFocusChange: function (event) {
        this._super(event);
        let fiFrom = event.detail.from;
        let fiTo = event.detail.to;

        // if (0 == fiFrom.node.getName().indexOf('DefaultStar') || 0 == fiFrom.node.getName().indexOf('navi_list_cell_')) {   //TODO:
        //     fiFrom.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
        // }
        // if (0 == fiFrom.node.getName().indexOf('BtnPicScore')) {   //TODO:
        //     fiFrom.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
        // }

        if (0 == fiFrom.node.getName().indexOf('DefaultStar')) {   //TODO:
            // fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            if (this._oImg.defaultStarImg) {
                Network.loadImageInNativeRuntime(
                    this._oImg.defaultStarImg,
                    function (texture) {
                        fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
                    }, null, this
                );
            }
        }

        if (0 == fiFrom.node.getName().indexOf('BtnPicScore')) {   //TODO:
            // fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            cc.loader.loadRes('button/add_class', cc.Texture2D, function (err, texture) {
                fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
            });
        }

        if (0 == fiFrom.node.getName().indexOf('HomeBtn')) {   //TODO:
            // fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            cc.loader.loadRes('button/home_button', cc.Texture2D, function (err, texture) {
                fiFrom.node.getChildByName("Bg").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
            });
        }

        if (0 == fiFrom.node.getName().indexOf('BtnPicCollect')) {   //收藏
            if (this._bCollected) {
                cc.loader.loadRes('button/be_collected', cc.Texture2D, function (err, texture) {
                    fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
                });
            } else {
                cc.loader.loadRes('button/not_collected', cc.Texture2D, function (err, texture) {
                    fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
                });
            }
        }
        if (0 == fiFrom.node.getName().indexOf('Score')) { //分数
            let picName = fiFrom.node.name.substring(0, 7).toLowerCase();
            cc.loader.loadRes('button/' + picName + "_1", cc.Texture2D, function (err, texture) {
                fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 380, 50));
            });
        }

        if (0 == fiFrom.node.getName().indexOf('NaviListCell') && 0 == fiTo.node.getName().indexOf('NaviListCell')) {    //剧集分类1-20.21-40...
            cc.find('Text', fiFrom.node).color = new cc.Color(255, 255, 255);
            // fiFrom.node.getChildByName('Bg').getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, fiFrom.node.getChildByName('Bg').width, fiFrom.node.getChildByName('Bg').height));
            cc.loader.loadRes('button/navi_bg', cc.Texture2D, function (err, texture) {
                fiFrom.node.getChildByName('Bg').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.getChildByName('Bg').width, fiFrom.node.getChildByName('Bg').height));
            });
        }
    },

    onAfterFocusChange: function (event) {
        this._super(event);
        let fiFrom = event.detail.from;
        let fiTo = event.detail.to;
        if (0 == fiTo.node.getName().indexOf('DefaultStar')) {   //TODO:
            // fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            if (this._oImg.defaultStarImg) {
                Network.loadImageInNativeRuntime(
                    this._oImg.defaultStarImg,
                    function (texture) {
                        fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
                    }, null, this
                );
            }
        }
        // if (0 == fiTo.node.getName().indexOf('navi_list_cell_')) {   //TODO:
        //     // fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
        //     cc.loader.loadRes('texture/button/navi_bg', cc.Texture2D, function (err, texture) {
        //         fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 42, 110, 42));
        //     });
        // }
        if (0 == fiTo.node.getName().indexOf('BtnPicScore')) {   //TODO:
            // fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            cc.loader.loadRes('button/add_class', cc.Texture2D, function (err, texture) {
                fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            });
        }

        if (0 == fiTo.node.getName().indexOf('HomeBtn')) {   //TODO:
            // fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            cc.loader.loadRes('button/home_button', cc.Texture2D, function (err, texture) {
                fiTo.node.getChildByName("Bg").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
            });
        }

        if (0 == fiTo.node.getName().indexOf('BtnPicCollect')) { //收藏
            if (this._bCollected) {
                cc.loader.loadRes('button/be_collected', cc.Texture2D, function (err, texture) {
                    fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
                });
            } else {
                cc.loader.loadRes('button/not_collected', cc.Texture2D, function (err, texture) {
                    fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
                });
            }
        }

        if (0 == fiTo.node.getName().indexOf('Score')) { //分数
            let picName = fiTo.node.name.substring(0, 7).toLowerCase();
            cc.loader.loadRes('button/' + picName + "_2", cc.Texture2D, function (err, texture) {
                fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 380, 50));
            });
        }
        if (0 == fiTo.node.getName().indexOf('NaviListCell')) {    //剧集分类1-20.21-40...

            this._oSceneContext.currentPage = 1;  //页面恢复

            cc.find('Text', fiTo.node).color = new cc.Color(112, 69, 61);
            // fiTo.node.getChildByName('Bg').getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.getChildByName('Bg').height, fiTo.node.getChildByName('Bg').width, fiTo.node.getChildByName('Bg').height));
            cc.loader.loadRes('button/navi_bg', cc.Texture2D, function (err, texture) {
                fiTo.node.getChildByName('Bg').getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.getChildByName('Bg').height, fiTo.node.getChildByName('Bg').width, fiTo.node.getChildByName('Bg').height));
            });
            let index = fiTo.node.name.replace('NaviListCell', '');
            this._iCurrentNaviNumLoc = index;
            this._oSceneContext.requestedStart = index * 20 - 20;
            this.getGatherDetailList();

            if (index > 1) {
                cc.find('NaviArea/LeftIcon', this.node).opacity = 255;
            }
            if (index == 1) {
                cc.find('NaviArea/LeftIcon', this.node).opacity = 0;
            }
            if (index > 1 && index < parseInt(this._iNaviNumTotal)) {
                cc.find('NaviArea/RightIcon', this.node).opacity = 255;
            }
            if (index == parseInt(this._iNaviNumTotal)) {
                cc.find('NaviArea/RightIcon', this.node).opacity = 0;
            }
        }
    },

    doCurrentFocusTVLinkAction: function (strAction) {
        let strTVLink = this._fiCurrentFocus.getTVLink();
        var joTVLink = null;
        try {
            joTVLink = JSON.parse(strTVLink);
            let jaOperationList = joTVLink.click;
            for (let i = 0; i < jaOperationList.length; i++) {
                switch (jaOperationList[i].action) {
                    default:
                        this.doTVLinkAction(jaOperationList[i]);
                        break;
                }
            }
        } catch (error) {
            cc.log("runTVLinkAction Exception..." + error);
        }
    },

    onDestroy: function () {
        cc.director.emit('stop_render');   //分发事件
    },
});