This commit is contained in:
van
2026-05-17 15:26:22 +08:00
parent 6d79995bcc
commit db893b5d95

View File

@@ -1410,6 +1410,8 @@ export default {
selectedRows: [], selectedRows: [],
// 列表加载后自动同步利润(防快速翻页乱序) // 列表加载后自动同步利润(防快速翻页乱序)
syncAutoProfitSeq: 0, syncAutoProfitSeq: 0,
/** 延后拉单条详情的防抖句柄(字符串 id -> timeout id */
_patchRowTimers: null,
/** 移动端卡片:当前展开的订单 idnull 表示全部收起,同时只展开一条) */ /** 移动端卡片:当前展开的订单 idnull 表示全部收起,同时只展开一条) */
mobileExpandedOrderId: null, mobileExpandedOrderId: null,
/** 视口高度(桌面端用于矮窗口下自动收起「跟进状态」筛选) */ /** 视口高度(桌面端用于矮窗口下自动收起「跟进状态」筛选) */
@@ -1511,6 +1513,7 @@ export default {
}, },
created() { created() {
this.applyMobileSlowOrderPageSize() this.applyMobileSlowOrderPageSize()
this._patchRowTimers = {}
// 设置默认日期为今天 // 设置默认日期为今天
this.setDefaultDateRange() this.setDefaultDateRange()
this.getListWithFallback() this.getListWithFallback()
@@ -1545,6 +1548,13 @@ export default {
if (this._onJdFilterViewportResize) { if (this._onJdFilterViewportResize) {
window.removeEventListener('resize', this._onJdFilterViewportResize) window.removeEventListener('resize', this._onJdFilterViewportResize)
} }
if (this._syncAutoProfitTimer) {
clearTimeout(this._syncAutoProfitTimer)
this._syncAutoProfitTimer = null
}
if (this._patchRowTimers) {
Object.keys(this._patchRowTimers).forEach(k => clearTimeout(this._patchRowTimers[k]))
}
}, },
methods: { methods: {
onJdFilterViewportResize() { onJdFilterViewportResize() {
@@ -1719,7 +1729,30 @@ export default {
if (!row || row.id == null) return if (!row || row.id == null) return
this.mobileExpandedOrderId = this.mobileExpandedOrderId === row.id ? null : row.id this.mobileExpandedOrderId = this.mobileExpandedOrderId === row.id ? null : row.id
}, },
/** 本页数据与库中规则对齐:仅未锁定利润的订单可能写库;有更新则静默拉一次列表(不再递归同步) */ /** 用户正在保存或与保存相关的回补时,取消「列表加载后自动同步利润」的挂起任务,避免与 PUT/GET 并发触发限流 */
invalidatePendingSyncAutoProfit() {
this.syncAutoProfitSeq++
if (this._syncAutoProfitTimer) {
clearTimeout(this._syncAutoProfitTimer)
this._syncAutoProfitTimer = null
}
},
/** 保存成功后错峰拉单条(替代与列表/同步抢同一时刻的带宽) */
schedulePatchOrderRowFromServer(id) {
if (id == null || !this._patchRowTimers) return
const sid = String(id)
if (this._patchRowTimers[sid]) {
clearTimeout(this._patchRowTimers[sid])
}
this._patchRowTimers[sid] = setTimeout(() => {
delete this._patchRowTimers[sid]
this.patchOrderRowFromServer(id)
}, 420)
},
/**
* 本页数据与库中规则对齐(未手填利润的订单后端可能微调);必要时再静默拉列表。
* 延迟较长并与 invalidatePendingSyncAutoProfit 递增的 seq 配合,避免与编辑保存 PUT、详情 GET 同一时间突发请求触发限流。
*/
runSyncAutoProfitAfterListLoad() { runSyncAutoProfitAfterListLoad() {
const ids = this.list.map(r => r.id).filter(id => id != null) const ids = this.list.map(r => r.id).filter(id => id != null)
if (!ids.length) return if (!ids.length) return
@@ -1737,7 +1770,7 @@ export default {
}) })
}) })
.catch(() => {}) .catch(() => {})
}, 120) }, 650)
}, },
getList() { getList() {
this.loading = true this.loading = true
@@ -2036,10 +2069,11 @@ export default {
return Promise.resolve() return Promise.resolve()
} }
this.ensureMoneyFieldsForPersist(row) this.ensureMoneyFieldsForPersist(row)
this.invalidatePendingSyncAutoProfit()
return updateJDOrder(row) return updateJDOrder(row)
.then(() => { .then(() => {
if (successMsg) this.$message.success(successMsg) if (successMsg) this.$message.success(successMsg)
this.patchOrderRowFromServer(row.id) this.schedulePatchOrderRowFromServer(row.id)
}) })
.catch(() => { .catch(() => {
this.$message.error('保存失败') this.$message.error('保存失败')
@@ -2242,10 +2276,11 @@ export default {
if (row.isRefunded === 0) { if (row.isRefunded === 0) {
row.refundDate = null row.refundDate = null
} }
this.invalidatePendingSyncAutoProfit()
// 调用后端API更新数据库 // 调用后端API更新数据库
updateJDOrder(row).then(() => { updateJDOrder(row).then(() => {
this.$message.success(`订单 ${row.remark} 的退款状态已更新`) this.$message.success(`订单 ${row.remark} 的退款状态已更新`)
this.patchOrderRowFromServer(row.id) this.schedulePatchOrderRowFromServer(row.id)
}).catch(() => { }).catch(() => {
this.$message.error('更新失败,请稍后重试') this.$message.error('更新失败,请稍后重试')
// 恢复原状态 // 恢复原状态