120 lines
4.4 KiB
Dart
Executable File
120 lines
4.4 KiB
Dart
Executable File
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart';
|
|
import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_data.dart';
|
|
import 'package:star_lock/network/api_repository.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
|
|
import 'lowBatteryReminder_state.dart';
|
|
|
|
class LowBatteryReminderLogic extends BaseGetXController {
|
|
LowBatteryReminderState state = LowBatteryReminderState();
|
|
|
|
Future<void> lockNoticeSettingAccountList() async {
|
|
final OpenDoorNotifyEntity entity = await ApiRepository.to.updatelowElecNoticeStateSetting(
|
|
lockId: state.getLockId.value,
|
|
lowElecNoticeState: state.isLowBatteryNotify.value == true ? 1 : 0,
|
|
lowElecNoticeWayList: [
|
|
<String, Object>{'type': 'mail', 'accounts': getEmailAndSMSAccountList(true)},
|
|
<String, Object>{'type': 'sms', 'accounts': getEmailAndSMSAccountList(false)}
|
|
]);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('设置成功'.tr);
|
|
Get.back(result: true);
|
|
}
|
|
}
|
|
|
|
//获取到家人信息的请求数组
|
|
List getEmailAndSMSAccountList(bool isEmail) {
|
|
final List list = [];
|
|
List accountList = [];
|
|
isEmail
|
|
? accountList = state.emailReceiverList.value
|
|
: accountList = state.phoneReceiverList.value;
|
|
for (int i = 0; i < accountList.length; i++) {
|
|
final MsgNoticeModeData item = accountList[i];
|
|
final Map map = {};
|
|
map['countryCode'] = isEmail ? 0 : item.countryCode;
|
|
map['account'] = isEmail ? item.receiveEmail : item.receivePhone;
|
|
list.add(map);
|
|
}
|
|
return list;
|
|
}
|
|
|
|
String getEmailListStr(Map val) {
|
|
String emailListStr = '';
|
|
if (val['emailReceiverList'] != null) {
|
|
state.emailReceiverList.value = val['emailReceiverList'];
|
|
final List emailReceiverList = state.emailReceiverList.value;
|
|
for (int i = 0; i < emailReceiverList.length; i++) {
|
|
final MsgNoticeModeData item = emailReceiverList[i];
|
|
emailListStr += item.receiveEmail;
|
|
// 检查是否为最后一个元素
|
|
if (i < emailReceiverList.length - 1) {
|
|
emailListStr += ',';
|
|
}
|
|
}
|
|
}
|
|
return emailListStr;
|
|
}
|
|
|
|
String getPhoneListStr(Map val) {
|
|
String phoneListStr = '';
|
|
|
|
if (val['phoneReceiverList'] != null) {
|
|
state.phoneReceiverList.value = val['phoneReceiverList'];
|
|
final List phoneReceiverList = state.phoneReceiverList.value;
|
|
for (int i = 0; i < phoneReceiverList.length; i++) {
|
|
final MsgNoticeModeData item = phoneReceiverList[i];
|
|
phoneListStr += item.receivePhone;
|
|
// 检查是否为最后一个元素
|
|
if (i < phoneReceiverList.length - 1) {
|
|
phoneListStr += ',';
|
|
}
|
|
}
|
|
}
|
|
return phoneListStr;
|
|
}
|
|
|
|
//根据列表返回值得到邮箱、手机列表
|
|
Map<String, List<MsgNoticeModeData>> getAccountsMap() {
|
|
final List<MsgNoticeModeData> mailAccounts = <MsgNoticeModeData>[];
|
|
final List<MsgNoticeModeData> smsAccounts = <MsgNoticeModeData>[];
|
|
|
|
if (state.msgNoticeInfo.value.lowElecNoticeWayList != null) {
|
|
for (final NoticeWay item in state.msgNoticeInfo.value.lowElecNoticeWayList!) {
|
|
if (item.type == 'mail' && item.accounts != null) {
|
|
for (final Accounts account in item.accounts!) {
|
|
if (account.account != null) {
|
|
final MsgNoticeModeData msgNoticeModeData = MsgNoticeModeData();
|
|
msgNoticeModeData.receiveEmail = account.account!;
|
|
mailAccounts.add(msgNoticeModeData);
|
|
}
|
|
}
|
|
} else if (item.type == 'sms' && item.accounts != null) {
|
|
for (final Accounts account in item.accounts!) {
|
|
if (account.account != null && account.countryCode != null) {
|
|
final MsgNoticeModeData msgNoticeModeData = MsgNoticeModeData();
|
|
msgNoticeModeData.receivePhone = account.account!;
|
|
msgNoticeModeData.countryCode = account.countryCode!;
|
|
smsAccounts.add(msgNoticeModeData);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return <String, List<MsgNoticeModeData>>{
|
|
'emailReceiverList': mailAccounts,
|
|
'phoneReceiverList': smsAccounts,
|
|
};
|
|
}
|
|
|
|
@override
|
|
onInit() {
|
|
super.onInit();
|
|
state.emailListStr.value = getEmailListStr(getAccountsMap());
|
|
state.phontListStr.value = getPhoneListStr(getAccountsMap());
|
|
}
|
|
}
|