// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        // scrollView: cc.Prefab,
        scrollViewBetter: cc.Prefab
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
        this.data = [];
        this.imgs = [
            "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=1820523987,3798556096&fm=26&gp=0.jpg",
            "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=320178652,790985626&fm=26&gp=0.jpg",
            "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1012507464,1777027127&fm=26&gp=0.jpg",
            "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=324013775,2946570240&fm=26&gp=0.jpg",
            "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2887116093,4058881618&fm=26&gp=0.jpg",
            "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2188301108,2208747323&fm=26&gp=0.jpg",
            "https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=4176040192,3002869256&fm=26&gp=0.jpg",
            "https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=1321463267,128419202&fm=26&gp=0.jpg",
            "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2677432097,397548121&fm=26&gp=0.jpg",
            "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2188118499,572678618&fm=26&gp=0.jpg",
            "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=3865525855,2169088944&fm=26&gp=0.jpg",
        ];
        for (let i = 0; i < 10; i ++) {
            this.data[i] = {des: 'test' + i, id: i, img: this.imgs[i]};
        }


        let dialog2 = cc.instantiate(this.scrollViewBetter);
        dialog2.parent = this.node;
        dialog2.getComponent('SVBetter').createList(this.data);

        this.dialog2 = dialog2;

        this.dialog2.getComponent('SVBetter').setMoreListener(function () {
            let l = this.data.length
           var data = [];
            var ii = 0
            for (let i = l; i < l+10; i ++) {
                data.push( {des: 'test' + i, id: i, img: this.imgs[ii]});
                ii++
                        }
            console.log("给的什么",data);
            this.dialog2.getComponent('SVBetter').moreItem(data);
            this.data = this.data.concat(data)
        }.bind(this))
    },

    onBtnClk: function (event, param) {
        switch (param) {
            case 'normal':
                if (!!this.dialog1 && this.dialog1.isValid) {
                    return;
                }

                let dialog1 = cc.instantiate(this.scrollView);
                dialog1.parent = this.node;
                dialog1.getComponent('SV').createList(this.data);

                this.dialog1 = dialog1;
                break;
            case 'better':
                if (!!this.dialog2 && this.dialog2.isValid) {
                    return;
                }

                let dialog2 = cc.instantiate(this.scrollViewBetter);
                dialog2.parent = this.node;
                dialog2.getComponent('SVBetter').createList(this.data);

                this.dialog2 = dialog2;

                this.dialog2.getComponent('SVBetter').setMoreListener(function () {
                    this.dialog2.getComponent('SVBetter').moreItem(this.data);
                }.bind(this))
                break;
        }
    }

    // update (dt) {},
});
