2021-04-09 09:44:06 +08:00
|
|
|
|
using Assets.Scripts;
|
|
|
|
|
|
using Assets.Scripts.Apis;
|
|
|
|
|
|
using Assets.Scripts.Apis.Models;
|
|
|
|
|
|
using Assets.Scripts.UI.Control;
|
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
2021-03-30 14:23:41 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
2021-04-09 09:44:06 +08:00
|
|
|
|
using UnityEngine.EventSystems;
|
|
|
|
|
|
using UnityEngine.UI;
|
2021-03-30 14:23:41 +08:00
|
|
|
|
|
|
|
|
|
|
public class EditUserController : PFUIPanel
|
|
|
|
|
|
{
|
2021-04-09 09:44:06 +08:00
|
|
|
|
private Button mSaveButton;
|
|
|
|
|
|
private PFUIDropdown mSexDropdown;
|
|
|
|
|
|
private PFUIDropdown mDayDropdown;
|
|
|
|
|
|
private PFUIDropdown mMonthDropdown;
|
|
|
|
|
|
private PFUIDropdown mYearDropdown;
|
|
|
|
|
|
private Text mIdText;
|
|
|
|
|
|
private Text mNameText;
|
|
|
|
|
|
private RawImage mHeadImage;
|
|
|
|
|
|
private UserApi userApi;
|
|
|
|
|
|
protected override void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
userApi = new UserApi();
|
|
|
|
|
|
|
|
|
|
|
|
mIdText = this.transform.Find("IdText").GetComponent<Text>();
|
|
|
|
|
|
mNameText = this.transform.Find("NameText").GetComponent<Text>();
|
|
|
|
|
|
var panel = this.transform.Find("Panel");
|
|
|
|
|
|
mSexDropdown = panel.Find("SexDropdown").GetComponent<PFUIDropdown>();
|
|
|
|
|
|
mYearDropdown = panel.Find("YearDropdown").GetComponent<PFUIDropdown>();
|
|
|
|
|
|
mMonthDropdown = panel.Find("MonthDropdown").GetComponent<PFUIDropdown>();
|
|
|
|
|
|
mDayDropdown = panel.Find("DayDropdown").GetComponent<PFUIDropdown>();
|
|
|
|
|
|
mSaveButton = this.transform.Find("SaveButton").GetComponent<Button>();
|
|
|
|
|
|
mHeadImage = this.transform.Find("HeadImage").GetComponent<RawImage>();
|
|
|
|
|
|
|
|
|
|
|
|
mSexDropdown.ClearOptions();
|
|
|
|
|
|
mSexDropdown.AddOptions(new List<string>
|
|
|
|
|
|
{
|
|
|
|
|
|
"男","女"
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mYearDropdown.ClearOptions();
|
|
|
|
|
|
var years = new List<string>();
|
|
|
|
|
|
for (int i = 1960; i < 2099; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
years.Add(i.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
mYearDropdown.AddOptions(years);
|
|
|
|
|
|
mYearDropdown.OnValueChange = (index) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
//Debug.Log(index);
|
|
|
|
|
|
SetDayDropdown();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
mMonthDropdown.ClearOptions();
|
|
|
|
|
|
var months = new List<string>();
|
|
|
|
|
|
for (int i = 1; i < 13; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
months.Add(i.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
mMonthDropdown.AddOptions(months);
|
|
|
|
|
|
//mMonthDropdown.SelectValue("9");
|
|
|
|
|
|
mMonthDropdown.OnValueChange = (index) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
SetDayDropdown();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mDayDropdown.ClearOptions();
|
|
|
|
|
|
SetDayDropdown();
|
|
|
|
|
|
|
|
|
|
|
|
//mDayDropdown.AddOptions()
|
|
|
|
|
|
|
|
|
|
|
|
//mDayDropdown.AddOptions(new List<Dropdown.OptionData>
|
|
|
|
|
|
//{
|
|
|
|
|
|
// new Dropdown.OptionData()
|
|
|
|
|
|
//});
|
|
|
|
|
|
|
|
|
|
|
|
LoadDataSync();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async void LoadDataSync()
|
|
|
|
|
|
{
|
|
|
|
|
|
Material material = null;
|
|
|
|
|
|
if (material == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
material = Instantiate(Resources.Load<Material>("UI/Material/RoundedCornersTextureMaterial"));
|
|
|
|
|
|
}
|
|
|
|
|
|
var rect = ((RectTransform)mHeadImage.transform).rect;
|
|
|
|
|
|
material.SetVector(Shader.PropertyToID("_WidthHeightRadius"), new Vector4(rect.width, rect.height, rect.height, 0));
|
|
|
|
|
|
mHeadImage.material = material;
|
|
|
|
|
|
|
2021-04-09 15:57:50 +08:00
|
|
|
|
//var currentUser = App.CurrentUser;
|
|
|
|
|
|
//mIdText.text = "ID:" + currentUser.Id.ToString();
|
|
|
|
|
|
//mNameText.text = currentUser.Nickname;
|
2021-04-09 09:44:06 +08:00
|
|
|
|
|
2021-04-09 15:57:50 +08:00
|
|
|
|
//if (!string.IsNullOrWhiteSpace(currentUser.WxHeadImg))
|
|
|
|
|
|
//{
|
|
|
|
|
|
// Utils.DisplayImage(StartCoroutine, mHeadImage, currentUser.WxHeadImg);
|
|
|
|
|
|
//}
|
|
|
|
|
|
//if (currentUser.Sex == 1)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// mSexDropdown.SelectValue("男");
|
|
|
|
|
|
//}
|
|
|
|
|
|
//else
|
|
|
|
|
|
//{
|
|
|
|
|
|
// mSexDropdown.SelectValue("女");
|
|
|
|
|
|
//}
|
|
|
|
|
|
//if (currentUser.Birthday.HasValue)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// var birthday = currentUser.Birthday.Value;
|
|
|
|
|
|
// mYearDropdown.SelectValue(birthday.Year.ToString());
|
|
|
|
|
|
// mMonthDropdown.SelectValue(birthday.Month.ToString());
|
|
|
|
|
|
// mDayDropdown.SelectValue(birthday.Day.ToString());
|
|
|
|
|
|
//}
|
2021-04-09 09:44:06 +08:00
|
|
|
|
|
|
|
|
|
|
UIManager.AddEvent(mSaveButton.gameObject, EventTriggerType.PointerClick, Save);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-03-30 14:23:41 +08:00
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
|
protected override void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Start();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2021-04-09 09:44:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SetDayDropdown()
|
|
|
|
|
|
{
|
|
|
|
|
|
mDayDropdown.ClearOptions();
|
|
|
|
|
|
var year = mYearDropdown.SelectedItem;
|
|
|
|
|
|
var month = mMonthDropdown.SelectedItem;
|
|
|
|
|
|
|
|
|
|
|
|
//var date = new DateTime(int.Parse(year), int.Parse(month), 1);
|
|
|
|
|
|
var days = DateTime.DaysInMonth(int.Parse(year), int.Parse(month));
|
|
|
|
|
|
var list = new List<string>();
|
|
|
|
|
|
for (int i = 1; i <= days; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
list.Add(i.ToString());
|
|
|
|
|
|
}
|
|
|
|
|
|
mDayDropdown.ClearOptions();
|
|
|
|
|
|
mDayDropdown.AddOptions(list);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async void Save(BaseEventData e)
|
|
|
|
|
|
{
|
|
|
|
|
|
//var user = JsonConvert.DeserializeObject<UserResultModel>(JsonConvert.SerializeObject(App.CurrentUser));
|
|
|
|
|
|
//user.Birthday = new DateTime(int.Parse(mYearDropdown.SelectedItem), int.Parse(mMonthDropdown.SelectedItem), int.Parse(mDayDropdown.SelectedItem));
|
|
|
|
|
|
//user.Sex = mSexDropdown.SelectedItem == "男" ? 1 : 2;
|
|
|
|
|
|
|
|
|
|
|
|
//var result = await userApi.Update(user);
|
|
|
|
|
|
//if (result.result == false)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// UIManager.ShowAlert(result.errMsg);
|
|
|
|
|
|
// return;
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
//App.CurrentUser = user;
|
|
|
|
|
|
|
|
|
|
|
|
UIManager.ShowAlert("result.errMsg");
|
|
|
|
|
|
}
|
2021-03-30 14:23:41 +08:00
|
|
|
|
}
|