452 lines
20 KiB
Dart
452 lines
20 KiB
Dart
import 'package:animated_tree_view/animated_tree_view.dart';
|
||
import 'package:flutter/cupertino.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/painting.dart';
|
||
import 'package:flutter/widgets.dart';
|
||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
import 'package:get/get.dart';
|
||
import 'package:starwork_flutter/api/model/team/response/depart_list_reponse.dart';
|
||
import 'package:starwork_flutter/base/app_logger.dart';
|
||
import 'package:starwork_flutter/common/constant/app_colors.dart';
|
||
import 'package:starwork_flutter/common/constant/app_images.dart';
|
||
import 'package:starwork_flutter/common/constant/app_view_parameter_keys.dart';
|
||
import 'package:starwork_flutter/common/widgets/custome_app_bar_wdiget.dart';
|
||
import 'package:starwork_flutter/extension/function_extension.dart';
|
||
import 'package:starwork_flutter/routes/app_routes.dart';
|
||
import 'personnel_manage_controller.dart';
|
||
|
||
class PersonnelManageView extends GetView<PersonnelManageController> {
|
||
PersonnelManageView({super.key});
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
// 即使不使用,只是引用一下 controller 就能触发初始化
|
||
final _ = controller; // 添加这一行
|
||
|
||
return Scaffold(
|
||
backgroundColor: AppColors.scaffoldBackgroundColor,
|
||
appBar: CustomAppBarWidget(
|
||
title: '人员管理'.tr,
|
||
backgroundColor: AppColors.scaffoldBackgroundColor,
|
||
),
|
||
body: SafeArea(
|
||
child: Column(
|
||
children: [
|
||
Container(
|
||
margin: EdgeInsets.symmetric(
|
||
horizontal: 10.w,
|
||
vertical: 10.h,
|
||
),
|
||
decoration: BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.circular(8.r),
|
||
),
|
||
padding: EdgeInsets.symmetric(
|
||
horizontal: 10.w,
|
||
vertical: 10.h,
|
||
),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||
children: [
|
||
Column(
|
||
children: [
|
||
Icon(
|
||
Icons.person,
|
||
),
|
||
SizedBox(
|
||
height: 4.h,
|
||
),
|
||
Text(
|
||
'人脸信息'.tr,
|
||
style: TextStyle(
|
||
fontSize: 10.sp,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
GestureDetector(
|
||
onTap: () {
|
||
Get.toNamed(AppRoutes.teamRoleManage);
|
||
},
|
||
child: Column(
|
||
children: [
|
||
Icon(
|
||
Icons.person,
|
||
),
|
||
SizedBox(
|
||
height: 4.h,
|
||
),
|
||
Text(
|
||
'角色管理'.tr,
|
||
style: TextStyle(
|
||
fontSize: 10.sp,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
Column(
|
||
children: [
|
||
Icon(
|
||
Icons.person,
|
||
),
|
||
SizedBox(
|
||
height: 4.h,
|
||
),
|
||
Text(
|
||
'新用户审核'.tr,
|
||
style: TextStyle(
|
||
fontSize: 10.sp,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
],
|
||
)
|
||
],
|
||
),
|
||
),
|
||
Container(
|
||
margin: EdgeInsets.symmetric(
|
||
horizontal: 10.w,
|
||
),
|
||
alignment: Alignment.centerLeft,
|
||
child: Text(
|
||
'组织架构',
|
||
textAlign: TextAlign.left,
|
||
style: TextStyle(
|
||
fontSize: 12.sp,
|
||
fontWeight: FontWeight.w500,
|
||
color: Colors.grey,
|
||
),
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 10.h,
|
||
),
|
||
Expanded(
|
||
child: Obx(
|
||
() {
|
||
return Container(
|
||
margin: EdgeInsets.symmetric(
|
||
horizontal: 10.w,
|
||
),
|
||
decoration: const BoxDecoration(
|
||
color: Colors.white,
|
||
borderRadius: BorderRadius.all(Radius.circular(8.0)),
|
||
),
|
||
child: RefreshIndicator(
|
||
onRefresh: () async {
|
||
await controller.requestDepartList();
|
||
},
|
||
color: const Color(0xFF4A90E2),
|
||
backgroundColor: Colors.white,
|
||
displacement: 60.0,
|
||
edgeOffset: 0.0,
|
||
triggerMode: RefreshIndicatorTriggerMode.onEdge,
|
||
strokeWidth: 2.5,
|
||
semanticsLabel: '下拉刷新首页内容',
|
||
semanticsValue: '刷新中...',
|
||
child: TreeView.simple(
|
||
tree: controller.treeData.value ?? TreeNode.root(),
|
||
showRootNode: false,
|
||
expansionIndicatorBuilder: noExpansionIndicatorBuilder,
|
||
indentation: const Indentation(style: IndentStyle.roundJoint),
|
||
onItemTap: (item) {},
|
||
onTreeReady: (c) {
|
||
controller.treeViewController = c;
|
||
},
|
||
builder: (context, node) {
|
||
String title = "";
|
||
DepartItem departInfo = DepartItem();
|
||
int personNum = 0;
|
||
bool hasChildren = node.childrenAsList.isNotEmpty; // 判断是否有子节点
|
||
bool isPersonItem = node.data is PersonItem; // 判断当前节点是否是人员节点
|
||
bool isOneself = false;
|
||
bool isRootNode = false;
|
||
bool isSuper = false;
|
||
|
||
if (node.data is DepartItem) {
|
||
final depart = node.data as DepartItem;
|
||
title = depart.departName ?? "未命名部门";
|
||
personNum = depart.personNum ?? 0;
|
||
departInfo = depart;
|
||
if (hasChildren) {
|
||
title = title + "($personNum)";
|
||
} else {
|
||
title = title + "(0)";
|
||
}
|
||
if (depart.parentId == -1) {
|
||
isRootNode = true;
|
||
}
|
||
} else if (node.data is PersonItem) {
|
||
// 处理人员节点
|
||
final person = node.data as PersonItem;
|
||
title = person.personName ?? "未命名人员";
|
||
var personUserId = person.userId;
|
||
person.roles?.forEach((role) {
|
||
if (role.isSuper == 1) {
|
||
isSuper = true;
|
||
}
|
||
});
|
||
if (personUserId != null && personUserId == controller.cacheUserInfo.value.id) {
|
||
isOneself = true;
|
||
}
|
||
}
|
||
|
||
return Container(
|
||
padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 6.h),
|
||
child: Row(
|
||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
children: [
|
||
Expanded(
|
||
child: Row(
|
||
children: [
|
||
!isPersonItem
|
||
? Container(
|
||
width: 34.w,
|
||
height: 34.w,
|
||
decoration: BoxDecoration(
|
||
color: Colors.grey[300],
|
||
borderRadius: BorderRadius.circular(8.r),
|
||
),
|
||
child: ClipRRect(
|
||
borderRadius: BorderRadius.circular(8.r),
|
||
child: Icon(
|
||
Icons.folder,
|
||
size: 22.w,
|
||
color: Colors.blue,
|
||
),
|
||
),
|
||
)
|
||
: Container(
|
||
width: 34.w,
|
||
height: 34.w,
|
||
decoration: BoxDecoration(
|
||
color: Colors.grey[200],
|
||
borderRadius: BorderRadius.circular(8.r),
|
||
),
|
||
child: ClipRRect(
|
||
borderRadius: BorderRadius.circular(8.r),
|
||
child: Image(
|
||
image: const AssetImage(AppImages.defaultAvatar),
|
||
width: 22.w,
|
||
height: 22.w,
|
||
fit: BoxFit.cover,
|
||
gaplessPlayback: true,
|
||
filterQuality: FilterQuality.medium,
|
||
errorBuilder: (context, error, stackTrace) {
|
||
return Icon(
|
||
Icons.person,
|
||
size: 30.sp,
|
||
color: Colors.grey[400],
|
||
);
|
||
},
|
||
),
|
||
),
|
||
),
|
||
SizedBox(
|
||
width: 10.w,
|
||
),
|
||
Expanded(
|
||
child: Text(
|
||
title,
|
||
style: TextStyle(
|
||
fontSize: 14.sp,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
maxLines: 1,
|
||
overflow: TextOverflow.ellipsis,
|
||
),
|
||
),
|
||
Visibility(
|
||
visible: isOneself,
|
||
child: Container(
|
||
padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 2.h),
|
||
decoration: BoxDecoration(
|
||
color: Colors.blue[50],
|
||
borderRadius: BorderRadius.circular(4.r),
|
||
border: Border.all(
|
||
color: Colors.blue,
|
||
width: 1.w,
|
||
),
|
||
),
|
||
child: Text(
|
||
'自己',
|
||
style: TextStyle(
|
||
fontSize: 12.sp,
|
||
fontWeight: FontWeight.w400,
|
||
color: Colors.blue,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
Visibility(
|
||
visible: isSuper && isOneself,
|
||
child: SizedBox(
|
||
width: 4.w,
|
||
),
|
||
),
|
||
Visibility(
|
||
visible: isSuper,
|
||
child: Container(
|
||
padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 2.h),
|
||
decoration: BoxDecoration(
|
||
color: Colors.blue[50],
|
||
borderRadius: BorderRadius.circular(4.r),
|
||
border: Border.all(
|
||
color: Colors.blue,
|
||
width: 1.w,
|
||
),
|
||
),
|
||
child: Text(
|
||
'超管',
|
||
style: TextStyle(
|
||
fontSize: 12.sp,
|
||
fontWeight: FontWeight.w400,
|
||
color: Colors.blue,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
Visibility(
|
||
visible: !isPersonItem,
|
||
child: Obx(
|
||
() => Radio<DepartItem>(
|
||
value: departInfo,
|
||
groupValue: controller.selectedDepartItem.value,
|
||
activeColor: Colors.blue,
|
||
visualDensity: VisualDensity.compact,
|
||
onChanged: (value) {
|
||
controller.selectedDepartItem.value = value as DepartItem;
|
||
controller.selectedDepartItem.refresh();
|
||
},
|
||
),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
);
|
||
},
|
||
),
|
||
),
|
||
);
|
||
},
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 4.h,
|
||
),
|
||
Obx(
|
||
() => Text(
|
||
'共${controller.totalPersonCount.value}人',
|
||
style: TextStyle(
|
||
fontSize: 14.sp,
|
||
color: Colors.grey[500],
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 4.h,
|
||
),
|
||
Container(
|
||
margin: EdgeInsets.symmetric(
|
||
horizontal: 10.w,
|
||
),
|
||
child: Row(
|
||
children: [
|
||
Expanded(
|
||
child: ElevatedButton(
|
||
onPressed: () async {
|
||
if (controller.selectedDepartItem.value.departNo == null) {
|
||
controller.showToast('请先选择一个组织');
|
||
return;
|
||
}
|
||
var result = await Get.toNamed(AppRoutes.teamAddPerson, arguments: {
|
||
AppViewParameterKeys.departItem: controller.selectedDepartItem.value.toJson(),
|
||
});
|
||
if (result != null && result == true) {
|
||
await controller.requestDepartList();
|
||
}
|
||
}.debounce(),
|
||
style: ElevatedButton.styleFrom(
|
||
backgroundColor: Colors.blue,
|
||
padding: EdgeInsets.symmetric(vertical: 10.h),
|
||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r)),
|
||
),
|
||
child: Text(
|
||
'添加人员'.tr,
|
||
style: TextStyle(
|
||
fontSize: 16.sp,
|
||
color: Colors.white,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
SizedBox(width: 10.w),
|
||
Expanded(
|
||
child: ElevatedButton(
|
||
onPressed: () {
|
||
if (controller.selectedDepartItem.value.departNo == null) {
|
||
controller.showToast('请先选择一个组织');
|
||
return;
|
||
}
|
||
Get.toNamed(AppRoutes.teamAddOrganization, arguments: {
|
||
AppViewParameterKeys.departItem: controller.selectedDepartItem.value.toJson(),
|
||
});
|
||
}.debounce(),
|
||
style: ElevatedButton.styleFrom(
|
||
backgroundColor: Colors.grey[50],
|
||
padding: EdgeInsets.symmetric(vertical: 10.h),
|
||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r)),
|
||
),
|
||
child: Text(
|
||
'添加子组织'.tr,
|
||
style: TextStyle(
|
||
fontSize: 16.sp,
|
||
color: Colors.blue,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
SizedBox(width: 10.w),
|
||
Expanded(
|
||
child: ElevatedButton(
|
||
onPressed: () {
|
||
controller.showFunctionNotOpen();
|
||
}.debounce(),
|
||
style: ElevatedButton.styleFrom(
|
||
backgroundColor: Colors.grey[50],
|
||
padding: EdgeInsets.symmetric(vertical: 10.h),
|
||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8.r)),
|
||
),
|
||
child: Text(
|
||
'更多管理'.tr,
|
||
style: TextStyle(
|
||
fontSize: 16.sp,
|
||
color: Colors.blue,
|
||
fontWeight: FontWeight.w500,
|
||
),
|
||
),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
SizedBox(
|
||
height: 20.h,
|
||
),
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|