using System;
using System.Threading.Tasks;
namespace Shared.Phone.UserCenter.User
{
///
/// 验证旧手机号码的画面
///
public class CheckOldPhoneNumForm : UserCenterCommonForm
{
///
/// 重新发送的状态控件
///
private RowMostRightTextView btnStatu = null;
///
/// 信息提示控件
///
private ViewNormalControl txtMsg = null;
///
/// 下一步的控件
///
private BottomClickButton btnBottom = null;
///
/// 线程运行
///
private bool IsAction = false;
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
public void ShowForm()
{
//设定标题
base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uCheckPhoneNumber));
//初始化中部控件
this.InitMiddleFrame();
}
///
/// 初始化中部控件
///
private void InitMiddleFrame()
{
//请输入原手机收到的验证码
var btnTitle = new ViewNormalControl(800, true);
btnTitle.X = ControlCommonResourse.XXLeft;
btnTitle.TextColor = UserCenterColor.Current.TextGrayColor;
btnTitle.TextID = R.MyInternationalizationString.uPleaseInputOldPhoneReceivedCode;
btnTitle.Y = Application.GetRealHeight(40);
bodyFrameLayout.AddChidren(btnTitle);
var rowlayout = new RowLayout();
rowlayout.Height = ControlCommonResourse.ListViewRowHeight;
rowlayout.Y = btnTitle.Bottom;
bodyFrameLayout.AddChidren(rowlayout);
//验证码
var btnCode = new RowTopBlackView(false);
btnCode.TextID = R.MyInternationalizationString.uVerificationCode;
rowlayout.AddChidren(btnCode);
//请输入验证码
var txtCode = new RowBottomEditorText();
txtCode.Width = Application.GetRealWidth(770);
txtCode.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputVerificationCode);
txtCode.PlaceholderTextColor = UserCenterColor.Current.TextTipColor;
rowlayout.AddChidren(txtCode);
//状态
btnStatu = new RowMostRightTextView();
btnStatu.TextID = R.MyInternationalizationString.uSendVerificationCode;
btnStatu.TextColor = UserCenterColor.Current.TextBlueColor;
rowlayout.AddChidren(btnStatu);
btnStatu.ReSetYaxis(UViewAlignment.Bottom);
//提示信息
txtMsg = new ViewNormalControl(800, true);
txtMsg.X = ControlCommonResourse.XXLeft;
txtMsg.Y = rowlayout.Bottom + Application.GetRealHeight(5);
txtMsg.TextColor = UserCenterColor.Current.Red;
bodyFrameLayout.AddChidren(txtMsg);
//下一步
btnBottom = new BottomClickButton();
btnBottom.TextID = R.MyInternationalizationString.uNextway;
btnBottom.Visible = false;
bodyFrameLayout.AddChidren(btnBottom);
btnBottom.MouseUpEvent += (sender, e) =>
{
if (this.IsAction == false || txtCode.Text.Trim() == string.Empty)
{
txtMsg.TextID = R.MyInternationalizationString.uVerificationCodeError;
return;
}
//验证验证码
this.CheckVerificationCode(txtCode.Text.Trim());
};
//发送验证码的单击事件
btnStatu.MouseUpEvent += (sender, e) =>
{
if (this.IsAction == true)
{
return;
}
txtMsg.Text = string.Empty;
//发送验证码到手机
this.SendCodeToPhone();
};
}
///
/// 线程开启倒计时
///
private void StartTimeOutThead()
{
if (this.IsAction == true)
{
return;
}
this.IsAction = true;
int waitime = 300;
//重发
string repeat = Language.StringByID(R.MyInternationalizationString.RepeatSend1);
new System.Threading.Thread(() =>
{
while (this.IsAction == true)
{
if (waitime == 0)
{
break;
}
Application.RunOnMainThread(() =>
{
this.btnStatu.Text = repeat + "(" + waitime + "s)";
});
waitime--;
System.Threading.Thread.Sleep(1000);
}
this.IsAction = false;
Application.RunOnMainThread(() =>
{
//重新发送
this.btnStatu.Text = Language.StringByID(R.MyInternationalizationString.RepeatSend2);
});
})
{ IsBackground = true }.Start();
}
///
/// 发送验证码到手机
///
private async void SendCodeToPhone()
{
var sendCodePra = new SendCodePra();
bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/LoginSendVerCode", sendCodePra);
if (flage == false)
{
return;
}
Application.RunOnMainThread(() =>
{
btnBottom.Visible = true;
btnStatu.Text = Language.StringByID(R.MyInternationalizationString.RepeatSend1) + " (300s)";
});
//线程开启倒计时
this.StartTimeOutThead();
}
///
/// 验证验证码
///
///
private async void CheckVerificationCode(string code)
{
var checkCodePra = new CheckCodePra();
checkCodePra.Code = code;
bool flage = await UserCenterLogic.GetResultStatuByRequestHttps("ZigbeeUsers/ValidatorCode", checkCodePra);
if (flage == false)
{
Application.RunOnMainThread(() =>
{
txtMsg.TextID = R.MyInternationalizationString.uVerificationCodeError;
});
return;
}
this.IsAction = false;
Application.RunOnMainThread(() =>
{
var from = new CheckNewPhoneNumForm();
base.AddFromAndRemoveNowForm(from);
});
}
///
/// 画面关闭
///
/// 是否关闭界面,false的时候,只会调用关闭函数里面的附加功能
public override void CloseForm(bool isCloseForm = true)
{
this.IsAction = false;
base.CloseForm(isCloseForm);
}
///
/// 发送验证码的启动参数
///
private class SendCodePra
{
///
/// 用户账号
///
public string Account = UserCenterResourse.UserInfo.Phone;
///
/// 公司编号,国内使用手机短信验证码时,此字段填入0,国外手机短信验证码,此字段填入4
///
public int Company = 0;
///
/// 语言
///
public string Language = Shared.Language.CurrentLanguage;
///
/// 国家地区代码,手机号发送验证码时使用
///
public int AreaCode = 0;
}
///
/// 发送验证码的启动参数
///
private class CheckCodePra
{
///
/// 用户账号
///
public string Account = UserCenterResourse.UserInfo.Phone;
///
/// 验证码
///
public string Code = "0";
///
/// 语言
///
public string Language = Shared.Language.CurrentLanguage;
///
/// 国家地区代码,手机号发送验证码时使用
///
public int AreaCode = 0;
}
}
}