2024-08-27 11:08:44 +08:00

58 lines
2.2 KiB
Dart
Executable File

import 'package:get/get.dart';
import 'package:star_lock/tools/baseGetXController.dart';
import '../../../../../network/api_repository.dart';
import '../../../../../tools/dateTool.dart';
import '../../../../../tools/eventBusEventManage.dart';
import '../../../lockOperatingRecord/keyOperationRecord_entity.dart';
import 'electronicKeyPeriodValidity_state.dart';
class ElectronicKeyPeriodValidityLogic extends BaseGetXController {
final ElectronicKeyPeriodValidityState state = ElectronicKeyPeriodValidityState();
//编辑电子钥匙有效期请求
Future<void> updateKeyDateRequest() async {
final int starDateTimestamp = DateTool().dateToTimestamp(state.starDate.value, 1);
final int endDateTimestamp = DateTool().dateToTimestamp(state.endDate.value, 1);
final int starTimeTimestamp = DateTool().dateToTimestamp(state.starTime.value, 0);
final int endTimeTimestamp = DateTool().dateToTimestamp(state.endTime.value, 0);
if (starDateTimestamp >= endDateTimestamp) {
showToast('失效日期需晚于生效日期'.tr);
return;
}
if (starTimeTimestamp >= endTimeTimestamp) {
showToast('失效时间需晚于生效时间'.tr);
return;
}
final KeyOperationRecordEntity entity = await ApiRepository.to.updateKeyDate(
keyId:state.keyId.value.toString(),
lockId:state.lockId.value.toString(),
endDate:endDateTimestamp.toString(),
startDate:starDateTimestamp.toString(),
weekDays:state.weekDay.value,
keyType:state.keyType.value!,
startTime: starTimeTimestamp,
endTime: endTimeTimestamp,
isOnlyManageSelf: state.isOnlyManageSelf.value!,
remoteEnable: state.remoteEnable.value!);
if (entity.errorCode!.codeIsSuccessful) {
showToast('修改成功'.tr, something: () {
eventBus.fire(ElectronicKeyListRefreshUI());
eventBus.fire(AuthorizedAdminPageRefreshUI());
Get.back(result: <String, Object>{
'starDate':starDateTimestamp.toString(),
'endDate':endDateTimestamp.toString(),
'starTime':starTimeTimestamp.toString(),
'endTime':endTimeTimestamp.toString(),
'validityValue':state.weekDay.value,
});
});
}
}
}