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
|
}
|
}
|