2023-09-21 14:12:22 +08:00
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
2024-02-29 17:31:30 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
2023-09-15 16:04:11 +08:00
|
|
|
|
import 'package:get/get.dart';
|
2024-05-20 11:04:15 +08:00
|
|
|
|
import 'package:star_lock/login/login/entity/LoginEntity.dart';
|
|
|
|
|
|
import 'package:star_lock/main/lockDetail/passwordKey/passwordKey_perpetual/passwordKeyEntity.dart';
|
2023-09-15 16:04:11 +08:00
|
|
|
|
import 'package:star_lock/tools/baseGetXController.dart';
|
|
|
|
|
|
import '../../../../../network/api_repository.dart';
|
|
|
|
|
|
import '../../../../../tools/eventBusEventManage.dart';
|
2024-01-23 17:29:18 +08:00
|
|
|
|
import 'checkingInAddStaffSelectKey_entity.dart';
|
2023-09-15 16:04:11 +08:00
|
|
|
|
import 'checkingInAddStaff_state.dart';
|
|
|
|
|
|
|
2024-05-15 15:07:19 +08:00
|
|
|
|
typedef KeyClickCallback = void Function(
|
|
|
|
|
|
List<CheckingInAddStaffKeyEntity> selectKeyList);
|
|
|
|
|
|
|
|
|
|
|
|
class CheckingInAddStaffLogic extends BaseGetXController {
|
2023-09-15 16:04:11 +08:00
|
|
|
|
CheckingInAddStaffState state = CheckingInAddStaffState();
|
|
|
|
|
|
|
2023-09-21 14:12:22 +08:00
|
|
|
|
// 下级界面修改成功后传递数据
|
|
|
|
|
|
StreamSubscription? _getNumberEvent;
|
2024-05-15 15:07:19 +08:00
|
|
|
|
|
2023-09-21 14:12:22 +08:00
|
|
|
|
void _initLoadDataAction() {
|
|
|
|
|
|
// 蓝牙协议通知传输跟蓝牙之外的数据传输类不一样 eventBus
|
2024-05-15 15:07:19 +08:00
|
|
|
|
_getNumberEvent = eventBus
|
|
|
|
|
|
.on<ChickInAddStaffCardAndFingerprintBlockNumberEvent>()
|
2024-05-20 11:04:15 +08:00
|
|
|
|
.listen((ChickInAddStaffCardAndFingerprintBlockNumberEvent event) {
|
2024-05-15 15:07:19 +08:00
|
|
|
|
state.attendanceWayNumber.value = event.number;
|
|
|
|
|
|
isCanClickAction();
|
|
|
|
|
|
});
|
2023-09-21 14:12:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-15 16:04:11 +08:00
|
|
|
|
// 添加员工
|
2024-05-20 11:04:15 +08:00
|
|
|
|
Future<void> addStaffLoadData() async {
|
|
|
|
|
|
String usernameType = '1';
|
|
|
|
|
|
if (state.appUnHaveAccount.value && state.staffAccount.contains('@')) {
|
|
|
|
|
|
usernameType = '2';
|
2023-09-15 16:04:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-03-28 13:46:35 +08:00
|
|
|
|
// 当是app且没有钥匙时,直接把账号赋值给attendanceWayNumber
|
2024-05-15 15:07:19 +08:00
|
|
|
|
if (state.appUnHaveAccount.value &&
|
2024-05-20 11:04:15 +08:00
|
|
|
|
state.selectPrintingMethodType.value == '1') {
|
2024-03-28 13:46:35 +08:00
|
|
|
|
state.attendanceWayNumber.value = state.staffAccountController.text;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-20 11:04:15 +08:00
|
|
|
|
final LoginEntity entity = await ApiRepository.to.addStaffData(
|
2024-01-23 17:48:06 +08:00
|
|
|
|
attendanceType: state.selectPrintingMethodType.value,
|
2024-02-29 17:31:30 +08:00
|
|
|
|
attendanceWay: state.attendanceWayNumber.value,
|
2023-09-15 16:04:11 +08:00
|
|
|
|
companyId: state.companyId.value,
|
2024-05-20 11:04:15 +08:00
|
|
|
|
have: state.appUnHaveAccount.value ? '2' : '1',
|
2023-09-15 16:04:11 +08:00
|
|
|
|
staffName: state.staffNameController.text,
|
|
|
|
|
|
countryCode: state.countryCode.value,
|
2024-05-15 15:07:19 +08:00
|
|
|
|
usernameType: usernameType,
|
2023-09-15 16:04:11 +08:00
|
|
|
|
);
|
2024-05-15 15:07:19 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2024-04-02 17:30:44 +08:00
|
|
|
|
eventBus.fire(RefreshCheckInSetDataEvent());
|
|
|
|
|
|
eventBus.fire(RefreshCheckInListEvent());
|
2024-05-20 11:04:15 +08:00
|
|
|
|
Get.back(result: 'addScuess');
|
2024-05-15 15:07:19 +08:00
|
|
|
|
} else if (entity.errorCode! == 425) {
|
2024-01-16 16:52:05 +08:00
|
|
|
|
showToast(entity.errorMsg!);
|
2023-09-15 16:04:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-05-15 15:07:19 +08:00
|
|
|
|
// 考勤设置添加员工-选择钥匙 1为APP,2为密码,3为卡,4为指纹,返回数据中,
|
|
|
|
|
|
// attendanceWay分别为用户名、密码、卡号、指纹号
|
2024-05-20 11:04:15 +08:00
|
|
|
|
Future<void> addStaffSelectKey(KeyClickCallback kyClickCallback) async {
|
|
|
|
|
|
final CheckingInAddStaffSelectKeyEntity entity =
|
|
|
|
|
|
await ApiRepository.to.addStaffSelectKeyData(
|
2023-09-15 16:04:11 +08:00
|
|
|
|
companyId: state.companyId.value,
|
2024-05-15 15:07:19 +08:00
|
|
|
|
type: state.selectPrintingMethodType.value,
|
2023-09-15 16:04:11 +08:00
|
|
|
|
);
|
2024-05-15 15:07:19 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2023-09-15 16:04:11 +08:00
|
|
|
|
state.keyEntity.value = entity.data!;
|
2024-05-21 17:56:50 +08:00
|
|
|
|
kyClickCallback(state.keyEntity);
|
2023-09-15 16:04:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 编辑员工
|
2024-05-20 11:04:15 +08:00
|
|
|
|
Future<void> editStaffLoadData() async {
|
|
|
|
|
|
String usernameType = '1';
|
|
|
|
|
|
if (state.appUnHaveAccount.value && state.staffAccount.contains('@')) {
|
|
|
|
|
|
usernameType = '2';
|
2023-09-15 16:04:11 +08:00
|
|
|
|
}
|
2024-05-21 17:56:50 +08:00
|
|
|
|
// 当是app且没有钥匙时,直接把账号赋值给attendanceWayNumber
|
|
|
|
|
|
if (state.appUnHaveAccount.value &&
|
|
|
|
|
|
state.selectPrintingMethodType.value == '1') {
|
|
|
|
|
|
state.attendanceWayNumber.value = state.staffAccountController.text;
|
|
|
|
|
|
}
|
2023-09-15 16:04:11 +08:00
|
|
|
|
|
2024-05-20 11:04:15 +08:00
|
|
|
|
final LoginEntity entity = await ApiRepository.to.editStaffData(
|
2024-01-23 17:48:06 +08:00
|
|
|
|
attendanceType: state.selectPrintingMethodType.value,
|
2024-02-29 17:31:30 +08:00
|
|
|
|
attendanceWay: state.attendanceWayNumber.value,
|
2023-09-15 16:04:11 +08:00
|
|
|
|
staffId: state.staffListItemData.value.staffId.toString(),
|
2024-05-20 11:04:15 +08:00
|
|
|
|
have: state.appUnHaveAccount.value ? '2' : '1',
|
2023-09-15 16:04:11 +08:00
|
|
|
|
staffName: state.staffNameController.text,
|
|
|
|
|
|
countryCode: state.countryCode.value,
|
2024-01-02 15:32:56 +08:00
|
|
|
|
usernameType: usernameType,
|
2023-09-15 16:04:11 +08:00
|
|
|
|
);
|
2024-01-02 15:32:56 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
2023-09-15 16:04:11 +08:00
|
|
|
|
eventBus.fire(RefreshCheckInStaffListDataEvent());
|
|
|
|
|
|
Get.close(2);
|
2024-01-02 15:32:56 +08:00
|
|
|
|
} else if (entity.errorCode! == 425) {
|
2024-01-16 16:52:05 +08:00
|
|
|
|
showToast(entity.errorMsg!);
|
2023-09-15 16:04:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-21 14:12:22 +08:00
|
|
|
|
//获取密码请求
|
2024-05-20 11:04:15 +08:00
|
|
|
|
Future<void> getKeyboardPwdRequest() async {
|
2024-01-02 15:32:56 +08:00
|
|
|
|
if (state.staffNameController.text.isEmpty) {
|
2024-05-20 11:04:15 +08:00
|
|
|
|
showToast('请输入姓名');
|
2023-09-21 14:12:22 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-05-20 11:04:15 +08:00
|
|
|
|
final PasswordKeyEntity entity = await ApiRepository.to.getPasswordKey(
|
|
|
|
|
|
endDate: '0',
|
2024-01-02 15:32:56 +08:00
|
|
|
|
keyboardPwdName: state.staffNameController.text,
|
|
|
|
|
|
keyboardPwdType: 2.toString(),
|
|
|
|
|
|
lockId: state.getKeyInfosData.value.lockId.toString(),
|
|
|
|
|
|
startDate: '0',
|
|
|
|
|
|
startHours: 0,
|
|
|
|
|
|
endHours: 0,
|
|
|
|
|
|
isCoerced: 1);
|
|
|
|
|
|
|
2023-09-21 14:12:22 +08:00
|
|
|
|
if (entity.errorCode!.codeIsSuccessful) {
|
|
|
|
|
|
if (entity.data != null) {
|
2024-02-29 17:31:30 +08:00
|
|
|
|
state.attendanceWayNumber.value = entity.data!.keyboardPwd!;
|
|
|
|
|
|
isCanClickAction();
|
2023-09-21 14:12:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2024-01-16 16:52:05 +08:00
|
|
|
|
showToast('${entity.errorMsg}');
|
2023-09-21 14:12:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-02-29 17:31:30 +08:00
|
|
|
|
void changeInput(TextEditingController controller) {
|
|
|
|
|
|
if (controller == state.staffNameController) {
|
|
|
|
|
|
state.staffName.value = controller.text;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (controller == state.staffAccountController) {
|
|
|
|
|
|
state.staffAccount.value = controller.text;
|
|
|
|
|
|
}
|
|
|
|
|
|
isCanClickAction();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 是否能点击
|
|
|
|
|
|
void isCanClickAction() {
|
2024-05-20 11:04:15 +08:00
|
|
|
|
if (state.selectPrintingMethodType.value == '1' &&
|
2024-05-15 15:07:19 +08:00
|
|
|
|
state.appUnHaveAccount.value) {
|
2024-02-29 17:31:30 +08:00
|
|
|
|
// 没有账号的时候直接判断姓名和账号是否为空
|
2024-05-15 15:07:19 +08:00
|
|
|
|
state.isCanClick.value =
|
|
|
|
|
|
state.staffNameIsNotEmpty && state.staffAccountIsNotEmpty;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
state.isCanClick.value =
|
|
|
|
|
|
state.staffNameIsNotEmpty && state.attendanceWayNumberIsNotEmpty;
|
2024-02-29 17:31:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-15 16:04:11 +08:00
|
|
|
|
@override
|
|
|
|
|
|
void onReady() {
|
|
|
|
|
|
super.onReady();
|
2023-09-21 14:12:22 +08:00
|
|
|
|
_initLoadDataAction();
|
2024-04-06 09:19:35 +08:00
|
|
|
|
changeInput(state.staffNameController);
|
2023-09-15 16:04:11 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
void onClose() {
|
2023-09-21 14:12:22 +08:00
|
|
|
|
super.onClose();
|
|
|
|
|
|
_getNumberEvent!.cancel();
|
2023-09-15 16:04:11 +08:00
|
|
|
|
}
|
2024-01-23 17:29:18 +08:00
|
|
|
|
}
|