/*
 * @Author: mojunshou 1637302775@qq.com
 * @Date: 2025-03-20 18:39:37
 * @LastEditors: mojunshou 1637302775@qq.com
 * @LastEditTime: 2025-04-11 14:06:25
 * @Description: 红包列表item
 */
import { _decorator, Label, Node, ProgressBar, Sprite } from 'cc';
import { oops } from 'db://oops-framework/core/Oops';
import VMParent from 'db://oops-framework/libs/model-view/VMParent';

const { ccclass, property } = _decorator;

/** 显示对象控制 */
@ccclass('RedPackeItemView')
export class RedPackeItemView extends VMParent {
    @property(Node)
    private receiveNode: Node = null!;

    @property(Node)
    private unReceiveNode: Node = null!;

    private lab_title: Label = null!;
    private lab_progress: Label = null!;
    private pro_progress: ProgressBar = null!;
    private sp_icon: Sprite = null!;
    private lab_num: Label = null!;

    data: any = {
        title: "完成任务即可领取红包~",
        current: 10,
        total: 100,
        state: 1,
        goods: [
            {
                type: 1001,
                num: 100
            }
        ]
    }

    protected start() {
        this.setButton();
        this.initComponent();
    }



    private initComponent() {
        this.lab_title = this.node.getChildByPath("Bg/lab_title")?.uiLabel!;
        this.lab_progress = this.node.getChildByPath("Bg/lab_progress")?.uiLabel!;
        this.pro_progress = this.node.getChildByPath("Bg/pro_progress")?.uiProgressBar!;
        this.sp_icon = this.node.getChildByPath("Bg/sp_icon")?.uiSprite!;
        this.lab_num = this.node.getChildByPath("Bg/lab_num")?.uiLabel!;

    }




    setItem(data: any, idx: number) {
        console.log("setData>>>>>>>>>>>>>", data);
        this.data = data;
        this.updateData();
    }

    //更新数据
    private updateData() {
        console.log("updateData", this.data);

        if (this.data.state == 0) {
            this.receiveNode.active = false;
            this.unReceiveNode.active = true;
        } else if (this.data.state == 1) {
            this.receiveNode.active = true;
            this.unReceiveNode.active = false;
        }
        // this.lab_title.string = this.data.title;
        // this.lab_progress.string = `${this.data.current}/${this.data.total}`;
        // this.pro_progress.progress = this.data.current / this.data.total;
        // // this.sp_icon.spriteFrame = oops.res.getSpriteFrame(this.data.goods[0].type);
        // this.lab_num.string = this.data.goods[0].num;
    }


    //进行中按钮
    private btn_none() {
        oops.gui.toast("完成任务即可领取红包~");
    }


    //可领取按钮
    private btn_receive() {
        oops.gui.toast("领取红包~");
        //发送领取红包请求
    }










}