flutter_integrated_whb/lib/pages/home/userInfo_page.dart

111 lines
3.1 KiB
Dart
Raw Normal View History

2025-07-11 11:03:21 +08:00
import 'package:flutter/material.dart';
import 'package:qhd_prevention/pages/my_appbar.dart';
import '../../http/ApiService.dart';
2025-07-11 11:03:21 +08:00
class UserinfoPage extends StatefulWidget {
const UserinfoPage({super.key});
@override
State<UserinfoPage> createState() => _UserinfoPageState();
}
class _UserinfoPageState extends State<UserinfoPage> {
Map<String, dynamic> user = {};
@override
void initState() {
// TODO: implement initState
super.initState();
_getUserInfo();
}
Future<void> _getUserInfo() async {
try {
final result = await ApiService.getUserInfo();
if (result['result'] == 'success') {
setState(() {
user= result['pd'];
});
}else{
_showMessage('加载数据失败');
}
} catch (e) {
// 出错时可以 Toast 或者在页面上显示错误状态
print('加载数据失败:$e');
}
}
2025-07-11 11:03:21 +08:00
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppbar(title: "人员信息"),
body: SafeArea(
child: ListView(
children: [
_userItemCell("姓名", user["NAME"]??"", false),
Divider(height: 1),
_userItemCell("性别", user["SEX_NAME"]??"", false),
Divider(height: 1),
_userItemCell("部门", user["DEPARTMENT_NAME"]??"", false),
Divider(height: 1),
2025-08-27 16:14:10 +08:00
_userItemCell("岗位(工种)", user["POST_NAME"]??"", true),
Divider(height: 1),
_userItemCell("人员类型", user["PERSONNEL_TYPE_NAME"]??"", false),
Divider(height: 1),
_userItemCell("入职时间", user["ENTRY_DATE"]??"", false),
Divider(height: 1),
2025-08-27 16:14:10 +08:00
// _userItemCell("工种", user["TYPE_OF_WORK_NAME"]??"", false),
2025-07-11 11:03:21 +08:00
],
),
),
);
}
Widget _userItemCell(final String title, final String detail, bool isLast) {
return Container(
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 15),
decoration:
isLast
? const BoxDecoration(
color: Colors.white,
border: Border(
bottom: BorderSide(color: Colors.grey, width: 0),
),
)
: const BoxDecoration(
color: Colors.white,
border: Border(
bottom: BorderSide(color: Colors.grey, width: 0.5),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text(title, style: const TextStyle(fontSize: 16, )),
2025-07-11 11:03:21 +08:00
Flexible(
child: Text(
detail,
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w500,color: Colors.grey),
2025-07-11 11:03:21 +08:00
textAlign: TextAlign.right,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
),
],
),
);
}
void _showMessage(String msg) {
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(msg)));
}
2025-07-11 11:03:21 +08:00
}