Example #1
0
        public RegisterViewModel()
        {
            AuthCodeButtonText = "发送验证码";
            IsEnable           = true;
            ButtonColor        = Color.FromHex("6ECBB8");

            SendCodeCommand = new Command(async() =>
            {
                try
                {
                    if (!Tools.IsNetConnective())
                    {
                        CrossToastPopUp.Current.ShowToastError("无网络连接,请检查网络。", ToastLength.Short);
                        return;
                    }

                    if (string.IsNullOrWhiteSpace(TelOrEmpNo))
                    {
                        CrossToastPopUp.Current.ShowToastError("手机号或员工号不能为空", ToastLength.Short);
                        return;
                    }

                    if (!Tools.IsPhoneNumber(TelOrEmpNo))
                    {
                        CrossToastPopUp.Current.ShowToastError("手机号格式不正确", ToastLength.Short);
                        return;
                    }

                    string ifExist = await RestSharpService.CheckIfRegister(TelOrEmpNo);

                    if (!string.IsNullOrWhiteSpace(ifExist))
                    {
                        BaseResponse baseResponse = JsonConvert.DeserializeObject <BaseResponse>(ifExist);
                        string res = (string)baseResponse.Result;
                        if (res == "TelExist")
                        {
                            CrossToastPopUp.Current.ShowToastSuccess("手机号已经注册", ToastLength.Long);
                        }
                        else    // 获取验证码前 需要先检查手机号 是否已注册
                        {
                            string result = await RestSharpService.SendCode(TelOrEmpNo);
                            if (string.IsNullOrWhiteSpace(result))
                            {
                                CrossToastPopUp.Current.ShowToastError("服务器错误", ToastLength.Short);
                            }
                            else
                            {
                                BaseResponse myResponse = JsonConvert.DeserializeObject <BaseResponse>(result);
                                CrossToastPopUp.Current.ShowToastSuccess(result, ToastLength.Long);
                                authCode = (string)myResponse.Result;
                                myTimer  = new MyTimer {
                                    EndDate = DateTime.Now.Add(new TimeSpan(900000000))
                                };
                                LoadAsync();
                                CrossToastPopUp.Current.ShowToastSuccess("请注意查收短信!", ToastLength.Short);
                            }
                        }
                    }
                    else
                    {
                        CrossToastPopUp.Current.ShowToastError("服务器错误", ToastLength.Short);
                        return;
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }, () => { return(true); });

            RegisterCommand = new Command(() =>
            {
                if (CheckInput())
                {
                    Register();
                }
            }, () => { return(true); });

            GetAreaCommand = new Command <int>((index) =>
            {
                GetAreaByDistrict(DistrictList[index].town);  //直接放参数,没有拿到这个值
            }, (index) => { return(true); });

            ReturnCommand = new Command(() =>
            {
                Application.Current.MainPage.Navigation.PopModalAsync();
            }, () => { return(true); });

            GetDistrictsByCity("cd");
        }