import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; import 'package:star_lock/tools/baseGetXController.dart'; import '../../../../main/lockMian/entity/lockListInfo_entity.dart'; import '../../../../network/api_repository.dart'; import 'recipientInformation_entity.dart'; import 'recipientInformation_state.dart'; class RecipientInformationLogic extends BaseGetXController{ RecipientInformationState state = RecipientInformationState(); // 转移智能锁确认 Future transferLockConfirmInfoData(void Function(RecipientInformationData recipientInformationData) action) async{ final RecipientInformationEntity entity = await ApiRepository.to.transferLockConfirmInfoData( receiverUsername: state.numberController.text, type: state.type.value.toString(), countryCode: state.countryCode.value ); if(entity.errorCode!.codeIsSuccessful){ action(entity.data!); }else { if(entity.errorCode! == 425){ showToast(entity.errorMsg!); } } } // 转移智能锁 Future transferLockInfoData() async{ final RecipientInformationEntity entity = await ApiRepository.to.transferLockInfoData( receiverUsername: state.numberController.text, lockIdList: state.idList.value, countryCode: state.countryCode.value ); if(entity.errorCode!.codeIsSuccessful){ showToast('转移成功'.tr, something: (){ Get.back(result: 'scuess'); }); } } // 移除坏锁 Future removeBrokenLockData() async{ final RecipientInformationEntity entity = await ApiRepository.to.removeBrokenLockData( lockIdList: state.idList.value, ); if(entity.errorCode!.codeIsSuccessful){ showToast('移除成功'.tr, something: (){ Get.back(result: 'scuess'); }); } } // 查询账户密码 Future checkLoginPassword() async { final LockListInfoEntity entity = await ApiRepository.to.checkLoginPassword( password: state.passwordTF.text, ); if (entity.errorCode!.codeIsSuccessful) { Get.back(); if (state.isFromType.value == 1) { // 转移智能锁 transferGatewayInfoData transferLockInfoData(); } else { // 转移网关 transferGatewayInfoData(); } } } // 转移网关确认 Future transferGateWayConfirmInfoData(void Function(RecipientInformationData recipientInformationData) action) async{ final RecipientInformationEntity entity = await ApiRepository.to.transferGatewayConfirmInfoData( receiverUsername: state.numberController.text, type: state.type.value.toString(), countryCode: state.countryCode.value ); if(entity.errorCode!.codeIsSuccessful){ action(entity.data!); } } // 转移网关 Future transferGatewayInfoData() async{ final RecipientInformationEntity entity = await ApiRepository.to.transferGatewayInfoData( receiverUsername: state.numberController.text, plugIdList: state.idList.value, countryCode: state.countryCode.value ); if(entity.errorCode!.codeIsSuccessful){ Get.back(result: 'scuess'); } } // 移除坏锁提示 void showDeletAlertDialog() { showCupertinoDialog( context: Get.context!, builder: (BuildContext context) { return CupertinoAlertDialog( title: Text('提示'.tr), content: Text('确定要移除所选中的坏锁吗?'.tr), actions: [ CupertinoDialogAction( child: Text('取消'.tr), onPressed: Get.back, ), CupertinoDialogAction( child: Text('确定'.tr), onPressed: () { Get.back(); removeBrokenLockData(); }, ), ], ); }, ); } }