黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.Safety
{
    /// <summary>
    /// 添加胁迫联系人
    /// </summary>
    public class CoercePswAddContactForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 添加联系方式的事件
        /// </summary>
        public Action AddPhoneEvent = null;
        /// <summary>
        /// 信息提示控件
        /// </summary>
        private NormalViewControl btnErrorMsg = null;
        /// <summary>
        /// 电话列表
        /// </summary>
        private List<Safeguard.PushTargetInfo> listPhoneData = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="listData"></param>
        public void ShowForm(List<Safeguard.PushTargetInfo> listData)
        {
            this.listPhoneData = listData;
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uAddContactPersion));
 
            var btnIcon = new MostRightIconControl(69, 69);
            btnIcon.UnSelectedImagePath = "Item/PhoneBook.png";
            topFrameLayout.AddChidren(btnIcon);
            btnIcon.InitControl();
            btnIcon.ButtonClickEvent += ((sender, e) =>
            {
                Contacts.ContactAction = (phoneName, phoneNum) =>
                {
                    if (string.IsNullOrEmpty(phoneName) == true)
                    {
                        return;
                    }
                    //手机号检测
                    if (this.CheckPhoneNumber("86", phoneNum, phoneName) == false)
                    {
                        return;
                    }
                    //保存联系人
                    this.SaveCoercePhoneNumber("86", phoneNum, phoneName);
                };
                Contacts.Open();
            });
 
            //初始化中部信息
            this.InitMiddleFrame();
 
            //重写底层返回按键事件
            this.BackButtonClickEvent = (sender) =>
            {
                this.AddPhoneEvent = null;
                this.CloseForm();
            };
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            var frameBack = new FrameLayout();
            frameBack.Height = Application.GetRealHeight(328);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(frameBack);
 
            //地区码
            var btnArea = new NormalViewControl(127, 60, true);
            btnArea.X = HdlControlResourse.XXLeft;
            btnArea.Y = Application.GetRealHeight(57);
            btnArea.Text = "+86";
            btnArea.TextAlignment = TextAlignment.Center;
            btnArea.TextColor = UserCenterColor.Current.TextGrayColor1;
            frameBack.AddChidren(btnArea);
            //目前只针对+86
            //btnArea.ButtonClickEvent += (sender, e) =>
            //{
            //    var form = new AreaCodeSelectForm();
            //    form.AddForm();
            //    form.FinishSelectEvent += (code) =>
            //    {
            //        btnArea.Text = "+" + code;
            //    };
            //};
            //电话输入框
            var txtPhone = new TextInputControl(Application.GetRealWidth(634), btnArea.Height, false);
            txtPhone.X = btnArea.Right + Application.GetRealWidth(35);
            txtPhone.Y = btnArea.Y;
            txtPhone.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPleaseInputPhoneNumber);
            frameBack.AddChidren(txtPhone);
            //取消图标
            var btnCancel1 = new MostRightIconControl(69, 69);
            btnCancel1.Gravity = Gravity.Frame;
            btnCancel1.Y = Application.GetRealHeight(23);
            btnCancel1.UnSelectedImagePath = "Item/CancelIcon.png";
            frameBack.AddChidren(btnCancel1);
            btnCancel1.InitControl();
            btnCancel1.ButtonClickEvent += (sender, e) =>
            {
                txtPhone.Text = string.Empty;
            };
            //线
            var btnLine = new NormalViewControl(Application.GetRealWidth(965), HdlControlResourse.BottomLineHeight, false);
            btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine;
            btnLine.Y = Application.GetRealHeight(150);
            btnLine.Gravity = Gravity.CenterHorizontal;
            frameBack.AddChidren(btnLine);
            //联动线的状态
            txtPhone.btnLine = btnLine;
 
            //备注
            var txtNote = new TextInputControl(Application.GetRealWidth(740), txtPhone.Height, false);
            txtNote.X = HdlControlResourse.XXLeft;
            txtNote.Y = btnLine.Bottom + Application.GetRealHeight(60);
            txtNote.PlaceholderText = Language.StringByID(R.MyInternationalizationString.uPlesaeInputNoteInformation);
            frameBack.AddChidren(txtNote);
            //取消图标
            var btnCancel2 = new MostRightIconControl(69, 69);
            btnCancel2.Gravity = Gravity.Frame;
            btnCancel2.Y = btnLine.Bottom + Application.GetRealHeight(29);
            btnCancel2.UnSelectedImagePath = "Item/CancelIcon.png";
            frameBack.AddChidren(btnCancel2);
            btnCancel2.InitControl();
            btnCancel2.ButtonClickEvent += (sender, e) =>
            {
                txtNote.Text = string.Empty;
            };
 
            //信息提示
            this.btnErrorMsg = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(60), false);
            btnErrorMsg.X = HdlControlResourse.XXLeft;
            btnErrorMsg.Y = frameBack.Bottom + Application.GetRealHeight(29);
            btnErrorMsg.TextColor = 0xfff75858;
            btnErrorMsg.TextSize = 12;
            bodyFrameLayout.AddChidren(btnErrorMsg);
 
            //完成
            var btnFinish = new BottomClickButton();
            btnFinish.TextID = R.MyInternationalizationString.uFinish;
            bodyFrameLayout.AddChidren(btnFinish);
            btnFinish.ButtonClickEvent += (sender, e) =>
            {
                //手机号检测
                if (this.CheckPhoneNumber(btnArea.Text.Substring(1), txtPhone.Text.Trim(), txtNote.Text.Trim()) == false)
                {
                    return;
                }
                //执行保存手机操作
                this.SaveCoercePhoneNumber(btnArea.Text.Substring(1), txtPhone.Text.Trim(), txtNote.Text.Trim());
            };
        }
 
        #endregion
 
        #region ■ 添加联系人方式_____________________
 
        /// <summary>
        /// 变更联系人方式
        /// </summary>
        /// <param name="areaCode"></param>
        /// <param name="phoneNum"></param>
        /// <param name="strNote"></param>
        private async void SaveCoercePhoneNumber(string areaCode, string phoneNum, string strNote)
        {
            var listPhone = new List<string>();
            listPhone.Add(areaCode + "-" + phoneNum);
            var listNote = new List<string>();
            listNote.Add(strNote);
 
            //变更
            var result = await HdlSafeguardLogic.Current.SetCoercePhoneNumber(listPhone, listNote);
            if (result == false)
            {
                return;
            }
            this.CloseForm();
 
            //调用回调函数
            this.AddPhoneEvent?.Invoke();
            this.AddPhoneEvent = null;
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 检测手机号
        /// </summary>
        /// <param name="areaCode"></param>
        /// <param name="phone"></param>
        /// <param name="strNote"></param>
        private bool CheckPhoneNumber(string areaCode, string phone,string strNote)
        {
            //输入为空
            if (phone == string.Empty)
            {
                //请输入手机号
                btnErrorMsg.Text = Language.StringByID(R.MyInternationalizationString.uPleaseInputPhoneNumber);
                return false;
            }
            if (strNote == string.Empty)
            {
                //请输入备注内容
                btnErrorMsg.Text = Language.StringByID(R.MyInternationalizationString.uPlesaeInputNoteInformation);
                return false;
            }
 
            //检测手机号格式
            if (HdlCheckLogic.Current.CheckPhoneNumber(phone, areaCode) == false)
            {
                //这不是一个有效的手机号
                btnErrorMsg.Text = Language.StringByID(R.MyInternationalizationString.uThisIsNotPhoneNumberType);
                return false;
            }
            foreach (var data in this.listPhoneData)
            {
                if (data.PushNumber == areaCode + "-" + phone)
                {
                    //联系方式已经存在
                    btnErrorMsg.Text = Language.StringByID(R.MyInternationalizationString.uThePhoneNumIsRepeat);
                    return false;
                }
            }
 
            btnErrorMsg.Text = string.Empty;
 
            return true;
        }
 
        #endregion
    }
}