feat: add descending sort by return date and color-coded warning for impending returns
This commit is contained in:
@ -199,7 +199,7 @@ class TransService:
|
|||||||
TransBorrow.sku.ilike(f'%{keyword}%') |
|
TransBorrow.sku.ilike(f'%{keyword}%') |
|
||||||
TransBorrow.borrow_no.ilike(f'%{keyword}%'))
|
TransBorrow.borrow_no.ilike(f'%{keyword}%'))
|
||||||
|
|
||||||
q = q.order_by(desc(TransBorrow.borrow_time))
|
q = q.order_by(desc(TransBorrow.expected_return_time))
|
||||||
pagination = q.paginate(page=page, per_page=limit, error_out=False)
|
pagination = q.paginate(page=page, per_page=limit, error_out=False)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@ -52,7 +52,7 @@
|
|||||||
<div v-else>
|
<div v-else>
|
||||||
<el-tag type="info" size="small">预计</el-tag>
|
<el-tag type="info" size="small">预计</el-tag>
|
||||||
{{ formatExpectedTime(row.expected_return_time).text }}
|
{{ formatExpectedTime(row.expected_return_time).text }}
|
||||||
<span :class="formatExpectedTime(row.expected_return_time).cssClass">
|
<span :style="formatExpectedTime(row.expected_return_time).style">
|
||||||
{{ formatExpectedTime(row.expected_return_time).diffText }}
|
{{ formatExpectedTime(row.expected_return_time).diffText }}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@ -166,7 +166,7 @@ const handlePage = (val: number) => {
|
|||||||
|
|
||||||
// ★ 新增:格式化预计归还时间及倒计时逻辑
|
// ★ 新增:格式化预计归还时间及倒计时逻辑
|
||||||
const formatExpectedTime = (timeStr: string) => {
|
const formatExpectedTime = (timeStr: string) => {
|
||||||
if (!timeStr) return { text: '无限期', diffText: '', cssClass: '' }
|
if (!timeStr) return { text: '无限期', diffText: '', style: {} }
|
||||||
|
|
||||||
// 后端返回的可能是 YYYY-MM-DD HH:mm:ss,我们只取日期部分比较
|
// 后端返回的可能是 YYYY-MM-DD HH:mm:ss,我们只取日期部分比较
|
||||||
const expected = dayjs(timeStr).startOf('day')
|
const expected = dayjs(timeStr).startOf('day')
|
||||||
@ -174,27 +174,27 @@ const formatExpectedTime = (timeStr: string) => {
|
|||||||
const diffDays = expected.diff(today, 'day')
|
const diffDays = expected.diff(today, 'day')
|
||||||
|
|
||||||
let diffText = ''
|
let diffText = ''
|
||||||
let cssClass = ''
|
let style: Record<string, string> = {}
|
||||||
|
|
||||||
// 这里的 timeStr 只展示前10位 (日期),或者展示完整
|
// 这里的 timeStr 只展示前10位 (日期),或者展示完整
|
||||||
// 需求说单号规则是日期,预计归还也主要看日期
|
// 需求说单号规则是日期,预计归还也主要看日期
|
||||||
const displayTime = timeStr.substring(0, 10)
|
const displayTime = timeStr.substring(0, 10)
|
||||||
|
|
||||||
if (diffDays < 0) {
|
if (diffDays <= 1) {
|
||||||
// 逾期
|
// 剩余1天及已逾期 - 红色加粗
|
||||||
diffText = ` (逾期 ${Math.abs(diffDays)} 天)`
|
diffText = diffDays < 0 ? ` (逾期 ${Math.abs(diffDays)} 天)` : diffDays === 0 ? ` (今天到期)` : ` (剩 ${diffDays} 天)`
|
||||||
cssClass = 'text-danger'
|
style = { color: '#F56C6C', fontWeight: 'bold' }
|
||||||
} else if (diffDays === 0) {
|
} else if (diffDays <= 7) {
|
||||||
// 今天到期
|
// 倒数7天内 - 警示黄
|
||||||
diffText = ` (今天到期)`
|
|
||||||
cssClass = 'text-warning'
|
|
||||||
} else {
|
|
||||||
// 剩余
|
|
||||||
diffText = ` (剩 ${diffDays} 天)`
|
diffText = ` (剩 ${diffDays} 天)`
|
||||||
cssClass = 'text-normal' // 正常,或者灰色
|
style = { color: '#E6A23C' }
|
||||||
|
} else {
|
||||||
|
// 正常 - 默认颜色
|
||||||
|
diffText = ` (剩 ${diffDays} 天)`
|
||||||
|
style = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { text: displayTime, diffText, cssClass }
|
return { text: displayTime, diffText, style }
|
||||||
}
|
}
|
||||||
|
|
||||||
// ★ 新增:表格行样式逻辑
|
// ★ 新增:表格行样式逻辑
|
||||||
|
|||||||
Reference in New Issue
Block a user