
import EffectMgr from "../mgr/EffectMgr";
import HttpMgr from "../mgr/HttpMgr";

const { ccclass, property } = cc._decorator;

@ccclass
export default class CashOutRecordUI extends cc.Component {

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

    @property(cc.Node)
    node_top: cc.Node = null;
    @property(cc.ScrollView)
    src_cashOutRecordItem: cc.ScrollView = null;
    @property(cc.Node)
    Content_cashOutRecordItemArr: cc.Node = null;

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {}

    start() {
        this.addapt();
    }

    // update (dt) {}

    addapt() {

        let offset = 1334 * 0.5 - this.node_top.y;
        this.node_top.y = cc.winSize.height * 0.5 - offset;
        this.src_cashOutRecordItem.node.y += offset;

        this.node_rectBg.setContentSize(cc.winSize.width, cc.winSize.height);
    }

    initCashOutRecordItem() {
        HttpMgr.Inst.caseRecords().then((data) => {
            if (!data) {
                return;
            }
            else {
                
                // let self = this;
                // if (this.content_recordItemUIArr.childrenCount <= 0) {
                //     cc.loader.loadRes(`./prefab/RecordItemUI`, function (err, prefab: cc.Prefab) {
                //         if (err) {
                //             LogUtil.log("加载预制体失败level", err);
                //         }
                //         else {
                //             self.prefab_recordItemUI = prefab;
                //             // LogUtil.log("获取广告信息成功 GameConst.recordData", GameConst.recordData);
                //             for (var i = 0; i < GameConst.recordData.length; i++) {
                //                 let data = GameConst.recordData[i];
                //                 let node_recordItemUI: cc.Node = cc.instantiate(prefab);
                //                 let recordItemUI = node_recordItemUI.getComponent(RecordItemUI);
                //                 recordItemUI.init(data);
                //                 self.content_recordItemUIArr.addChild(node_recordItemUI);
                //             }
                //             self.content_recordItemUIArr.getComponent(cc.Layout).updateLayout();
                //             if (self.content_recordItemUIArr.height > self.view_recordItemUIArr.height) {
                //                 self.content_recordItemUIArr.y = -(self.content_recordItemUIArr.height - self.view_recordItemUIArr.height) * 0.5;
                //             }
                //         }
                //     }.bind(this));
                // }
                // else {
                //     for (var i = 0; i < GameConst.recordData.length; i++) {
                //         let data = GameConst.recordData[i];
                //         let node_recordItemUI = this.content_recordItemUIArr.children[i];
                //         if (!node_recordItemUI) {
                //             node_recordItemUI = cc.instantiate(this.prefab_recordItemUI);
                //             this.content_recordItemUIArr.addChild(node_recordItemUI);
                //         }
                //         let recordItemUI = node_recordItemUI.getComponent(RecordItemUI);
                //         recordItemUI.init(data);
                //     }
                //     self.content_recordItemUIArr.getComponent(cc.Layout).updateLayout();
                //     if (self.content_recordItemUIArr.height > self.view_recordItemUIArr.height) {
                //         self.content_recordItemUIArr.y = -(self.content_recordItemUIArr.height - self.view_recordItemUIArr.height) * 0.5;
                //     }
                // }
            }

        }).catch(() => {
            EffectMgr.Inst.addTip("提现记录拉取异常,请稍后再试");
        });

    }
}
