448 lines
19 KiB
Vue
448 lines
19 KiB
Vue
<!-- 生产管理 — 生产任务 -->
|
||
<template>
|
||
<div class="page-container">
|
||
<header class="page-head">
|
||
<h1>生产任务</h1>
|
||
<p class="page-desc">管理生产工单下的任务执行,跟踪工艺步骤及物料消耗。</p>
|
||
</header>
|
||
|
||
<section class="panel">
|
||
<div class="panel-top">
|
||
<h2>任务列表</h2>
|
||
</div>
|
||
|
||
<div class="filter-block">
|
||
<el-form :model="searchForm" class="filter-form" @submit.prevent>
|
||
<div class="filter-grid">
|
||
<el-form-item label="关键词">
|
||
<el-input v-model="searchForm.keyword" placeholder="任务号/所属工单号/协议号/样本编码" clearable @keyup.enter="handleSearch" />
|
||
</el-form-item>
|
||
<el-form-item label="任务状态">
|
||
<el-select v-model="searchForm.taskStatus" placeholder="全部" clearable style="width: 100%">
|
||
<el-option label="待配置" value="dpz" />
|
||
<el-option label="进行中" value="jxz" />
|
||
<el-option label="已完成" value="ywc" />
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="开始时间">
|
||
<el-date-picker
|
||
v-model="startedTimeRange"
|
||
type="daterange"
|
||
range-separator="至"
|
||
start-placeholder="开始日期"
|
||
end-placeholder="结束日期"
|
||
value-format="YYYY-MM-DD"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
</div>
|
||
<div class="filter-actions-row">
|
||
<span class="filter-hint">默认展示近 30 天内已开始的任务;清空日期可查看尚未开始的待配置任务。</span>
|
||
<div class="filter-actions-end">
|
||
<el-button class="btn-ghost" @click="handleReset"><el-icon><RefreshLeft /></el-icon>重置</el-button>
|
||
<el-button class="btn-main" type="primary" @click="handleSearch"><el-icon><Search /></el-icon>搜索</el-button>
|
||
</div>
|
||
</div>
|
||
</el-form>
|
||
</div>
|
||
|
||
<div class="list-body list-wrap">
|
||
<el-table
|
||
class="list-table"
|
||
:data="tableData"
|
||
v-loading="loading"
|
||
stripe
|
||
@row-dblclick="handleViewDetail"
|
||
>
|
||
<el-table-column type="index" label="序号" min-width="68" align="center" :index="(i: number) => (pagination.page - 1) * pagination.pageSize + i + 1" />
|
||
<el-table-column prop="taskNo" label="任务号" min-width="150" align="center" />
|
||
<el-table-column prop="workOrderNo" label="所属工单号" min-width="140" align="center" />
|
||
<el-table-column prop="orderSource" label="来源" min-width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="row.orderSource === 'temporary' ? 'warning' : 'success'" size="small">
|
||
{{ row.orderSource === 'temporary' ? '临时' : '入库' }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="protocolNo" label="协议号" min-width="140" align="center">
|
||
<template #default="{ row }">{{ row.protocolNo || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="protocolStatus" label="协议状态" min-width="100" align="center">
|
||
<template #default="{ row }">
|
||
<span v-if="shouldShowTempEmptyField(row, row.protocolStatus)">—</span>
|
||
<el-tag
|
||
v-else
|
||
:type="protocolStatusTagTypeBySource(String(row.protocolStatus || ''), row.receptionSource || 'cell_storage')"
|
||
size="small"
|
||
>{{ protocolStatusLabelBySource(String(row.protocolStatus || ''), row.receptionSource || 'cell_storage') }}</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="sampleCode" label="样本编码" min-width="130" align="center">
|
||
<template #default="{ row }">{{ row.sampleCode || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="sampleTypeName" label="样本类型" min-width="110" align="center">
|
||
<template #default="{ row }">{{ row.sampleTypeName || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="taskType" label="任务类型" min-width="120" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="taskTypeTag(row.taskType, row.orderSource).type" size="small">{{ taskTypeTag(row.taskType, row.orderSource).label }}</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="taskName" label="任务名称" min-width="160" align="center" show-overflow-tooltip />
|
||
<el-table-column prop="routeName" label="工艺路线" min-width="140" align="center" show-overflow-tooltip>
|
||
<template #default="{ row }">{{ row.routeName || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="receiverName" label="接收人" min-width="100" align="center">
|
||
<template #default="{ row }">{{ row.receiverName || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="receptionTime" label="接收时间" min-width="170" align="center">
|
||
<template #default="{ row }">{{ row.receptionTime || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="taskStatus" label="任务状态" min-width="110" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="taskStatusTag(row.taskStatus).type" size="small">{{ taskStatusTag(row.taskStatus).label }}</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="conclusion" label="生产结论" min-width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag
|
||
v-if="productionConclusionTagType(row.conclusion)"
|
||
:type="productionConclusionTagType(row.conclusion)"
|
||
size="small"
|
||
>
|
||
{{ row.conclusionLabel || productionConclusionLabel(row.conclusion) }}
|
||
</el-tag>
|
||
<span v-else>—</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="startedTime" label="开始时间" min-width="170" align="center">
|
||
<template #default="{ row }">{{ row.startedTime || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="completedTime" label="完成时间" min-width="170" align="center">
|
||
<template #default="{ row }">{{ row.completedTime || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" min-width="400" fixed="right" align="center">
|
||
<template #default="{ row }">
|
||
<el-button class="btn-op-item primary" @click="handleEnterExecution(row)"><el-icon><VideoPlay /></el-icon>进入执行</el-button>
|
||
<el-button class="btn-op-item" @click="handleEditTask(row)">
|
||
<el-icon><EditPen /></el-icon>编辑
|
||
</el-button>
|
||
<el-button class="btn-op-item" @click="handleViewDetail(row)"><el-icon><View /></el-icon>查看详情</el-button>
|
||
<el-button v-if="row.taskStatus === 'dpz'" class="btn-op-item" @click="handleDelete(row)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div class="pagination list-pager-bar">
|
||
<el-pagination
|
||
:current-page="pagination.page"
|
||
:page-size="pagination.pageSize"
|
||
:total="pagination.total"
|
||
:page-sizes="[10, 20, 50]"
|
||
layout="total, sizes, prev, pager, next"
|
||
@size-change="(val: number) => ((pagination.page = 1), (pagination.pageSize = val), loadData())"
|
||
@current-change="(val: number) => ((pagination.page = val), loadData())"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 任务执行弹窗 -->
|
||
<TaskExecutionDialog
|
||
v-model:visible="executionDialogVisible"
|
||
:task-id="executionTaskId"
|
||
:task-name="executionTaskName"
|
||
:readonly="executionReadonly"
|
||
@success="loadData"
|
||
/>
|
||
|
||
<el-dialog
|
||
v-model="addSelectWoVisible"
|
||
title="选择生产工单"
|
||
width="800px"
|
||
align-center
|
||
destroy-on-close
|
||
>
|
||
<div style="margin-bottom: 12px">
|
||
<el-input
|
||
v-model="addSelectWoKeyword"
|
||
placeholder="搜索工单号/协议号/样本编码"
|
||
clearable
|
||
@keyup.enter="searchWorkOrders"
|
||
>
|
||
<template #append>
|
||
<el-button @click="searchWorkOrders"><el-icon><Search /></el-icon></el-button>
|
||
</template>
|
||
</el-input>
|
||
</div>
|
||
<el-table
|
||
:data="addSelectWoList"
|
||
v-loading="addSelectWoLoading"
|
||
stripe
|
||
style="width: 100%"
|
||
max-height="400"
|
||
@row-click="selectWorkOrder"
|
||
highlight-current-row
|
||
>
|
||
<el-table-column prop="workOrderNo" label="工单号" min-width="150" align="center" />
|
||
<el-table-column prop="protocolNo" label="协议号" min-width="140" align="center">
|
||
<template #default="{ row }">{{ row.protocolNo || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="sampleCode" label="样本编码" min-width="120" align="center">
|
||
<template #default="{ row }">{{ row.sampleCode || '—' }}</template>
|
||
</el-table-column>
|
||
<el-table-column prop="receptionSource" label="来源" min-width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="row.receptionSource === 'research_donation' ? 'warning' : 'success'" size="small">
|
||
{{ row.receptionSourceLabel || (row.receptionSource === 'research_donation' ? '科研捐赠' : '细胞存储') }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="workOrderStatus" label="状态" min-width="100" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag :type="row.workOrderStatus === 'jxz' ? 'warning' : 'info'" size="small">
|
||
{{ row.workOrderStatus === 'jxz' ? '进行中' : '待配置' }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" min-width="100" align="center" fixed="right">
|
||
<template #default="{ row }">
|
||
<el-button link type="primary" size="small" @click.stop="selectWorkOrder(row)">选择</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<el-empty v-if="!addSelectWoLoading && !addSelectWoList.length" description="暂无可选工单" :image-size="48" />
|
||
</el-dialog>
|
||
|
||
<DispatchTaskDialog
|
||
v-model:visible="addDispatchVisible"
|
||
:work-order-row="addDispatchRow"
|
||
@success="loadData"
|
||
/>
|
||
|
||
<EditTaskInfoDialog
|
||
v-model:visible="editTaskInfoVisible"
|
||
:task-id="editTaskInfoId"
|
||
@success="loadData"
|
||
/>
|
||
</section>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { RefreshLeft, Search, VideoPlay, View, Plus, Close, Check, EditPen } from '@element-plus/icons-vue'
|
||
import { fetchProductionTaskList, fetchDeleteProductionTask } from '@/api/production-task'
|
||
import { fetchProductionWorkOrderList } from '@/api/production-work-order'
|
||
import {
|
||
protocolStatusLabel,
|
||
protocolStatusTagType,
|
||
donationStatusLabel,
|
||
donationStatusTagType,
|
||
} from '@/utils/status-tag-registry'
|
||
import type { TagType } from '@/utils/status-tag-registry'
|
||
import TaskExecutionDialog from '../production-work-order/TaskExecutionDialog.vue'
|
||
import DispatchTaskDialog from '../production-work-order/DispatchTaskDialog.vue'
|
||
import EditTaskInfoDialog from '../production-work-order/EditTaskInfoDialog.vue'
|
||
import {
|
||
productionConclusionLabel,
|
||
productionConclusionTagType
|
||
} from '@/utils/production-labels'
|
||
|
||
/** 根据来源类型返回协议状态标签 */
|
||
function protocolStatusLabelBySource(status: string, source: string): string {
|
||
return source === 'research_donation' ? donationStatusLabel(status) : protocolStatusLabel(status)
|
||
}
|
||
function protocolStatusTagTypeBySource(status: string, source: string): TagType {
|
||
return source === 'research_donation' ? donationStatusTagType(status) : protocolStatusTagType(status)
|
||
}
|
||
|
||
/** 临时工单无关联协议/样本时,空字段展示为 — */
|
||
function shouldShowTempEmptyField(row: { orderSource?: string }, value?: string | null) {
|
||
return row.orderSource === 'temporary' && !String(value || '').trim()
|
||
}
|
||
|
||
defineOptions({ name: 'ProductionProductionTask' })
|
||
|
||
// ── 新增任务(工单选择 → 复用 DispatchTaskDialog) ──
|
||
const addSelectWoVisible = ref(false)
|
||
const addSelectWoList = ref<Record<string, any>[]>([])
|
||
const addSelectWoLoading = ref(false)
|
||
const addSelectWoKeyword = ref('')
|
||
const addDispatchVisible = ref(false)
|
||
const addDispatchRow = ref<Record<string, any> | null>(null)
|
||
|
||
async function handleAdd() {
|
||
addSelectWoKeyword.value = ''
|
||
addSelectWoVisible.value = true
|
||
addSelectWoLoading.value = true
|
||
try {
|
||
const res = await fetchProductionWorkOrderList({ pageSize: 100 })
|
||
addSelectWoList.value = (res.list || []).filter(
|
||
(wo: Record<string, any>) => wo.workOrderStatus === 'dpz' || wo.workOrderStatus === 'jxz'
|
||
)
|
||
} catch {
|
||
addSelectWoList.value = []
|
||
} finally {
|
||
addSelectWoLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function searchWorkOrders() {
|
||
addSelectWoLoading.value = true
|
||
try {
|
||
const res = await fetchProductionWorkOrderList({
|
||
keyword: addSelectWoKeyword.value || undefined,
|
||
pageSize: 100
|
||
})
|
||
addSelectWoList.value = (res.list || []).filter(
|
||
(wo: Record<string, any>) => wo.workOrderStatus === 'dpz' || wo.workOrderStatus === 'jxz'
|
||
)
|
||
} catch {
|
||
addSelectWoList.value = []
|
||
} finally {
|
||
addSelectWoLoading.value = false
|
||
}
|
||
}
|
||
|
||
function selectWorkOrder(row: Record<string, any>) {
|
||
addDispatchRow.value = row
|
||
addSelectWoVisible.value = false
|
||
addDispatchVisible.value = true
|
||
}
|
||
|
||
const route = useRoute()
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// 状态标签映射
|
||
// ---------------------------------------------------------------------------
|
||
function taskStatusTag(status: string) {
|
||
const map: Record<string, { label: string; type: string }> = {
|
||
dpz: { label: '待配置', type: 'info' },
|
||
jxz: { label: '进行中', type: 'warning' },
|
||
ywc: { label: '已完成', type: 'success' }
|
||
}
|
||
return map[status] || { label: status, type: 'info' }
|
||
}
|
||
|
||
function taskTypeTag(taskType: string, orderSource?: string) {
|
||
if (orderSource === 'temporary') {
|
||
return { label: '临时生产单', type: 'warning' }
|
||
}
|
||
const map: Record<string, { label: string; type: string }> = {
|
||
cell_storage: { label: '入库生产单', type: 'primary' },
|
||
outbound: { label: '出库生产单', type: 'warning' }
|
||
}
|
||
return map[taskType] || { label: taskType, type: 'info' }
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// 列表视图
|
||
// ---------------------------------------------------------------------------
|
||
function formatLocalDate(d: Date): string {
|
||
const y = d.getFullYear()
|
||
const m = String(d.getMonth() + 1).padStart(2, '0')
|
||
const day = String(d.getDate()).padStart(2, '0')
|
||
return `${y}-${m}-${day}`
|
||
}
|
||
|
||
function getDefaultLast30DaysRange(): [string, string] {
|
||
const end = new Date()
|
||
const start = new Date()
|
||
start.setDate(start.getDate() - 30)
|
||
return [formatLocalDate(start), formatLocalDate(end)]
|
||
}
|
||
|
||
const searchForm = reactive({ keyword: '', taskStatus: '' })
|
||
const startedTimeRange = ref<[string, string] | null>(getDefaultLast30DaysRange())
|
||
const tableData = ref<Record<string, any>[]>([])
|
||
const loading = ref(false)
|
||
const pagination = reactive({ page: 1, pageSize: 10, total: 0 })
|
||
|
||
async function handleDelete(row: any) {
|
||
await ElMessageBox.confirm('确定要删除该生产任务吗?', '提示', { type: 'warning' })
|
||
await fetchDeleteProductionTask(row.id)
|
||
ElMessage.success('删除成功')
|
||
await loadData()
|
||
}
|
||
|
||
async function loadData() {
|
||
loading.value = true
|
||
try {
|
||
const res = await fetchProductionTaskList({
|
||
page: pagination.page,
|
||
pageSize: pagination.pageSize,
|
||
keyword: searchForm.keyword || undefined,
|
||
taskStatus: searchForm.taskStatus || undefined,
|
||
startedTimeStart: startedTimeRange.value?.[0] || undefined,
|
||
startedTimeEnd: startedTimeRange.value?.[1] || undefined
|
||
})
|
||
tableData.value = res.list || []
|
||
pagination.total = res.total ?? 0
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function handleSearch() {
|
||
pagination.page = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleReset() {
|
||
searchForm.keyword = ''
|
||
searchForm.taskStatus = ''
|
||
startedTimeRange.value = getDefaultLast30DaysRange()
|
||
pagination.page = 1
|
||
loadData()
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// 任务执行弹窗
|
||
// ---------------------------------------------------------------------------
|
||
const executionDialogVisible = ref(false)
|
||
const executionTaskId = ref('')
|
||
const executionTaskName = ref('')
|
||
const executionReadonly = ref(false)
|
||
|
||
function handleEnterExecution(row: Record<string, any>) {
|
||
executionTaskId.value = row.id
|
||
executionTaskName.value = row.taskName || ''
|
||
executionReadonly.value = false
|
||
executionDialogVisible.value = true
|
||
}
|
||
|
||
function handleViewDetail(row: Record<string, any>) {
|
||
executionTaskId.value = row.id
|
||
executionTaskName.value = row.taskName || ''
|
||
executionReadonly.value = true
|
||
executionDialogVisible.value = true
|
||
}
|
||
|
||
const editTaskInfoVisible = ref(false)
|
||
const editTaskInfoId = ref('')
|
||
|
||
function handleEditTask(row: Record<string, any>) {
|
||
editTaskInfoId.value = row.id
|
||
editTaskInfoVisible.value = true
|
||
}
|
||
|
||
// ---------------------------------------------------------------------------
|
||
// 初始化(支持从工单页面跳转带 keyword 筛选)
|
||
// ---------------------------------------------------------------------------
|
||
// 输入检索条件时自动搜索(防抖 300ms)
|
||
watchDebounced(
|
||
[searchForm, startedTimeRange],
|
||
() => {
|
||
pagination.page = 1
|
||
loadData()
|
||
},
|
||
{ debounce: 300, deep: true }
|
||
)
|
||
onMounted(() => {
|
||
const qKeyword = (route.query.keyword || route.query.workOrderNo) as string
|
||
if (qKeyword) {
|
||
searchForm.keyword = qKeyword
|
||
}
|
||
loadData()
|
||
})
|
||
</script>
|