const Api = require('../net/Api');

cc.Class({
    extends: cc.Component,

    properties: {
        noticeItem: {
            default: null,
            type: cc.Prefab,
            tooltip: "消息内容预制资源"
        },
        noticeWrap: {
            default: null,
            type: cc.Node,
            tooltip: "消息列表容器"
        }
    },

    onLoad () {
    },

    init () {
    },

    start () {
        let bouncesActionArray = [];

        let space = 50;
        let upAction = cc.moveTo(0.25, cc.v2(0, space));
        let downAction = cc.moveBy(0.1, cc.v2(0, -space));

        bouncesActionArray.push(upAction);
        bouncesActionArray.push(downAction);
        
        this.node.runAction(cc.sequence(bouncesActionArray));
        setTimeout(() => {
            this._initNoticeList()
        }, 300)
    },

    _initNoticeList () {
        Api.httpGet({
            url: "/post/getIndexPost.do",
            data: {},
            success: (res) => {
                res.list && res.list.forEach(n => {
                    let noticeItem = cc.instantiate(this.noticeItem);
                    noticeItem.getComponent("NoticeItem").init(0, n.postMsg, n.createTime);
                    this.noticeWrap.addChild(noticeItem)
                })
            },
            fail: () => {}
        })
    },

    close() {
        this.node.destroy();
    },

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