2024-04-08 13:50:23 +08:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
2024-04-09 11:44:55 +08:00
|
|
|
import 'package:sk_base_mobile/apis/api.dart';
|
2024-04-08 13:50:23 +08:00
|
|
|
import 'package:sk_base_mobile/app_theme.dart';
|
|
|
|
import 'package:sk_base_mobile/constants/bg_color.dart';
|
2024-04-09 08:31:17 +08:00
|
|
|
import 'package:sk_base_mobile/constants/constants.dart';
|
2024-04-08 13:50:23 +08:00
|
|
|
import 'package:sk_base_mobile/models/user_info.model.dart';
|
2024-04-09 08:31:17 +08:00
|
|
|
import 'package:sk_base_mobile/screens/hr_manage/components/edit_userinfo.dart';
|
2024-04-10 11:04:27 +08:00
|
|
|
|
2024-04-08 13:50:23 +08:00
|
|
|
import 'package:sk_base_mobile/util/date.util.dart';
|
|
|
|
import 'package:sk_base_mobile/util/debouncer.dart';
|
2024-04-09 08:31:17 +08:00
|
|
|
import 'package:sk_base_mobile/util/device.util.dart';
|
|
|
|
import 'package:sk_base_mobile/util/media_util.dart';
|
|
|
|
import 'package:sk_base_mobile/util/modal.util.dart';
|
2024-04-10 17:08:26 +08:00
|
|
|
import 'package:sk_base_mobile/util/router.util.dart';
|
2024-04-08 13:50:23 +08:00
|
|
|
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
2024-04-09 08:31:17 +08:00
|
|
|
import 'package:sk_base_mobile/util/snack_bar.util.dart';
|
2024-04-10 17:08:26 +08:00
|
|
|
import 'package:sk_base_mobile/widgets/core/sk_avatar.dart';
|
2024-04-08 13:50:23 +08:00
|
|
|
import 'package:sk_base_mobile/widgets/core/sk_ink.dart';
|
|
|
|
import 'package:sk_base_mobile/widgets/core/sk_tag.dart';
|
2024-04-10 11:04:27 +08:00
|
|
|
import 'package:sk_base_mobile/widgets/form_item/sk_text_input.dart';
|
2024-04-08 13:50:23 +08:00
|
|
|
import 'package:sk_base_mobile/widgets/empty.dart';
|
2024-04-09 08:31:17 +08:00
|
|
|
import 'package:sk_base_mobile/widgets/fade_in_cache_image.dart';
|
|
|
|
import 'package:sk_base_mobile/widgets/loading_indicator.dart';
|
|
|
|
import 'package:sk_base_mobile/widgets/core/sk_appbar.dart';
|
2024-04-08 13:50:23 +08:00
|
|
|
|
|
|
|
class HrManagePage extends StatelessWidget {
|
|
|
|
final controller = Get.put(HrManageController());
|
|
|
|
HrManagePage({super.key});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return GestureDetector(
|
|
|
|
onTap: () {
|
|
|
|
// 取消焦点
|
|
|
|
FocusScope.of(context).requestFocus(FocusNode());
|
|
|
|
},
|
|
|
|
child: Scaffold(
|
2024-04-09 08:31:17 +08:00
|
|
|
appBar: const SkAppbar(
|
2024-04-08 13:50:23 +08:00
|
|
|
backgroundColor: AppTheme.nearlyWhite,
|
|
|
|
iconAndTextColor: AppTheme.black,
|
|
|
|
title: '人事管理',
|
|
|
|
),
|
|
|
|
body: buildBody(),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildBody() {
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
buildSearchBar(),
|
|
|
|
Expanded(
|
|
|
|
child: Container(
|
|
|
|
margin: EdgeInsets.symmetric(
|
2024-04-09 08:31:17 +08:00
|
|
|
horizontal: ScreenAdaper.height(defaultPadding),
|
|
|
|
),
|
2024-04-08 13:50:23 +08:00
|
|
|
child: Obx(
|
2024-04-09 08:31:17 +08:00
|
|
|
() => controller.loading.value
|
|
|
|
? const LoadingIndicator(common: true)
|
|
|
|
: SmartRefresher(
|
|
|
|
enablePullDown: true,
|
|
|
|
enablePullUp: true,
|
|
|
|
controller: controller.refreshController,
|
|
|
|
onLoading: controller.onLoading,
|
|
|
|
onRefresh: controller.onRefresh,
|
|
|
|
child: controller.list.isEmpty
|
|
|
|
? const Center(
|
|
|
|
child: Empty(text: '暂无员工'),
|
|
|
|
)
|
|
|
|
: ListView.builder(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
vertical:
|
|
|
|
ScreenAdaper.height(defaultPadding)),
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
return buildUserCard(index);
|
|
|
|
},
|
|
|
|
itemCount: controller.list.length,
|
|
|
|
)),
|
2024-04-08 13:50:23 +08:00
|
|
|
)),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildSearchBar() {
|
|
|
|
final doSearch = debouncer((String value) {
|
|
|
|
controller.searchKey.value = value;
|
|
|
|
controller.onRefresh();
|
|
|
|
}, delayTime: 500);
|
|
|
|
return Container(
|
|
|
|
color: AppTheme.nearlyWhite,
|
2024-04-09 08:31:17 +08:00
|
|
|
padding: EdgeInsets.all(ScreenAdaper.width(20)),
|
|
|
|
child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
|
2024-04-08 13:50:23 +08:00
|
|
|
Expanded(
|
|
|
|
child: SizedBox(
|
|
|
|
height: ScreenAdaper.height(70),
|
|
|
|
child: SkTextInput(
|
2024-04-10 11:04:27 +08:00
|
|
|
fillColor: AppTheme.inputFillColor,
|
2024-04-08 13:50:23 +08:00
|
|
|
textController: controller.searchBarTextConroller,
|
|
|
|
onChanged: (value) => doSearch(value),
|
|
|
|
floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
|
|
border: OutlineInputBorder(
|
|
|
|
borderSide: BorderSide.none,
|
|
|
|
borderRadius: BorderRadius.circular(ScreenAdaper.sp(15))),
|
|
|
|
prefix: Icon(
|
|
|
|
Icons.search,
|
|
|
|
color: AppTheme.nearlyBlack,
|
|
|
|
size: ScreenAdaper.height(40),
|
|
|
|
), // 当searchBarController有值时不显示
|
|
|
|
suffixIcon: Obx(() => controller.searchKey.value.isEmpty
|
|
|
|
? const SizedBox()
|
|
|
|
: IconButton(
|
|
|
|
icon: const Icon(Icons.clear),
|
|
|
|
onPressed: () {
|
|
|
|
controller.searchKey.value = '';
|
|
|
|
controller.searchBarTextConroller.clear();
|
|
|
|
doSearch('');
|
|
|
|
},
|
|
|
|
)),
|
2024-04-10 11:43:59 +08:00
|
|
|
hint: '查询员工 姓名、手机号、邮箱',
|
2024-04-08 13:50:23 +08:00
|
|
|
isDense: true,
|
|
|
|
contentPadding:
|
|
|
|
EdgeInsets.symmetric(vertical: ScreenAdaper.height(10)),
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
SizedBox(
|
|
|
|
width: ScreenAdaper.width(10),
|
|
|
|
),
|
2024-04-10 11:43:59 +08:00
|
|
|
buildFilterBtn()
|
2024-04-08 13:50:23 +08:00
|
|
|
]),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-04-10 11:43:59 +08:00
|
|
|
Widget buildFilterBtn() {
|
|
|
|
return SkInk(
|
|
|
|
border: Border.all(color: AppTheme.grey.withOpacity(0.8)),
|
|
|
|
borderRadius: BorderRadius.circular(ScreenAdaper.sp(15)),
|
|
|
|
onTap: () {},
|
|
|
|
child: SizedBox(
|
|
|
|
width: ScreenAdaper.height(65),
|
|
|
|
height: ScreenAdaper.height(65),
|
|
|
|
child: Icon(
|
|
|
|
Icons.filter_list_sharp,
|
|
|
|
size: ScreenAdaper.height(50),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2024-04-08 13:50:23 +08:00
|
|
|
Widget buildUserCard(int index) {
|
2024-04-09 08:31:17 +08:00
|
|
|
return SkInk(
|
|
|
|
onTap: () {
|
2024-04-10 17:08:26 +08:00
|
|
|
RouterUtil.toNamed(RouteConfig.employeeDetail,
|
2024-04-09 08:31:17 +08:00
|
|
|
arguments: controller.list[index]);
|
|
|
|
},
|
2024-04-08 13:50:23 +08:00
|
|
|
margin: EdgeInsets.only(bottom: ScreenAdaper.height(defaultPadding)),
|
2024-04-09 08:31:17 +08:00
|
|
|
borderRadius: BorderRadius.circular(ScreenAdaper.sp(15)),
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
horizontal: ScreenAdaper.height(defaultPadding),
|
|
|
|
vertical: ScreenAdaper.height(defaultPadding)),
|
|
|
|
child: Column(
|
|
|
|
children: [
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
// 头像
|
2024-04-10 17:08:26 +08:00
|
|
|
SkAvatar(url: controller.list[index].avatar),
|
2024-04-09 08:31:17 +08:00
|
|
|
SizedBox(
|
|
|
|
width: ScreenAdaper.height(defaultPadding),
|
|
|
|
),
|
|
|
|
// 中间信息
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text('${controller.list[index].nickname}',
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: ScreenAdaper.height(30),
|
|
|
|
fontWeight: FontWeight.w600)),
|
2024-04-08 13:50:23 +08:00
|
|
|
|
2024-04-09 08:31:17 +08:00
|
|
|
SizedBox(
|
|
|
|
height: ScreenAdaper.height(5),
|
|
|
|
), // role
|
|
|
|
Text('${controller.list[index].dept?.name}',
|
|
|
|
style: TextStyle(color: AppTheme.grey)),
|
|
|
|
SizedBox(
|
|
|
|
height: ScreenAdaper.height(5),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
child: Wrap(
|
|
|
|
spacing: ScreenAdaper.height(5),
|
|
|
|
runSpacing: ScreenAdaper.height(5),
|
|
|
|
children: [
|
|
|
|
...controller.list[index].roles.map((e) => SkTag(
|
|
|
|
text: '${e.name}',
|
|
|
|
color: AppTheme.primaryColorLight))
|
|
|
|
],
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
)),
|
2024-04-08 13:50:23 +08:00
|
|
|
|
2024-04-09 08:31:17 +08:00
|
|
|
/// 右侧action
|
|
|
|
/// 电话
|
|
|
|
buildActionButton(
|
|
|
|
onTap: () {
|
|
|
|
if (controller.list[index].phone == null) {
|
|
|
|
SnackBarUtil().info('该员工没有录入手机号');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DeviceUtil.callPhone(controller.list[index].phone!);
|
|
|
|
},
|
|
|
|
icon: Icons.phone,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: ScreenAdaper.height(defaultPadding),
|
|
|
|
),
|
2024-04-08 13:50:23 +08:00
|
|
|
|
2024-04-09 08:31:17 +08:00
|
|
|
/// 邮件
|
|
|
|
buildActionButton(
|
|
|
|
onTap: () {
|
|
|
|
if (controller.list[index].email == null) {
|
|
|
|
SnackBarUtil().info('该员工没有录入邮箱');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
DeviceUtil.sendEmail(controller.list[index].email!);
|
|
|
|
},
|
|
|
|
icon: Icons.email_outlined,
|
|
|
|
),
|
|
|
|
SizedBox(
|
|
|
|
width: ScreenAdaper.height(defaultPadding),
|
|
|
|
),
|
2024-04-08 13:50:23 +08:00
|
|
|
|
2024-04-09 08:31:17 +08:00
|
|
|
/// 编辑
|
|
|
|
buildActionButton(
|
|
|
|
onTap: () {
|
2024-04-10 11:04:27 +08:00
|
|
|
ModalUtil.showGeneralDialog<UserInfoModel>(
|
2024-04-09 08:31:17 +08:00
|
|
|
content: EditUserInfo(
|
|
|
|
userId: controller.list[index].id!,
|
2024-04-10 11:04:27 +08:00
|
|
|
)).then((value) {
|
|
|
|
Get.delete<EditUserInfoController>();
|
|
|
|
if (value != null) {
|
|
|
|
controller.list[index] = value;
|
|
|
|
}
|
|
|
|
});
|
2024-04-09 08:31:17 +08:00
|
|
|
|
|
|
|
// Get.toNamed(RouteConfig.employeeDetail,
|
|
|
|
// arguments: controller.list[index]);
|
|
|
|
},
|
|
|
|
icon: Icons.edit,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
const Divider(),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
'工龄: ${SkDateUtil.howLongAgo(controller.list[index].createdAt!)}'),
|
|
|
|
const Spacer(),
|
|
|
|
const SkTag(
|
|
|
|
text: '在职',
|
|
|
|
color: Colors.green,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2024-04-08 13:50:23 +08:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget buildActionButton({
|
|
|
|
required Function() onTap,
|
|
|
|
required IconData icon,
|
|
|
|
}) {
|
|
|
|
return SkInk(
|
2024-04-09 08:31:17 +08:00
|
|
|
onTap: onTap,
|
2024-04-08 13:50:23 +08:00
|
|
|
border: Border.all(color: AppTheme.grey.withOpacity(0.8)),
|
2024-04-09 08:31:17 +08:00
|
|
|
borderRadius: BorderRadius.circular(ScreenAdaper.sp(40)),
|
2024-04-08 13:50:23 +08:00
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(ScreenAdaper.height(5)),
|
|
|
|
child: Icon(
|
|
|
|
icon,
|
2024-04-09 08:31:17 +08:00
|
|
|
size: ScreenAdaper.height(40),
|
2024-04-08 13:50:23 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class HrManageController extends GetxController {
|
|
|
|
RxList<UserInfoModel> list = RxList([]);
|
|
|
|
RxString searchKey = ''.obs;
|
|
|
|
final searchBarTextConroller = TextEditingController();
|
2024-04-09 08:31:17 +08:00
|
|
|
RefreshController refreshController =
|
|
|
|
RefreshController(initialRefresh: false);
|
2024-04-08 13:50:23 +08:00
|
|
|
int page = 1;
|
|
|
|
int limit = 15;
|
|
|
|
int total = 0;
|
2024-04-09 08:31:17 +08:00
|
|
|
RxBool loading = false.obs;
|
|
|
|
@override
|
|
|
|
onReady() {
|
|
|
|
super.onReady();
|
|
|
|
initData();
|
|
|
|
}
|
|
|
|
|
|
|
|
initData() async {
|
|
|
|
loading.value = true;
|
|
|
|
try {
|
|
|
|
await getData(isRefresh: true);
|
|
|
|
} finally {
|
|
|
|
loading.value = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-08 13:50:23 +08:00
|
|
|
Future<List<UserInfoModel>> getData({bool isRefresh = false}) async {
|
|
|
|
if (isRefresh == true) {
|
|
|
|
page = 1;
|
|
|
|
} else {
|
|
|
|
page++;
|
|
|
|
}
|
|
|
|
final res = await Api.getUsers({
|
|
|
|
'page': page,
|
|
|
|
'pageSize': 15,
|
|
|
|
'keyword': searchKey.value,
|
|
|
|
});
|
|
|
|
List<UserInfoModel> newList =
|
|
|
|
res.data!.items.map((e) => UserInfoModel.fromJson(e)).toList();
|
|
|
|
isRefresh == true ? list.assignAll(newList) : list.addAll(newList);
|
|
|
|
|
|
|
|
return newList;
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> onRefresh() async {
|
|
|
|
await getData(isRefresh: true).then((_) {
|
|
|
|
refreshController.refreshCompleted(resetFooterState: true);
|
|
|
|
}).catchError((_) {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> onLoading() async {
|
|
|
|
await getData().then((_) {
|
|
|
|
if (_.isEmpty) {
|
|
|
|
refreshController.loadNoData();
|
|
|
|
} else {
|
|
|
|
refreshController.loadComplete();
|
|
|
|
}
|
|
|
|
}).catchError((_) {
|
|
|
|
refreshController.loadFailed();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|