Commit 0bfae6cc by wusiyi

feat: 工厂订单new添加默认时间排序功能 #1009800

parent 237d010d
......@@ -15,6 +15,43 @@ import type {
operateOrderListData,
} from '@/types/api/order/factoryOrderNew'
const CREATE_TIME_LIST_SORT_PROP = 'po.create_time'
/** 创建时间升序 */
const CREATE_TIME_SORT_ASC_STATUSES = new Set([
'PENDING_RECEIVE',
'PENDING_CREATE_LOGISTICS',
'PENDING_SCHEDULE',
'PENDING_PICK',
'PENDING_REPLENISH',
'IN_PRODUCTION',
'PENDING_PACKING',
'PENDING_DELIVERY',
'SUSPEND',
])
/** 创建时间降序 */
const CREATE_TIME_SORT_DESC_STATUSES = new Set([
'ALL',
'PICKING',
'COMPLETED',
'CANCELLED',
'ARCHIVE',
])
// 构建默认时间排序参数
export function getDefaultCreateTimeSortParams(
treeStatus: string,
): { prop: string; order: 'asc' | 'desc' } | null {
if (CREATE_TIME_SORT_ASC_STATUSES.has(treeStatus)) {
return { prop: CREATE_TIME_LIST_SORT_PROP, order: 'asc' }
}
if (CREATE_TIME_SORT_DESC_STATUSES.has(treeStatus)) {
return { prop: CREATE_TIME_LIST_SORT_PROP, order: 'desc' }
}
return null
}
interface UseOrderListAndDetailOptions {
status: Ref<string>
// 查询的状态树,与左侧状态树参数不同,用于挂起状态下suspendReason参数的修改
......@@ -53,6 +90,18 @@ export function useOrderListAndDetail(options: UseOrderListAndDetailOptions) {
const listSortProp = ref<string | null>(null)
const listSortOrder = ref<'asc' | 'desc' | null>(null)
// 默认排序参数
const applyDefaultListSort = () => {
const defaultSort = getDefaultCreateTimeSortParams(treeStatus.value)
if (defaultSort) {
listSortProp.value = defaultSort.prop
listSortOrder.value = defaultSort.order
} else {
listSortProp.value = null
listSortOrder.value = null
}
}
const buildListQueryBody = (): SearchForm => {
const base = { ...getQueryPayload() } as SearchForm
if (listSortProp.value && listSortOrder.value) {
......@@ -110,8 +159,7 @@ export function useOrderListAndDetail(options: UseOrderListAndDetailOptions) {
operationOrderList.value = []
logList.value = []
currentRow.value = null
listSortProp.value = null
listSortOrder.value = null
applyDefaultListSort()
}
const SORTABLE_COLUMN_PROPS = [
......@@ -125,7 +173,7 @@ export function useOrderListAndDetail(options: UseOrderListAndDetailOptions) {
(typeof SORTABLE_COLUMN_PROPS)[number],
string
> = {
createTime: 'po.create_time',
createTime: CREATE_TIME_LIST_SORT_PROP,
startStockingTime: 'po.start_stocking_time',
finishTime: 'po.finish_time',
}
......@@ -152,8 +200,7 @@ export function useOrderListAndDetail(options: UseOrderListAndDetailOptions) {
listSortProp.value = sortProp
listSortOrder.value = 'desc'
} else {
listSortProp.value = null
listSortOrder.value = null
applyDefaultListSort()
}
refreshTableList()
}
......
......@@ -1313,7 +1313,10 @@ import type { StatusTreeNode } from '@/types/api/order/factoryOrderNew'
import { useOrderDictionaries } from './hooks/useOrderDictionaries'
import { useOrderSearchForm } from './hooks/useOrderSearchForm'
import { useOrderStatusTree } from './hooks/useOrderStatusTree'
import { useOrderListAndDetail } from './hooks/useOrderListAndDetail'
import {
getDefaultCreateTimeSortParams,
useOrderListAndDetail,
} from './hooks/useOrderListAndDetail'
import { useOrderBatchActions } from './hooks/useOrderBatchActions'
import { ElButton, ElTag } from 'element-plus'
import OrderInventoryDetailDialog from './component/OrderInventoryDialog.vue'
......@@ -1454,6 +1457,12 @@ const getListQueryPayload = () => {
} else {
delete payload.status
}
// 添加默认时间排序参数
const defaultSort = getDefaultCreateTimeSortParams(status.value)
if (defaultSort) {
payload.prop = defaultSort.prop
payload.order = defaultSort.order
}
return payload
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment