1028 lines
33 KiB
Vue
1028 lines
33 KiB
Vue
<template>
|
||
<div class="order-sub-container">
|
||
<scan-box
|
||
ref="scanBox"
|
||
:width="waveScanBoxConfig.width"
|
||
:tree-props="waveScanBoxConfig.treeProps"
|
||
:auto-submit="waveScanBoxConfig.autoSubmit"
|
||
:preset-tree="presetTree"
|
||
:available-fields="pickTaskWaveAvailableFields"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
/>
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left" @wheel="handleToolbarWheel">
|
||
<div
|
||
class="toolbar-scroll-container"
|
||
ref="scrollContainerRef"
|
||
@mousedown="handleMouseDown"
|
||
@mousemove="handleMouseMove"
|
||
@mouseup="handleMouseUp"
|
||
@mouseleave="handleMouseUp"
|
||
>
|
||
<el-button
|
||
v-for="btn in pickTaskWaveToolbarButtons"
|
||
:key="btn.key"
|
||
:size="btn.size || 'small'"
|
||
:type="btn.type"
|
||
:plain="btn.plain"
|
||
:disabled="resolvePickToolbarDisabled(btn)"
|
||
:loading="resolvePickToolbarLoading(btn)"
|
||
@click="handlePickToolbarClick(btn.key)"
|
||
>
|
||
{{ resolvePickToolbarLabel(btn) }}
|
||
</el-button>
|
||
</div>
|
||
</div>
|
||
<div class="toolbar-right">
|
||
<span class="toolbar-switch-label">{{ pickTaskWaveListDefaults.toolbarHint }}</span>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="split-stack" ref="splitStackRef">
|
||
<div class="upper-wrapper" :style="upperPaneFullStyle">
|
||
<div class="upper-table-container small">
|
||
<div class="table-container">
|
||
<el-table
|
||
v-loading="loading"
|
||
:data="list"
|
||
style="width: 100%"
|
||
size="small"
|
||
@selection-change="handleSelectionChange"
|
||
border
|
||
stripe
|
||
height="100%"
|
||
>
|
||
<el-table-column type="selection" width="52" align="center" fixed="left" />
|
||
<el-table-column prop="task_id" label="任务ID" width="90" align="center" />
|
||
<el-table-column prop="task_no" label="任务编号" min-width="220" show-overflow-tooltip />
|
||
<el-table-column prop="batch_no" label="波次号" min-width="150" show-overflow-tooltip />
|
||
<el-table-column label="任务状态" width="110" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag size="small" :type="getPickTaskStatusTagType(row.status)">
|
||
{{ formatPickTaskStatus(row.status) }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="复核状态" width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag size="small" :type="getPickTaskReviewStatusTagType(row.review_status)">
|
||
{{ formatPickTaskReviewStatus(row.review_status) }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="拣货模式" width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag size="small" type="info">
|
||
{{ formatPickTaskPickMode(row.pick_mode) }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="来源" width="90" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag size="small" :type="getPickTaskSourceTagType(row.source)">
|
||
{{ formatPickTaskSource(row.source) }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="wave_count" label="波次数" width="90" align="right" />
|
||
<el-table-column prop="order_count" label="订单数" width="90" align="right" />
|
||
<el-table-column label="箱数" width="110" align="right">
|
||
<template #default="{ row }">
|
||
<el-tooltip v-if="row.box_count === 0" content="可能未统计" placement="top">
|
||
<span>{{ row.box_count }}</span>
|
||
</el-tooltip>
|
||
<span v-else>{{ row.box_count }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作人" min-width="120" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ row.operator_name || row.operator_id || '-' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="拣货员" min-width="120" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ row.pick_user_name || row.pick_user_id || '-' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="复核人" min-width="120" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ row.review_user_name || row.review_user_id || '-' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="current_cart_id" label="当前车ID" width="100" align="center" />
|
||
<el-table-column prop="current_cart_code_snapshot" label="当前车编码" min-width="140" show-overflow-tooltip />
|
||
<el-table-column prop="device_id" label="设备ID" min-width="140" show-overflow-tooltip />
|
||
<el-table-column label="开始时间" min-width="168" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ formatDateTime(row.start_at || row.start_time) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="完成时间" min-width="168" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ formatDateTime(row.finish_at || row.finish_time) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="复核开始" min-width="168" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ formatDateTime(row.review_start_time) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="复核完成" min-width="168" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ formatDateTime(row.review_finish_time) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="创建时间" min-width="168" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ formatDateTime(row.created_at || row.create_time) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="更新时间" min-width="168" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ formatDateTime(row.update_time) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="220" fixed="right" align="center">
|
||
<template #default="{ row }">
|
||
<el-button type="primary" link :disabled="!getTaskId(row)" @click="openTaskDetail(row)">详情</el-button>
|
||
<!-- <el-button
|
||
v-if="isSelfCreatedTask(row)"
|
||
type="warning"
|
||
link
|
||
:loading="cancelSelfTaskId === getTaskId(row)"
|
||
:disabled="!getTaskId(row) || isPickTaskCancelled(row)"
|
||
@click="handleCancelSelfTask(row)"
|
||
>
|
||
取消本人任务
|
||
</el-button> -->
|
||
<el-button
|
||
v-if="!isPickTaskCancelled(row)"
|
||
type="danger"
|
||
link
|
||
:loading="cancelingTaskId === getTaskId(row)"
|
||
:disabled="!getTaskId(row)"
|
||
@click="handleCancelTask(row)"
|
||
>
|
||
取消任务
|
||
</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
<template #empty>
|
||
<div class="empty-tip">{{ emptyText }}</div>
|
||
</template>
|
||
</el-table>
|
||
</div>
|
||
|
||
<div class="pagination-container">
|
||
<div class="pagination-info">
|
||
已选 {{ selectedTaskRows.length }} 条,查询用时 {{ (queryTime / 1000).toFixed(2) }} 秒
|
||
</div>
|
||
<el-pagination
|
||
:current-page="pagination.currentPage"
|
||
:page-size="pagination.pageSize"
|
||
:page-sizes="pickTaskWavePaginationPageSizes"
|
||
:total="pagination.total"
|
||
:layout="pickTaskWavePaginationDefaults.layout"
|
||
background
|
||
size="small"
|
||
@size-change="handlePageSizeChange"
|
||
@current-change="handlePageChange"
|
||
/>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<el-dialog
|
||
v-model="taskDetailDialogVisible"
|
||
:title="pickTaskWaveDetailDialogDefaults.title"
|
||
:width="pickTaskWaveDetailDialogDefaults.width"
|
||
destroy-on-close
|
||
align-center
|
||
class="pick-task-detail-dialog"
|
||
@closed="resetTaskDetailState"
|
||
>
|
||
<div v-if="taskDetailDialogMode === 'query'" class="pick-task-detail-query">
|
||
<el-form :model="taskDetailQueryForm" label-width="100px" @submit.prevent>
|
||
<el-form-item label="任务ID" required>
|
||
<el-input-number
|
||
v-model="taskDetailQueryForm.task_id"
|
||
:min="1"
|
||
:step="1"
|
||
controls-position="right"
|
||
placeholder="必填,对应 wms_wave_pick_task 主键"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" :loading="taskDetailLoading" @click="submitTaskDetailQuery">查询详情</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
</div>
|
||
|
||
<div v-loading="taskDetailLoading" class="pick-task-detail-body">
|
||
<el-alert
|
||
v-if="taskDetailPermissionHint"
|
||
:title="taskDetailPermissionHint"
|
||
type="info"
|
||
show-icon
|
||
:closable="false"
|
||
class="pick-task-detail-alert"
|
||
/>
|
||
<template v-if="taskDetailPayload && !taskDetailLoading">
|
||
<el-tabs v-model="taskDetailActiveTab" type="border-card">
|
||
<el-tab-pane label="任务 task" name="task">
|
||
<el-descriptions v-if="taskDetailTaskEntries.length" :column="2" border size="small">
|
||
<el-descriptions-item
|
||
v-for="(pair, idx) in taskDetailTaskEntries"
|
||
:key="'t-' + idx"
|
||
:label="String(pair[0])"
|
||
>
|
||
<span class="pick-task-detail-value">{{ formatDetailScalar(pair[1]) }}</span>
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
<el-empty v-else description="无 task 数据" />
|
||
</el-tab-pane>
|
||
<el-tab-pane label="箱列表 boxes" name="boxes">
|
||
<el-table v-if="taskDetailBoxes.length" :data="taskDetailBoxes" border size="small" max-height="360">
|
||
<el-table-column
|
||
v-for="col in taskDetailBoxesColumns"
|
||
:key="col"
|
||
:prop="col"
|
||
:label="col"
|
||
min-width="120"
|
||
show-overflow-tooltip
|
||
/>
|
||
</el-table>
|
||
<el-empty v-else description="无箱数据" />
|
||
</el-tab-pane>
|
||
<el-tab-pane label="拣货明细 picking_details" name="details">
|
||
<el-table v-if="taskDetailPickingDetails.length" :data="taskDetailPickingDetails" border size="small" max-height="360">
|
||
<el-table-column
|
||
v-for="col in taskDetailDetailColumns"
|
||
:key="col"
|
||
:prop="col"
|
||
:label="col"
|
||
min-width="120"
|
||
show-overflow-tooltip
|
||
/>
|
||
</el-table>
|
||
<el-empty v-else description="无明细数据" />
|
||
</el-tab-pane>
|
||
<el-tab-pane label="汇总 picking_summary" name="summary">
|
||
<el-descriptions v-if="taskDetailSummaryEntries.length" :column="1" border size="small">
|
||
<el-descriptions-item
|
||
v-for="(pair, idx) in taskDetailSummaryEntries"
|
||
:key="'s-' + idx"
|
||
:label="String(pair[0])"
|
||
>
|
||
<span class="pick-task-detail-value">{{ formatDetailScalar(pair[1]) }}</span>
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
<el-empty v-else description="无汇总数据" />
|
||
</el-tab-pane>
|
||
<el-tab-pane label="视图 picking_view" name="view">
|
||
<pre v-if="taskDetailViewJson" class="pick-task-detail-json">{{ taskDetailViewJson }}</pre>
|
||
<el-empty v-else description="无 picking_view 数据" />
|
||
</el-tab-pane>
|
||
</el-tabs>
|
||
</template>
|
||
</div>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import { useUserStore } from '@/stores/modules/user'
|
||
import {
|
||
orderWaveWavePickTaskCancel,
|
||
orderWaveWavePickTaskCancelSelf,
|
||
orderWaveWavePickTaskList
|
||
} from '@/api/order.wave/orderwave'
|
||
import { pickWavePickTaskDetail } from '@/api/pick/pick'
|
||
import {
|
||
waveScanBoxConfig,
|
||
pickTaskWaveAvailableFields,
|
||
pickTaskWaveListDefaults,
|
||
pickTaskWavePaginationDefaults,
|
||
pickTaskWavePaginationPageSizes,
|
||
pickTaskWaveDetailDialogDefaults,
|
||
pickTaskWaveToolbarButtons,
|
||
formatPickTaskStatus,
|
||
formatPickTaskReviewStatus,
|
||
formatPickTaskPickMode,
|
||
formatPickTaskSource,
|
||
getPickTaskStatusTagType,
|
||
getPickTaskReviewStatusTagType,
|
||
getPickTaskSourceTagType,
|
||
type PickTaskWaveToolbarButton,
|
||
type PickTaskWaveToolbarKey
|
||
} from './config/wave-config'
|
||
|
||
const userStore = useUserStore()
|
||
const loading = ref(false)
|
||
const list = ref<Array<Record<string, any>>>([])
|
||
const emptyText = ref(pickTaskWaveListDefaults.emptyText)
|
||
const scanBox = ref<any>(null)
|
||
const presetTree = ref<unknown[]>([])
|
||
const splitStackRef = ref<HTMLElement | null>(null)
|
||
const scrollContainerRef = ref<HTMLElement | null>(null)
|
||
const queryTime = ref(0)
|
||
const isDragging = ref(false)
|
||
const startX = ref(0)
|
||
const scrollLeft = ref(0)
|
||
const cancelingTaskId = ref<number | string | null>(null)
|
||
const batchCancelLoading = ref(false)
|
||
const selectedTaskRows = ref<Array<Record<string, any>>>([])
|
||
|
||
const pagination = reactive({
|
||
currentPage: 1,
|
||
pageSize: pickTaskWavePaginationDefaults.initialPageSize,
|
||
total: 0
|
||
})
|
||
|
||
const warehouseId = computed(() => Number(userStore.user?.warehouse_id ?? userStore.user?.store_id ?? 0))
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden' as const
|
||
}))
|
||
|
||
/** 与接口文档中 operator_id / pick_user_id(employees)对齐 */
|
||
const currentEmployeeId = computed(() => Number(userStore.user?.employees_id ?? userStore.roleId ?? 0))
|
||
|
||
const taskDetailDialogVisible = ref(false)
|
||
const taskDetailDialogMode = ref<'query' | 'row'>('query')
|
||
const taskDetailLoading = ref(false)
|
||
const taskDetailPayload = ref<Record<string, any> | null>(null)
|
||
const taskDetailPermissionHint = ref('')
|
||
const taskDetailActiveTab = ref('task')
|
||
const taskDetailQueryForm = reactive<{ task_id: number | undefined }>({ task_id: undefined })
|
||
|
||
const cancelSelfTaskId = ref<number | string | null>(null)
|
||
|
||
const taskDetailTaskEntries = computed(() => {
|
||
const t = taskDetailPayload.value?.task
|
||
if (!t || typeof t !== 'object') return [] as Array<[string, unknown]>
|
||
return Object.entries(t as Record<string, unknown>)
|
||
})
|
||
|
||
const taskDetailBoxes = computed(() => {
|
||
const b = taskDetailPayload.value?.boxes
|
||
return Array.isArray(b) ? b : []
|
||
})
|
||
|
||
function collectObjectKeys(rows: Array<Record<string, unknown>>): string[] {
|
||
const keys = new Set<string>()
|
||
for (const r of rows) {
|
||
if (r && typeof r === 'object') Object.keys(r).forEach((k) => keys.add(k))
|
||
}
|
||
return [...keys].sort((a, b) => a.localeCompare(b, 'zh-CN'))
|
||
}
|
||
|
||
const taskDetailBoxesColumns = computed(() =>
|
||
collectObjectKeys(taskDetailBoxes.value as Array<Record<string, unknown>>)
|
||
)
|
||
|
||
const taskDetailPickingDetails = computed(() => {
|
||
const d = taskDetailPayload.value?.picking_details
|
||
return Array.isArray(d) ? d : []
|
||
})
|
||
|
||
const taskDetailDetailColumns = computed(() =>
|
||
collectObjectKeys(taskDetailPickingDetails.value as Array<Record<string, unknown>>)
|
||
)
|
||
|
||
const taskDetailSummaryEntries = computed(() => {
|
||
const s = taskDetailPayload.value?.picking_summary
|
||
if (!s || typeof s !== 'object') return [] as Array<[string, unknown]>
|
||
return Object.entries(s as Record<string, unknown>)
|
||
})
|
||
|
||
const taskDetailViewJson = computed(() => {
|
||
const v = taskDetailPayload.value?.picking_view
|
||
if (v === undefined || v === null) return ''
|
||
try {
|
||
return JSON.stringify(v, null, 2)
|
||
} catch {
|
||
return String(v)
|
||
}
|
||
})
|
||
|
||
const okCode = (code: unknown) => code === 1 || code === 200 || code === 0
|
||
|
||
const handleToolbarWheel = (e: WheelEvent) => {
|
||
if (scrollContainerRef.value) {
|
||
e.preventDefault()
|
||
scrollContainerRef.value.scrollLeft += e.deltaY
|
||
}
|
||
}
|
||
|
||
const handleMouseDown = (e: MouseEvent) => {
|
||
if (!scrollContainerRef.value) return
|
||
isDragging.value = true
|
||
startX.value = e.pageX - scrollContainerRef.value.offsetLeft
|
||
scrollLeft.value = scrollContainerRef.value.scrollLeft
|
||
}
|
||
|
||
const handleMouseMove = (e: MouseEvent) => {
|
||
if (!isDragging.value || !scrollContainerRef.value) return
|
||
e.preventDefault()
|
||
const x = e.pageX - scrollContainerRef.value.offsetLeft
|
||
const walk = (x - startX.value) * 1.5
|
||
scrollContainerRef.value.scrollLeft = scrollLeft.value - walk
|
||
}
|
||
|
||
const handleMouseUp = () => {
|
||
isDragging.value = false
|
||
}
|
||
|
||
/** 将 ScanBox getConditions() 压平为接口入参(与 SandanWaveBatchListPanel 中 buildWhereConditions 一致) */
|
||
function buildPickTaskScanFilters(rawConditions: Record<string, any>) {
|
||
const out: Record<string, any> = {}
|
||
Object.keys(rawConditions || {}).forEach((key) => {
|
||
const condition = rawConditions[key]
|
||
if (condition && typeof condition === 'object' && 'operator' in condition) {
|
||
const value = condition.value
|
||
if (value === undefined || value === null || value === '' || (Array.isArray(value) && value.length === 0)) {
|
||
return
|
||
}
|
||
out[key] = value
|
||
return
|
||
}
|
||
if (condition !== undefined && condition !== null && condition !== '') {
|
||
out[key] = Array.isArray(condition) ? condition[0] ?? '' : condition
|
||
}
|
||
})
|
||
return out
|
||
}
|
||
|
||
function resolvePickToolbarDisabled(btn: PickTaskWaveToolbarButton): boolean {
|
||
if (btn.key === 'batchCancel') return selectedTaskRows.value.length === 0
|
||
return false
|
||
}
|
||
|
||
function resolvePickToolbarLoading(btn: PickTaskWaveToolbarButton): boolean {
|
||
if (btn.key === 'batchCancel') return batchCancelLoading.value
|
||
return false
|
||
}
|
||
|
||
function resolvePickToolbarLabel(btn: PickTaskWaveToolbarButton): string {
|
||
if (btn.key === 'batchCancel') {
|
||
return `${btn.label}(${selectedTaskRows.value.length})`
|
||
}
|
||
return btn.label
|
||
}
|
||
|
||
function handlePickToolbarClick(key: PickTaskWaveToolbarKey) {
|
||
switch (key) {
|
||
case 'search':
|
||
handleSearch()
|
||
break
|
||
case 'detailQuery':
|
||
openDetailQueryDialog()
|
||
break
|
||
case 'batchCancel':
|
||
void handleBatchCancelTasks()
|
||
break
|
||
case 'refresh':
|
||
void loadData()
|
||
break
|
||
default:
|
||
break
|
||
}
|
||
}
|
||
|
||
function toNumber(value: unknown, fallback = 0): number {
|
||
const num = Number(value)
|
||
return Number.isFinite(num) ? num : fallback
|
||
}
|
||
|
||
function normalizePickTaskRow(row: Record<string, any>) {
|
||
return {
|
||
...row,
|
||
raw: row,
|
||
task_id: toNumber(row.task_id),
|
||
warehouse_id: toNumber(row.warehouse_id),
|
||
pick_mode: toNumber(row.pick_mode),
|
||
status: toNumber(row.status),
|
||
review_status: toNumber(row.review_status),
|
||
source: toNumber(row.source),
|
||
wave_count: toNumber(row.wave_count),
|
||
order_count: toNumber(row.order_count),
|
||
box_count: toNumber(row.box_count),
|
||
/** 任务创建/操作人(与 pick_user_id 区分;接口 wavePickTaskCancelSelf 按创建人校验) */
|
||
operator_id: row.operator_id,
|
||
operator_name: row.operator_name || '',
|
||
pick_user_id: row.pick_user_id,
|
||
pick_user_name: row.pick_user_name || '',
|
||
start_at: row.start_at || row.start_time || '',
|
||
finish_at: row.finish_at || row.finish_time || '',
|
||
created_at: row.created_at || row.create_time || '',
|
||
update_time: row.update_time || ''
|
||
}
|
||
}
|
||
|
||
function formatDateTime(value: unknown): string {
|
||
if (value === null || value === undefined || value === '') return '-'
|
||
const text = String(value)
|
||
const ts = Number(text)
|
||
if (Number.isFinite(ts) && ts > 0) {
|
||
const date = new Date(ts)
|
||
if (!Number.isNaN(date.getTime())) {
|
||
return date.toLocaleString('zh-CN', { hour12: false })
|
||
}
|
||
}
|
||
const date = new Date(text)
|
||
if (!Number.isNaN(date.getTime())) {
|
||
return date.toLocaleString('zh-CN', { hour12: false })
|
||
}
|
||
return text
|
||
}
|
||
|
||
function getTaskId(row: Record<string, any>): number | string | null {
|
||
const taskId = row.task_id
|
||
if (taskId === null || taskId === undefined || taskId === '') return null
|
||
return taskId
|
||
}
|
||
|
||
function getValidTaskIds(rows: Array<Record<string, any>>): Array<number | string> {
|
||
return rows
|
||
.map((row) => getTaskId(row))
|
||
.filter((taskId): taskId is number | string => taskId !== null)
|
||
}
|
||
|
||
function formatDetailScalar(v: unknown): string {
|
||
if (v === null || v === undefined) return '—'
|
||
if (typeof v === 'object') {
|
||
try {
|
||
return JSON.stringify(v)
|
||
} catch {
|
||
return String(v)
|
||
}
|
||
}
|
||
return String(v)
|
||
}
|
||
|
||
/** order.wave.wavePickTaskCancelSelf:仅允许取消本人创建的任务(按 operator_id / creator 与当前登录 employees_id 对齐) */
|
||
function isSelfCreatedTask(row: Record<string, any>): boolean {
|
||
const cur = currentEmployeeId.value
|
||
if (!cur) return false
|
||
const oid = row.operator_id ?? row.raw?.operator_id ?? row.creator_id ?? row.created_by
|
||
const creatorId = Number(oid)
|
||
return Number.isFinite(creatorId) && creatorId > 0 && creatorId === cur
|
||
}
|
||
|
||
function isPickTaskCancelled(row: Record<string, any>): boolean {
|
||
return Number(row.status) === 9
|
||
}
|
||
|
||
function resetTaskDetailState() {
|
||
taskDetailPayload.value = null
|
||
taskDetailLoading.value = false
|
||
taskDetailActiveTab.value = 'task'
|
||
taskDetailPermissionHint.value = ''
|
||
taskDetailQueryForm.task_id = undefined
|
||
}
|
||
|
||
function openDetailQueryDialog() {
|
||
taskDetailDialogMode.value = 'query'
|
||
taskDetailPayload.value = null
|
||
taskDetailQueryForm.task_id = undefined
|
||
taskDetailPermissionHint.value =
|
||
'pick.wavePickTaskDetail:仅当拣货任务的 pick_user_id 与当前登录用户一致时可查看详情(否则接口 403)。'
|
||
taskDetailDialogVisible.value = true
|
||
}
|
||
|
||
function openTaskDetail(row: Record<string, any>) {
|
||
const id = getTaskId(row)
|
||
if (!id) {
|
||
ElMessage.warning('未获取到任务ID')
|
||
return
|
||
}
|
||
taskDetailDialogMode.value = 'row'
|
||
taskDetailQueryForm.task_id = Number(id)
|
||
taskDetailPayload.value = null
|
||
taskDetailPermissionHint.value =
|
||
'pick.wavePickTaskDetail:仅拣货员本人可查看完整详情(pick_user_id 需与当前账号一致)。'
|
||
taskDetailDialogVisible.value = true
|
||
void fetchTaskDetailById(Number(id))
|
||
}
|
||
|
||
function submitTaskDetailQuery() {
|
||
const tid = taskDetailQueryForm.task_id
|
||
if (tid === undefined || tid === null || !Number.isFinite(Number(tid)) || Number(tid) <= 0) {
|
||
ElMessage.warning('请输入有效的任务ID(正整数)')
|
||
return
|
||
}
|
||
void fetchTaskDetailById(Number(tid))
|
||
}
|
||
|
||
async function fetchTaskDetailById(taskId: number) {
|
||
taskDetailLoading.value = true
|
||
taskDetailPayload.value = null
|
||
try {
|
||
const res = await pickWavePickTaskDetail({ task_id: taskId })
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error((res as any)?.message || '获取拣货任务详情失败')
|
||
}
|
||
const inner =
|
||
res && typeof (res as any).data === 'object' && (res as any).data !== null && !Array.isArray((res as any).data)
|
||
? (res as any).data
|
||
: res
|
||
taskDetailPayload.value = inner as Record<string, any>
|
||
taskDetailActiveTab.value = 'task'
|
||
} catch (error: any) {
|
||
console.error('pickWavePickTaskDetail failed:', error)
|
||
ElMessage.error(error?.message || '获取拣货任务详情失败')
|
||
taskDetailPayload.value = null
|
||
} finally {
|
||
taskDetailLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function handleCancelSelfTask(row: Record<string, any>) {
|
||
const taskId = getTaskId(row)
|
||
if (!taskId) {
|
||
ElMessage.warning('未获取到任务ID')
|
||
return
|
||
}
|
||
if (!isSelfCreatedTask(row)) {
|
||
ElMessage.warning('仅可取消本人创建的任务')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确认取消本人创建的任务「${row.task_no || taskId}」吗?将调用 order.wave.wavePickTaskCancelSelf(仅单个 task_id)。`,
|
||
'取消本人拣货任务',
|
||
{
|
||
type: 'warning',
|
||
confirmButtonText: '确认取消',
|
||
cancelButtonText: '返回'
|
||
}
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
cancelSelfTaskId.value = taskId
|
||
try {
|
||
const res = await orderWaveWavePickTaskCancelSelf({ task_id: Number(taskId) })
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error((res as any)?.message || '取消本人任务失败')
|
||
}
|
||
const cancelled = Number(res.cancelled_count ?? (res as any).data?.cancelled_count ?? 0)
|
||
ElMessage.success(cancelled > 0 ? `已取消任务(${cancelled})` : '操作已提交')
|
||
await loadData()
|
||
} catch (error: any) {
|
||
console.error('wavePickTaskCancelSelf failed:', error)
|
||
ElMessage.error(error?.message || '取消本人任务失败')
|
||
} finally {
|
||
cancelSelfTaskId.value = null
|
||
}
|
||
}
|
||
|
||
async function loadData() {
|
||
const wid = warehouseId.value
|
||
if (!Number.isFinite(wid) || wid <= 0) {
|
||
emptyText.value = pickTaskWaveListDefaults.noWarehouseEmptyText
|
||
list.value = []
|
||
pagination.total = 0
|
||
queryTime.value = 0
|
||
return
|
||
}
|
||
|
||
if (loading.value) return
|
||
const start = Date.now()
|
||
loading.value = true
|
||
emptyText.value = pickTaskWaveListDefaults.loadingEmptyText
|
||
|
||
try {
|
||
const flat = buildPickTaskScanFilters(scanBox.value?.getConditions?.() || {})
|
||
const startRange = Array.isArray(flat.start_time_range) ? flat.start_time_range : []
|
||
const res = await orderWaveWavePickTaskList({
|
||
warehouse_id: wid,
|
||
page_no: pagination.currentPage,
|
||
page_size: pagination.pageSize,
|
||
status: flat.status,
|
||
review_status: flat.review_status,
|
||
pick_mode: flat.pick_mode,
|
||
source:
|
||
flat.source === undefined || flat.source === null || flat.source === '' ? undefined : String(flat.source),
|
||
pick_user_id: flat.pick_user_id,
|
||
review_user_id: flat.review_user_id,
|
||
task_no: String(flat.task_no || '').trim() || undefined,
|
||
cart_id: flat.cart_id,
|
||
keyword: String(flat.keyword || '').trim() || undefined,
|
||
start_time_start: startRange[0] || undefined,
|
||
start_time_end: startRange[1] || undefined
|
||
})
|
||
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '获取拣货任务列表失败')
|
||
}
|
||
|
||
const responseList = Array.isArray(res.list)
|
||
? res.list
|
||
: Array.isArray(res.data?.list)
|
||
? res.data.list
|
||
: []
|
||
|
||
const responseTotal = Number(res.total ?? res.data?.total ?? 0)
|
||
const responsePage = Number(res.page ?? res.data?.page ?? pagination.currentPage)
|
||
const responsePageSize = Number(res.page_size ?? res.data?.page_size ?? pagination.pageSize)
|
||
|
||
list.value = responseList.map((item) => normalizePickTaskRow(item as Record<string, any>))
|
||
selectedTaskRows.value = []
|
||
pagination.total = Number.isFinite(responseTotal) ? responseTotal : 0
|
||
pagination.currentPage = Number.isFinite(responsePage) && responsePage > 0 ? responsePage : pagination.currentPage
|
||
pagination.pageSize = Number.isFinite(responsePageSize) && responsePageSize > 0 ? responsePageSize : pagination.pageSize
|
||
emptyText.value = pickTaskWaveListDefaults.emptyText
|
||
} catch (error: any) {
|
||
console.error('load wave pick task list failed:', error)
|
||
ElMessage.error(error?.message || '获取拣货任务列表失败')
|
||
list.value = []
|
||
pagination.total = 0
|
||
emptyText.value = pickTaskWaveListDefaults.loadFailedEmptyText
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Date.now() - start
|
||
}
|
||
}
|
||
|
||
function handleSearch() {
|
||
pagination.currentPage = 1
|
||
void loadData()
|
||
}
|
||
|
||
function handleConditionChange() {
|
||
pagination.currentPage = 1
|
||
void loadData()
|
||
}
|
||
|
||
function handleSelectionChange(rows: Array<Record<string, any>>) {
|
||
selectedTaskRows.value = rows
|
||
}
|
||
|
||
function handleConditionClear() {
|
||
pagination.currentPage = 1
|
||
void loadData()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
pagination.currentPage = 1
|
||
scanBox.value?.reset?.()
|
||
void loadData()
|
||
}
|
||
|
||
async function handleCancelTask(row: Record<string, any>) {
|
||
const taskId = getTaskId(row)
|
||
if (!taskId) {
|
||
ElMessage.warning('未获取到任务ID')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确认取消任务 ${row.task_no || taskId} 吗?取消后会释放关联波次并回池订单。`,
|
||
'取消拣货任务',
|
||
{
|
||
type: 'warning',
|
||
confirmButtonText: '确认取消',
|
||
cancelButtonText: '返回'
|
||
}
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
cancelingTaskId.value = taskId
|
||
try {
|
||
await cancelTasks([taskId])
|
||
} catch (error: any) {
|
||
console.error('cancel wave pick task failed:', error)
|
||
ElMessage.error(error?.message || '取消拣货任务失败')
|
||
} finally {
|
||
cancelingTaskId.value = null
|
||
}
|
||
}
|
||
|
||
async function handleBatchCancelTasks() {
|
||
const taskIds = getValidTaskIds(selectedTaskRows.value)
|
||
if (taskIds.length === 0) {
|
||
ElMessage.warning('请先选择要取消的任务')
|
||
return
|
||
}
|
||
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确认批量取消 ${taskIds.length} 个任务吗?取消后会释放关联波次并回池订单。`,
|
||
'批量取消拣货任务',
|
||
{
|
||
type: 'warning',
|
||
confirmButtonText: '确认取消',
|
||
cancelButtonText: '返回'
|
||
}
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
batchCancelLoading.value = true
|
||
try {
|
||
await cancelTasks(taskIds)
|
||
} catch (error: any) {
|
||
console.error('batch cancel wave pick task failed:', error)
|
||
ElMessage.error(error?.message || '批量取消拣货任务失败')
|
||
} finally {
|
||
batchCancelLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function cancelTasks(taskIds: Array<number | string>) {
|
||
const res = await orderWaveWavePickTaskCancel({ task_ids: taskIds })
|
||
if (!res || !okCode(res.code)) {
|
||
throw new Error(res?.message || '取消拣货任务失败')
|
||
}
|
||
|
||
const cancelledCount = Number(res.cancelled_count ?? res.data?.cancelled_count ?? 0)
|
||
ElMessage.success(cancelledCount > 0 ? `已取消 ${cancelledCount} 个任务` : '取消任务成功')
|
||
|
||
if (list.value.length === taskIds.length && pagination.currentPage > 1) {
|
||
pagination.currentPage -= 1
|
||
}
|
||
await loadData()
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
void loadData()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
void loadData()
|
||
}
|
||
|
||
watch(
|
||
warehouseId,
|
||
(next, prev) => {
|
||
if (next === prev) return
|
||
pagination.currentPage = 1
|
||
void loadData()
|
||
}
|
||
)
|
||
|
||
onMounted(() => {
|
||
void loadData()
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@use "../orderManagement/styles/order-sub.scss";
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
line-height: 1.5;
|
||
}
|
||
|
||
/* 与 UpperTable 主表白卡片一致(散单页 upper-table 同款阴影与圆角) */
|
||
.upper-wrapper :deep(.upper-table-container) {
|
||
border-radius: 4px;
|
||
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
||
position: relative;
|
||
}
|
||
|
||
/* 与 SandanWaveBatchListPanel.vue 工具栏块一致 */
|
||
.order-sub-container .main-content {
|
||
.toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
|
||
.toolbar-right {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
flex-shrink: 0;
|
||
padding-left: 8px;
|
||
}
|
||
|
||
.toolbar-switch-label {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-regular);
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.toolbar-left {
|
||
cursor: grab;
|
||
|
||
&:active {
|
||
cursor: grabbing;
|
||
}
|
||
|
||
.toolbar-scroll-container {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
overflow-x: auto;
|
||
scrollbar-width: none;
|
||
|
||
&::-webkit-scrollbar {
|
||
display: none;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/* 与 UpperTable 底部分页条一致 */
|
||
.pagination-container {
|
||
padding: 5px 10px;
|
||
border-top: 1px solid #e8e8e8;
|
||
background: #fff;
|
||
display: flex;
|
||
flex-direction: row;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
flex-wrap: wrap;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.pagination-container .pagination-info {
|
||
font-size: 12px;
|
||
color: #606266;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.pagination-container :deep(.el-pagination__sizes),
|
||
.pagination-container :deep(.el-pagination__jump),
|
||
.pagination-container :deep(.el-pagination__total) {
|
||
display: inline-flex !important;
|
||
margin-right: 8px;
|
||
}
|
||
|
||
.pagination-container :deep(.el-pagination) {
|
||
flex-wrap: wrap;
|
||
justify-content: flex-end;
|
||
--el-pagination-button-width: 28px;
|
||
--el-pagination-button-height: 28px;
|
||
}
|
||
|
||
.pagination-container :deep(.el-select--small) {
|
||
width: 80px;
|
||
}
|
||
|
||
.pagination-container :deep(.el-input__wrapper) {
|
||
padding: 0 4px;
|
||
}
|
||
|
||
.upper-table-container.small :deep(.el-table) {
|
||
font-size: 12px;
|
||
}
|
||
|
||
.upper-table-container.small :deep(.el-table td),
|
||
.upper-table-container.small :deep(.el-table th) {
|
||
padding: 6px 0;
|
||
}
|
||
|
||
.pick-task-detail-query {
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.pick-task-detail-alert {
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.pick-task-detail-body {
|
||
min-height: 120px;
|
||
}
|
||
|
||
.pick-task-detail-value {
|
||
word-break: break-all;
|
||
}
|
||
|
||
.pick-task-detail-json {
|
||
margin: 0;
|
||
padding: 12px;
|
||
max-height: 420px;
|
||
overflow: auto;
|
||
font-size: 12px;
|
||
line-height: 1.45;
|
||
background: #f5f7fa;
|
||
border-radius: 4px;
|
||
}
|
||
</style>
|