This commit is contained in:
van
2026-04-06 11:15:08 +08:00
parent db7687e7df
commit 679e0dd3af
3 changed files with 63 additions and 15 deletions

View File

@@ -1063,7 +1063,7 @@
</template>
<script>
import { listJDOrders, updateJDOrder, delJDOrder, fetchLogisticsManually, batchMarkRebateReceived, generateExcelText, importGroupRebateExcelBatch, listGroupRebateExcelUploads, deleteGroupRebateUpload, recalcProfitBatch } from '@/api/system/jdorder'
import { listJDOrders, getJDOrder, updateJDOrder, delJDOrder, fetchLogisticsManually, batchMarkRebateReceived, generateExcelText, importGroupRebateExcelBatch, listGroupRebateExcelUploads, deleteGroupRebateUpload, recalcProfitBatch, syncAutoProfitBatch } from '@/api/system/jdorder'
import { fillLogisticsByOrderNo, getTokenStatus, getTencentDocAuthUrl, testUserInfo, getAutoWriteConfig, reverseSyncThirdPartyOrderNo } from '@/api/jarvis/tendoc'
import { mapGetters } from 'vuex'
import ListLayout from '@/components/ListLayout'
@@ -1158,7 +1158,9 @@ export default {
// 已复制录单格式的订单ID集合页面级缓存刷新后消失
copiedExcelTextOrderIds: new Set(),
// 选中的行数据
selectedRows: []
selectedRows: [],
// 列表加载后自动同步利润(防快速翻页乱序)
syncAutoProfitSeq: 0
}
},
computed: {
@@ -1312,13 +1314,37 @@ export default {
profitManual: item.profitManual != null ? item.profitManual : 0
}
},
assignListFromResponse(res) {
const list = (res.rows || res.data || [])
this.list = list.map(item => this.normalizeOrderListItem(item))
this.total = res.total || 0
},
/** 本页数据与库中规则对齐:仅未锁定利润的订单可能写库;有更新则静默拉一次列表(不再递归同步) */
runSyncAutoProfitAfterListLoad() {
const ids = this.list.map(r => r.id).filter(id => id != null)
if (!ids.length) return
const seq = ++this.syncAutoProfitSeq
if (this._syncAutoProfitTimer) clearTimeout(this._syncAutoProfitTimer)
this._syncAutoProfitTimer = setTimeout(() => {
syncAutoProfitBatch(ids)
.then(res => {
if (seq !== this.syncAutoProfitSeq) return
const u = res && res.data && typeof res.data.updated === 'number' ? res.data.updated : 0
if (u <= 0) return
return listJDOrders(this.queryParams).then(r2 => {
if (seq !== this.syncAutoProfitSeq) return
this.assignListFromResponse(r2)
})
})
.catch(() => {})
}, 120)
},
getList() {
this.loading = true
listJDOrders(this.queryParams).then(res => {
const list = (res.rows || res.data || [])
this.list = list.map(item => this.normalizeOrderListItem(item))
this.total = res.total || 0
this.assignListFromResponse(res)
this.loading = false
this.runSyncAutoProfitAfterListLoad()
}).catch(() => { this.loading = false })
},
/** 智能查询列表,如果今天数据为空则查询昨天 */
@@ -1327,10 +1353,7 @@ export default {
try {
const res = await listJDOrders(this.queryParams)
let list = (res.rows || res.data || [])
list = list.map(item => this.normalizeOrderListItem(item))
this.list = list
this.total = res.total || 0
this.assignListFromResponse(res)
// 如果今天的数据为空,且是默认查询(没有手动选择日期),则尝试查询昨天
if (this.list.length === 0 && this.isDefaultQuery()) {
@@ -1348,11 +1371,7 @@ export default {
// 查询昨天的数据
const yesterdayRes = await listJDOrders(this.queryParams)
let yesterdayList = (yesterdayRes.rows || yesterdayRes.data || [])
// 为退款相关字段设置默认值
yesterdayList = yesterdayList.map(item => this.normalizeOrderListItem(item))
this.list = yesterdayList
this.total = yesterdayRes.total || 0
this.assignListFromResponse(yesterdayRes)
if (this.list.length > 0) {
this.$message.success(`已查询到昨天(${yesterdayStr})的慢单数据`)
@@ -1362,6 +1381,7 @@ export default {
}
this.loading = false
this.runSyncAutoProfitAfterListLoad()
} catch (error) {
this.loading = false
this.$message.error('查询失败,请稍后重试')
@@ -1591,10 +1611,25 @@ export default {
const reb = hasReb ? Number(row.rebateAmount) : 0
return (pay - reb).toFixed(2)
},
/** 保存后拉取单条,展示服务端重算后的利润/售价 */
patchOrderRowFromServer(id) {
if (id == null) return
getJDOrder(id)
.then(res => {
const raw = res && res.data
if (!raw) return
const idx = this.list.findIndex(r => r.id === id)
if (idx === -1) return
const merged = this.normalizeOrderListItem({ ...this.list[idx], ...raw })
this.$set(this.list, idx, merged)
})
.catch(() => {})
},
persistOrderRow(row, successMsg) {
return updateJDOrder(row)
.then(() => {
if (successMsg) this.$message.success(successMsg)
this.patchOrderRowFromServer(row.id)
})
.catch(() => {
this.$message.error('保存失败')
@@ -1603,10 +1638,12 @@ export default {
},
onOrderSellingPriceTypeChange(row) {
row.sellingPriceManual = 0
row.profitManual = 0
this.persistOrderRow(row)
},
onOrderSellingPriceChange(row) {
row.sellingPriceManual = 1
row.profitManual = 0
this.persistOrderRow(row)
},
onOrderProfitChange(row) {
@@ -1615,6 +1652,7 @@ export default {
},
fillSellingPriceFromConfig(row) {
row.sellingPriceManual = 0
row.profitManual = 0
this.persistOrderRow(row, '已按型号配置回填售价并重算利润')
},
recalcOrderProfitOnly(row) {