using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone.UserCenter.Password { /// /// 验证新手机的画面 /// public class CheckNewPhoneForm : EditorCommonForm { #region ■ 变量声明___________________________ /// /// 错误信息控件 /// private NormalViewControl btnErrorMsg = null; /// /// 标记是否能够校验验证码了 /// private bool canCheckCode = false; /// /// 新手机(防止恶意变更) /// private string newPhone = string.Empty; /// /// 能否发送验证码 /// private bool canSendCode = true; #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// public void ShowForm() { //设置头部信息 base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uEditorPhoneNumber)); //初始化中部信息 this.InitMiddleFrame(); } /// /// 初始化中部信息 /// private void InitMiddleFrame() { //清空bodyFrame this.ClearBodyFrame(); var frame = new FrameLayout(); frame.Y = Application.GetRealHeight(161); frame.Gravity = Gravity.CenterHorizontal; frame.Width = Application.GetRealWidth(688); frame.Height = Application.GetRealHeight(127); bodyFrameLayout.AddChidren(frame); //地区码 var btnArea = new NormalViewControl(127, 58, true); btnArea.Text = "+86"; btnArea.TextAlignment = TextAlignment.Center; btnArea.TextColor = UserCenterColor.Current.TextGrayColor3; btnArea.Gravity = Gravity.CenterVertical; frame.AddChidren(btnArea); //目前只针对+86 //btnArea.ButtonClickEvent += (sender, e) => //{ // var form = new AreaCodeSelectForm(); // form.AddForm(); // form.FinishSelectEvent += (code) => // { // btnArea.Text = "+" + code; // }; //}; //输入框 var txtValue = new TextInputControl(Application.GetRealWidth(510), frame.Height - HdlControlResourse.BottomLineHeight, false); txtValue.X = btnArea.Right + Application.GetRealWidth(35); txtValue.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputNewPhoneNumber); frame.AddChidren(txtValue); //线 var btnLine = new NormalViewControl(frame.Width, HdlControlResourse.BottomLineHeight, false); btnLine.Y = txtValue.Bottom; btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine; frame.AddChidren(btnLine); //联动线的状态 txtValue.btnLine = btnLine; if (string.IsNullOrEmpty(HdlUserCenterResourse.UserInfo.UserPhone) == false) { //确认身份成功,请绑定新手机号码 var btnMsg1 = new NormalViewControl(800, 49, false); btnMsg1.X = Application.GetRealWidth(196); btnMsg1.Y = frame.Bottom + Application.GetRealHeight(40); btnMsg1.TextSize = 12; btnMsg1.TextColor = UserCenterColor.Current.TextGrayColor1; btnMsg1.TextID = R.MyInternationalizationString.uAuthenticationSuccessAndBindNewPhone; bodyFrameLayout.AddChidren(btnMsg1); } //初始化验证码控件 var btnCodeControl = new VerificationCodeControl(6); btnCodeControl.Y = Application.GetRealHeight(475); bodyFrameLayout.AddChidren(btnCodeControl); btnCodeControl.InitControl(); btnCodeControl.TxtCodeChangeEvent += (sender, e) => { if (btnErrorMsg.Visible == true) { btnErrorMsg.Visible = false; } }; btnCodeControl.FinishInputEvent += (value) => { //绑定新手机 this.SaveNewPhoneNumber(btnCodeControl, value); }; //验证码错误,请重新输入 this.btnErrorMsg = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(58), false); btnErrorMsg.Y = Application.GetRealHeight(677); btnErrorMsg.TextAlignment = TextAlignment.Center; btnErrorMsg.TextColor = 0xfff75858; btnErrorMsg.IsBold = true; btnErrorMsg.TextID = R.MyInternationalizationString.uVerificationCodeErrorInputAgain; bodyFrameLayout.AddChidren(btnErrorMsg); btnErrorMsg.Visible = false; var btnOk = new BottomClickButton(688); btnOk.Y = Application.GetRealHeight(792); btnOk.TextID = R.MyInternationalizationString.uGetVerificationCode; bodyFrameLayout.AddChidren(btnOk); btnOk.oldBackgroundColor = UserCenterColor.Current.ClickButtonDefultColor; btnOk.CanClick = false; btnOk.ButtonClickEvent += (sender, e) => { //清空输入的值 btnCodeControl.ClearInputValue(); this.btnErrorMsg.Visible = false; string areaCode = btnArea.Text.Substring(1); //检测手机号码 if (this.CheckPhoneNumber(areaCode, txtValue.Text.Trim()) == false) { return; } //发送验证码到手机 this.SendCodeToPhone(btnOk, areaCode, txtValue.Text.Trim()); }; txtValue.TextChangeEventHandler += (sender, value) => { if (value == string.Empty) { //按键不可用 btnOk.CanClick = false; } else if (btnOk.CanClick == false) { //按键可用 btnOk.CanClick = true; } }; } #endregion #region ■ 发送验证码到手机___________________ /// /// 发送验证码到手机 /// private void SendCodeToPhone(BottomClickButton btnNext,string areaCode, string phoneNum) { var errorMsg = HdlAccountLogic.Current.SendVeriCodeToPhone(areaCode, phoneNum, VerCodeType.A绑定); if (errorMsg != null) { //显示错误 this.btnErrorMsg.Visible = true; this.btnErrorMsg.Text = errorMsg; return; } //不能再发送验证码 this.canSendCode = false; //可以开始校验验证码了 this.canCheckCode = true; //记录起这个手机,防止恶意变更 this.newPhone = phoneNum; //控件不能再次按下 btnNext.CanClick = false; //?s后重发 string repeat = Language.StringByID(R.MyInternationalizationString.RepeatSend1); //有效时间60秒 int waitime = 60; btnNext.Text = waitime + "s" + repeat; HdlThreadLogic.Current.RunThread(() => { while (this.Parent != null && this.canSendCode == false) { waitime--; System.Threading.Thread.Sleep(1000); if (waitime == 0) { break; } HdlThreadLogic.Current.RunMain(() => { if (btnNext != null) { btnNext.Text = waitime + "s" + repeat; } }, ShowErrorMode.NO); } Application.RunOnMainThread(() => { if (btnNext != null) { //获取验证码 btnNext.TextID = R.MyInternationalizationString.uGetVerificationCode; //按键可以按下 btnNext.CanClick = true; } }); }); } #endregion #region ■ 变更手机___________________________ /// /// 变更手机号 /// private void SaveNewPhoneNumber(VerificationCodeControl btnCodeControl, string code) { if (this.canCheckCode == false) { //验证码错误,请重新输入 this.btnErrorMsg.Visible = true; this.btnErrorMsg.TextID = R.MyInternationalizationString.uVerificationCodeErrorInputAgain; //清空输入值 btnCodeControl.ClearInputValue(); return; } //执行绑定 var errorMsg = HdlAccountLogic.Current.BindAccount(this.newPhone, code); if (errorMsg != null) { this.ShowMassage(ShowMsgType.Tip, errorMsg); //可以重新发送验证码 this.canSendCode = true; return; } //成功绑定新手机号 string msg = Language.StringByID(R.MyInternationalizationString.uBindPhoneNumberSuccess); this.ShowMassage(ShowMsgType.Normal, msg, () => { //刷新个人信息画面 this.RefreshUserInfoForm(); }); } /// /// 刷新个人信息画面 /// private void RefreshUserInfoForm() { //如果修改的是账号的话,则重新登录 if (HdlUserCenterResourse.UserInfo.UserPhone == Shared.Common.Config.Instance.Account) { HdlAccountLogic.Current.ReLoginAgain(newPhone); return; } HdlUserCenterResourse.UserInfo.UserPhone = newPhone; this.CloseForm(); } #endregion #region ■ 一般方法___________________________ /// /// 检测手机号 /// private bool CheckPhoneNumber(string areaCode, string phoneNum) { //输入为空 if (phoneNum == string.Empty) { //请输入新手机号码 this.btnErrorMsg.Visible = true; this.btnErrorMsg.TextID = R.MyInternationalizationString.uPleaseInputNewPhoneNumber; return false; } //检测手机号格式 if (HdlCheckLogic.Current.CheckPhoneNumber(phoneNum, areaCode) == false) { //这不是一个有效的手机号 this.btnErrorMsg.Visible = true; this.btnErrorMsg.TextID = R.MyInternationalizationString.uThisIsNotPhoneNumberType; return false; } return true; } #endregion } }