diff --git a/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_logic.dart b/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_logic.dart index bab8a869..71217497 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_logic.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_logic.dart @@ -1,5 +1,6 @@ import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/messageWarn/addFamily/addFamily_state.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'; @@ -7,6 +8,7 @@ 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, @@ -27,6 +29,18 @@ class AddFamilyLogic extends BaseGetXController { } } +//删除开门通知 + void deleteLockNoticeSetting() async { + var entity = await ApiRepository.to.deleteLockNoticeSettingAccount( + lockNoticeSettingAccountId: state.familyData.value.id!, + ); + if (entity.errorCode!.codeIsSuccessful) { + showToast('删除成功'.tr); + Get.back(result: true); + } + } + +//获取到家人信息的请求数组 List getEmailAndSMSAccountList(bool isEmail) { List list = []; List accountList = []; @@ -78,6 +92,7 @@ class AddFamilyLogic extends BaseGetXController { return phoneListStr; } +//检查按钮是否可用 bool checkBtnDisable() { if ((state.emailListStr.value.isEmpty || state.phontListStr.value.isEmpty) || @@ -88,4 +103,65 @@ class AddFamilyLogic extends BaseGetXController { return true; } } + + //当前钥匙类型 1:电子钥匙 2:密码钥匙 3:指纹钥匙 4:卡钥匙 5:人脸钥匙 + String getKeyTypeStr() { + int keyType = state.familyData.value.settingValue!.openDoorType!; + switch (keyType) { + case 1: + return '电子钥匙'; + case 2: + return '密码'; + case 3: + return '指纹'; + case 4: + return '卡'; + case 5: + return '人脸'; + default: + return ''; + } + } + +//根据列表返回值得到邮箱、手机列表 + Map> getAccountsMap() { + List mailAccounts = []; + List smsAccounts = []; + + if (state.familyData.value.settingValue != null) { + for (NoticeWay item + in state.familyData.value.settingValue!.noticeWayList!) { + 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/addFamily/addFamily_page.dart b/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_page.dart index e10c50d6..bc34102e 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_page.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_page.dart @@ -25,7 +25,7 @@ class _AddFamilyPageState extends State { return Scaffold( backgroundColor: AppColors.mainBackgroundColor, appBar: TitleAppBar( - barTitle: '添加家人'.tr, + barTitle: state.isDetail.value ? '家人详情'.tr : '添加家人'.tr, haveBack: true, backgroundColor: AppColors.mainColor), body: Container( @@ -34,8 +34,9 @@ class _AddFamilyPageState extends State { children: [ Obx(() => CommonItem( leftTitel: '开门方式'.tr, - rightTitle: - state.lockUserKeys.value.currentKeyTypeStr ?? '请选择'.tr, + rightTitle: state.isDetail.value + ? logic.getKeyTypeStr() + : state.lockUserKeys.value.currentKeyTypeStr ?? '请选择'.tr, isHaveLine: true, isHaveDirection: true, action: () { @@ -50,7 +51,9 @@ class _AddFamilyPageState extends State { })), Obx(() => CommonItem( leftTitel: '家人'.tr, - rightTitle: state.lockUserKeys.value.currentKeyName ?? '', + rightTitle: state.isDetail.value + ? state.familyData.value.settingValue?.remark + : state.lockUserKeys.value.currentKeyName, isHaveLine: true, isHaveRightWidget: state.lockUserKeys.value.currentKeyName == null @@ -99,10 +102,17 @@ class _AddFamilyPageState extends State { height: 40.h, )), Obx(() => SubmitBtn( - btnName: '保存'.tr, - isDisabled: logic.checkBtnDisable(), + btnName: state.isDetail.value == true ? '删除'.tr : '保存'.tr, + isDisabled: state.isDetail.value == true + ? true + : logic.checkBtnDisable(), + isDelete: state.isDetail.value, onClick: () { - logic.addLockNoticeSetting(); + if (state.isDetail.value) { + logic.deleteLockNoticeSetting(); + } else { + logic.addLockNoticeSetting(); + } }, )), SizedBox( @@ -145,6 +155,9 @@ class _AddFamilyPageState extends State { // 接受者邮箱输入框 Widget getFamilyWidget(String tfStr) { TextEditingController emailController = TextEditingController(); + if (state.isDetail.value) { + emailController.text = state.familyData.value.settingValue?.remark ?? ''; + } return SizedBox( height: 50.h, width: 360.w, @@ -157,6 +170,7 @@ class _AddFamilyPageState extends State { maxLines: 1, autofocus: false, textAlign: TextAlign.end, + style: TextStyle(fontSize: 22.sp), decoration: InputDecoration( //输入里面输入文字内边距设置 contentPadding: const EdgeInsets.only(top: -12.0, bottom: 0.0), diff --git a/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_state.dart b/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_state.dart index 355b2e0c..79d4ea97 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_state.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/addFamily/addFamily_state.dart @@ -1,5 +1,6 @@ import 'package:get/get.dart'; import 'package:star_lock/main/lockDetail/messageWarn/lockUser/lockUser_entity.dart'; +import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart'; class AddFamilyState { var getLockId = 0.obs; @@ -11,11 +12,21 @@ class AddFamilyState { var openDoorId = 0.obs; var openDoorType = 0.obs; + var familyData = DataList().obs; + var isDetail = false.obs; AddFamilyState() { Map map = Get.arguments; - if (map['getLockId'] != null) { - getLockId.value = map['getLockId']; + if (map['lockId'] != null) { + getLockId.value = map['lockId']; + } + + if (map['isDetail'] != null) { + isDetail.value = map['isDetail']; + } + + if (map['itemData'] != null) { + familyData.value = map['itemData']; } } } diff --git a/star_lock/lib/main/lockDetail/messageWarn/familyDetails/familyDetails_state.dart b/star_lock/lib/main/lockDetail/messageWarn/familyDetails/familyDetails_state.dart index c3acf13a..f397f63e 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/familyDetails/familyDetails_state.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/familyDetails/familyDetails_state.dart @@ -1,15 +1,21 @@ import 'package:flutter/material.dart'; import 'package:get/get.dart'; +import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_entity.dart'; class FamilyDetailsState { TextEditingController changeNameController = TextEditingController(); //修改名称 var familyName = '我'.obs; var getLockId = 0.obs; + var familyData = DataList().obs; FamilyDetailsState() { Map map = Get.arguments; if (map['lockId'] != null) { getLockId.value = map['lockId']; } + + if (map['itemData'] != null) { + familyData.value = map['itemData']; + } } } 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 0db28a37..923d3669 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 @@ -103,19 +103,19 @@ class SettingValue { int? openDoorId; int? openDoorType; String? remark; - List? noticeWay; + List? noticeWayList; SettingValue( - {this.openDoorId, this.openDoorType, this.remark, this.noticeWay}); + {this.openDoorId, this.openDoorType, this.remark, this.noticeWayList}); SettingValue.fromJson(Map json) { openDoorId = json['openDoorId']; openDoorType = json['openDoorType']; remark = json['remark']; if (json['noticeWay'] != null) { - noticeWay = []; + noticeWayList = []; json['noticeWay'].forEach((v) { - noticeWay!.add(NoticeWay.fromJson(v)); + noticeWayList!.add(NoticeWay.fromJson(v)); }); } } @@ -125,8 +125,8 @@ class SettingValue { data['openDoorId'] = openDoorId; data['openDoorType'] = openDoorType; data['remark'] = remark; - if (noticeWay != null) { - data['noticeWay'] = noticeWay!.map((v) => v.toJson()).toList(); + if (noticeWayList != null) { + data['noticeWay'] = noticeWayList!.map((v) => v.toJson()).toList(); } return data; } diff --git a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_logic.dart b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_logic.dart index 8988a109..4e194d0b 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_logic.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_logic.dart @@ -16,4 +16,23 @@ class OpenDoorNotifyLogic extends BaseGetXController { state.openDoorNotifyList.value = entity.data!.list!; } } + + //当前钥匙类型 1:电子钥匙 2:密码钥匙 3:指纹钥匙 4:卡钥匙 5:人脸钥匙 + String getKeyTypeStr(DataList itemData) { + int keyType = itemData.settingValue!.openDoorType!; + switch (keyType) { + case 1: + return '电子钥匙'; + case 2: + return '密码'; + case 3: + return '指纹'; + case 4: + return '卡'; + case 5: + return '人脸'; + default: + return ''; + } + } } diff --git a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_page.dart b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_page.dart index b800ac59..a05f19b8 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_page.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_page.dart @@ -2,6 +2,8 @@ import 'package:flutter/material.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/openDoorNotify/openDoorNotify_entity.dart'; +import 'package:star_lock/tools/noData.dart'; import '../../../../../app_settings/app_colors.dart'; import '../../../../../tools/submitBtn.dart'; @@ -41,13 +43,17 @@ class _OpenDoorNotifyPageState extends State { SizedBox( height: 20.h, ), - Expanded(child: Obx(() => _buildMainUI())), + Expanded( + child: Obx(() => state.openDoorNotifyList.value.isNotEmpty + ? _buildMainUI() + : NoData())), AddBottomWhiteBtn( btnName: '添加家人'.tr, onClick: () { - Get.toNamed(Routers.addFamilyPage, - arguments: {'getLockId': state.getLockId.value}) - ?.then((value) { + Get.toNamed(Routers.addFamilyPage, arguments: { + 'lockId': state.getLockId.value, + 'isDetail': false + })?.then((value) { if (value != null) { logic.lockNoticeSettingAccountList(); } @@ -76,10 +82,7 @@ class _OpenDoorNotifyPageState extends State { shrinkWrap: true, itemCount: state.openDoorNotifyList.length, itemBuilder: (c, index) { - return _electronicKeyItem( - 'images/controls_user.png', '18682150237', '电子钥匙', () { - Get.toNamed(Routers.familyDetailsPage); - }); + return _electronicKeyItem(state.openDoorNotifyList.value[index]); }, separatorBuilder: (BuildContext context, int index) { return const Divider( @@ -90,10 +93,19 @@ class _OpenDoorNotifyPageState extends State { ); } - Widget _electronicKeyItem(String avatarURL, String familyAccount, - String openDoorWay, Function() action) { + Widget _electronicKeyItem(DataList itemData) { return GestureDetector( - onTap: action, + onTap: () { + Get.toNamed(Routers.addFamilyPage, arguments: { + 'itemData': itemData, + 'lockId': state.getLockId.value, + 'isDetail': true + })?.then((value) { + if (value != null) { + logic.lockNoticeSettingAccountList(); + } + }); + }, child: Container( color: Colors.white, height: 90.h, @@ -103,7 +115,7 @@ class _OpenDoorNotifyPageState extends State { width: 30.w, ), Image.asset( - avatarURL, + 'images/controls_user.png', width: 60.w, height: 60.w, ), @@ -117,7 +129,7 @@ class _OpenDoorNotifyPageState extends State { Row( children: [ Text( - familyAccount, + itemData.settingValue!.remark ?? '', style: TextStyle( fontSize: 24.sp, color: AppColors.blackColor), ), @@ -133,7 +145,7 @@ class _OpenDoorNotifyPageState extends State { mainAxisAlignment: MainAxisAlignment.start, children: [ Text( - openDoorWay, + logic.getKeyTypeStr(itemData), style: TextStyle( fontSize: 18.sp, color: AppColors.placeholderTextColor), diff --git a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_state.dart b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_state.dart index f20aec5c..42e880c1 100644 --- a/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_state.dart +++ b/star_lock/lib/main/lockDetail/messageWarn/msgNotification/openDoorNotify/openDoorNotify_state.dart @@ -1,19 +1,11 @@ import 'package:get/get.dart'; -import 'package:star_lock/main/lockDetail/messageWarn/msgNotification/msgNotification/msgNotification_entity.dart'; class OpenDoorNotifyState { - var msgNoticeInfo = MsgNoticeData().obs; - var pageNum = 1.obs; //请求页码 - final pageSize = 20.obs; //请求每页数据条数 - var itemDataList = [].obs; var getLockId = 0.obs; - var openDoorNotifyList = [].obs; + var openDoorNotifyList = [].obs; //开门通知列表 OpenDoorNotifyState() { Map map = Get.arguments; - if (map['msgNoticeInfo'] != null) { - msgNoticeInfo.value = map['msgNoticeInfo']; - } if (map['lockId'] != null) { getLockId.value = map['lockId']; } diff --git a/star_lock/lib/network/api.dart b/star_lock/lib/network/api.dart index 3f14e73a..10bdf951 100644 --- a/star_lock/lib/network/api.dart +++ b/star_lock/lib/network/api.dart @@ -204,6 +204,8 @@ abstract class Api { '/lockNoticeSettingAccount/add'; //添加开门通知 final String lockNoticeSettingListURL = '/lockNoticeSettingAccount/list'; //开门通知列表 + final String deleteLockNoticeSettingAccountURL = + '/lockNoticeSettingAccount/delete'; //删除开门通知 final String setWechatPushSwitchURL = '/user/setMpWechatPushSwitch'; //设置微信公众号推送 diff --git a/star_lock/lib/network/api_provider.dart b/star_lock/lib/network/api_provider.dart index 3f120386..9b065376 100644 --- a/star_lock/lib/network/api_provider.dart +++ b/star_lock/lib/network/api_provider.dart @@ -674,13 +674,12 @@ class ApiProvider extends BaseProvider { })); /// 更新网络信息 配网之后把网络信息提交到服务器保存 - Future updateNetworkInfo(int lockId, String network) => - post( - updateLockSettingUrl.toUrl, - jsonEncode({ - 'lockId': lockId, - 'network': network, - })); + Future updateNetworkInfo(int lockId, String network) => post( + updateLockSettingUrl.toUrl, + jsonEncode({ + 'lockId': lockId, + 'network': network, + })); // 锁声音 Future setLockSoundData( @@ -1889,6 +1888,14 @@ class ApiProvider extends BaseProvider { post(lockNoticeSettingListURL.toUrl, jsonEncode({'lockId': lockId, 'noticeType': noticeType})); + // 删除开门通知 + Future deleteLockNoticeSettingAccount( + int lockNoticeSettingAccountId) => + post( + deleteLockNoticeSettingAccountURL.toUrl, + jsonEncode( + {'lockNoticeSettingAccountId': lockNoticeSettingAccountId})); + // 设置微信公众号推送 Future setMpWechatPushSwitch(int mpWechatPushSwitch) => post( setWechatPushSwitchURL.toUrl, diff --git a/star_lock/lib/network/api_repository.dart b/star_lock/lib/network/api_repository.dart index 8974a1b1..301f9291 100644 --- a/star_lock/lib/network/api_repository.dart +++ b/star_lock/lib/network/api_repository.dart @@ -714,8 +714,6 @@ class ApiRepository { return LoginEntity.fromJson(res.body); } - - // 锁声音 Future setLockSound({ required int lockId, @@ -1909,6 +1907,14 @@ class ApiRepository { return OpenDoorNotifyEntity.fromJson(res.body); } + // 删除开门通知 + Future deleteLockNoticeSettingAccount( + {required int lockNoticeSettingAccountId}) async { + final res = await apiProvider + .deleteLockNoticeSettingAccount(lockNoticeSettingAccountId); + return OpenDoorNotifyEntity.fromJson(res.body); + } + // 设置微信公众号推送 Future setMpWechatPushSwitch( {required int mpWechatPushSwitch}) async {