增添優化功能
This commit is contained in:
@@ -64,7 +64,7 @@ class LeaveApiService {
|
||||
// *** 關聯取得假別名稱,存到 Cache
|
||||
|
||||
// 排序:按單據日期降冪
|
||||
String queryFilter = "1^100^billdate^*^start_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 7 DAY) AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)^^personid^$personId";
|
||||
String queryFilter = "1^100^billdate^*^start_date BETWEEN DATE_SUB(CURDATE(), INTERVAL 21 DAY) AND DATE_ADD(CURDATE(), INTERVAL 7 DAY)^hrsm11^personid^$personId";
|
||||
|
||||
return await _apiService.fetchList<Leave>(
|
||||
tableName: "hrs_leave",
|
||||
@@ -147,4 +147,55 @@ class LeaveApiService {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 上呈請假單
|
||||
/// 上呈請假單
|
||||
/// 對應 API 規格: bpmm02_spread
|
||||
Future<bool> promoteLeave(String personId, String billNo) async {
|
||||
// 依據標準規範,參數一律使用 para0x
|
||||
final Map<String, String> params = {
|
||||
"para01": "eipm21",
|
||||
"para02": personId,
|
||||
"para03": billNo,
|
||||
};
|
||||
|
||||
try {
|
||||
// 使用與 sign_todo_api.dart 相同的 fetchProcedure 結構
|
||||
// 依據您提供的 url: ".../bpmm02_spread/1/",這裡將 endpoint 設為 "bpmm02_spread/1/"
|
||||
// (若底層機制會自動補齊後方的 /1/,可自行改為 "bpmm02_spread")
|
||||
await _apiService.fetchProcedure<dynamic>(
|
||||
procedureEndpoint: "bpmm02_spread",
|
||||
params: params,
|
||||
fromJson: (json) => json, // 僅需確認執行成功,回傳值暫不處理
|
||||
);
|
||||
|
||||
// 只要 fetchProcedure 沒有拋出異常 (且底層已處理 code == 0),即視為成功
|
||||
return true;
|
||||
} catch (e) {
|
||||
// 統一的錯誤捕獲與日誌
|
||||
print("LeaveApiService.promoteLeave 異常: $e");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// 取得簽核進度歷程
|
||||
/// 對應 API: bpm_sign_history/2/
|
||||
Future<List<Map<String, dynamic>>> fetchSignHistory(String billNo) async {
|
||||
final Map<String, String> params = {
|
||||
"para01": "eipm21", // 來源單別 functiontag
|
||||
"para02": billNo, // 原單單號 query_id
|
||||
};
|
||||
|
||||
try {
|
||||
// 呼叫 SP,並將回傳的每一筆資料解析為 Map
|
||||
return await _apiService.fetchProcedure<Map<String, dynamic>>(
|
||||
procedureEndpoint: "bpm_sign_history",
|
||||
params: params,
|
||||
fromJson: (json) => json as Map<String, dynamic>,
|
||||
);
|
||||
} catch (e) {
|
||||
print("LeaveApiService.fetchSignHistory 異常: $e");
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
+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,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,9 @@ class _LeaveFormState extends State<LeaveForm> {
|
||||
billNo: '', // API 端生成
|
||||
personId: widget.userId,
|
||||
agentId: _selectedAgent!['id'].toString(), // 確保轉為 String
|
||||
agentName: '',
|
||||
leaveType: _selectedType!.id, // 傳送 ID 給後端
|
||||
leaveTypeName: '',
|
||||
startTime: start,
|
||||
endTime: end,
|
||||
days: calcDays, // 寫入計算後的天數
|
||||
|
||||
@@ -47,9 +47,9 @@ class Leave {
|
||||
this.billDate,
|
||||
required this.personId,
|
||||
required this.agentId,
|
||||
this.agentName = '',
|
||||
required this.agentName,
|
||||
required this.leaveType,
|
||||
this.leaveTypeName = '',
|
||||
required this.leaveTypeName,
|
||||
this.startTime,
|
||||
this.endTime,
|
||||
this.days = 0,
|
||||
@@ -70,7 +70,7 @@ class Leave {
|
||||
billDate: json['billdate'] != null ? DateTime.tryParse(json['billdate']) : null,
|
||||
personId: json['personid'] as String? ?? '',
|
||||
agentId: json['agentid'] as String? ?? '',
|
||||
agentName: json['agentname'] ?? '', /// 假設 API 會 Join 姓名
|
||||
agentName: json['agentName'] ?? '', /// 假設 API 會 Join 姓名
|
||||
leaveType: json['leavetype'] as String? ?? '',
|
||||
// leaveTypeName: json['leavetype_name'] ?? json['leavetype'] ?? '',
|
||||
leaveTypeName: typeName, // 這裡現在保證有值
|
||||
|
||||
Reference in New Issue
Block a user