// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import { ryw_Event } from "../../FrameWork/Event/EventEnum";
import EventMgr from "../../FrameWork/Event/EventMgr";
import Common5 from "../../Platform/th/Common5";
import BagManager from "../Manager/BagManager";

const {ccclass, property} = cc._decorator;

@ccclass
export default class CangKuItem extends cc.Component {

    @property(cc.Sprite)
    iconSpr: cc.Sprite = null;

    @property(cc.Label)
    iconNum: cc.Label = null;
    // LIFE-CYCLE CALLBACKS:

    @property(cc.Label)
    iconName: cc.Label = null;
    // onLoad () {}
    @property(cc.Node)
    chooseNode: cc.Node = null;

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

    _data = null



    start () {
      
        EventMgr.onEvent_custom(ryw_Event.ViewpPoperty,(goodId)=>{
            if(!this._data){
                return
            }
            if(this._data.goodId == goodId){
                this.chooseNode.active = true
            }else{
                this.chooseNode.active = false
            }
        },this)
        this.chooseNode.active = false

    }

    initView(data){
        this._data = data
        //console.log(this._data, 'initView+++++++++++++++====')
     
        if( this._data){
            this.iconSpr.node.active = true
            this.iconNum.node.active = true
            this.iconName.node.active = true
            
        }else{
            this.iconSpr.node.active = false
            this.iconNum.node.active = false
            this.iconName.node.active = false
            return
        }
        let goodId = this._data.goodId
        let goodNum = this._data.goodNum
  
        // Common5.getSpriteFrameFromBundle("CommonRes","GoodIcon/texture/icon/"+ goodId, this.iconSpr); 

        Common5.addUrlSprite_custom("GoodIcon/texture/icon/"+ goodId, this.iconSpr)


        this.iconNum.string = goodNum

        let _pro = BagManager.getGoodsProperty(goodId)
        this.iconName.string = _pro.goodName
      
        if(this.LabMoney){
            this.LabMoney.string = Common5.getNumberChangeHanzi(_pro.priceNum,'1',1)+''
        }
    }

    iconBtnClick(){
        if(!this._data){
            return
        }
        let goodId = this._data.goodId
        let goodNum =  this._data.goodNum
        EventMgr.emitEvent_custom(ryw_Event.ViewpPoperty, goodId, goodNum);
    }


    setCanTouch(isTouch){
        this.node.getChildByName('sprdi').getComponent(cc.Button).interactable = isTouch
    }

    myselfClickEvent(){

    }


}