import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/messageWarn/addFamily/addFamily_state.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'; class AddFamilyLogic extends BaseGetXController { final AddFamilyState state = AddFamilyState(); void addLockNoticeSetting() async { var entity = await ApiRepository.to.addLockNoticeSetting( lockId: state.getLockId.value, noticeType: 10, settingValue: { 'openDoorId': state.lockUserKeys.value.currentOpenDoorID, 'openDoorType': state.lockUserKeys.value.currentKeyType, 'remark': state.lockUserKeys.value.currentKeyName ?? '', 'noticeWay': [ {'type': 'mail', 'accounts': getEmailAndSMSAccountList(true)}, {'type': 'sms', 'accounts': getEmailAndSMSAccountList(false)} ] }, ); if (entity.errorCode!.codeIsSuccessful) { showToast('添加成功'.tr); Get.back(result: true); } } List getEmailAndSMSAccountList(bool isEmail) { List list = []; List accountList = []; isEmail ? accountList = state.emailReceiverList.value : accountList = state.phoneReceiverList.value; for (int i = 0; i < accountList.length; i++) { MsgNoticeModeData item = accountList[i]; 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']; List emailReceiverList = state.emailReceiverList.value; for (int i = 0; i < emailReceiverList.length; i++) { 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']; List phoneReceiverList = state.phoneReceiverList.value; for (int i = 0; i < phoneReceiverList.length; i++) { MsgNoticeModeData item = phoneReceiverList[i]; phoneListStr += item.receivePhone; // 检查是否为最后一个元素 if (i < phoneReceiverList.length - 1) { phoneListStr += ','; } } } return phoneListStr; } bool checkBtnDisable() { if ((state.emailListStr.value.isEmpty || state.phontListStr.value.isEmpty) || state.lockUserKeys.value.currentKeyTypeStr!.isEmpty || state.lockUserKeys.value.currentKeyName!.isEmpty) { return false; } else { return true; } } }