提交
This commit is contained in:
@@ -8,6 +8,7 @@ import { can } from '../utils/perm'
|
||||
import { confirmAction } from '../utils/confirm'
|
||||
import { exportXlsxFetch } from '../utils/export'
|
||||
import { getToken } from '../utils/auth'
|
||||
import { InfoFilled } from '@element-plus/icons-vue'
|
||||
import PageHelp from '../components/PageHelp.vue'
|
||||
import AttachmentPanel from '../components/AttachmentPanel.vue'
|
||||
import { helpZone, helpMaterial } from '../help'
|
||||
@@ -203,13 +204,13 @@ async function saveNode() {
|
||||
|
||||
/* ---------- 区域维护:位置号批量生成 ---------- */
|
||||
const batchDialog = ref(false)
|
||||
const batchForm = reactive({ zoneCode: '', shelfNo: '', layerNo: '', posStart: 1, posEnd: 1 })
|
||||
const batchForm = reactive({ zoneCode: '', shelfNo: '', layerNo: '', count: 1 })
|
||||
const batchPreview = ref([])
|
||||
const batchPreviewing = ref(false)
|
||||
const batchSubmitting = ref(false)
|
||||
|
||||
function openBatchGen() {
|
||||
Object.assign(batchForm, { zoneCode: '', shelfNo: '', layerNo: '', posStart: 1, posEnd: 1 })
|
||||
Object.assign(batchForm, { zoneCode: '', shelfNo: '', layerNo: '', count: 1 })
|
||||
bShelf.value = []; bLayer.value = []
|
||||
batchPreview.value = []
|
||||
batchDialog.value = true
|
||||
@@ -223,14 +224,17 @@ async function onBatchRegionChange() {
|
||||
// 选定货架后加载该货架下已存在的层(只能选具体层,批量生成只生成位置、不创建父级层)
|
||||
async function onBatchShelfChange() {
|
||||
batchForm.layerNo = ''
|
||||
await loadLayerOpts(bLayer, batchForm.zoneCode, batchForm.shelfNo)
|
||||
}
|
||||
async function previewBatch() {
|
||||
if (!batchForm.zoneCode || !batchForm.shelfNo) { ElMessage.warning('请选择区域与货架'); return }
|
||||
if (!batchForm.layerNo) { ElMessage.warning('请选择具体的层'); return }
|
||||
if (!batchForm.layerNo) { ElMessage.warning('请填写层号'); return }
|
||||
if (!batchForm.count || batchForm.count < 1) { ElMessage.warning('请填写生成数量(≥1)'); return }
|
||||
batchPreviewing.value = true
|
||||
try {
|
||||
const data = await request.post('/zone/batch-generate', { ...batchForm, preview: true })
|
||||
const data = await request.post('/zone/batch-generate', {
|
||||
zoneCode: batchForm.zoneCode, shelfNo: batchForm.shelfNo,
|
||||
layerNo: (batchForm.layerNo || '').toUpperCase(), count: batchForm.count, level: 4, preview: true
|
||||
})
|
||||
batchPreview.value = data?.list || []
|
||||
} finally {
|
||||
batchPreviewing.value = false
|
||||
@@ -242,11 +246,12 @@ async function submitBatch() {
|
||||
batchSubmitting.value = true
|
||||
try {
|
||||
const data = await request.post('/zone/batch-generate', {
|
||||
...batchForm, preview: false,
|
||||
zoneCode: batchForm.zoneCode, shelfNo: batchForm.shelfNo,
|
||||
layerNo: (batchForm.layerNo || '').toUpperCase(), count: batchForm.count, level: 4, preview: false,
|
||||
// 提交时带上预览表里(可能被手改过的)位置名称,后端优先采用
|
||||
positions: batchPreview.value.map((x) => ({ positionNo: x.positionNo, positionName: x.positionName }))
|
||||
})
|
||||
ElMessage.success(`已生成 ${data?.created || 0} 个位置,跳过已存在 ${data?.skipped || 0} 个`)
|
||||
ElMessage.success(`生成 ${data?.created || 0} 个,跳过 ${data?.skipped || 0} 个`)
|
||||
batchDialog.value = false
|
||||
zoneTabLoaded[4] = false
|
||||
if (activeZoneTab.value === 4) await loadNodes(4)
|
||||
@@ -340,6 +345,18 @@ async function toggleMatStatus(row) {
|
||||
} catch { /* request 层已提示 */ }
|
||||
}
|
||||
|
||||
// C4 反向:手动重推单条到 MES(对齐 MES 物料同步失败标记设计,不做自动重推)
|
||||
const retryingId = ref(null)
|
||||
async function retrySync(row) {
|
||||
retryingId.value = row.id
|
||||
try {
|
||||
await request.post('/material/retry-sync', { id: row.id })
|
||||
ElMessage.success(`已重推 ${row.code} 到 MES`)
|
||||
loadMaterials()
|
||||
} catch { /* request 层已提示 */ }
|
||||
finally { retryingId.value = null }
|
||||
}
|
||||
|
||||
async function loadMaterials() {
|
||||
materialLoading.value = true
|
||||
try {
|
||||
@@ -534,6 +551,29 @@ function pickMaterialFile() {
|
||||
matFileRef.value?.click()
|
||||
}
|
||||
|
||||
// 导入模板下载(2026-10-21):与导入同权限(material:import),GET /api/material/import-template
|
||||
async function downloadMaterialTemplate() {
|
||||
try {
|
||||
const res = await fetch('/api/material/import-template', {
|
||||
headers: { Authorization: 'Bearer ' + getToken() }
|
||||
})
|
||||
if (!res.ok) {
|
||||
const body = await res.json().catch(() => null)
|
||||
ElMessage.error('模板下载失败:' + (body?.message || `服务器错误(${res.status})`))
|
||||
return
|
||||
}
|
||||
const blob = await res.blob()
|
||||
const url = URL.createObjectURL(blob)
|
||||
const a = document.createElement('a')
|
||||
a.href = url
|
||||
a.download = '物料档案导入模板.xlsx'
|
||||
a.click()
|
||||
URL.revokeObjectURL(url)
|
||||
} catch {
|
||||
ElMessage.error('模板下载失败:网络异常,请稍后重试')
|
||||
}
|
||||
}
|
||||
|
||||
async function onMaterialFile(e) {
|
||||
const file = e.target.files?.[0]
|
||||
e.target.value = '' // 允许重复选择同一文件
|
||||
@@ -779,7 +819,8 @@ async function onMaterialFile(e) {
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table :data="nodeState[4].list" border size="small" v-loading="nodeState[4].loading" row-key="id" empty-text="暂无位置号">
|
||||
<el-table-column label="区域" min-width="110"><template #default="{ row }">{{ row.zoneName || row.zoneCode || '-' }}</template></el-table-column>
|
||||
<el-table-column prop="zoneCode" label="区域编码" width="110" align="center"><template #default="{ row }">{{ row.zoneCode || '-' }}</template></el-table-column>
|
||||
<el-table-column label="区域名称" min-width="120"><template #default="{ row }">{{ row.zoneName || '-' }}</template></el-table-column>
|
||||
<el-table-column label="货架号" width="90" align="center"><template #default="{ row }">{{ row.shelfNo || '-' }}</template></el-table-column>
|
||||
<el-table-column label="层" width="70" align="center"><template #default="{ row }">{{ row.layerNo || '-' }}</template></el-table-column>
|
||||
<el-table-column prop="code" label="位置号" width="90" align="center" />
|
||||
@@ -853,16 +894,14 @@ async function onMaterialFile(e) {
|
||||
<el-option v-for="s in bShelf" :key="s.code" :value="s.code" :label="s.code" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="层" required>
|
||||
<el-select v-model="batchForm.layerNo" placeholder="请选择具体的层" filterable :disabled="!batchForm.shelfNo" style="width:100%" @visible-change="(v) => onDropdownOpen(v, () => loadLayerOpts(bLayer, batchForm.zoneCode, batchForm.shelfNo))">
|
||||
<el-option v-for="l in bLayer" :key="l.code" :value="l.code" :label="'层 '+l.code" />
|
||||
</el-select>
|
||||
<div style="color:#909399;font-size:12px;margin-top:4px">只能选择已存在的层;批量生成只在该层下生成位置号,不会创建父级层。</div>
|
||||
<el-form-item label="层号" required>
|
||||
<el-input v-model="batchForm.layerNo" placeholder="如 A、L1、2(字母或数字均可)" clearable style="width:220px"
|
||||
@input="batchForm.layerNo = (batchForm.layerNo || '').toUpperCase()" />
|
||||
<div style="color:#909399;font-size:12px;margin-top:4px">层号放开:可填字母或数字(如 A、L1、2);该层若不存在将自动创建。</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="位置范围">
|
||||
<el-input-number v-model="batchForm.posStart" :min="0" :step="1" step-strictly controls-position="right" style="width:120px" />
|
||||
<span style="margin:0 8px">至</span>
|
||||
<el-input-number v-model="batchForm.posEnd" :min="0" :step="1" step-strictly controls-position="right" style="width:120px" />
|
||||
<el-form-item label="生成数量" required>
|
||||
<el-input-number v-model="batchForm.count" :min="1" :max="2000" :step="1" step-strictly controls-position="right" style="width:160px" />
|
||||
<span style="margin-left:10px;color:#909399;font-size:12px">从「该层已存在的最大位置号 +1」起连续生成</span>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" :loading="batchPreviewing" @click="previewBatch">预览</el-button>
|
||||
@@ -870,7 +909,7 @@ async function onMaterialFile(e) {
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<el-table v-if="batchPreview.length" :data="batchPreview" border size="small" max-height="300">
|
||||
<el-table-column prop="layerNo" label="层" width="80" align="center" />
|
||||
<el-table-column prop="layerNo" label="层号" width="90" align="center" />
|
||||
<el-table-column prop="positionNo" label="位置号" width="100" align="center" />
|
||||
<el-table-column label="位置名称" min-width="200">
|
||||
<template #default="{ row }">
|
||||
@@ -977,9 +1016,36 @@ async function onMaterialFile(e) {
|
||||
<el-button v-if="can('material:create')" type="success" @click="openMatCreate">新增物料档案</el-button>
|
||||
<el-button v-if="can('material:import')" type="warning" :loading="matImporting" @click="pickMaterialFile">导入</el-button>
|
||||
<el-button v-if="can('material:export')" :loading="matExporting" @click="exportMaterials">导出</el-button>
|
||||
<el-tooltip v-if="can('material:import')" content="Excel 首行表头按名称识别(列顺序可变、可含多余列):图号 | 名称 | 规格 | 单位 | 类型(结构件/电气件/其他) | 物料类别(原材料/成品/其他,可选;半成品不是物料类别) | 说明(除「说明」「物料类别」外均为必填)">
|
||||
<el-link type="info" :underline="false" style="margin-left:4px">导入说明</el-link>
|
||||
</el-tooltip>
|
||||
<el-popover v-if="can('material:import')" placement="bottom-start" :width="680" trigger="hover">
|
||||
<template #reference>
|
||||
<el-icon style="margin-left:6px;cursor:pointer;color:#909399;font-size:17px;vertical-align:middle"><InfoFilled /></el-icon>
|
||||
</template>
|
||||
<div style="max-height:62vh;overflow:auto">
|
||||
<div style="font-weight:600;margin-bottom:6px">一、字段说明(Excel 首行表头按名称识别,列顺序可变、可含多余列)</div>
|
||||
<table style="width:100%;border-collapse:collapse;font-size:12px" border>
|
||||
<thead><tr style="background:#f5f7fa"><th>列</th><th>字段</th><th>必填</th><th>格式</th><th>说明</th></tr></thead>
|
||||
<tbody>
|
||||
<tr><td style="text-align:center">1</td><td>图号</td><td style="text-align:center">是</td><td>字符串,唯一</td><td>物料唯一标识,不可重复</td></tr>
|
||||
<tr><td style="text-align:center">2</td><td>名称</td><td style="text-align:center">是</td><td>字符串</td><td>物料名称</td></tr>
|
||||
<tr><td style="text-align:center">3</td><td>规格</td><td style="text-align:center">是</td><td>字符串</td><td>规格型号</td></tr>
|
||||
<tr><td style="text-align:center">4</td><td>单位</td><td style="text-align:center">是</td><td>字符串</td><td>如「个」「件」「套」</td></tr>
|
||||
<tr><td style="text-align:center">5</td><td>类型</td><td style="text-align:center">是</td><td>结构件/电气件/其他</td><td>决定出入库按数量还是按序列号记账</td></tr>
|
||||
<tr><td style="text-align:center">6</td><td>物料类别</td><td style="text-align:center">否</td><td>原材料/成品</td><td>留空默认原材料(半成品不是物料类别)</td></tr>
|
||||
<tr><td style="text-align:center">7</td><td>说明</td><td style="text-align:center">否</td><td>字符串</td><td>备注</td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div style="font-weight:600;margin:10px 0 4px">二、常见错误</div>
|
||||
<div style="font-size:12px;color:#606266;line-height:1.9">
|
||||
· 图号重复:系统中已存在相同图号,该行被拒绝<br/>
|
||||
· 类型不在枚举内:必须填「结构件」「电气件」「其他」之一(兼容 1/2/3)<br/>
|
||||
· 物料类别不在枚举内:只能填「原材料」或「成品」<br/>
|
||||
· 必填列为空:该行被拒绝;任一行出错则整批回退,一行不写
|
||||
</div>
|
||||
<div style="font-weight:600;margin:10px 0 4px">三、下载模板</div>
|
||||
<el-button size="small" type="primary" @click="downloadMaterialTemplate">下载模板</el-button>
|
||||
<span style="font-size:12px;color:#909399;margin-left:8px">建议先下载模板,按模板格式填写后导入</span>
|
||||
</div>
|
||||
</el-popover>
|
||||
<input ref="matFileRef" type="file" accept=".xlsx,.xls" style="display:none" @change="onMaterialFile" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
@@ -1022,10 +1088,17 @@ async function onMaterialFile(e) {
|
||||
<el-table-column label="创建时间" width="155" align="center">
|
||||
<template #default="{ row }">{{ fmtTime(row.createdAt) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="170" align="center" fixed="right">
|
||||
<el-table-column label="同步状态" width="100" align="center">
|
||||
<template #default="{ row }">
|
||||
<el-tag v-if="row.syncPending" type="danger" size="small">同步失败</el-tag>
|
||||
<el-tag v-else type="success" size="small">正常</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200" align="center" fixed="right">
|
||||
<template #default="{ row }">
|
||||
<el-button v-if="can('material:edit')" type="primary" size="small" @click="openMatEdit(row)">编辑</el-button>
|
||||
<el-button link type="primary" size="small" @click="openMatAttach(row)">附件</el-button>
|
||||
<el-button v-if="can('material:edit') && row.syncPending" link type="danger" size="small" :loading="retryingId === row.id" @click="retrySync(row)">重推</el-button>
|
||||
<el-popconfirm :title="row.isActive !== false ? '确认停用该物料?' : '确认启用该物料?'" @confirm="toggleMatStatus(row)">
|
||||
<template #reference>
|
||||
<el-button link :type="row.isActive !== false ? 'warning' : 'success'" size="small">{{ row.isActive !== false ? '停用' : '启用' }}</el-button>
|
||||
|
||||
Reference in New Issue
Block a user