105 lines
3.7 KiB
Dart
Executable File

import 'dart:async';
import 'package:get/get.dart';
import 'package:star_lock/login/login/entity/LoginEntity.dart';
import 'package:star_lock/main/lockDetail/checkingIn/checkingInSet/checkingInSet_entity.dart';
import 'package:star_lock/main/lockDetail/lockSet/lockSet/checkingInInfoData_entity.dart';
import '../../../../network/api_repository.dart';
import '../../../../tools/baseGetXController.dart';
import '../../../../tools/dateTool.dart';
import '../../../../tools/eventBusEventManage.dart';
import 'checkingInSet_state.dart';
class CheckingInSetLogic extends BaseGetXController {
CheckingInSetState state = CheckingInSetState();
// 开启考勤获取是否有公司
Future<void> openCheckingInData() async {
final CheckingInInfoDataEntity entity = await ApiRepository.to.openCheckingInData(
lockId: state.getKeyInfosData.value.lockId.toString(),
);
if (entity.errorCode!.codeIsSuccessful) {
state.companyId.value = entity.data!.companyId.toString();
getCheckInSetInfoData();
}
}
// 获取获取考勤设置信息
Future<void> getCheckInSetInfoData() async {
final CheckingInSetEntity entity = await ApiRepository.to.getCheckInSetInfoData(
companyId: state.companyId.value,
);
if (entity.errorCode!.codeIsSuccessful) {
state.checkingInSetInfo.value = entity.data!;
state.beginTime.value = DateTool().dateToHNString(
state.checkingInSetInfo.value.workStartTime.toString());
state.endTime.value = DateTool()
.dateToHNString(state.checkingInSetInfo.value.workEndTime.toString());
state.beginTimeTimestamp.value =
state.checkingInSetInfo.value.workStartTime.toString();
state.endTimeTimestamp.value =
state.checkingInSetInfo.value.workEndTime.toString();
state.weekDays.value = state.checkingInSetInfo.value.workDay!;
state.weekDaysStr.value = state.weekDays.join(',');
state.isCustom.value = state.checkingInSetInfo.value.attendanceType! == 0;
state.staffNumber.value =
state.checkingInSetInfo.value.staffNum!.toString();
state.companyName.value = state.checkingInSetInfo.value.companyName!;
state.changeNameController.text = state.companyName.value;
}
}
// 编辑考勤设置信息
Future<void> editCheckInSetInfoData() async {
final LoginEntity entity = await ApiRepository.to.editCheckInSetInfoData(
attendanceType: state.checkingInSetInfo.value.attendanceType.toString(),
companyId: state.checkingInSetInfo.value.companyId.toString(),
type: '1',
companyName: state.changeNameController.text,
workEndTime: state.checkingInSetInfo.value.workEndTime.toString(),
workStartTime: state.checkingInSetInfo.value.workStartTime.toString(),
workDay: state.checkingInSetInfo.value.workDay!,
);
if (entity.errorCode!.codeIsSuccessful) {
state.companyName.value = state.changeNameController.text;
showToast('修改成功'.tr);
}
}
// 删除公司
Future<void> deletCompanyData() async {
final CheckingInInfoDataEntity entity = await ApiRepository.to.deletCompanyData(
companyId: state.checkingInSetInfo.value.companyId!,
);
if (entity.errorCode!.codeIsSuccessful) {
eventBus.fire(LockSetChangeSetRefreshLockDetailWithType(0, '0'));
Get.close(2);
}
}
late StreamSubscription _teamEvent;
void _initLoadDataAction() {
_teamEvent = eventBus.on<RefreshCheckInSetDataEvent>().listen((RefreshCheckInSetDataEvent event) {
getCheckInSetInfoData();
});
}
@override
void onReady() {
super.onReady();
_initLoadDataAction();
openCheckingInData();
}
@override
void onClose() {
_teamEvent.cancel();
}
}