96 lines
3.3 KiB
Dart
Executable File
96 lines
3.3 KiB
Dart
Executable File
|
|
import 'package:get/get.dart';
|
|
import 'package:star_lock/common/XSConstantMacro/XSConstantMacro.dart';
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
import 'package:star_lock/tools/eventBusEventManage.dart';
|
|
import '../../../../main/lockDetail/electronicKey/electronicKeyList/entity/ElectronicKeyListEntity.dart';
|
|
import '../../../../network/api_repository.dart';
|
|
import '../lockUserManageList/keyListByUserEntity.dart';
|
|
import 'ownedKeyList_state.dart';
|
|
|
|
class OwnedKeyListLogic extends BaseGetXController {
|
|
OwnedKeyListState state = OwnedKeyListState();
|
|
|
|
//请求用户拥有的锁
|
|
Future<KeyListByUserEntity> mockNetworkDataRequest() async {
|
|
final KeyListByUserEntity entity = await ApiRepository.to.keyListByUser(pageNo.toString(), pageSize, state.getUidStr.toString());
|
|
// if (entity.errorCode!.codeIsSuccessful) {
|
|
// }
|
|
// if (entity.data != null) {
|
|
// return entity.data!.keyList!;
|
|
// } else {
|
|
// List<KeyListItem> dataList = [];
|
|
// return dataList;
|
|
// }
|
|
|
|
if(entity.errorCode!.codeIsSuccessful){
|
|
if (pageNo == 1) {
|
|
state.dataList.value = entity.data!.keyList!;
|
|
pageNo++;
|
|
} else {
|
|
if (entity.data!.keyList!.isNotEmpty) {
|
|
state.dataList.value.addAll(entity.data!.keyList!);
|
|
pageNo++;
|
|
}
|
|
}
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
//删除电子钥匙名称请求 setAdministrator
|
|
Future<void> deleteKeyRequest(int keyId) async {
|
|
final ElectronicKeyListEntity entity = await ApiRepository.to.deleteElectronicKey(
|
|
keyId:keyId.toString(),
|
|
includeUnderlings: 0
|
|
);
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
showToast('删除成功'.tr, something: () {
|
|
pageNo = 1;
|
|
mockNetworkDataRequest();
|
|
eventBus.fire(LockUserManageListRefreshUI());
|
|
});
|
|
}
|
|
}
|
|
|
|
//设置授权管理员
|
|
Future<void> setAdministrator() async {
|
|
// ElectronicKeyListEntity entity = await ApiRepository.to.setAdministrator(
|
|
// keyId:state.itemData.value.keyId.toString(),
|
|
// );
|
|
// if (entity.errorCode!.codeIsSuccessful) {
|
|
// showToast("设置成功", something: () {
|
|
// // eventBus.fire(ElectronicKeyListRefreshUI());
|
|
// // eventBus.fire(AuthorizedAdminPageRefreshUI());
|
|
// Get.back();
|
|
// });
|
|
// }
|
|
}
|
|
|
|
//使用期限
|
|
String getUseDateStr(KeyListItem indexEntity) {
|
|
String useDateStr = '';
|
|
if (indexEntity.keyType == XSConstantMacro.keyTypeTime) {
|
|
//限期
|
|
if (indexEntity.startDate != null && indexEntity.endDate != null) {
|
|
final DateTime startDateStr =
|
|
DateTime.fromMillisecondsSinceEpoch(indexEntity.startDate!);
|
|
final DateTime endDateStr =
|
|
DateTime.fromMillisecondsSinceEpoch(indexEntity.endDate!);
|
|
useDateStr =
|
|
'${startDateStr.toLocal().toString().substring(0, 16)}-${endDateStr.toLocal().toString().substring(0, 16)}';
|
|
} else {
|
|
useDateStr = '限时'.tr;
|
|
}
|
|
} else if (indexEntity.keyType == XSConstantMacro.keyTypeLong) {
|
|
//永久
|
|
useDateStr = '永久'.tr;
|
|
} else if (indexEntity.keyType == XSConstantMacro.keyTypeOnce) {
|
|
//单次
|
|
useDateStr = '单次'.tr;
|
|
} else if (indexEntity.keyType == XSConstantMacro.keyTypeLoop) {
|
|
//循环
|
|
useDateStr = '循环'.tr;
|
|
}
|
|
return useDateStr;
|
|
}
|
|
} |