297 lines
8.8 KiB
Dart
297 lines
8.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:intl/intl.dart';
|
|
import 'package:qhd_prevention/pages/my_appbar.dart';
|
|
|
|
import '../../http/ApiService.dart';
|
|
import '../../tools/tools.dart';
|
|
import 'mine_duty_application.dart';
|
|
import 'mine_duty_detail.dart';
|
|
|
|
class LeaveRecord {
|
|
final String applicant;
|
|
final String department;
|
|
final String position;
|
|
final DateTime startDate;
|
|
final DateTime endDate;
|
|
final String status;
|
|
final Color statusColor;
|
|
|
|
LeaveRecord({
|
|
required this.applicant,
|
|
required this.department,
|
|
required this.position,
|
|
required this.startDate,
|
|
required this.endDate,
|
|
required this.status,
|
|
required this.statusColor,
|
|
});
|
|
}
|
|
|
|
class MineDutyManagementPage extends StatefulWidget {
|
|
const MineDutyManagementPage({super.key});
|
|
|
|
@override
|
|
State<MineDutyManagementPage> createState() => _MineDutyManagementPageState();
|
|
}
|
|
|
|
class _MineDutyManagementPageState extends State<MineDutyManagementPage> {
|
|
|
|
int showCount=-1;
|
|
int currentPage=1;
|
|
|
|
Future<void> _onRefresh() async {
|
|
// 模拟网络请求
|
|
await Future.delayed(const Duration(seconds: 2));
|
|
// 刷新数据逻辑,如 fetchData()
|
|
setState(() {
|
|
// TODO: 更新数据源
|
|
});
|
|
}
|
|
|
|
@override
|
|
void initState() {
|
|
_getListData();
|
|
|
|
}
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
|
|
// 模拟数据
|
|
final leaveRecords = [
|
|
LeaveRecord(
|
|
applicant: "王轩",
|
|
department: "测试部",
|
|
position: "测试员",
|
|
startDate: DateTime(2025, 7, 18),
|
|
endDate: DateTime(2025, 7, 18),
|
|
status: "无需审批",
|
|
statusColor: const Color(0xFF4CAF50),
|
|
),
|
|
LeaveRecord(
|
|
applicant: "王轩",
|
|
department: "测试部",
|
|
position: "测试员",
|
|
startDate: DateTime(2025, 7, 16),
|
|
endDate: DateTime(2025, 7, 16),
|
|
status: "无需审批",
|
|
statusColor: const Color(0xFF4CAF50),
|
|
),
|
|
LeaveRecord(
|
|
applicant: "李思",
|
|
department: "开发部",
|
|
position: "高级工程师",
|
|
startDate: DateTime(2025, 7, 20),
|
|
endDate: DateTime(2025, 7, 22),
|
|
status: "待审批",
|
|
statusColor: const Color(0xFFF57C00),
|
|
),
|
|
LeaveRecord(
|
|
applicant: "张伟",
|
|
department: "产品部",
|
|
position: "产品经理",
|
|
startDate: DateTime(2025, 7, 15),
|
|
endDate: DateTime(2025, 7, 17),
|
|
status: "已拒绝",
|
|
statusColor: const Color(0xFFF44336),
|
|
),
|
|
];
|
|
|
|
return Scaffold(
|
|
backgroundColor: const Color(0xFFF5F7FA),
|
|
appBar: MyAppbar(title: "离岗管理",actions: [
|
|
TextButton(
|
|
onPressed: () {
|
|
pushPage(MineDutyApplicationPage(), context);
|
|
},
|
|
child: Text("申请",style: TextStyle(color: Colors.white,fontSize: 16,fontWeight:FontWeight.bold),))
|
|
],),
|
|
body:
|
|
RefreshIndicator(
|
|
onRefresh: _onRefresh,
|
|
child:
|
|
// Column(
|
|
// children: [
|
|
// 顶部信息栏
|
|
// Container(
|
|
// padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
// color: const Color(0xFFE3F2FD),
|
|
// child: const Row(
|
|
// children: [
|
|
// Icon(Icons.info_outline, color: Color(0xFF1976D2)),
|
|
// SizedBox(width: 8),
|
|
// Text(
|
|
// "离岗记录显示最近30天内的申请记录",
|
|
// style: TextStyle(color: Color(0xFF1976D2), fontSize: 14),
|
|
// ),
|
|
// ],
|
|
// ),
|
|
// ),
|
|
|
|
// 记录列表
|
|
Expanded(
|
|
child: ListView.builder(
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
itemCount: leaveRecords.length,
|
|
itemBuilder: (context, index) {
|
|
final record = leaveRecords[index];
|
|
return _buildRecordCard(record,context);
|
|
},
|
|
),
|
|
// ),
|
|
// ],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildRecordCard(LeaveRecord record, BuildContext context) {
|
|
final dateFormat = DateFormat('yyyy-MM-dd');
|
|
final isSameDay = record.startDate == record.endDate;
|
|
final dateRange = isSameDay
|
|
? dateFormat.format(record.startDate)
|
|
: "${dateFormat.format(record.startDate)} 至 ${dateFormat.format(record.endDate)}";
|
|
|
|
return
|
|
// GestureDetector(
|
|
// onTap: () {
|
|
// pushPage(MineDutyDetailPage(), context);
|
|
// },
|
|
// child:
|
|
Container(
|
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(12),
|
|
boxShadow: [
|
|
BoxShadow(
|
|
color: Colors.grey.withOpacity(0.1),
|
|
spreadRadius: 1,
|
|
blurRadius: 6,
|
|
offset: const Offset(0, 2),
|
|
)
|
|
],
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
// 申请人信息
|
|
Row(
|
|
children: [
|
|
// Container(
|
|
// width: 40,
|
|
// height: 40,
|
|
// decoration: BoxDecoration(
|
|
// color: const Color(0xFFE3F2FD),
|
|
// shape: BoxShape.circle,
|
|
// ),
|
|
// child: const Icon(Icons.person, color: Color(0xFF1976D2)),
|
|
// ),
|
|
// const SizedBox(width: 12),
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
"申请人:${record.applicant}",
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Text(
|
|
"部门:${record.department} \n岗位:${record.position}",
|
|
style: TextStyle(
|
|
fontSize: 13,
|
|
color: Colors.grey[600],
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const Spacer(),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
|
decoration: BoxDecoration(
|
|
color: record.statusColor.withOpacity(0.1),
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: Text(
|
|
record.status,
|
|
style: TextStyle(
|
|
color: record.statusColor,
|
|
fontWeight: FontWeight.w500,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
// 离岗时间
|
|
Row(
|
|
children: [
|
|
const Icon(Icons.calendar_today, size: 18, color: Colors.grey),
|
|
const SizedBox(width: 8),
|
|
Text(
|
|
"离岗时间: $dateRange",
|
|
style: const TextStyle(color: Colors.grey),
|
|
),
|
|
],
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
// 操作按钮
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.end,
|
|
children: [
|
|
TextButton(
|
|
onPressed: () {
|
|
pushPage(MineDutyDetailPage(), context);
|
|
},
|
|
style: TextButton.styleFrom(
|
|
foregroundColor: const Color(0xFF1976D2),
|
|
),
|
|
child: const Text("查看详情"),
|
|
),
|
|
// const SizedBox(width: 16),
|
|
// if (record.status == "待审批")
|
|
// ElevatedButton(
|
|
// onPressed: () {},
|
|
// style: ElevatedButton.styleFrom(
|
|
// backgroundColor: const Color(0xFF1976D2),
|
|
// padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
// ),
|
|
// child: const Text("审批", style: TextStyle(color: Colors.white)),
|
|
// )
|
|
],
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// ),
|
|
);
|
|
|
|
}
|
|
|
|
Future<void> _getListData() async {
|
|
try {
|
|
|
|
final raw = await ApiService.getDutyManagement(showCount,currentPage);
|
|
|
|
|
|
|
|
} catch (e) {
|
|
// 出错时可以 Toast 或者在页面上显示错误状态
|
|
print('加载首页数据失败:$e');
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|