接单工单状态筛选支持多选
- 前端:状态筛选改为多选(Select mode=multiple),可一次筛选多个状态 - 后端:listWorkOrders 支持 statuses 数组查询(ANY 匹配),兼容旧单状态参数 - 批量验收入口仅在单独筛选待验收时显示,避免多选误操作
This commit is contained in:
@@ -209,7 +209,10 @@ export type GrabWorkOrderResult = {
|
||||
export type ListInput = {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
/** 单状态筛选(兼容 worker 用户等其他列表) */
|
||||
status?: string
|
||||
/** 支持多个状态同时筛选(空数组表示全部状态) */
|
||||
statuses?: string[]
|
||||
keyword?: string
|
||||
workerId?: number
|
||||
categoryId?: number
|
||||
|
||||
@@ -737,6 +737,7 @@ export async function listWorkOrdersByPlatformOrderId(
|
||||
export async function listWorkOrders({
|
||||
page = 1,
|
||||
pageSize = 20,
|
||||
statuses = [],
|
||||
status = '',
|
||||
keyword = '',
|
||||
workerId = 0,
|
||||
@@ -745,8 +746,10 @@ export async function listWorkOrders({
|
||||
visibleAfterIso = '',
|
||||
sort = 'id_desc',
|
||||
}: ListInput = {}): Promise<{ items: WorkOrderRow[]; total: number }> {
|
||||
const effectiveStatuses =
|
||||
statuses.length > 0 ? statuses : status.trim() ? [status.trim()] : []
|
||||
const { whereClause, params } = buildWorkOrderWhere({
|
||||
status,
|
||||
statuses: effectiveStatuses,
|
||||
keyword,
|
||||
workerId,
|
||||
categoryId,
|
||||
@@ -2522,7 +2525,7 @@ async function getWorkOrderByIdWithClient(
|
||||
}
|
||||
|
||||
function buildWorkOrderWhere({
|
||||
status = '',
|
||||
statuses = [],
|
||||
keyword = '',
|
||||
workerId = 0,
|
||||
categoryId = 0,
|
||||
@@ -2531,9 +2534,16 @@ function buildWorkOrderWhere({
|
||||
}: ListInput) {
|
||||
const filters: string[] = []
|
||||
const params: unknown[] = []
|
||||
if (status) {
|
||||
params.push(status)
|
||||
filters.push(`wo.status = $${params.length}`)
|
||||
const normalizedStatuses = [
|
||||
...new Set(
|
||||
statuses
|
||||
.map((item) => String(item || '').trim())
|
||||
.filter(Boolean),
|
||||
),
|
||||
]
|
||||
if (normalizedStatuses.length > 0) {
|
||||
params.push(normalizedStatuses)
|
||||
filters.push(`wo.status = ANY($${params.length}::text[])`)
|
||||
}
|
||||
if (keyword) {
|
||||
params.push(`%${keyword}%`)
|
||||
|
||||
@@ -92,7 +92,7 @@ import {
|
||||
saveWorkerFinanceConfig,
|
||||
} from './worker-finance-config-service.js'
|
||||
|
||||
import { DEFAULT_CATEGORY_KEY, DEFAULT_DEPOSIT_THRESHOLD_AMOUNT, DEFAULT_LEVEL_KEY, DEFAULT_LEVEL_NAME, mapFinanceRequest, mapWallet, mapWorkCategory, mapWorkOrderAdmin, mapWorkOrderShare, mapWorkProductRule, mapWorkerLevel, mapWorkerUser, normalizeAdminFinanceReviewStatus, normalizeAmountFen, normalizeBoolean, normalizeEnabledStatus, normalizeFinanceRequestStatus, normalizeFinanceRequestType, normalizeInteger, normalizeMatchType, normalizeOptionalId, normalizePositiveInteger, normalizeProblemResolutionAction, normalizeRequirementFields, normalizeRequirementFieldsFromPayload, normalizeReviewStatus, normalizeSessionVersion, normalizeSlugKey, normalizeSubmittedFields, normalizeUploadedFiles, normalizeWorkerType, resolveFreezeDepositAmount, resolveMatchingProductRule, resolveRequirementFields, resolveSkuNameQuantity, resolveWorkerPermissions } from './mappers.js'
|
||||
import { DEFAULT_CATEGORY_KEY, DEFAULT_DEPOSIT_THRESHOLD_AMOUNT, DEFAULT_LEVEL_KEY, DEFAULT_LEVEL_NAME, mapFinanceRequest, mapWallet, mapWorkCategory, mapWorkOrderAdmin, mapWorkOrderShare, mapWorkProductRule, mapWorkerLevel, mapWorkerUser, normalizeAdminFinanceReviewStatus, normalizeAmountFen, normalizeBoolean, normalizeEnabledStatus, normalizeFinanceRequestStatus, normalizeFinanceRequestType, normalizeInteger, normalizeMatchType, normalizeOptionalId, normalizePositiveInteger, normalizeProblemResolutionAction, normalizeRequirementFields, normalizeRequirementFieldsFromPayload, normalizeReviewStatus, normalizeSessionVersion, normalizeSlugKey, normalizeStatuses, normalizeSubmittedFields, normalizeUploadedFiles, normalizeWorkerType, resolveFreezeDepositAmount, resolveMatchingProductRule, resolveRequirementFields, resolveSkuNameQuantity, resolveWorkerPermissions } from './mappers.js'
|
||||
import { ensureWorkerPlatformDefaults, getRequiredWorkOrder, getRequiredWorker, normalizeWorkOrderTimeoutPolicy } from './worker-service.js'
|
||||
|
||||
export async function listAdminWorkerLevels() {
|
||||
@@ -566,7 +566,7 @@ export async function listAdminWorkOrders(query: JsonObject = {}) {
|
||||
const { items, total } = await listWorkOrders({
|
||||
page,
|
||||
pageSize,
|
||||
status: String(query.status || '').trim(),
|
||||
statuses: normalizeStatuses(query.status),
|
||||
keyword: String(query.keyword || '').trim(),
|
||||
workerSharingId: workerId,
|
||||
})
|
||||
@@ -1321,9 +1321,9 @@ export async function cancelAdminWorkOrder(
|
||||
export async function getAdminWorkerPlatformSummary() {
|
||||
const [pendingWorkers, pendingMaterial, openOrders, inProgressOrders] = await Promise.all([
|
||||
listWorkerUsers({ page: 1, pageSize: 1, status: 'pending_review' }),
|
||||
listWorkOrders({ page: 1, pageSize: 1, status: WORK_ORDER_STATUS.PENDING_MATERIAL }),
|
||||
listWorkOrders({ page: 1, pageSize: 1, status: WORK_ORDER_STATUS.OPEN }),
|
||||
listWorkOrders({ page: 1, pageSize: 1, status: WORK_ORDER_STATUS.IN_PROGRESS }),
|
||||
listWorkOrders({ page: 1, pageSize: 1, statuses: [WORK_ORDER_STATUS.PENDING_MATERIAL] }),
|
||||
listWorkOrders({ page: 1, pageSize: 1, statuses: [WORK_ORDER_STATUS.OPEN] }),
|
||||
listWorkOrders({ page: 1, pageSize: 1, statuses: [WORK_ORDER_STATUS.IN_PROGRESS] }),
|
||||
])
|
||||
return {
|
||||
pendingWorkerCount: pendingWorkers.total,
|
||||
|
||||
@@ -758,6 +758,27 @@ export function normalizeStringArray(value: unknown): string[] {
|
||||
return value.map((item) => String(item || '').trim()).filter(Boolean)
|
||||
}
|
||||
|
||||
/**
|
||||
* 将查询参数中的状态过滤解析为去重后的状态数组。
|
||||
* 支持:逗号分隔的字符串(如 "open,in_progress")、字符串数组、单个字符串。
|
||||
*/
|
||||
export function normalizeStatuses(value: unknown): string[] {
|
||||
const rawList: unknown[] = Array.isArray(value)
|
||||
? value
|
||||
: typeof value === 'string' && value.trim()
|
||||
? value.split(',')
|
||||
: value === undefined || value === null
|
||||
? []
|
||||
: [value]
|
||||
return [
|
||||
...new Set(
|
||||
rawList
|
||||
.map((item) => String(item || '').trim())
|
||||
.filter(Boolean),
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
export function normalizeUploadedFiles(value: unknown) {
|
||||
if (!Array.isArray(value)) return []
|
||||
return value
|
||||
|
||||
@@ -101,7 +101,7 @@ import {
|
||||
saveWorkerFinanceConfig,
|
||||
} from './worker-finance-config-service.js'
|
||||
|
||||
import { DEFAULT_CATEGORY_KEY, DEFAULT_LEVEL_KEY, DEFAULT_LEVEL_NAME, INVITE_CODE_LENGTH, INVITE_CODE_RETRY_LIMIT, createWorkerSession, ensureWorkerAuthConfigured, hashWorkerPassword, isIgnorableWorkerAuthError, mapCollectLookupOrder, mapFinanceRequest, mapWalletLedger, mapWorkCategory, mapWorkOrderForWorker, mapWorkOrderPublic, mapWorkOrderShare, mapWorkerUser, normalizeAmountFen, normalizeFinanceRequestStatus, normalizeFinanceRequestType, normalizeInteger, normalizeOptionalId, normalizePassword, normalizePositiveInteger, normalizeProofFiles, normalizeSessionVersion, normalizeStringArray, normalizeSubmittedFields, normalizeUploadedFiles, normalizeUsername, normalizeWalletLedgerType, normalizeWithdrawChannel, resolveFreezeDepositAmount, resolveRequirementFields, resolveWorkerPermissions, safeCompare, signWorkerPayload, throwGrabWorkOrderFailure, validateWorkerPassword, validateWorkerUsername, verifyWorkerPassword } from './mappers.js'
|
||||
import { DEFAULT_CATEGORY_KEY, DEFAULT_LEVEL_KEY, DEFAULT_LEVEL_NAME, INVITE_CODE_LENGTH, INVITE_CODE_RETRY_LIMIT, createWorkerSession, ensureWorkerAuthConfigured, hashWorkerPassword, isIgnorableWorkerAuthError, mapCollectLookupOrder, mapFinanceRequest, mapWalletLedger, mapWorkCategory, mapWorkOrderForWorker, mapWorkOrderPublic, mapWorkOrderShare, mapWorkerUser, normalizeAmountFen, normalizeFinanceRequestStatus, normalizeFinanceRequestType, normalizeInteger, normalizeOptionalId, normalizePassword, normalizePositiveInteger, normalizeProofFiles, normalizeSessionVersion, normalizeStatuses, normalizeStringArray, normalizeSubmittedFields, normalizeUploadedFiles, normalizeUsername, normalizeWalletLedgerType, normalizeWithdrawChannel, resolveFreezeDepositAmount, resolveRequirementFields, resolveWorkerPermissions, safeCompare, signWorkerPayload, throwGrabWorkOrderFailure, validateWorkerPassword, validateWorkerUsername, verifyWorkerPassword } from './mappers.js'
|
||||
|
||||
export type WorkerSession = {
|
||||
sessionId: string
|
||||
@@ -820,7 +820,7 @@ export async function listWorkerHallOrders(query: JsonObject = {}, session: Work
|
||||
const { items, total } = await listWorkOrders({
|
||||
page,
|
||||
pageSize,
|
||||
status: WORK_ORDER_STATUS.OPEN,
|
||||
statuses: [WORK_ORDER_STATUS.OPEN],
|
||||
keyword: String(query.keyword || '').trim(),
|
||||
categoryId: categoryId || 0,
|
||||
visibleAfterIso,
|
||||
@@ -991,7 +991,7 @@ export async function listWorkerMyOrders(query: JsonObject = {}, session: Worker
|
||||
const { items, total } = await listWorkOrders({
|
||||
page,
|
||||
pageSize,
|
||||
status: String(query.status || '').trim(),
|
||||
statuses: normalizeStatuses(query.status),
|
||||
keyword: String(query.keyword || '').trim(),
|
||||
workerSharingId: worker.id,
|
||||
sort: 'worker_claimed_at_desc',
|
||||
|
||||
Reference in New Issue
Block a user