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