using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class CashOutPanel : BasePanel
{
    public CashOutCell NowCell;
    public override void OnHide(object data = null)
    {
        
    }

    public override void OnInit(object data = null)
    {
        GetControl<Button>("btnBack").onClick.AddListener(() => 
        {
            UIMgr.Getinstance().HidePanel<CashOutPanel>();
        });

        GetControl<Text>("txtMoney").text = "当前余额:" + UIMgr.Getinstance().GetPanel<MainPanel>().GetControl<Text>("CashNumTv").text + "元";

        Dictionary<string, object> paras = new Dictionary<string, object>();
        paras.Add("type", 1);
        HttpTool.Instance._Get<WithDrawBean>("app/v1/watermelon/list_wd", paras, result =>
        {
            for (int i = 0; i < result.list.Count; i++)
            {
                GameObject obj = ResMgr.Getinstance().Load<GameObject>("Cells/CashOutCell");
                obj.transform.ResetToCanvas(GetControl<GridLayoutGroup>("GridLayOut").transform);
                obj.GetComponent<CashOutCell>().OnInit(result.list[i]);

                if(i == 0) 
                {
                    NowCell = obj.GetComponent<CashOutCell>();
                }
            }
            NowCell.GetComponent<Toggle>().isOn = true;
        }, 
        (code, msg) =>
        {
            Debug.unityLogger.Log("获取提现列表 " + code + " msg " + msg);
        });
    }

    public override void OnRefresh(object data = null)
    {
        
    }

    public void UpdateNowCell(CashOutCell cell) 
    {
        NowCell = cell;

        GetControl<Text>("txtDescribe").text = cell.bean.tip;
    }
}
