fix: 修复页面间状态丢失问题并优化选择页面
- 修复选择审批人后再选择抄送人导致状态丢失的问题 - 使用独立的 sessionStorage key (selectedApprovers, selectedCc) - 组件每次挂载时从 sessionStorage 恢复状态 - 只在提交/保存成功后清除 sessionStorage - 优化人员选择页面布局和样式 - 更新 CLAUDE.md 文档记录问题和解决方案 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class BusinessTrip extends Model
|
||||
{
|
||||
protected $table = 'business_trip';
|
||||
|
||||
protected $fillable = [
|
||||
'user_id',
|
||||
'reason',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'destination',
|
||||
'estimated_cost',
|
||||
'status',
|
||||
'approval_order_id',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'user_id' => 'integer',
|
||||
'estimated_cost' => 'decimal:2',
|
||||
'created_at' => 'datetime',
|
||||
'updated_at' => 'datetime',
|
||||
];
|
||||
|
||||
/**
|
||||
* 状态常量
|
||||
*/
|
||||
const STATUS_DRAFT = 'draft'; // 草稿
|
||||
const STATUS_PENDING = 'pending'; // 审批中
|
||||
const STATUS_APPROVED = 'approved'; // 已通过
|
||||
const STATUS_REJECTED = 'rejected'; // 已拒绝
|
||||
const STATUS_CANCELLED = 'cancelled'; // 已撤销
|
||||
|
||||
/**
|
||||
* 关联用户
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联行程明细
|
||||
*/
|
||||
public function itineraries()
|
||||
{
|
||||
return $this->hasMany(BusinessTripItinerary::class, 'business_trip_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联审批单
|
||||
*/
|
||||
public function approvalOrder()
|
||||
{
|
||||
return $this->belongsTo(ApprovalOrder::class, 'approval_order_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算总天数
|
||||
*/
|
||||
public function getDurationDays(): int
|
||||
{
|
||||
if (!$this->start_date || !$this->end_date) {
|
||||
return 0;
|
||||
}
|
||||
$start = \DateTime::createFromFormat('Y-m-d', $this->start_date);
|
||||
$end = \DateTime::createFromFormat('Y-m-d', $this->end_date);
|
||||
if (!$start || !$end) {
|
||||
return 0;
|
||||
}
|
||||
return $end->diff($start)->days + 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否可以编辑
|
||||
*/
|
||||
public function canEdit(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_DRAFT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否可以提交
|
||||
*/
|
||||
public function canSubmit(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_DRAFT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否可以取消
|
||||
*/
|
||||
public function canCancel(): bool
|
||||
{
|
||||
return $this->status === self::STATUS_PENDING;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user