JLChen
2020-11-18 7153e420d66bce0a06b7e972ac3a5c34197fa2e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using System;
using Shared;
using HDL_ON.UI.CSS;
using System.Threading;
using System.Text.RegularExpressions;
using HDL_ON.DAL.Server;
 
 
namespace HDL_ON.UI
{
    /// <summary>
    ///  新绑定或者换绑--手机或者邮箱发送验证码
    /// </summary>
    public partial class NewBindAccountPage : FrameLayout
    {
        FrameLayout bodyView;
        Button btnBind;
        EditText etContent;
        Action<string> action;
 
        /// <summary>
        /// 标题ID
        /// </summary>
        int titleId;
        /// <summary>
        /// 是否手机
        /// </summary>
        bool isPhone;
        /// <summary>
        /// 是否换绑
        /// </summary>
        bool isModifyBind;
 
        /// <summary>
        /// 手机区号
        /// </summary>
        string phoneZoneCode = "86";
 
        /// <summary>
        /// 
        /// </summary>
        public NewBindAccountPage()
        {
            bodyView = this;
        }
 
        /// <summary>
        /// LoadPage
        /// </summary>
        /// <param name="act"></param>
        /// <param name="isPhone">是否绑定手机</param>
        public void LoadPage(Action<string> act, bool isPhone = false, bool isModifyBind = false)
        {
            action = act;
            this.isPhone = isPhone;
            this.isModifyBind = isModifyBind;
            if (isModifyBind)
            {
                //修改绑定
                titleId = isPhone ? StringId.ModifyBindingPhone : StringId.ModifyBindingEmail;
            }
            else
            {
                //新绑定
                titleId = isPhone ? StringId.BoundMobileInfo : StringId.BoundEmailInfo;
            }
         
            
 
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(titleId)).LoadTopView();
 
            FrameLayout rowView = new FrameLayout()
            {
                Y = Application.GetRealHeight(72),
                Height = Application.GetRealHeight(50),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(rowView);
 
            //绑定邮箱或者绑定手机号
            Button btnTitle = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(180),
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = titleId,
            };
            rowView.AddChidren(btnTitle);
 
            etContent = new EditText()
            {
                Width = Application.GetRealWidth(359),
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.TextFontSize,
                TextAlignment = TextAlignment.CenterRight,
                Foucs = true
            };
            rowView.AddChidren(etContent);
 
            btnBind = new Button()
            {
                Y = Application.GetRealHeight(213),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                BackgroundColor = CSS_Color.MainColor,
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainBackgroundColor,
                TextID = StringId.GetVerificationCode,
                TextSize = CSS_FontSize.SubheadingFontSize,
                IsBold = true,
                Radius = (uint)Application.GetRealWidth(22),
                BorderColor = 0x00000000,
                BorderWidth = 0,
            };
            bodyView.AddChidren(btnBind);
 
            //点击获取验证码
            LoadEvent_GetVerification(btnBind);
           
        }
    }
 
 
    //--------------------------------------------
    public partial class NewBindAccountPage
    {
        /// <summary>
        /// 点击获取验证码
        /// </summary>
        void LoadEvent_GetVerification(Button button)
        {
            button.MouseUpEventHandler = (sender, e) =>
            {
                if (button.Text == Language.StringByID(StringId.GetVerificationCode))
                {
                    Application.HideSoftInput();
                    var account = etContent.Text.Trim();
                    #region 正则表达式
                    //1.检测账号是否合法
                    if (!isPhone)
                    {
                        if (!Utlis.CheckEmail(account))
                        {
                            Utlis.ShowTip(Language.StringByID(StringId.PlsEntryCorrectEmailAddress), bodyView);
                            return;
                        }
                    }
                    else
                    {
                        if (!Utlis.CheckPhoneNumber(account, phoneZoneCode))
                        {
                            Utlis.ShowTip(Language.StringByID(StringId.PlsEntryCorrectMobilNeumber), bodyView);
                            return;
                        }
                    }
                    #endregion
                    int time = 0;
                    //2.检验通过
                    new Thread(() =>
                    {
                        //2.2  获取验证码
                        ResponsePackNew resultObj;
                        if (!isPhone)//邮箱
                        {
                            resultObj = new HttpServerRequest().VerificationCodeSend(VerifyType.REGISTER_USER_SYSTEM, account);
                        }
                        else
                        {
                            resultObj = new HttpServerRequest().VerificationCodeSend(VerifyType.REGISTER_USER_SYSTEM, account, true, phoneZoneCode);
                        }
 
                        if (resultObj.Code != StateCode.SUCCESS)
                        {
                            // 提示错误
                            IMessageCommon.Current.ShowErrorInfoAlter(NewAPI.API_POST_Verification_Send, resultObj.Code);
                        }
                        else
                        {
                            if (time == 0)
                            {
                                time = 60;
                                new Thread(() =>
                                {
                                    while (time > 0)
                                    {
                                        time--;
                                        Application.RunOnMainThread(() =>
                                        {
                                            button.Text = time.ToString() + "s";
                                        });
                                        Thread.Sleep(1000);
                                    }
                                    Application.RunOnMainThread(() =>
                                    {
                                        button.IsSelected = true;
                                        button.TextID = StringId.GetVerificationCode;
                                        button.BackgroundColor = CSS_Color.MainColor;
                                        time = 0;
                                    });
                                })
                                { IsBackground = true }.Start();
                            }
                            Application.RunOnMainThread(() =>
                            {
                                button.BackgroundColor = CSS_Color.PromptingColor1;
                                var vcp = new NewBindVerificationCodePage();
                                vcp.phoneZoneCode = phoneZoneCode;
                                MainPage.BasePageView.AddChidren(vcp);
                                vcp.LoadPage(action, titleId, account, isPhone, time, isModifyBind);
                                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                            });
                        }
 
                    })
                    { IsBackground = true }.Start();
                }
 
            };
        }
    }
}