refactor(crm order item): 移排序逻辑到后端并简化前端代码
1. 将原前端的分组排序逻辑迁移到后端service实现 2. 后端实现三级排序:交货日期倒序→订单ID升序→创建时间倒序,保证跨页排序一致性和合同组连续排列 3. 移除前端冗余的groupSort方法和排序状态变量,简化前端页面逻辑 4. 更新前端排序提示文案为固定描述
This commit is contained in:
@@ -76,7 +76,7 @@
|
||||
/>
|
||||
<el-button type="primary" size="small" icon="el-icon-search" @click="handleQuery">筛选</el-button>
|
||||
<el-button size="small" icon="el-icon-refresh" @click="resetQuery">重置</el-button>
|
||||
<span v-if="sortInfo" class="sort-hint">{{ sortInfo }}</span>
|
||||
<span class="sort-hint">已按合同交货日期倒序 + 明细创建时间倒序排列</span>
|
||||
</div>
|
||||
|
||||
<!-- 订单明细表格 -->
|
||||
@@ -345,9 +345,7 @@ export default {
|
||||
// 存储原始数据,用于判断是否有修改
|
||||
originalData: {},
|
||||
// 表面处理选项
|
||||
surfaceTreatmentOptions: [],
|
||||
// 排序状态提示
|
||||
sortInfo: ''
|
||||
surfaceTreatmentOptions: []
|
||||
}
|
||||
},
|
||||
created() {
|
||||
@@ -382,7 +380,7 @@ export default {
|
||||
// 批量获取合同信息
|
||||
this.loadContractInfo(orderIds, items)
|
||||
} else {
|
||||
this.orderItemList = this.groupSort(items)
|
||||
this.orderItemList = items
|
||||
this.loading = false
|
||||
}
|
||||
}).catch(e => {
|
||||
@@ -405,8 +403,8 @@ export default {
|
||||
contracts.forEach(contract => {
|
||||
this.contractMap[contract.orderId] = contract
|
||||
})
|
||||
// 合并数据
|
||||
const merged = items.map(item => {
|
||||
// 直接合并数据(后端已按 deliveryDate DESC + createTime DESC 排序)
|
||||
this.orderItemList = items.map(item => {
|
||||
const contract = this.contractMap[item.orderId] || {}
|
||||
return {
|
||||
...item,
|
||||
@@ -417,8 +415,6 @@ export default {
|
||||
deliveryDate: contract.deliveryDate || ''
|
||||
}
|
||||
})
|
||||
// 排序后赋值
|
||||
this.orderItemList = this.groupSort(merged)
|
||||
// 保存原始数据副本
|
||||
this.originalData = {}
|
||||
this.orderItemList.forEach(row => {
|
||||
@@ -426,53 +422,12 @@ export default {
|
||||
})
|
||||
}).catch(e => {
|
||||
console.error(e)
|
||||
this.orderItemList = this.groupSort(items)
|
||||
this.orderItemList = items
|
||||
}).finally(() => {
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
|
||||
// 分组排序:组间按交货日期倒序,组内按创建时间倒序
|
||||
groupSort(items) {
|
||||
if (!items || items.length === 0) {
|
||||
this.sortInfo = ''
|
||||
this._groupColorIndex = 0
|
||||
return items
|
||||
}
|
||||
// 构建每个orderId对应的deliveryDate映射
|
||||
const deliveryDateMap = {}
|
||||
items.forEach(item => {
|
||||
if (item.orderId && !deliveryDateMap[item.orderId]) {
|
||||
deliveryDateMap[item.orderId] = item.deliveryDate || ''
|
||||
}
|
||||
})
|
||||
const sorted = [...items].sort((a, b) => {
|
||||
// 同组:按createTime倒序
|
||||
if (a.orderId && a.orderId === b.orderId) {
|
||||
const timeA = a.createTime || ''
|
||||
const timeB = b.createTime || ''
|
||||
if (timeA === timeB) return 0
|
||||
if (!timeA) return 1
|
||||
if (!timeB) return -1
|
||||
return timeB > timeA ? 1 : -1
|
||||
}
|
||||
// 异组:按deliveryDate倒序
|
||||
const dateA = deliveryDateMap[a.orderId] || ''
|
||||
const dateB = deliveryDateMap[b.orderId] || ''
|
||||
if (dateA === dateB) {
|
||||
// 交货日期相同或都为空时,按orderId排序保证分组连续
|
||||
return (a.orderId || 0) - (b.orderId || 0)
|
||||
}
|
||||
if (!dateA) return 1
|
||||
if (!dateB) return -1
|
||||
return dateB > dateA ? 1 : -1
|
||||
})
|
||||
// 设置排序状态提示
|
||||
const groupCount = Object.keys(deliveryDateMap).length
|
||||
this.sortInfo = `已按合同交货日期倒序 + 明细创建时间倒序排列(共${groupCount}个合同组)`
|
||||
return sorted
|
||||
},
|
||||
|
||||
// 分组行样式:同一合同组使用交替背景色
|
||||
groupRowClassName({ row, rowIndex }) {
|
||||
// 记录上一个orderId,切换时翻转颜色
|
||||
|
||||
Reference in New Issue
Block a user