feat(plugin): XQ0031_XQ0032 1.1.8 物料收发汇总列结构可自定义(界面可视化编辑)
- 新增配置项 material_columns(JSON,留空=内置标准),logic/material_summary.resolve_columns 解析并校验,配置错误在取数前 fail-fast,不生成半截文件 - 导出列按 2026-11-16 平台样本对齐:新版 12 列、数量列 0 值留空、数字格式、 按「物料编码→仓库编码」排序、末行只汇总期初/收入/发出/结存 - 插件界面新增「05 导出列」可视化编辑表(表头/字段/数值/格式 + 上移下移删除/重置) - 同步 README 与开发文档;重建 ui 产物
This commit is contained in:
@@ -150,6 +150,73 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 05 导出列(物料收发汇总,可视化编辑) -->
|
||||
<section v-show="form.mode !== '采购订单列表'" class="sec">
|
||||
<div class="sec-head">
|
||||
<span class="sec-badge">05</span>
|
||||
<span class="sec-name">导出列(物料收发汇总)</span>
|
||||
<span class="sec-line" />
|
||||
<span class="sec-tag">{{ colSummary }}</span>
|
||||
</div>
|
||||
<div class="sec-body">
|
||||
<div class="col-hint">
|
||||
下表就是导出到 Excel 的列,<b>从上到下即列顺序</b>。不动就用内置标准(与平台「引出」一致);
|
||||
要跟某个方案对齐,直接在这里改表头、换字段、调顺序即可,配置随「保存配置/存为方案」存本机。
|
||||
</div>
|
||||
<div class="col-toolbar">
|
||||
<el-button size="small" :disabled="running" @click="addColumn">+ 新增一列</el-button>
|
||||
<el-button size="small" :disabled="running" @click="resetColumnsToBuiltin">按内置标准重置</el-button>
|
||||
<el-button size="small" :disabled="running" @click="clearColumns">清除自定义(用内置标准)</el-button>
|
||||
<span class="col-count">{{ colRows.length }} 列<template v-if="hasCustomCols">· 已自定义</template></span>
|
||||
</div>
|
||||
<div class="col-table">
|
||||
<div class="col-row col-head">
|
||||
<span class="c-idx">#</span>
|
||||
<span>表头文字</span>
|
||||
<span>接口字段</span>
|
||||
<span class="c-center">数值</span>
|
||||
<span>数字格式</span>
|
||||
<span>顺序 / 删除</span>
|
||||
</div>
|
||||
<div v-for="(row, i) in colRows" :key="i" class="col-row">
|
||||
<span class="c-idx" :title="sumTag(row)">{{ i + 1 }}{{ sumTag(row) ? '*' : '' }}</span>
|
||||
<el-input v-model="row.title" size="small" placeholder="表头文字" :disabled="running"
|
||||
class="c-input" @input="onColumnEdit" />
|
||||
<el-select v-model="row.field" size="small" filterable allow-create default-first-option
|
||||
:reserve-keyword="false" placeholder="接口字段" :disabled="running" class="c-input"
|
||||
@change="onColumnEdit">
|
||||
<el-option v-for="f in FIELD_OPTIONS" :key="f.value" :value="f.value"
|
||||
:label="f.value + '(' + f.label + ')'" />
|
||||
</el-select>
|
||||
<span class="c-center">
|
||||
<el-switch v-model="row.numeric" size="small" :disabled="running" @change="onColumnEdit" />
|
||||
</span>
|
||||
<el-select v-model="row.format" size="small" filterable allow-create default-first-option
|
||||
:reserve-keyword="false" clearable placeholder="常规" :disabled="running || !row.numeric"
|
||||
class="c-input" @change="onColumnEdit">
|
||||
<el-option v-for="f in FORMAT_OPTIONS" :key="f.value" :value="f.value" :label="f.label" />
|
||||
</el-select>
|
||||
<span class="c-act">
|
||||
<el-button size="small" text :disabled="running || i === 0" @click="moveColumn(i, -1)">↑</el-button>
|
||||
<el-button size="small" text :disabled="running || i === colRows.length - 1"
|
||||
@click="moveColumn(i, 1)">↓</el-button>
|
||||
<el-button size="small" text type="danger" :disabled="running || colRows.length <= 1"
|
||||
@click="removeColumn(i)">🗑</el-button>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tip">
|
||||
数值列导出时 0 会留空;末行合计只汇总期初/收入/发出/结存四个字段,上表序号带 <b>*</b> 的列就是计入合计的。
|
||||
字段名可从下拉选,也可直接输入;拿不准就保持默认。
|
||||
</div>
|
||||
<details class="col-json-wrap">
|
||||
<summary>高级:直接编辑底层 JSON(排查用,一般不用管)</summary>
|
||||
<el-input v-model="form.material_columns" type="textarea" :rows="6" :disabled="running"
|
||||
resize="vertical" class="col-json" placeholder="留空 = 内置标准" />
|
||||
</details>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 流程说明收进折叠区 -->
|
||||
<details class="help">
|
||||
<summary><span>导出口径与说明</span><span class="h-arrow">▾</span></summary>
|
||||
@@ -193,7 +260,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { computed, nextTick, ref, watch } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { usePluginUI } from './usePluginUI'
|
||||
|
||||
@@ -231,6 +298,38 @@ const STOCK_DEFAULTS = {
|
||||
'旧版': STOCK_OPTIONS['旧版'].map((w) => w.code),
|
||||
}
|
||||
|
||||
// 内置标准列结构:仅用于「填入当前标准模板」按钮,必须与后端
|
||||
// logic/material_summary.py 的 _COLUMNS 保持一致(改了后端记得同步这里)
|
||||
const COLUMN_TEMPLATES = {
|
||||
'新版': [
|
||||
{ title: '仓库名称', field: 'FSTOCKNAME', numeric: false },
|
||||
{ title: '物料编码', field: 'FMATERIALNUMBER', numeric: false },
|
||||
{ title: '物料名称', field: 'FMATERIALNAME', numeric: false },
|
||||
{ title: '规格型号', field: 'FMATERIALMODEL', numeric: false },
|
||||
{ title: '库存单位', field: 'FSTOCKUNITNAME', numeric: false },
|
||||
{ title: '(期初)数量(库存)', field: 'FSTOCKQCQTY', numeric: true, format: '#,##0.00' },
|
||||
{ title: '(收入)数量(库存)', field: 'FSTOCKINQTY', numeric: true, format: 'General' },
|
||||
{ title: '(发出)数量(库存)', field: 'FSTOCKOUTQTY', numeric: true, format: '#,##0.00' },
|
||||
{ title: '(结存)数量(库存)', field: 'FSTOCKJCQTY', numeric: true, format: '#,##0.00' },
|
||||
{ title: '(库存周转)库存周转次数', field: 'finvturnovernum', numeric: true, format: '#,##0.0' },
|
||||
{ title: '(库存周转)库存周转天数', field: 'finvturnoverdays', numeric: true, format: '#,##0.00' },
|
||||
{ title: '货主', field: 'FOWNERNAME', numeric: false },
|
||||
],
|
||||
'旧版': [
|
||||
{ title: '仓库名称', field: 'FSTOCKNAME', numeric: false },
|
||||
{ title: '物料编码', field: 'FMATERIALNUMBER', numeric: false },
|
||||
{ title: '物料名称', field: 'FMATERIALNAME', numeric: false },
|
||||
{ title: '规格型号', field: 'FMATERIALMODEL', numeric: false },
|
||||
{ title: '库存单位', field: 'FSTOCKUNITNAME', numeric: false },
|
||||
{ title: '期初', field: 'FSTOCKQCQTY', numeric: true },
|
||||
{ title: '收入', field: 'FSTOCKINQTY', numeric: true },
|
||||
{ title: '发出', field: 'FSTOCKOUTQTY', numeric: true },
|
||||
{ title: '结存', field: 'FSTOCKJCQTY', numeric: true },
|
||||
{ title: '库存周转次数', field: 'finvturnovernum', numeric: true },
|
||||
{ title: '库存周转天数', field: 'finvturnoverdays', numeric: true },
|
||||
],
|
||||
}
|
||||
|
||||
// 恢复默认时按当前 ERP 系统带出对应默认组织/仓库
|
||||
const DEFAULTS = (cur) => {
|
||||
const sys = (cur && cur.erp_system) || '新版'
|
||||
@@ -244,6 +343,7 @@ const DEFAULTS = (cur) => {
|
||||
date_options: [...DATE_PRESETS],
|
||||
scheme_name: '',
|
||||
save_dir: '',
|
||||
material_columns: '',
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,6 +368,10 @@ const {
|
||||
ElMessage.warning('请填写查询组织')
|
||||
return false
|
||||
}
|
||||
if (colRows.value.some((r) => !String(r.title || '').trim() || !String(r.field || '').trim())) {
|
||||
ElMessage.warning('导出列里有「表头文字」或「接口字段」为空,请先在 05 区补全')
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
},
|
||||
@@ -297,6 +401,171 @@ async function pickDir() {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- 导出列:可视化编辑(底层仍以 material_columns JSON 存配置) ----
|
||||
const SUM_FIELDS = ['FSTOCKQCQTY', 'FSTOCKINQTY', 'FSTOCKOUTQTY', 'FSTOCKJCQTY']
|
||||
// 配置里的系统键名(与后端 resolve_columns 的 new/old 对齐;旧版界面曾写过中文键,读取时兼容)
|
||||
const ERP_KEYS = { '新版': 'new', '旧版': 'old' }
|
||||
const erpKey = () => ERP_KEYS[form.erp_system] || 'new'
|
||||
// 常用接口字段(下拉可选,也可直接输入;完整字段以接口返回为准)
|
||||
const FIELD_OPTIONS = [
|
||||
{ value: 'FSTOCKNAME', label: '仓库名称' },
|
||||
{ value: 'FSTOCKNUMBER', label: '仓库编码' },
|
||||
{ value: 'FMATERIALNUMBER', label: '物料编码' },
|
||||
{ value: 'FMATERIALNAME', label: '物料名称' },
|
||||
{ value: 'FMATERIALMODEL', label: '规格型号' },
|
||||
{ value: 'FSTOCKUNITNAME', label: '库存单位' },
|
||||
{ value: 'FOWNERTYPENAME', label: '货主类型' },
|
||||
{ value: 'FOWNERNAME', label: '货主' },
|
||||
{ value: 'FSTOCKQCQTY', label: '期初数量' },
|
||||
{ value: 'FSTOCKINQTY', label: '收入数量' },
|
||||
{ value: 'FSTOCKOUTQTY', label: '发出数量' },
|
||||
{ value: 'FSTOCKJCQTY', label: '结存数量' },
|
||||
{ value: 'finvturnovernum', label: '库存周转次数' },
|
||||
{ value: 'finvturnoverdays', label: '库存周转天数' },
|
||||
{ value: 'FSTOCKQCPRICE', label: '期初单价' },
|
||||
{ value: 'FSTOCKINPRICE', label: '收入单价' },
|
||||
{ value: 'FSTOCKOUTPRICE', label: '发出单价' },
|
||||
{ value: 'FSTOCKJCPRICE', label: '结存单价' },
|
||||
{ value: 'FQCAMOUNT', label: '期初金额' },
|
||||
{ value: 'FINAMOUNT', label: '收入金额' },
|
||||
{ value: 'FOUTAMOUNT', label: '发出金额' },
|
||||
{ value: 'FJCAMOUNT', label: '结存金额' },
|
||||
{ value: 'FLOTNO', label: '批号' },
|
||||
{ value: 'FSTOCKLOC', label: '仓位' },
|
||||
{ value: 'FPRODUCEDATE', label: '生产日期' },
|
||||
{ value: 'FEXPIRYDATE', label: '有效期至' },
|
||||
{ value: 'FSTOCKORGNAME', label: '库存组织' },
|
||||
]
|
||||
// 数字格式预设(可留空=常规,也可直接输入)
|
||||
const FORMAT_OPTIONS = [
|
||||
{ value: '#,##0.00', label: '#,##0.00(千分位 2 位)' },
|
||||
{ value: '#,##0.0', label: '#,##0.0(千分位 1 位)' },
|
||||
{ value: '#,##0', label: '#,##0(千分位整数)' },
|
||||
{ value: '0.00', label: '0.00(2 位小数)' },
|
||||
{ value: '0.0', label: '0.0(1 位小数)' },
|
||||
{ value: '0', label: '0(整数)' },
|
||||
{ value: '0.00%', label: '0.00%' },
|
||||
]
|
||||
|
||||
const colRows = ref([]) // 当前 ERP 系统的可编辑列(数组顺序 = 导出列顺序)
|
||||
const hasCustomCols = ref(false)
|
||||
let writtenRaw = '' // 界面上一次写进 form 的 JSON(用于区分"自己写的"和"外部加载的")
|
||||
|
||||
// 内置标准列(作为可视化默认,与后端 _COLUMNS 保持同步)
|
||||
const builtinRows = (sys) => (COLUMN_TEMPLATES[sys] || COLUMN_TEMPLATES['新版']).map((c) => ({ ...c }))
|
||||
|
||||
function normalizeColumn(x) {
|
||||
if (Array.isArray(x)) {
|
||||
return { title: String(x[0] || ''), field: String(x[1] || ''), numeric: !!x[3], format: x[2] || '' }
|
||||
}
|
||||
return {
|
||||
title: String(x.title || ''),
|
||||
field: String(x.field || ''),
|
||||
numeric: !!x.numeric,
|
||||
format: x.format || x.number_format || '',
|
||||
}
|
||||
}
|
||||
|
||||
// 配置里取当前 ERP 系统那一份列;空/坏 JSON/没有该分支 → null(用内置标准)
|
||||
function parseBranch(raw, sys) {
|
||||
const text = (raw || '').trim()
|
||||
if (!text) return null
|
||||
try {
|
||||
const d = JSON.parse(text)
|
||||
const arr = Array.isArray(d)
|
||||
? d
|
||||
: (d[ERP_KEYS[sys] || 'new'] || d[sys] || d.columns || null)
|
||||
if (!Array.isArray(arr) || !arr.length) return null
|
||||
return arr.map(normalizeColumn)
|
||||
} catch (_) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
function readBranchMap(raw) {
|
||||
const text = (raw || '').trim()
|
||||
if (!text) return {}
|
||||
try {
|
||||
const d = JSON.parse(text)
|
||||
return d && typeof d === 'object' && !Array.isArray(d) ? { ...d } : null
|
||||
} catch (_) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
async function loadColumnRows() {
|
||||
const parsed = parseBranch(form.material_columns, form.erp_system)
|
||||
hasCustomCols.value = !!parsed
|
||||
colRows.value = parsed || builtinRows(form.erp_system)
|
||||
await nextTick()
|
||||
}
|
||||
|
||||
function rowsForConfig() {
|
||||
return colRows.value.map((r) => {
|
||||
const one = { title: String(r.title || '').trim(), field: String(r.field || '').trim(), numeric: !!r.numeric }
|
||||
if (r.format) one.format = r.format
|
||||
return one
|
||||
})
|
||||
}
|
||||
|
||||
function pushColumnRows() {
|
||||
const map = readBranchMap(form.material_columns) || {}
|
||||
delete map['新版'] // 清掉历史中文键,统一写 new/old(与后端一致)
|
||||
delete map['旧版']
|
||||
map[erpKey()] = rowsForConfig()
|
||||
const raw = JSON.stringify(map)
|
||||
writtenRaw = raw
|
||||
hasCustomCols.value = true
|
||||
form.material_columns = raw
|
||||
}
|
||||
|
||||
const onColumnEdit = () => pushColumnRows()
|
||||
|
||||
function addColumn() {
|
||||
colRows.value.push({ title: '新列', field: '', numeric: false, format: '' })
|
||||
pushColumnRows()
|
||||
}
|
||||
|
||||
function removeColumn(i) {
|
||||
if (colRows.value.length <= 1) return
|
||||
colRows.value.splice(i, 1)
|
||||
pushColumnRows()
|
||||
}
|
||||
|
||||
function moveColumn(i, delta) {
|
||||
const j = i + delta
|
||||
if (j < 0 || j >= colRows.value.length) return
|
||||
const [item] = colRows.value.splice(i, 1)
|
||||
colRows.value.splice(j, 0, item)
|
||||
pushColumnRows()
|
||||
}
|
||||
|
||||
function resetColumnsToBuiltin() {
|
||||
colRows.value = builtinRows(form.erp_system)
|
||||
pushColumnRows()
|
||||
ElMessage.info('已按内置标准重置,可继续微调')
|
||||
}
|
||||
|
||||
function clearColumns() {
|
||||
writtenRaw = ''
|
||||
form.material_columns = ''
|
||||
loadColumnRows()
|
||||
ElMessage.info('已清除自定义,恢复内置标准列')
|
||||
}
|
||||
|
||||
const sumTag = (row) => (row.numeric && SUM_FIELDS.includes(row.field) ? '计入末行合计' : '')
|
||||
|
||||
const colSummary = computed(() => `${hasCustomCols.value ? '自定义' : '内置标准'} ${colRows.value.length} 列`)
|
||||
|
||||
// 表单配置被外部改动(读配置/应用方案/恢复默认/切 ERP)→ 重建表格
|
||||
watch(() => form.material_columns, (raw) => {
|
||||
if ((raw || '') === writtenRaw) return
|
||||
loadColumnRows()
|
||||
})
|
||||
|
||||
// 首次加载完成后再建表(避免与配置加载互相覆盖)
|
||||
watch(loaded, (v) => { if (v) loadColumnRows() })
|
||||
|
||||
const orgOptions = computed(() => ORG_OPTIONS[form.erp_system] || ORG_OPTIONS['新版'])
|
||||
const stockOptions = computed(() => STOCK_OPTIONS[form.erp_system] || STOCK_OPTIONS['新版'])
|
||||
|
||||
@@ -321,6 +590,7 @@ watch(() => form.erp_system, (sys) => {
|
||||
} else {
|
||||
form.stock_codes = kept
|
||||
}
|
||||
loadColumnRows() // 新旧系统的标准列不同,切系统后重载列编辑表
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -346,6 +616,31 @@ watch(() => form.erp_system, (sys) => {
|
||||
.dir-ctrl .dir-input { flex: 1 1 auto; min-width: 0; }
|
||||
.dir-ctrl .dir-btn { flex: 0 0 auto; }
|
||||
|
||||
/* 导出列:可视化编辑表(窄屏横向滚动,不挤压布局) */
|
||||
.col-hint { font-size: 12px; opacity: 0.75; line-height: 1.6; margin-bottom: 8px; }
|
||||
.col-toolbar { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: 8px; }
|
||||
.col-count { font-size: 12px; opacity: 0.6; margin-left: auto; }
|
||||
.col-table { border: 1px solid var(--el-border-color-lighter); border-radius: 6px; overflow-x: auto; }
|
||||
.col-row {
|
||||
display: grid;
|
||||
grid-template-columns: 30px minmax(110px, 1.2fr) minmax(150px, 1.4fr) 46px minmax(96px, 1fr) 96px;
|
||||
gap: 6px;
|
||||
align-items: center;
|
||||
padding: 5px 8px;
|
||||
border-top: 1px solid var(--el-border-color-lighter);
|
||||
min-width: 560px;
|
||||
}
|
||||
.col-row.col-head { background: var(--el-fill-color-light); font-size: 12px; opacity: 0.7; border-top: none; }
|
||||
.col-row :deep(.el-input__wrapper), .col-row :deep(.el-select__wrapper) { padding: 0 6px; }
|
||||
.c-idx { font-size: 12px; opacity: 0.65; text-align: center; cursor: help; }
|
||||
.c-center { display: flex; justify-content: center; }
|
||||
.c-act { display: flex; justify-content: flex-end; gap: 2px; }
|
||||
.c-act :deep(.el-button) { padding: 0 4px; margin-left: 0; }
|
||||
.col-json-wrap { margin-top: 10px; }
|
||||
.col-json-wrap summary { font-size: 12px; opacity: 0.6; cursor: pointer; }
|
||||
.col-json { margin-top: 6px; }
|
||||
.col-json :deep(textarea) { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
|
||||
|
||||
/* 区块标题右侧的即时摘要 */
|
||||
.sec-tag { flex: 0 0 auto; font-size: 12px; opacity: 0.6; white-space: nowrap; }
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user