This commit is contained in:
zlwu committed 2026-08-18 17:23:46 +08:00
1 parent 0707a4c95e
commit 21e772db3a
25 files changed
+9914 -12166

No files matched your search

+6
View File
@@ -87,6 +87,12 @@ export function fetchCreateProductionTaskSetFromWorkOrder(data: {
workOrderId: string
setName: string
remark?: string
items?: Array<{
taskName: string
routeId?: string
description?: string
remark?: string
}>
}) {
return request.post<ProductionTaskSet>({
url: '/web/admin/production-task-sets/from-work-order',
+10 -1
View File
@@ -10,7 +10,16 @@ export function fetchCreateProductionTask(data: Record<string, any>) {
return request.post({ url: '/web/admin/production-tasks', params: data })
}
export function fetchCreateProductionTasksFromSet(data: { workOrderId: string; setId: string }) {
export function fetchCreateProductionTasksFromSet(data: {
workOrderId: string
setId: string
items?: Array<{
taskName: string
routeId?: string
description?: string
remark?: string
}>
}) {
return request.post<{ createdCount: number; list: any[] }>({
url: '/web/admin/production-tasks/from-set',
params: data
+1 -1
View File
@@ -929,7 +929,7 @@ export const sqxpAdminRoutes: AppRouteRecord[] = [
path: 'production-task-set',
component: '/production/production-task-set/index',
meta: {
title: '生产任务集合',
title: '生产任务组合模版',
keepAlive: true,
menuCode: 'production:task-set:list'
}
@@ -140,7 +140,7 @@
<el-dialog
v-model="dialogVisible"
:title="dialogTitle"
width="860px"
width="1200px"
class="dialog-form-layout"
align-center
append-to-body
@@ -151,7 +151,7 @@
<el-form
ref="formRef"
:model="formData"
:rules="isView ? {} : formRules"
:rules="formRules"
label-position="top"
class="biz-dialog-form"
scroll-to-error
@@ -163,11 +163,10 @@
v-model="formData.setName"
placeholder="请输入集合名称"
maxlength="200"
:disabled="isView"
/>
</el-form-item>
<el-form-item label="状态" prop="status">
<el-radio-group v-model="formData.status" :disabled="isView">
<el-radio-group v-model="formData.status">
<el-radio value="1">启用</el-radio>
<el-radio value="0">停用</el-radio>
</el-radio-group>
@@ -179,93 +178,132 @@
:rows="2"
placeholder="可选"
maxlength="512"
:disabled="isView"
/>
</el-form-item>
<el-form-item class="form-col-span-2" prop="items">
<div class="set-items-toolbar">
<span class="set-items-title">任务条目</span>
<el-button v-if="!isView" class="btn-ghost" @click="addItem">
<el-icon><Plus /></el-icon>添加条目
</el-button>
<el-form-item class="form-col-span-2 set-items-field" prop="items" label="任务条目">
<div class="set-items-block">
<div class="list-toolbar">
<div class="list-toolbar-row">
<el-button class="btn-main" type="primary" @click="addItem">
<el-icon><Plus /></el-icon>添加条目
</el-button>
</div>
</div>
<div class="list-body list-wrap inner-table-wrap">
<el-table
class="list-table"
:data="formData.items"
stripe
:row-key="itemRowKey"
>
<el-table-column
type="index"
label="序号"
min-width="68"
align="center"
header-align="center"
:index="(index) => index + 1"
/>
<el-table-column
label="任务名称"
min-width="180"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-input
v-model="row.taskName"
placeholder="请输入任务名称"
maxlength="200"
/>
</template>
</el-table-column>
<el-table-column
label="工艺路线"
min-width="220"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-select
v-model="row.routeId"
placeholder="输入路线名称检索(可选)"
filterable
remote
reserve-keyword
clearable
style="width: 100%"
:loading="routeLoading"
:remote-method="remoteSearchRoutes"
@visible-change="onRouteSelectVisible"
>
<el-option
v-for="route in routeOptions"
:key="route.id"
:label="`${route.routeName}(${route.routeCode})`"
:value="route.id"
/>
</el-select>
</template>
</el-table-column>
<el-table-column
label="描述"
min-width="180"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-input
v-model="row.description"
placeholder="可选"
maxlength="500"
/>
</template>
</el-table-column>
<el-table-column
label="备注"
min-width="160"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-input
v-model="row.remark"
placeholder="可选"
maxlength="512"
/>
</template>
</el-table-column>
<el-table-column
label="操作"
min-width="280"
fixed="right"
align="center"
header-align="center"
>
<template #default="{ $index }">
<el-button
class="btn-op-item"
:disabled="$index === 0"
@click="moveItem($index, -1)"
>
<el-icon><Top /></el-icon>上移
</el-button>
<el-button
class="btn-op-item"
:disabled="$index === formData.items.length - 1"
@click="moveItem($index, 1)"
>
<el-icon><Bottom /></el-icon>下移
</el-button>
<el-button class="btn-op-item" @click="removeItem($index)">
<el-icon><Delete /></el-icon>删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
<el-table class="list-table" :data="formData.items" stripe :row-key="itemRowKey">
<el-table-column label="任务名称" min-width="160">
<template #default="{ row }">
<el-input
v-model="row.taskName"
placeholder="请输入任务名称"
maxlength="200"
:disabled="isView"
/>
</template>
</el-table-column>
<el-table-column label="工艺路线" min-width="200">
<template #default="{ row }">
<el-select
v-model="row.routeId"
placeholder="输入路线名称检索(可选)"
filterable
remote
reserve-keyword
clearable
style="width: 100%"
:disabled="isView"
:loading="routeLoading"
:remote-method="remoteSearchRoutes"
@visible-change="onRouteSelectVisible"
>
<el-option
v-for="route in routeOptions"
:key="route.id"
:label="`${route.routeName}(${route.routeCode})`"
:value="route.id"
/>
</el-select>
</template>
</el-table-column>
<el-table-column label="描述" min-width="160">
<template #default="{ row }">
<el-input
v-model="row.description"
placeholder="可选"
maxlength="500"
:disabled="isView"
/>
</template>
</el-table-column>
<el-table-column label="备注" min-width="140">
<template #default="{ row }">
<el-input
v-model="row.remark"
placeholder="可选"
maxlength="512"
:disabled="isView"
/>
</template>
</el-table-column>
<el-table-column v-if="!isView" label="操作" min-width="200" fixed="right">
<template #default="{ $index }">
<el-button
class="btn-op-item"
:disabled="$index === 0"
@click="moveItem($index, -1)"
>
<el-icon><Top /></el-icon>上移
</el-button>
<el-button
class="btn-op-item"
:disabled="$index === formData.items.length - 1"
@click="moveItem($index, 1)"
>
<el-icon><Bottom /></el-icon>下移
</el-button>
<el-button class="btn-op-item" @click="removeItem($index)">
<el-icon><Delete /></el-icon>删除
</el-button>
</template>
</el-table-column>
</el-table>
</el-form-item>
</div>
</el-form>
@@ -274,7 +312,6 @@
<el-icon><Close /></el-icon>取消
</el-button>
<el-button
v-if="!isView"
class="btn-main"
type="primary"
:loading="submitLoading"
@@ -284,6 +321,67 @@
</el-button>
</template>
</el-dialog>
<SystemViewDialog
v-model:visible="viewVisible"
:title="viewRow?.setName || '集合详情'"
:icon="Collection"
:sections="viewSections"
:loading="viewLoading"
width="960px"
:grid-columns="3"
>
<template #set-items>
<div v-if="viewItems.length" class="view-subtable-wrap">
<el-table :data="viewItems" stripe class="list-table view-subtable">
<el-table-column
type="index"
label="序号"
min-width="68"
align="center"
header-align="center"
/>
<el-table-column
label="任务名称"
min-width="160"
align="center"
header-align="center"
show-overflow-tooltip
>
<template #default="{ row }">{{ row.taskName || '—' }}</template>
</el-table-column>
<el-table-column
label="工艺路线"
min-width="160"
align="center"
header-align="center"
show-overflow-tooltip
>
<template #default="{ row }">{{ row.routeName || '—' }}</template>
</el-table-column>
<el-table-column
label="描述"
min-width="160"
align="center"
header-align="center"
show-overflow-tooltip
>
<template #default="{ row }">{{ row.description || '—' }}</template>
</el-table-column>
<el-table-column
label="备注"
min-width="140"
align="center"
header-align="center"
show-overflow-tooltip
>
<template #default="{ row }">{{ row.remark || '—' }}</template>
</el-table-column>
</el-table>
</div>
<p v-else class="view-empty-hint">暂无任务条目</p>
</template>
</SystemViewDialog>
</section>
</div>
</template>
@@ -303,9 +401,11 @@
Switch,
View,
Top,
Bottom
Bottom,
Collection
} from '@element-plus/icons-vue'
import { useMenuPerm } from '@/hooks/core/useMenuPerm'
import SystemViewDialog from '@/components/business/system-view-dialog/index.vue'
import { fetchProcessRouteList } from '@/api/production'
import {
fetchProductionTaskSetList,
@@ -332,14 +432,42 @@
const pagination = reactive({ page: 1, pageSize: 10, total: 0 })
const dialogVisible = ref(false)
const dialogTitle = ref('新增集合')
const dialogMode = ref<'add' | 'edit' | 'view'>('add')
const dialogMode = ref<'add' | 'edit'>('add')
const submitLoading = ref(false)
const formRef = ref()
const editingId = ref<string | null>(null)
const routeOptions = ref<any[]>([])
const routeLoading = ref(false)
const viewVisible = ref(false)
const viewLoading = ref(false)
const viewRow = ref<ProductionTaskSet | null>(null)
const isView = computed(() => dialogMode.value === 'view')
const viewItems = computed(() => viewRow.value?.items || [])
const viewSections = computed(() => {
const row = viewRow.value
if (!row) return []
return [
{
title: '基本信息',
fields: [
{ label: '集合名称', value: row.setName },
{
label: '状态',
value: row.status === '1' ? '启用' : '停用',
tagType: row.status === '1' ? 'success' : 'info'
},
{ label: '任务条数', value: row.itemCount ?? viewItems.value.length },
{ label: '创建时间', value: formatDisplayOrDash(row.createTime) },
{ label: '备注', value: row.remark }
]
},
{
title: '任务条目',
slot: 'set-items',
fields: []
}
]
})
const formData = reactive({
setName: '',
@@ -488,9 +616,9 @@
void remoteSearchRoutes('')
}
async function openDetailDialog(row: ProductionTaskSet, mode: 'edit' | 'view') {
dialogMode.value = mode
dialogTitle.value = mode === 'edit' ? '编辑集合' : '查看集合'
async function handleEdit(row: ProductionTaskSet) {
dialogMode.value = 'edit'
dialogTitle.value = '编辑集合'
resetForm()
editingId.value = row.id
const detail = await fetchProductionTaskSetDetail(row.id)
@@ -499,12 +627,15 @@
void remoteSearchRoutes('')
}
function handleEdit(row: ProductionTaskSet) {
void openDetailDialog(row, 'edit')
}
function handleView(row: ProductionTaskSet) {
void openDetailDialog(row, 'view')
async function handleView(row: ProductionTaskSet) {
viewRow.value = row
viewVisible.value = true
viewLoading.value = true
try {
viewRow.value = await fetchProductionTaskSetDetail(row.id)
} finally {
viewLoading.value = false
}
}
function buildPayload() {
@@ -565,16 +696,20 @@
</script>
<style scoped lang="scss">
.set-items-toolbar {
display: flex;
align-items: center;
gap: 12px;
margin-bottom: 8px;
.set-items-field :deep(.el-form-item__content) {
display: block;
width: 100%;
max-width: 100%;
}
.set-items-title {
font-size: 13px;
font-weight: 600;
color: #1e293b;
.set-items-block {
width: 100%;
min-width: 0;
}
.inner-table-wrap {
border-top: 1px solid var(--mint-border, #e2e8f0);
border-radius: 0;
overflow: hidden;
}
</style>
@@ -5,8 +5,14 @@
:title="
phase === 'form' ? '派发生产任务' : `编辑生产任务 — ${createdTaskName || editTaskName || ''}`
"
:width="phase === 'form' ? (dispatchMode === 'set' ? '720px' : '560px') : '90vw'"
:class="phase === 'edit' ? 'dialog-form-layout dispatch-route-dialog' : 'dispatch-dialog'"
:width="phase === 'form' ? (dispatchMode === 'set' ? '1200px' : '560px') : '90vw'"
:class="
phase === 'edit'
? 'dialog-form-layout dispatch-route-dialog'
: dispatchMode === 'set'
? 'dialog-form-layout dispatch-dialog'
: 'dispatch-dialog'
"
align-center
modal-class="protocol-dialog-mask"
append-to-body
@@ -39,7 +45,7 @@
<el-form-item v-if="!editTaskId && canUseSet" label="派发方式" class="form-col-span-2">
<el-radio-group v-model="dispatchMode" @change="onDispatchModeChange">
<el-radio-button value="single">单条任务</el-radio-button>
<el-radio-button value="set">任务集合</el-radio-button>
<el-radio-button value="set">任务组合模版</el-radio-button>
</el-radio-group>
</el-form-item>
<template v-if="dispatchMode !== 'set'">
@@ -90,10 +96,10 @@
</el-form-item>
</template>
<template v-else>
<el-form-item label="任务集合" class="form-col-span-2">
<el-form-item label="任务组合模版" class="form-col-span-2">
<el-select
v-model="selectedSetId"
placeholder="请选择任务集合"
placeholder="请选择任务组合模版"
filterable
clearable
style="width: 100%"
@@ -108,25 +114,112 @@
/>
</el-select>
</el-form-item>
<el-form-item v-if="selectedSetId" label="集合预览" class="form-col-span-2">
<el-table class="list-table" :data="setPreviewItems" stripe max-height="280">
<el-table-column
prop="taskName"
label="任务名称"
min-width="140"
show-overflow-tooltip
/>
<el-table-column label="工艺路线" min-width="140" show-overflow-tooltip>
<template #default="{ row }">{{ row.routeName || '—' }}</template>
</el-table-column>
<el-table-column
prop="description"
label="描述"
min-width="140"
show-overflow-tooltip
/>
<el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip />
</el-table>
<el-form-item
v-if="selectedSetId"
label="任务条目"
class="form-col-span-2 set-items-field"
>
<div class="set-items-block">
<div class="list-toolbar">
<div class="list-toolbar-row">
<el-button class="btn-main" type="primary" @click="addDispatchItem">
<el-icon><Plus /></el-icon>添加条目
</el-button>
</div>
</div>
<div class="list-body list-wrap inner-table-wrap">
<el-table
class="list-table"
:data="setDispatchItems"
stripe
:row-key="dispatchItemRowKey"
>
<el-table-column
type="index"
label="序号"
min-width="68"
align="center"
header-align="center"
:index="(index) => index + 1"
/>
<el-table-column
label="任务名称"
min-width="180"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-input
v-model="row.taskName"
placeholder="请输入任务名称"
maxlength="200"
/>
</template>
</el-table-column>
<el-table-column
label="工艺路线"
min-width="220"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-select
v-model="row.routeId"
placeholder="输入路线名称检索(可选)"
filterable
remote
reserve-keyword
clearable
style="width: 100%"
:loading="routeLoading"
:remote-method="remoteSearchRoutes"
@visible-change="onRouteSelectVisible"
>
<el-option
v-for="route in routeOptions"
:key="route.id"
:label="`${route.routeName}(${route.routeCode})`"
:value="route.id"
/>
</el-select>
</template>
</el-table-column>
<el-table-column
label="描述"
min-width="180"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-input v-model="row.description" placeholder="可选" maxlength="500" />
</template>
</el-table-column>
<el-table-column
label="备注"
min-width="160"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-input v-model="row.remark" placeholder="可选" maxlength="512" />
</template>
</el-table-column>
<el-table-column
label="操作"
min-width="120"
fixed="right"
align="center"
header-align="center"
>
<template #default="{ $index }">
<el-button class="btn-op-item" @click="removeDispatchItem($index)">
<el-icon><Delete /></el-icon>删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
</el-form-item>
</template>
</div>
@@ -379,8 +472,47 @@
const dispatchMode = ref<'single' | 'set'>('single')
const selectedSetId = ref('')
const setOptions = ref<ProductionTaskSet[]>([])
const setPreviewItems = ref<ProductionTaskSetItem[]>([])
const setDispatchItems = ref<Array<ProductionTaskSetItem & { _key: string }>>([])
const setLoading = ref(false)
let dispatchItemKeySeq = 0
function createDispatchItem(partial?: Partial<ProductionTaskSetItem>) {
dispatchItemKeySeq += 1
return {
_key: `dispatch-item-${dispatchItemKeySeq}`,
taskName: partial?.taskName || '',
routeId: partial?.routeId || '',
routeName: partial?.routeName || '',
description: partial?.description || '',
remark: partial?.remark || ''
}
}
function dispatchItemRowKey(row: { _key: string }) {
return row._key
}
function addDispatchItem() {
setDispatchItems.value.push(createDispatchItem())
}
function removeDispatchItem(index: number) {
setDispatchItems.value.splice(index, 1)
}
function seedRouteOptionsFromItems(items: ProductionTaskSetItem[]) {
const seen = new Set(routeOptions.value.map((r) => r.id))
for (const item of items) {
const id = String(item.routeId || '').trim()
if (!id || seen.has(id)) continue
seen.add(id)
routeOptions.value.push({
id,
routeName: item.routeName || id,
routeCode: ''
})
}
}
const editor = useTaskStepEditor()
const {
@@ -445,7 +577,7 @@
function resetSetDispatchState() {
dispatchMode.value = 'single'
selectedSetId.value = ''
setPreviewItems.value = []
setDispatchItems.value = []
setOptions.value = []
}
@@ -463,21 +595,25 @@
function onDispatchModeChange() {
selectedSetId.value = ''
setPreviewItems.value = []
setDispatchItems.value = []
if (dispatchMode.value === 'set') {
void loadActiveSets()
void remoteSearchRoutes('')
}
}
async function onSelectedSetChange(id: string) {
setPreviewItems.value = []
setDispatchItems.value = []
const setId = String(id || '').trim()
if (!setId) return
try {
const detail = await fetchProductionTaskSetDetail(setId)
setPreviewItems.value = detail?.items || []
const items = detail?.items || []
setDispatchItems.value = items.map((item) => createDispatchItem(item))
seedRouteOptionsFromItems(items)
void remoteSearchRoutes('')
} catch {
setPreviewItems.value = []
setDispatchItems.value = []
}
}
@@ -501,17 +637,25 @@
const setId = String(selectedSetId.value || '').trim()
const workOrderId = String(props.workOrderRow?.id || '').trim()
if (!setId) {
ElMessage.warning('请选择任务集合')
ElMessage.warning('请选择任务组合模版')
return
}
if (!setPreviewItems.value.length) {
ElMessage.warning('集合没有可派发的任务')
const items = setDispatchItems.value
.filter((item) => String(item.taskName || '').trim())
.map((item) => ({
taskName: String(item.taskName).trim(),
routeId: String(item.routeId || '').trim() || undefined,
description: String(item.description || '').trim() || undefined,
remark: String(item.remark || '').trim() || undefined
}))
if (!items.length) {
ElMessage.warning('请至少添加一条任务名称非空的条目')
return
}
submitting.value = true
try {
const result = await fetchCreateProductionTasksFromSet({ workOrderId, setId })
ElMessage.success(`已生成 ${result?.createdCount || setPreviewItems.value.length} 条生产任务`)
const result = await fetchCreateProductionTasksFromSet({ workOrderId, setId, items })
ElMessage.success(`已生成 ${result?.createdCount || items.length} 条生产任务`)
pendingListRefresh.value = true
handleClose()
} catch {
@@ -698,4 +842,35 @@
padding: 0 10px;
}
}
.set-items-field :deep(.el-form-item__content) {
display: block;
width: 100%;
max-width: 100%;
}
.set-items-block {
display: flex;
flex-direction: column;
gap: 12px;
width: 100%;
min-width: 0;
:deep(.list-toolbar) {
padding: 0;
margin: 0;
background: transparent;
border: none;
}
:deep(.list-toolbar-row) {
padding: 0;
}
}
.inner-table-wrap {
border-top: 1px solid var(--mint-border, #e2e8f0);
border-radius: 0;
overflow: hidden;
}
</style>
@@ -72,6 +72,13 @@
>
<el-icon><View /></el-icon>查看
</el-button>
<el-button
v-if="canSaveTaskSet(row)"
class="btn-op-item"
@click="emit('command', 'save-set', row)"
>
<el-icon><FolderAdd /></el-icon>保存为模版
</el-button>
<el-button class="btn-op-item" @click="emit('view-qc', row)">
<el-icon><DataLine /></el-icon>查看质检数据
</el-button>
@@ -118,9 +125,6 @@
<el-dropdown-item v-if="canDispatchTask(row)" command="view">
<el-icon><View /></el-icon>查看
</el-dropdown-item>
<el-dropdown-item v-if="canSaveTaskSet(row)" command="save-set">
<el-icon><FolderAdd /></el-icon>存为任务集合
</el-dropdown-item>
<el-dropdown-item v-if="canEditWorkOrder(row)" command="edit">
<el-icon><EditPen /></el-icon>编辑
</el-dropdown-item>
@@ -318,7 +322,6 @@
import type { TagType } from '@/utils/status-tag-registry'
import { productStatusLabel, productStatusTagType } from '@/utils/status-tag-registry'
import { useUserStore } from '@/store/modules/user'
import { useMenuPerm } from '@/hooks/core/useMenuPerm'
import { sumProductionWorkOrderStepBadgeCount } from '@/utils/production-work-order-step-badge'
import WorkOrderTaskSubList from './WorkOrderTaskSubList.vue'
import ProductionStepBadge from './ProductionStepBadge.vue'
@@ -355,7 +358,6 @@
)
const userStore = useUserStore()
const { hasMenuPerm } = useMenuPerm()
const isMineMode = computed(() => props.pageMode === 'mine')
function resolveCurrentUserId() {
@@ -551,19 +553,12 @@
function canSaveTaskSet(row: ProductionWorkOrderItem) {
if (isMineMode.value) return false
if (!hasMenuPerm('production:task-set:add')) return false
const tasks = resolvePresetTasks(row.id)
return Array.isArray(tasks) && tasks.some((t) => String(t?.taskName || '').trim())
}
function hasMoreActions(row: ProductionWorkOrderItem) {
return (
canDispatchTask(row) ||
canSaveTaskSet(row) ||
canEditWorkOrder(row) ||
canDeleteWorkOrder(row) ||
true
)
return canDispatchTask(row) || canEditWorkOrder(row) || canDeleteWorkOrder(row) || true
}
</script>
@@ -817,9 +812,23 @@
flex-wrap: wrap;
align-items: center;
justify-content: flex-end;
gap: 6px;
gap: 8px;
flex-shrink: 0;
margin-left: auto;
/* 统一用 gap 控制间距,去掉 Element Plus 相邻按钮默认 margin,避免夹 tooltip/dropdown 时疏密不一 */
:deep(.el-button),
:deep(.el-button + .el-button),
:deep(.el-button + .el-dropdown),
:deep(.el-dropdown) {
margin-left: 0;
margin-right: 0;
}
:deep(.el-tooltip__trigger),
:deep(.el-dropdown) {
display: inline-flex;
}
}
:deep(.production-work-order-card__fee-in-head) {
@@ -1,10 +1,10 @@
<!-- 将当前工单已派发任务存为生产任务集合 -->
<!-- 将当前工单已派发任务生成生产任务组合模版 -->
<!-- eslint-disable vue/no-v-model-argument -->
<template>
<el-dialog
v-model="dialogVisible"
title="存为任务集合"
width="720px"
title="保存为模版"
width="1200px"
class="dialog-form-layout"
align-center
append-to-body
@@ -21,8 +21,8 @@
class="biz-dialog-form"
>
<div class="form-grid-2">
<el-form-item label="集合名称" prop="setName" class="form-col-span-2">
<el-input v-model="form.setName" placeholder="请输入集合名称" maxlength="200" />
<el-form-item label="模版名称" prop="setName" class="form-col-span-2">
<el-input v-model="form.setName" placeholder="请输入模版名称" maxlength="200" />
</el-form-item>
<el-form-item label="备注" class="form-col-span-2">
<el-input
@@ -33,29 +33,106 @@
maxlength="512"
/>
</el-form-item>
<el-form-item label="将保存的任务" class="form-col-span-2">
<p v-if="!preview.items.length" class="hint-muted">没有可保存的任务名称</p>
<p v-else-if="preview.skippedEmptyNameCount" class="hint-muted">
将跳过 {{ preview.skippedEmptyNameCount }} 条空名称任务
</p>
<el-table v-if="preview.items.length" class="list-table" :data="preview.items" stripe>
<el-table-column
prop="taskName"
label="任务名称"
min-width="140"
show-overflow-tooltip
/>
<el-table-column label="工艺路线" min-width="140" show-overflow-tooltip>
<template #default="{ row }">{{ row.routeName || '—' }}</template>
</el-table-column>
<el-table-column
prop="description"
label="描述"
min-width="140"
show-overflow-tooltip
/>
<el-table-column prop="remark" label="备注" min-width="120" show-overflow-tooltip />
</el-table>
<el-form-item class="form-col-span-2 set-items-field" prop="items" label="将保存的任务">
<div class="set-items-block">
<div class="list-toolbar">
<div class="list-toolbar-row">
<el-button class="btn-main" type="primary" @click="addItem">
<el-icon><Plus /></el-icon>添加条目
</el-button>
</div>
</div>
<p v-if="emptyNameCount" class="hint-muted">
将跳过 {{ emptyNameCount }} 条空名称任务
</p>
<div class="list-body list-wrap inner-table-wrap">
<el-table class="list-table" :data="form.items" stripe :row-key="itemRowKey">
<el-table-column
type="index"
label="序号"
min-width="68"
align="center"
header-align="center"
:index="(index) => index + 1"
/>
<el-table-column
label="任务名称"
min-width="180"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-input
v-model="row.taskName"
placeholder="请输入任务名称"
maxlength="200"
/>
</template>
</el-table-column>
<el-table-column
label="工艺路线"
min-width="220"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-select
v-model="row.routeId"
placeholder="输入路线名称检索(可选)"
filterable
remote
reserve-keyword
clearable
style="width: 100%"
:loading="routeLoading"
:remote-method="remoteSearchRoutes"
@visible-change="onRouteSelectVisible"
>
<el-option
v-for="route in routeOptions"
:key="route.id"
:label="`${route.routeName}(${route.routeCode})`"
:value="route.id"
/>
</el-select>
</template>
</el-table-column>
<el-table-column
label="描述"
min-width="180"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-input v-model="row.description" placeholder="可选" maxlength="500" />
</template>
</el-table-column>
<el-table-column
label="备注"
min-width="160"
align="center"
header-align="center"
>
<template #default="{ row }">
<el-input v-model="row.remark" placeholder="可选" maxlength="512" />
</template>
</el-table-column>
<el-table-column
label="操作"
min-width="120"
fixed="right"
align="center"
header-align="center"
>
<template #default="{ $index }">
<el-button class="btn-op-item" @click="removeItem($index)">
<el-icon><Delete /></el-icon>删除
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div>
</el-form-item>
</div>
</el-form>
@@ -67,7 +144,7 @@
class="btn-main"
type="primary"
:loading="submitting"
:disabled="!preview.items.length"
:disabled="!validItems.length"
@click="handleSubmit"
>
<el-icon><Check /></el-icon>确定
@@ -78,13 +155,19 @@
<script setup lang="ts">
import { ElMessage } from 'element-plus'
import { Close, Check } from '@element-plus/icons-vue'
import { Close, Check, Plus, Delete } from '@element-plus/icons-vue'
import type { FormInstance, FormRules } from 'element-plus'
import { fetchCreateProductionTaskSetFromWorkOrder } from '@/api/production-task-set'
import { fetchProcessRouteList } from '@/api/production'
import {
fetchCreateProductionTaskSetFromWorkOrder,
type ProductionTaskSetItem
} from '@/api/production-task-set'
import { mapWorkOrderTasksToSetItems } from '@/utils/production-task-set'
defineOptions({ name: 'SaveProductionTaskSetDialog' })
type FormItem = ProductionTaskSetItem & { _key: string }
const props = defineProps<{
visible: boolean
workOrderId: string
@@ -103,32 +186,146 @@
const formRef = ref<FormInstance>()
const submitting = ref(false)
const form = reactive({ setName: '', remark: '' })
const rules: FormRules = {
setName: [{ required: true, message: '请输入集合名称', trigger: 'blur' }]
const routeOptions = ref<any[]>([])
const routeLoading = ref(false)
const form = reactive({
setName: '',
remark: '',
items: [] as FormItem[]
})
const validateItems = (_rule: unknown, _value: unknown, callback: (e?: Error) => void) => {
if (!form.items.some((item) => String(item.taskName || '').trim())) {
callback(new Error('请至少添加一条任务名称非空的条目'))
return
}
callback()
}
const preview = computed(() => mapWorkOrderTasksToSetItems(props.tasks))
const rules: FormRules = {
setName: [{ required: true, message: '请输入模版名称', trigger: 'blur' }],
items: [{ validator: validateItems, trigger: 'change' }]
}
const validItems = computed(() =>
form.items.filter((item) => String(item.taskName || '').trim())
)
const emptyNameCount = computed(() => form.items.length - validItems.value.length)
let itemKeySeq = 0
function createItem(partial?: Partial<ProductionTaskSetItem>): FormItem {
itemKeySeq += 1
return {
_key: `save-set-item-${itemKeySeq}`,
taskName: partial?.taskName || '',
routeId: partial?.routeId || '',
routeName: partial?.routeName || '',
description: partial?.description || '',
remark: partial?.remark || ''
}
}
function itemRowKey(row: FormItem) {
return row._key
}
function addItem() {
form.items.push(createItem())
}
function removeItem(index: number) {
form.items.splice(index, 1)
if (!form.items.length) {
form.items.push(createItem())
}
}
async function remoteSearchRoutes(query: string) {
routeLoading.value = true
try {
const kw = query?.trim()
const res = await fetchProcessRouteList({
page: 1,
pageSize: 100,
routeName: kw || undefined
})
routeOptions.value = res.list || []
seedRouteOptionsFromItems(form.items)
} catch {
routeOptions.value = []
seedRouteOptionsFromItems(form.items)
} finally {
routeLoading.value = false
}
}
function onRouteSelectVisible(visible: boolean) {
if (visible) void remoteSearchRoutes('')
}
function seedRouteOptionsFromItems(items: ProductionTaskSetItem[]) {
const seen = new Set(routeOptions.value.map((r) => r.id))
for (const item of items) {
const id = String(item.routeId || '').trim()
if (!id || seen.has(id)) continue
seen.add(id)
routeOptions.value.push({
id,
routeName: item.routeName || id,
routeCode: ''
})
}
}
async function initForm() {
form.setName = ''
form.remark = ''
const mapped = mapWorkOrderTasksToSetItems(props.tasks)
form.items = mapped.items.length
? mapped.items.map((item) => createItem(item))
: [createItem()]
await remoteSearchRoutes('')
}
function resetForm() {
form.setName = ''
form.remark = ''
form.items = []
routeOptions.value = []
}
function handleClose() {
dialogVisible.value = false
form.setName = ''
form.remark = ''
resetForm()
}
watch(
() => props.visible,
(val) => {
if (val) void initForm()
}
)
async function handleSubmit() {
if (!preview.value.items.length) {
ElMessage.warning('没有可保存的任务名称')
if (!validItems.value.length) {
ElMessage.warning('请至少添加一条任务名称非空的条目')
return
}
const valid = await formRef.value?.validate?.().catch(() => false)
if (!valid) return
submitting.value = true
try {
const items = validItems.value.map((item) => ({
taskName: String(item.taskName).trim(),
routeId: String(item.routeId || '').trim() || undefined,
description: String(item.description || '').trim() || undefined,
remark: String(item.remark || '').trim() || undefined
}))
const result = await fetchCreateProductionTaskSetFromWorkOrder({
workOrderId: props.workOrderId,
setName: form.setName.trim(),
remark: form.remark || undefined
remark: form.remark || undefined,
items
})
const skipped = Number(result?.skippedEmptyNameCount || 0)
ElMessage.success(skipped > 0 ? `保存成功,已跳过 ${skipped} 条空名称任务` : '保存成功')
@@ -144,8 +341,39 @@
<style scoped lang="scss">
.hint-muted {
margin: 0 0 8px;
margin: 0;
font-size: 12px;
color: var(--mint-text-muted, #94a3b8);
}
.set-items-field :deep(.el-form-item__content) {
display: block;
width: 100%;
max-width: 100%;
}
.set-items-block {
display: flex;
flex-direction: column;
gap: 12px;
width: 100%;
min-width: 0;
:deep(.list-toolbar) {
padding: 0;
margin: 0;
background: transparent;
border: none;
}
:deep(.list-toolbar-row) {
padding: 0;
}
}
.inner-table-wrap {
border-top: 1px solid var(--mint-border, #e2e8f0);
border-radius: 0;
overflow: hidden;
}
</style>