import { GFun } from './../../libs/tc/util/GFun';

import Panel from "../views/Panel";
import MItem from '../components/MItem';

import { GDispatcher } from '../../libs/tc/util/GDispatcher';

export default class PrizeItem extends MItem {

    public moneyLab:eui.Label;
    public stateLab:eui.Label;
    public prizeBtnGroup:eui.Group;
    public prizeIcon:eui.Image;

    constructor() {
        super();
    }
   
    dataChanged(){
        this.prizeIcon.source = this.data.icon;
        

        if(this.data.refType == 'virtual'){
            if(this.data.hasMainOrder){
                if(this.data.status == 'success'){
                    this.stateLab.text = '领取成功';
                }else{
                    this.stateLab.text = '账号异常涉及微信官方风险，请点击补领';
                }
            }else{
                this.stateLab.text = '未领取';
            }
            // this.stateLab.text = '已发放';
            // if(!this.data.hasMainOrder ){
            //     console.log('微信红包发放出错',this.data)
            // }
            this.moneyLab.text = `微信${this.data.name}元`;
        }
        if(this.data.refType == 'alipay'){
            if(this.data.hasMainOrder){
                if(this.data.status == 'consume_success'){
                    this.stateLab.text = '处理中';
                }else if(this.data.status == 'success'){
                    this.stateLab.text = '领取成功';
                }else{
                    this.stateLab.text = '领取失败';
                }
            }else{
                this.stateLab.text = '未领取';
            }
            this.moneyLab.text = `支付宝${this.data.name}元`;
        }

    }

    onSkinComplete(){
        //去完成按钮
        this.prizeBtnGroup.addEventListener(egret.TouchEvent.TOUCH_TAP,this.onClick,this)
    }
    
    onClick():void{
        GDispatcher.dispatchEvent("onClickPrize",this.data)
    }
    
}