/*
 * @Author: mojunshou 1637302775@qq.com
 * @Date: 2025-03-21 10:17:49
 * @LastEditors: mojunshou 1637302775@qq.com
 * @LastEditTime: 2025-03-28 14:57:51
 * @Description: 提现记录
 */
import { _decorator, Node } from "cc";
import { ecs } from "db://oops-framework/libs/ecs/ECS";
import { CCComp } from "db://oops-framework/module/common/CCComp";
import List from "../ui/List";
import { Label } from "cc";
import { oops } from "db://oops-framework/core/Oops";
import { UIID } from "../../common/config/GameUIConfig";

const { ccclass, property } = _decorator;

/** 视图层对象 */
@ccclass('WithdrawalRecordViewComp')
@ecs.register('WithdrawalRecordView', false)
export class WithdrawalRecordViewComp extends CCComp {
    /** 视图层逻辑代码分离演示 */
    @property(List)
    recordList: List = null!;

    data: any[] = [];

    start() {

        const data = {
            state: "提现成功",
            time: "2025-03-20 17:30",
            money: 0.1,
            type: "已打款"
        }

        for (let i = 0; i < 20; i++) {
            data.money = i;
            this.data.push(data);
        }
        this.recordList.numItems = this.data.length;

        this.setButton();
        // const entity = this.ent as ecs.Entity;         // ecs.Entity 可转为当前模块的具体实体对象
    }


    // 列表渲染器
    private onListRender(item: Node, idx: number) {
        // item.getComponentInChildren(Label)!.string = this.data[idx] + '';
        const data = this.data[idx];
        const stateLabel = item.getChildByName("lab_state")?.getComponent(Label);
        if (stateLabel) stateLabel.string = data.state;

        const timeLabel = item.getChildByName("lab_time")?.getComponent(Label);
        if (timeLabel) timeLabel.string = data.time;

        const moneyLabel = item.getChildByName("lab_money")?.getComponent(Label);
        if (moneyLabel) moneyLabel.string = data.money + "元";

        const typeLabel = item.getChildByName("lab_moneyState")?.getComponent(Label);
        if (typeLabel) typeLabel.string = data.type;
    }


    private btn_back() {
        oops.gui.remove(UIID.WithdrawRecord)
    }

    /** 视图对象通过 ecs.Entity.remove(WithdrawalRecordViewComp) 删除组件是触发组件处理自定义释放逻辑 */
    reset() {
        this.node.destroy();
    }

}