115 lines
3.6 KiB
Dart
Executable File
115 lines
3.6 KiB
Dart
Executable File
import 'dart:async';
|
|
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/electronicKeyList_state.dart';
|
|
import 'package:star_lock/main/lockDetail/electronicKey/electronicKeyList/entity/ElectronicKeyListEntity.dart';
|
|
import 'package:star_lock/network/api_repository.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
import 'package:star_lock/tools/commonDataManage.dart';
|
|
import 'package:star_lock/tools/showTipView.dart';
|
|
|
|
import '../../../../tools/eventBusEventManage.dart';
|
|
|
|
class ElectronicKeyListLogic extends BaseGetXController {
|
|
final ElectronicKeyListState state = ElectronicKeyListState();
|
|
|
|
//请求电子钥匙列表
|
|
Future<ElectronicKeyListEntity> mockNetworkDataRequest() async {
|
|
ElectronicKeyListEntity entity = await ApiRepository.to.electronicKeyList(
|
|
endDate: '0',
|
|
keyId: CommonDataManage().currentKeyInfo.keyId.toString(),
|
|
keyStatus: '',
|
|
keyRight: '0',
|
|
lockId: CommonDataManage().currentKeyInfo.lockId.toString(),
|
|
pageNo: pageNo.toString(),
|
|
pageSize: pageSize.toString(),
|
|
startDate: '0',
|
|
searchStr: state.searchController.text);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
if (pageNo == 1) {
|
|
state.itemDataList.value = entity.data!.itemList!;
|
|
pageNo++;
|
|
} else {
|
|
if (entity.data!.itemList!.isNotEmpty) {
|
|
state.itemDataList.value.addAll(entity.data!.itemList!);
|
|
pageNo++;
|
|
}
|
|
}
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
//电子钥匙重置请求
|
|
Future<void> resetElectronicKeyListRequest() async {
|
|
ElectronicKeyListEntity entity = await ApiRepository.to
|
|
.resetElectronicKey(CommonDataManage().currentKeyInfo.lockId.toString(), '0');
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast("重置成功".tr, something: (){
|
|
pageNo = 1;
|
|
mockNetworkDataRequest();
|
|
});
|
|
}
|
|
}
|
|
|
|
//删除电子钥匙名称请求
|
|
Future<void> deleteKeyRequest(String keyId, int includeUnderlings) async {
|
|
ElectronicKeyListEntity entity =
|
|
await ApiRepository.to.deleteElectronicKey(
|
|
keyId:keyId,
|
|
includeUnderlings:includeUnderlings
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast("删除成功".tr,something: (){
|
|
pageNo = 1;
|
|
mockNetworkDataRequest();
|
|
});
|
|
}
|
|
}
|
|
|
|
deletKeyLogic(ElectronicKeyListItem electronicKeyListItem){
|
|
if(electronicKeyListItem.keyRight == 1){
|
|
// 授权管理员
|
|
ShowTipView().showDeleteAdministratorIsHaveAllDataDialog('同时删除其发送的所有钥匙,钥匙删除后不能恢复'.tr, (isAllData) {
|
|
deleteKeyRequest(electronicKeyListItem.keyId.toString(), isAllData ? 1 : 0);
|
|
});
|
|
}else{
|
|
// 普通用户
|
|
ShowTipView().showIosTipWithContentDialog("删除钥匙会在用户APP连网后生效".tr,(){
|
|
deleteKeyRequest(electronicKeyListItem.keyId.toString(), 0);
|
|
});
|
|
}
|
|
}
|
|
|
|
/// 刷新电子钥匙列表
|
|
StreamSubscription? _getElectronicKeyListRefreshUIEvent;
|
|
void _getElectronicKeyListRefreshUIAction() {
|
|
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
|
_getElectronicKeyListRefreshUIEvent = eventBus.on<ElectronicKeyListRefreshUI>().listen((event) {
|
|
pageNo = 1;
|
|
mockNetworkDataRequest();
|
|
});
|
|
}
|
|
|
|
@override
|
|
void onReady() {
|
|
// TODO: implement onReady
|
|
super.onReady();
|
|
|
|
_getElectronicKeyListRefreshUIAction();
|
|
}
|
|
|
|
@override
|
|
void onInit() {
|
|
// TODO: implement onInit
|
|
super.onInit();
|
|
}
|
|
|
|
@override
|
|
void onClose() {
|
|
// TODO: implement onClose
|
|
super.onClose();
|
|
|
|
_getElectronicKeyListRefreshUIEvent?.cancel();
|
|
}
|
|
}
|