diff --git a/star_lock/images/lan/lan_en.json b/star_lock/images/lan/lan_en.json index 02973a34..eabf1dd9 100644 --- a/star_lock/images/lan/lan_en.json +++ b/star_lock/images/lan/lan_en.json @@ -771,5 +771,6 @@ "邮件提醒":"Email reminder", "关锁":"关锁", "功能":"功能", - "配件":"配件" + "配件":"配件", + "N天未开门提醒":"N days did not open the door reminder" } diff --git a/star_lock/images/lan/lan_keys.json b/star_lock/images/lan/lan_keys.json index 68bff2cc..30a992c3 100644 --- a/star_lock/images/lan/lan_keys.json +++ b/star_lock/images/lan/lan_keys.json @@ -770,5 +770,6 @@ "邮件提醒":"邮件提醒", "关锁":"Close Lock", "功能":"Function", - "配件":"Parts" + "配件":"Parts", + "N天未开门提醒":"N天未开门提醒" } diff --git a/star_lock/images/lan/lan_zh.json b/star_lock/images/lan/lan_zh.json index 72573a1a..fce57f55 100644 --- a/star_lock/images/lan/lan_zh.json +++ b/star_lock/images/lan/lan_zh.json @@ -773,5 +773,6 @@ "邮件提醒":"邮件提醒", "关锁":"关锁", "功能":"功能", - "配件":"配件" + "配件":"配件", + "N天未开门提醒":"N天未开门提醒" } diff --git a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart index 34ccd392..312aa0e5 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart @@ -1,3 +1,5 @@ +import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart'; + class MsgNotificationEntity { int? errorCode; String? description; @@ -27,21 +29,19 @@ class MsgNotificationEntity { } class MsgNoticeData { - List? openDoorNoticeList; int? dayNotOpenDoorState; int? dayNotOpenDoorValue; - List? dayNotOpenDoorNoticeWayList; + List? dayNotOpenDoorNoticeWayList; int? doorNotCloseState; int? tamperAlarmState; int? lowElecNoticeState; - List? lowElecNoticeWayList; - List? coercionOpenDoorNoticeList; + List? lowElecNoticeWayList; + List? coercionOpenDoorNoticeList; int? doorbellNoticeState; int? someoneAtDoorNoticeState; MsgNoticeData( - {this.openDoorNoticeList, - this.dayNotOpenDoorState, + {this.dayNotOpenDoorState, this.dayNotOpenDoorValue, this.dayNotOpenDoorNoticeWayList, this.doorNotCloseState, @@ -53,18 +53,12 @@ class MsgNoticeData { this.someoneAtDoorNoticeState}); MsgNoticeData.fromJson(Map json) { - if (json['openDoorNoticeList'] != null) { - openDoorNoticeList = []; - json['openDoorNoticeList'].forEach((v) { - openDoorNoticeList!.add(v); - }); - } dayNotOpenDoorState = json['dayNotOpenDoorState']; dayNotOpenDoorValue = json['dayNotOpenDoorValue']; if (json['dayNotOpenDoorNoticeWayList'] != null) { - dayNotOpenDoorNoticeWayList = []; + dayNotOpenDoorNoticeWayList = []; json['dayNotOpenDoorNoticeWayList'].forEach((v) { - dayNotOpenDoorNoticeWayList!.add(v); + dayNotOpenDoorNoticeWayList!.add(NoticeWay.fromJson(v)); }); } doorNotCloseState = json['doorNotCloseState']; @@ -88,10 +82,6 @@ class MsgNoticeData { Map toJson() { final Map data = {}; - if (openDoorNoticeList != null) { - data['openDoorNoticeList'] = - openDoorNoticeList!.map((v) => v.toJson()).toList(); - } data['dayNotOpenDoorState'] = dayNotOpenDoorState; data['dayNotOpenDoorValue'] = dayNotOpenDoorValue; if (dayNotOpenDoorNoticeWayList != null) { @@ -103,11 +93,11 @@ class MsgNoticeData { data['lowElecNoticeState'] = lowElecNoticeState; if (lowElecNoticeWayList != null) { data['lowElecNoticeWayList'] = - lowElecNoticeWayList!.map((v) => v).toList(); + lowElecNoticeWayList!.map((v) => v.toJson()).toList(); } if (coercionOpenDoorNoticeList != null) { data['coercionOpenDoorNoticeList'] = - coercionOpenDoorNoticeList!.map((v) => v).toList(); + coercionOpenDoorNoticeList!.map((v) => v.toJson()).toList(); } data['doorbellNoticeState'] = doorbellNoticeState; data['someoneAtDoorNoticeState'] = someoneAtDoorNoticeState; diff --git a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_page.dart b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_page.dart index 0fe9b209..fc22ca2f 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_page.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_page.dart @@ -89,7 +89,14 @@ class _MsgNotificationPageState extends State { isHaveLine: true, isHaveDirection: true, action: () { - Get.toNamed(Routers.nDaysUnopenedPage); + Get.toNamed(Routers.nDaysUnopenedPage, arguments: { + 'lockSetInfoData': state.msgNoticeInfo.value, + 'lockId': state.getLockId.value + })?.then((value) { + if (value != null) { + logic.getLockNoticeSetting(); + } + }); }, )), // SizedBox( diff --git a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_logic.dart b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_logic.dart index e986ef89..797daa1b 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_logic.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_logic.dart @@ -1,7 +1,120 @@ +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 'nDaysUnopened_state.dart'; class NDaysUnopenedLogic extends BaseGetXController { NDaysUnopenedState state = NDaysUnopenedState(); + + void lockNoticeSettingAccountList() async { + var entity = await ApiRepository.to.updateNdaysNotCloseDoorNoticeSetting( + lockId: state.getLockId.value, + dayNotOpenDoorState: state.isUnOpenNotice.value == true ? 1 : 0, + dayNotOpenDoorValue: state.unOpenDoorTime.value, + dayNotOpenDoorNoticeWayList: [ + {'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; + } + + //根据列表返回值得到邮箱、手机列表 + Map> getAccountsMap() { + List mailAccounts = []; + List smsAccounts = []; + + if (state.msgNoticeInfo.value.dayNotOpenDoorNoticeWayList != null) { + for (NoticeWay item + in state.msgNoticeInfo.value.dayNotOpenDoorNoticeWayList!) { + if (item.type == 'mail' && item.accounts != null) { + for (Accounts account in item.accounts!) { + if (account.account != null) { + MsgNoticeModeData msgNoticeModeData = MsgNoticeModeData(); + msgNoticeModeData.receiveEmail = account.account!; + mailAccounts.add(msgNoticeModeData); + } + } + } else if (item.type == 'sms' && item.accounts != null) { + for (Accounts account in item.accounts!) { + if (account.account != null && account.countryCode != null) { + MsgNoticeModeData msgNoticeModeData = MsgNoticeModeData(); + msgNoticeModeData.receivePhone = account.account!; + msgNoticeModeData.countryCode = account.countryCode!; + smsAccounts.add(msgNoticeModeData); + } + } + } + } + } + + return { + 'emailReceiverList': mailAccounts, + 'phoneReceiverList': smsAccounts, + }; + } + + @override + onInit() { + super.onInit(); + state.emailListStr.value = getEmailListStr(getAccountsMap()); + state.phontListStr.value = getPhoneListStr(getAccountsMap()); + } } diff --git a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_page.dart b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_page.dart index 50504d6d..4e89157b 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_page.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_page.dart @@ -1,10 +1,9 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -// import 'package:flutter_pickers/pickers.dart'; -// import 'package:flutter_pickers/style/default_style.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; +import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart'; import 'package:star_lock/tools/commonItem.dart'; import 'package:star_lock/tools/pickers/pickers.dart'; import 'package:star_lock/tools/pickers/style/default_style.dart'; @@ -30,7 +29,7 @@ class _NDaysUnopenedPageState extends State { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( - barTitle: 'N天未开门', + barTitle: 'N天未开门'.tr, haveBack: true, backgroundColor: AppColors.mainColor), body: Container( @@ -52,7 +51,7 @@ class _NDaysUnopenedPageState extends State { height: 20.h, ), CommonItem( - leftTitel: 'N天未开门提醒', + leftTitel: 'N天未开门提醒'.tr, rightTitle: '', isHaveLine: true, isHaveDirection: false, @@ -60,12 +59,12 @@ class _NDaysUnopenedPageState extends State { rightWidget: _unOpenDoorSwitch(), action: () {}), Visibility( - visible: state.isunOpenNotice.value, + visible: state.isUnOpenNotice.value, child: Column( children: [ Obx(() => CommonItem( leftTitel: '门未开时间', - rightTitle: state.unOpenDoorTime.value, + rightTitle: '${state.unOpenDoorTime.value}天', isHaveLine: true, isHaveRightWidget: false, isHaveDirection: true, @@ -77,41 +76,46 @@ class _NDaysUnopenedPageState extends State { SizedBox( height: 20.h, ), - Container( - color: Colors.white, - margin: EdgeInsets.only(bottom: 10.h), - child: Column( - children: [ - CommonItem( - leftTitel: '提醒方式'.tr, - rightTitle: "", - isHaveLine: false, - isHaveRightWidget: false, - isHaveDirection: true, - action: () { - Get.toNamed(Routers.notificationModePage); - }, - ), - Container( - padding: EdgeInsets.only( - left: 10.w, - right: 10.w, - top: 12.h, - bottom: 12.h), - margin: EdgeInsets.only(bottom: 20.h, top: 10.h), - decoration: BoxDecoration( - color: AppColors.mainBackgroundColor, - borderRadius: BorderRadius.circular(6.0.w), + GestureDetector( + onTap: () { + Get.toNamed(Routers.notificationModePage, arguments: { + 'msgNoticeInfo': state.msgNoticeInfo.value + })?.then((val) { + if (val != null) { + state.emailListStr.value = + logic.getEmailListStr(val); + state.phontListStr.value = + logic.getPhoneListStr(val); + print( + 'emailListStr:${state.emailListStr.value},phontListStr:${state.phontListStr.value}'); + } + }); + }, + child: Container( + color: Colors.white, + margin: EdgeInsets.only(bottom: 10.h), + child: Column( + children: [ + CommonItem( + leftTitel: '提醒方式'.tr, + rightTitle: "", + isHaveLine: false, + isHaveRightWidget: false, + isHaveDirection: true, ), - child: Text( - 'APP推送 管理员', - style: TextStyle( - color: Colors.black, fontSize: 20.sp), - ), - ) - ], + _buildNotifyContain('APP推送'.tr, '管理员'.tr), + Obx(() => state.emailListStr.value.isNotEmpty + ? _buildNotifyContain( + '邮件提醒'.tr, state.emailListStr.value) + : Container()), + Obx(() => state.phontListStr.value.isNotEmpty + ? _buildNotifyContain( + '短信提醒'.tr, state.phontListStr.value) + : Container()), + ], + ), ), - ) + ), ], )), Expanded( @@ -120,7 +124,9 @@ class _NDaysUnopenedPageState extends State { )), SubmitBtn( btnName: '保存', - onClick: () {}, + onClick: () { + logic.lockNoticeSettingAccountList(); + }, ), SizedBox( height: 60.h, @@ -131,15 +137,46 @@ class _NDaysUnopenedPageState extends State { ); } + Widget _buildNotifyContain(String notifyTitle, String notifyContent) { + return Container( + padding: + EdgeInsets.only(left: 10.w, right: 10.w, top: 12.h, bottom: 12.h), + margin: EdgeInsets.only(bottom: 20.h, top: 10.h, left: 20.w, right: 20.w), + decoration: BoxDecoration( + color: AppColors.mainBackgroundColor, + borderRadius: BorderRadius.circular(6.0.w), + ), + child: Row( + children: [ + Text( + notifyTitle, + style: TextStyle(color: Colors.black, fontSize: 20.sp), + ), + Expanded( + child: SizedBox( + width: 20.w, + )), + Text(notifyContent, + textAlign: TextAlign.end, + style: TextStyle( + color: AppColors.placeholderTextColor, fontSize: 20.sp)), + ], + ), + ); + } + CupertinoSwitch _unOpenDoorSwitch() { return CupertinoSwitch( activeColor: CupertinoColors.activeBlue, trackColor: CupertinoColors.systemGrey5, thumbColor: CupertinoColors.white, - value: state.isunOpenNotice.value, + value: state.isUnOpenNotice.value, onChanged: (value) { setState(() { - state.isunOpenNotice.value = value; + state.isUnOpenNotice.value = value; + if (!state.isUnOpenNotice.value) { + state.msgNoticeInfo.value = MsgNoticeData(); + } }); }, ); diff --git a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_state.dart b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_state.dart index f7c79b23..6ef90838 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_state.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/nDaysUnopened/nDaysUnopened_state.dart @@ -1,24 +1,50 @@ import 'package:get/get.dart'; +import 'package:star_lock/main/lockDetail/messageWarn/lockUser/lockUser_entity.dart'; +import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart'; +import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart'; class NDaysUnopenedState { - final List unopenDoorTimeList = [ - '1天', - '2天', - '3天', - '4天', - '5天', - '6天', - '7天', - '8天', - '9天', - '10天', - '11天', - '12天', - '13天', - '14天', - '15天', + final List unopenDoorTimeList = [ + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, ]; - var isunOpenNotice = false.obs; // 是否N天未开门提醒 - var unOpenDoorTime = '1天'.obs; // 未开门时间 + var isUnOpenNotice = false.obs; // 是否N天未开门提醒 + var unOpenDoorTime = 1.obs; // 未开门时间 + + var getLockId = 0.obs; + var lockUserKeys = LockUserListKeys().obs; + var emailReceiverList = [].obs; + var phoneReceiverList = [].obs; + var emailListStr = ''.obs; + var phontListStr = ''.obs; + + var msgNoticeInfo = MsgNoticeData().obs; + + NDaysUnopenedState() { + Map map = Get.arguments; + if (map['lockId'] != null) { + getLockId.value = map['lockId']; + } + + if (map['lockSetInfoData'] != null) { + msgNoticeInfo.value = map['lockSetInfoData']; + isUnOpenNotice.value = + msgNoticeInfo.value.dayNotOpenDoorState == 1 ? true : false; + unOpenDoorTime.value = msgNoticeInfo.value.dayNotOpenDoorValue!; + } + } } diff --git a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart index 923d3669..0b3fc846 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart @@ -1,3 +1,5 @@ +import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart'; + class OpenDoorNotifyEntity { int? errorCode; String? description; diff --git a/star_lock/lib/main/lockDetail/messageWarn/notificationMode/notificationMode_page.dart b/star_lock/lib/main/lockDetail/messageWarn/notificationMode/notificationMode_page.dart index c4dea969..ab5e4920 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/notificationMode/notificationMode_page.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/notificationMode/notificationMode_page.dart @@ -3,7 +3,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:star_lock/appRouters.dart'; -import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart'; import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_data.dart'; import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_logic.dart'; import 'package:star_lock/tools/commonItem.dart'; diff --git a/star_lock/lib/main/lockDetail/messageWarn/notificationMode/notificationMode_state.dart b/star_lock/lib/main/lockDetail/messageWarn/notificationMode/notificationMode_state.dart index bf7eeb80..57c33ebd 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/notificationMode/notificationMode_state.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/notificationMode/notificationMode_state.dart @@ -1,4 +1,5 @@ import 'package:get/get.dart'; +import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart'; import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart'; import 'package:star_lock/main/lockDetail/messageWarn/notificationMode/notificationMode_data.dart'; @@ -9,6 +10,7 @@ class NotificationModeState { var countryName = '中国'.obs; var countryCode = 86.obs; var familyData = DataList().obs; + var msgNoticeInfo = MsgNoticeData().obs; NotificationModeState() { Map map = Get.arguments; @@ -37,5 +39,32 @@ class NotificationModeState { } } } + + if (map['msgNoticeInfo'] != null) { + msgNoticeInfo.value = map['msgNoticeInfo']; + if (msgNoticeInfo.value.dayNotOpenDoorNoticeWayList != null) { + for (NoticeWay item + in msgNoticeInfo.value.dayNotOpenDoorNoticeWayList!) { + if (item.type == 'mail' && item.accounts != null) { + for (Accounts account in item.accounts!) { + if (account.account != null) { + MsgNoticeModeData msgNoticeModeData = MsgNoticeModeData(); + msgNoticeModeData.receiveEmail = account.account!; + emailReceiverList.value.add(msgNoticeModeData); + } + } + } else if (item.type == 'sms' && item.accounts != null) { + for (Accounts account in item.accounts!) { + if (account.account != null && account.countryCode != null) { + MsgNoticeModeData msgNoticeModeData = MsgNoticeModeData(); + msgNoticeModeData.receivePhone = account.account!; + msgNoticeModeData.countryCode = account.countryCode!; + phoneReceiverList.value.add(msgNoticeModeData); + } + } + } + } + } + } } } diff --git a/star_lock/lib/network/api_repository.dart b/star_lock/lib/network/api_repository.dart index 8971d845..f1522ab1 100644 --- a/star_lock/lib/network/api_repository.dart +++ b/star_lock/lib/network/api_repository.dart @@ -1850,14 +1850,14 @@ class ApiRepository { } // 设置N天未开门 - Future updateNdaysNotCloseDoorNoticeSetting( + Future updateNdaysNotCloseDoorNoticeSetting( {required int lockId, required int dayNotOpenDoorState, required int dayNotOpenDoorValue, required List dayNotOpenDoorNoticeWayList}) async { final res = await apiProvider.updateNdaysNotCloseDoorNoticeSetting(lockId, dayNotOpenDoorState, dayNotOpenDoorValue, dayNotOpenDoorNoticeWayList); - return MsgNotificationEntity.fromJson(res.body); + return OpenDoorNotifyEntity.fromJson(res.body); } // 设置门未关好