import { ryw_Event } from "../../FrameWork/Event/EventEnum";
import EventMgr from "../../FrameWork/Event/EventMgr";

import TaskManager from "./TaskManager";


const {ccclass, property} = cc._decorator;

@ccclass
export default class TaskInfoView extends cc.Component {

    @property(cc.Node)
    boxNode: cc.Node = null;

    @property(cc.Label)
    tittleStr: cc.Label = null;

    @property(cc.Label)
    contentDesc: cc.Label = null;


    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}
    isCanTouch = false
    start () {

        //let mengban = this.node.getChildByName('mengban')
        //监听事件
        // mengban.on(cc.Node.EventType.TOUCH_START, (event) => {
        //     this.onClose()
        // })
        // mengban['_touchListener'].setSwallowTouches(false);

        this.refreshView()
        cc.tween(this.boxNode)
        .to(0.3,{x:-288.5},{easing:'backInOut'})
        .call(()=>{
            this.isCanTouch = true
            // this.node.getChildByName('收起按钮').active = true 
        })
        .delay(3.0)
        .call(()=>{
            this.onClose()
        })
        .start()
        
    }
    refreshView(){
       
        let customTaskInfo:any = TaskManager.getCurUnLockMainTaskInfo()
        let taskId = customTaskInfo.Id
        console.log(taskId, 'TaskInfoView')

        let config = TaskManager.getTaskConfigById(taskId)
        if(config){
            this.tittleStr.string = config.TaskTittle
            this.contentDesc.string = config.TaskDesc        
    
        }

        

    }

    onClose(){
        if(!cc.isValid(this.node)){
            return
        }
        if(!this.isCanTouch){
            return
        }
    
        this.node.getChildByName('收起按钮').active = false
        EventMgr.emitEvent_custom(ryw_Event.renwuzhushouSBZT);
        cc.tween(this.boxNode)
        .to(0.3,{x:-1000})
        .call(()=>{
            this.node.active = false
            this.node.removeFromParent()
            this.node.destroy()
        })
        .start()


        //this.node.active = false
    }

    // update (dt) {}
}