296 lines
9.5 KiB
Dart
296 lines
9.5 KiB
Dart
|
import 'package:flutter/material.dart';
|
||
|
import 'package:get/get.dart';
|
||
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
||
|
import 'package:sk_base_mobile/apis/index.dart';
|
||
|
import 'package:sk_base_mobile/app_theme.dart';
|
||
|
import 'package:sk_base_mobile/constants/bg_color.dart';
|
||
|
import 'package:sk_base_mobile/models/user_info.model.dart';
|
||
|
import 'package:sk_base_mobile/util/date.util.dart';
|
||
|
import 'package:sk_base_mobile/util/debouncer.dart';
|
||
|
import 'package:sk_base_mobile/util/screen_adaper_util.dart';
|
||
|
import 'package:sk_base_mobile/widgets/core/sk_ink.dart';
|
||
|
import 'package:sk_base_mobile/widgets/core/sk_tag.dart';
|
||
|
import 'package:sk_base_mobile/widgets/core/sk_text_input.dart';
|
||
|
import 'package:sk_base_mobile/widgets/empty.dart';
|
||
|
import 'package:sk_base_mobile/widgets/sk_appbar.dart';
|
||
|
|
||
|
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(
|
||
|
backgroundColor: Color(0xFFe9f0fd),
|
||
|
appBar: SkAppbar(
|
||
|
backgroundColor: AppTheme.nearlyWhite,
|
||
|
iconAndTextColor: AppTheme.black,
|
||
|
title: '人事管理',
|
||
|
),
|
||
|
body: buildBody(),
|
||
|
));
|
||
|
}
|
||
|
|
||
|
Widget buildBody() {
|
||
|
return Column(
|
||
|
children: [
|
||
|
buildSearchBar(),
|
||
|
Expanded(
|
||
|
child: Container(
|
||
|
margin: EdgeInsets.symmetric(
|
||
|
horizontal: ScreenAdaper.height(defaultPadding),
|
||
|
vertical: ScreenAdaper.height(defaultPadding)),
|
||
|
child: Obx(
|
||
|
() => 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(
|
||
|
itemBuilder: (context, index) {
|
||
|
return buildUserCard(index);
|
||
|
},
|
||
|
itemCount: controller.list.length,
|
||
|
)),
|
||
|
)),
|
||
|
)
|
||
|
],
|
||
|
);
|
||
|
}
|
||
|
|
||
|
Widget buildSearchBar() {
|
||
|
final doSearch = debouncer((String value) {
|
||
|
controller.searchKey.value = value;
|
||
|
controller.onRefresh();
|
||
|
}, delayTime: 500);
|
||
|
return Container(
|
||
|
color: AppTheme.nearlyWhite,
|
||
|
padding: EdgeInsets.only(
|
||
|
right: ScreenAdaper.width(20),
|
||
|
left: ScreenAdaper.width(20),
|
||
|
bottom: ScreenAdaper.height(20)),
|
||
|
child: Row(children: [
|
||
|
Expanded(
|
||
|
child: SizedBox(
|
||
|
height: ScreenAdaper.height(70),
|
||
|
child: SkTextInput(
|
||
|
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('');
|
||
|
},
|
||
|
)),
|
||
|
hint: '查询员工',
|
||
|
isDense: true,
|
||
|
contentPadding:
|
||
|
EdgeInsets.symmetric(vertical: ScreenAdaper.height(10)),
|
||
|
),
|
||
|
)),
|
||
|
SizedBox(
|
||
|
width: ScreenAdaper.width(10),
|
||
|
),
|
||
|
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),
|
||
|
),
|
||
|
),
|
||
|
)
|
||
|
]),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
Widget buildUserCard(int index) {
|
||
|
return Container(
|
||
|
padding: EdgeInsets.symmetric(
|
||
|
horizontal: ScreenAdaper.height(defaultPadding),
|
||
|
vertical: ScreenAdaper.height(defaultPadding)),
|
||
|
margin: EdgeInsets.only(bottom: ScreenAdaper.height(defaultPadding)),
|
||
|
decoration: BoxDecoration(
|
||
|
color: AppTheme.white,
|
||
|
borderRadius: BorderRadius.circular(ScreenAdaper.sp(15))),
|
||
|
child: Column(
|
||
|
children: [
|
||
|
Row(
|
||
|
children: [
|
||
|
// 头像
|
||
|
ClipRRect(
|
||
|
borderRadius: BorderRadius.all(Radius.circular(30)),
|
||
|
child: Image(
|
||
|
height: ScreenAdaper.height(80),
|
||
|
image: NetworkImage(
|
||
|
'https://thirdqq.qlogo.cn/g?b=qq&s=100&nk=1743369777')),
|
||
|
),
|
||
|
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)),
|
||
|
|
||
|
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))
|
||
|
],
|
||
|
)),
|
||
|
],
|
||
|
)),
|
||
|
|
||
|
/// 右侧action
|
||
|
/// 电话
|
||
|
buildActionButton(
|
||
|
onTap: () {},
|
||
|
icon: Icons.phone,
|
||
|
),
|
||
|
SizedBox(
|
||
|
width: ScreenAdaper.height(defaultPadding),
|
||
|
),
|
||
|
|
||
|
/// 邮件
|
||
|
buildActionButton(
|
||
|
onTap: () {},
|
||
|
icon: Icons.email_outlined,
|
||
|
),
|
||
|
SizedBox(
|
||
|
width: ScreenAdaper.height(defaultPadding),
|
||
|
),
|
||
|
|
||
|
/// 编辑
|
||
|
buildActionButton(
|
||
|
onTap: () {},
|
||
|
icon: Icons.edit,
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
const Divider(),
|
||
|
Row(
|
||
|
children: [
|
||
|
Text(
|
||
|
'工龄: ${SkDateUtil.howLongAgo(controller.list[index].createdAt!)}'),
|
||
|
const Spacer(),
|
||
|
const SkTag(
|
||
|
text: '在职',
|
||
|
color: Colors.green,
|
||
|
)
|
||
|
],
|
||
|
)
|
||
|
],
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
|
||
|
Widget buildActionButton({
|
||
|
required Function() onTap,
|
||
|
required IconData icon,
|
||
|
}) {
|
||
|
return SkInk(
|
||
|
onTap: () {},
|
||
|
border: Border.all(color: AppTheme.grey.withOpacity(0.8)),
|
||
|
borderRadius: BorderRadius.circular(ScreenAdaper.sp(30)),
|
||
|
child: Container(
|
||
|
padding: EdgeInsets.all(ScreenAdaper.height(5)),
|
||
|
child: Icon(
|
||
|
icon,
|
||
|
size: ScreenAdaper.height(35),
|
||
|
),
|
||
|
),
|
||
|
);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class HrManageController extends GetxController {
|
||
|
RxList<UserInfoModel> list = RxList([]);
|
||
|
RxString searchKey = ''.obs;
|
||
|
final searchBarTextConroller = TextEditingController();
|
||
|
RefreshController refreshController = RefreshController(initialRefresh: true);
|
||
|
int page = 1;
|
||
|
int limit = 15;
|
||
|
int total = 0;
|
||
|
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();
|
||
|
});
|
||
|
}
|
||
|
}
|