增添優化功能
This commit is contained in:
+138
-50
@@ -13,30 +13,46 @@ class LeaveDetail extends StatefulWidget {
|
||||
|
||||
class _LeaveDetailState extends State<LeaveDetail> {
|
||||
final LeaveApiService _apiService = LeaveApiService();
|
||||
bool _isWithdrawing = false;
|
||||
bool _isPromoting = false;
|
||||
|
||||
// 實作撤回邏輯
|
||||
Future<void> _handleWithdraw() async {
|
||||
// 實作上呈邏輯
|
||||
Future<void> _handlePromote() async {
|
||||
final confirm = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (ctx) => AlertDialog(
|
||||
title: const Text('確認撤回'),
|
||||
content: const Text('您確定要撤回此張請假單嗎?'),
|
||||
title: const Text('確認上呈'),
|
||||
content: const Text('您確定要將此張請假單上呈簽核嗎?'),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, false), child: const Text('取消')),
|
||||
TextButton(onPressed: () => Navigator.pop(ctx, true), child: const Text('確定', style: TextStyle(color: Colors.red))),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, false),
|
||||
child: const Text('取消', style: TextStyle(color: Colors.grey))
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx, true),
|
||||
child: const Text('確定上呈', style: TextStyle(color: Colors.blue, fontWeight: FontWeight.bold))
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (confirm == true) {
|
||||
setState(() => _isWithdrawing = true);
|
||||
final success = await _apiService.withdrawLeave(widget.leave.billNo);
|
||||
setState(() => _isWithdrawing = false);
|
||||
setState(() => _isPromoting = true);
|
||||
|
||||
final success = await _apiService.promoteLeave(
|
||||
widget.leave.personId,
|
||||
widget.leave.billNo
|
||||
);
|
||||
|
||||
setState(() => _isPromoting = false);
|
||||
|
||||
if (success && mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(const SnackBar(content: Text('已成功撤回')));
|
||||
Navigator.pop(context, true); // 回傳 true 讓前一頁 (Manager) 重新整理列表
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('已成功上呈單據'),
|
||||
backgroundColor: Colors.green,
|
||||
)
|
||||
);
|
||||
Navigator.pop(context, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,24 +72,31 @@ class _LeaveDetailState extends State<LeaveDetail> {
|
||||
_buildInfoCard(context),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 修正 3: 新增簽核進度區塊
|
||||
// 簽核進度區塊
|
||||
const Text('簽核進度', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.blueGrey)),
|
||||
const SizedBox(height: 8),
|
||||
_buildFlowTimeline(),
|
||||
_buildSignHistoryTable(),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// 修正 5: 實作撤回按鈕邏輯
|
||||
if (leave.flowStatus == '0' || leave.flowStatus == '1')
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
child: OutlinedButton.icon(
|
||||
onPressed: _isWithdrawing ? null : _handleWithdraw,
|
||||
icon: _isWithdrawing ? const CircularProgressIndicator(strokeWidth: 2) : const Icon(Icons.history_outlined),
|
||||
label: Text(_isWithdrawing ? '處理中...' : '撤回申請'),
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: Colors.red,
|
||||
side: const BorderSide(color: Colors.red),
|
||||
padding: const EdgeInsets.symmetric(vertical: 12),
|
||||
child: ElevatedButton.icon(
|
||||
onPressed: _isPromoting ? null : _handlePromote,
|
||||
icon: _isPromoting
|
||||
? const SizedBox(
|
||||
width: 20, height: 20,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: Colors.white)
|
||||
)
|
||||
: const Icon(Icons.send_rounded),
|
||||
label: Text(_isPromoting ? '上呈處理中...' : '上呈申請'),
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.blue,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -92,7 +115,6 @@ class _LeaveDetailState extends State<LeaveDetail> {
|
||||
children: [
|
||||
Text('單號: ${widget.leave.billNo}', style: const TextStyle(fontSize: 14, color: Colors.grey)),
|
||||
const SizedBox(height: 4),
|
||||
// 修正 4: 顯示 leaveTypeName
|
||||
Text(widget.leave.leaveTypeName, style: const TextStyle(fontSize: 28, fontWeight: FontWeight.bold)),
|
||||
],
|
||||
),
|
||||
@@ -106,10 +128,7 @@ class _LeaveDetailState extends State<LeaveDetail> {
|
||||
}
|
||||
|
||||
Widget _buildInfoCard(BuildContext context) {
|
||||
// 處理代理人顯示文字 (防呆處理)
|
||||
String displayAgent = widget.leave.agentName.isNotEmpty
|
||||
? '${widget.leave.agentName} (${widget.leave.agentId})'
|
||||
: widget.leave.agentId;
|
||||
String displayAgent = '${widget.leave.agentId} ${widget.leave.agentName}';
|
||||
|
||||
return Card(
|
||||
elevation: 0,
|
||||
@@ -122,7 +141,6 @@ class _LeaveDetailState extends State<LeaveDetail> {
|
||||
const Divider(height: 30),
|
||||
_buildDetailRow(Icons.timer_outlined, '請假時數', '${widget.leave.days} 天 ${widget.leave.hours} 小時'),
|
||||
const Divider(height: 30),
|
||||
// 修正 6: 顯示帶有姓名的代理人資訊
|
||||
_buildDetailRow(Icons.person_outline, '代理人', displayAgent),
|
||||
const Divider(height: 30),
|
||||
_buildDetailRow(Icons.edit_note, '事由', widget.leave.leaveNote ?? '未填寫'),
|
||||
@@ -148,33 +166,103 @@ class _LeaveDetailState extends State<LeaveDetail> {
|
||||
);
|
||||
}
|
||||
|
||||
// 實作簽核時間軸 (搭配 FutureBuilder)
|
||||
Widget _buildFlowTimeline() {
|
||||
return FutureBuilder<List<FlowLog>>(
|
||||
future: _apiService.fetchFlowLogs(widget.leave.billNo),
|
||||
// ===== 簽核進度 Table (精準對接 SP 欄位) =====
|
||||
Widget _buildSignHistoryTable() {
|
||||
return FutureBuilder<List<Map<String, dynamic>>>(
|
||||
future: _apiService.fetchSignHistory(widget.leave.billNo),
|
||||
builder: (context, snapshot) {
|
||||
if (snapshot.connectionState == ConnectionState.waiting) return const Center(child: CircularProgressIndicator());
|
||||
if (!snapshot.hasData || snapshot.data!.isEmpty) return const Text('尚無簽核歷程', style: TextStyle(color: Colors.grey));
|
||||
if (snapshot.connectionState == ConnectionState.waiting) {
|
||||
return const Center(child: Padding(
|
||||
padding: EdgeInsets.all(20.0),
|
||||
child: CircularProgressIndicator(),
|
||||
));
|
||||
}
|
||||
if (!snapshot.hasData || snapshot.data!.isEmpty) {
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
width: double.infinity,
|
||||
decoration: BoxDecoration(color: Colors.grey.shade50, borderRadius: BorderRadius.circular(10)),
|
||||
child: const Text('尚無簽核歷程', style: TextStyle(color: Colors.grey), textAlign: TextAlign.center),
|
||||
);
|
||||
}
|
||||
|
||||
final logs = snapshot.data!;
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(color: Colors.grey.shade50, borderRadius: BorderRadius.circular(10), border: Border.all(color: Colors.grey.shade200)),
|
||||
child: Column(
|
||||
children: logs.map((log) {
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(
|
||||
log.status == '1' ? Icons.check_circle : (log.status == 'X' ? Icons.cancel : Icons.pending),
|
||||
color: log.status == '1' ? Colors.green : (log.status == 'X' ? Colors.red : Colors.orange),
|
||||
),
|
||||
title: Text('${log.stepName} - ${log.approverName}'),
|
||||
subtitle: Text(log.time != null ? DateFormat('MM/dd HH:mm').format(log.time!) : ''),
|
||||
);
|
||||
}).toList(),
|
||||
|
||||
return ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Table(
|
||||
border: TableBorder.all(color: Colors.grey.shade300, width: 1),
|
||||
// 設定各欄位的寬度比例:意見欄位給予最大空間
|
||||
columnWidths: const {
|
||||
0: FlexColumnWidth(2.0), // 簽核人
|
||||
1: FlexColumnWidth(2.0), // 狀態
|
||||
2: FlexColumnWidth(3.0), // 意見
|
||||
3: FlexColumnWidth(2.5), // 時間
|
||||
},
|
||||
children: [
|
||||
// 表頭列
|
||||
TableRow(
|
||||
decoration: BoxDecoration(color: Colors.blueGrey.shade50),
|
||||
children: [
|
||||
_buildTableCell('簽核人', isHeader: true),
|
||||
_buildTableCell('狀態', isHeader: true),
|
||||
_buildTableCell('意見', isHeader: true),
|
||||
_buildTableCell('時間', isHeader: true),
|
||||
],
|
||||
),
|
||||
// 動態產生資料列,對接 SP 欄位
|
||||
...logs.map((log) {
|
||||
final approver = log['personcname']?.toString() ?? '-';
|
||||
final statusName = log['sign_status_name']?.toString() ?? '-';
|
||||
final note = log['sign_note']?.toString() ?? '';
|
||||
final timeStr = log['create_date']?.toString() ?? '';
|
||||
|
||||
// 簡單判斷狀態文字來給予顏色提示 (依照中文涵義)
|
||||
Color statusColor = Colors.black87;
|
||||
if (statusName.contains('同意') || statusName.contains('核准')) {
|
||||
statusColor = Colors.green;
|
||||
} else if (statusName.contains('駁回') || statusName.contains('拒絕')) {
|
||||
statusColor = Colors.red;
|
||||
} else if (statusName.contains('待簽')) {
|
||||
statusColor = Colors.orange;
|
||||
}
|
||||
|
||||
// 處理時間格式,如果為 yyyy-MM-dd HH:mm:ss 則截取 MM-dd HH:mm 以節省空間
|
||||
String displayTime = timeStr;
|
||||
if (displayTime.length >= 16) {
|
||||
// 如果前面有年份(例如: 2026-03-04),可視需求決定要不要擷取 substring(5, 16)
|
||||
displayTime = displayTime.substring(5, 16);
|
||||
}
|
||||
|
||||
return TableRow(
|
||||
children: [
|
||||
_buildTableCell(approver),
|
||||
_buildTableCell(statusName, textColor: statusColor),
|
||||
_buildTableCell(note.isEmpty ? '-' : note),
|
||||
_buildTableCell(displayTime),
|
||||
],
|
||||
);
|
||||
}).toList(),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// 表格單元格的小元件
|
||||
Widget _buildTableCell(String text, {bool isHeader = false, Color? textColor}) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 4),
|
||||
child: Text(
|
||||
text,
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
fontWeight: isHeader ? FontWeight.bold : FontWeight.normal,
|
||||
color: textColor ?? (isHeader ? Colors.blueGrey.shade700 : Colors.black87),
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user