- 新增配置项 material_columns(JSON,留空=内置标准),logic/material_summary.resolve_columns 解析并校验,配置错误在取数前 fail-fast,不生成半截文件 - 导出列按 2026-11-16 平台样本对齐:新版 12 列、数量列 0 值留空、数字格式、 按「物料编码→仓库编码」排序、末行只汇总期初/收入/发出/结存 - 插件界面新增「05 导出列」可视化编辑表(表头/字段/数值/格式 + 上移下移删除/重置) - 同步 README 与开发文档;重建 ui 产物
647 lines
29 KiB
Vue
647 lines
29 KiB
Vue
<template>
|
||
<div class="page">
|
||
<!-- 方案工具条:整组靠右;方案供「定时任务」按 config_id 引用 -->
|
||
<div class="toolbar">
|
||
<span class="spacer" />
|
||
<span class="saved" :class="{ 'is-idle': !lastSavedAt }">
|
||
<i />{{ lastSavedAt ? '已保存 ' + lastSavedAt : '尚未保存' }}
|
||
</span>
|
||
<el-select v-model="schemeSel" class="scheme-sel" size="small" :disabled="running"
|
||
placeholder="当前配置(自动保存)" @change="onSchemeChange">
|
||
<el-option v-for="o in schemeOptions" :key="o.value" :label="o.label" :value="o.value" />
|
||
</el-select>
|
||
<el-button size="small" :disabled="running" @click="saveSchemeAs">存为方案</el-button>
|
||
<el-button size="small" text type="danger" :disabled="running || !schemeSel"
|
||
@click="removeScheme">删除</el-button>
|
||
</div>
|
||
|
||
<!-- 内联提示:未登录(不可关)/ 本次动作短提示 -->
|
||
<div v-if="notice" class="notice" :class="'is-' + notice.type">
|
||
<span class="n-ico">{{ notice.type === 'ok' ? '✓' : (notice.type === 'error' ? '✕' : '!') }}</span>
|
||
<span>{{ notice.text }}</span>
|
||
</div>
|
||
|
||
<!-- 01 执行模式:决定导哪张报表 -->
|
||
<section class="sec">
|
||
<div class="sec-head">
|
||
<span class="sec-badge">01</span>
|
||
<span class="sec-name">执行模式</span>
|
||
<span class="sec-line" />
|
||
</div>
|
||
<div class="sec-body">
|
||
<el-form label-position="top">
|
||
<el-radio-group v-model="form.mode" class="mode-group" :disabled="running">
|
||
<el-radio value="两个都导" border class="mode-card">
|
||
<span class="m-title">两个都导</span>
|
||
<span class="m-desc">物料收发汇总表(多档)+ 采购订单列表,一次登录连导</span>
|
||
</el-radio>
|
||
<el-radio value="物料收发汇总表" border class="mode-card">
|
||
<span class="m-title">仅物料收发汇总</span>
|
||
<span class="m-desc">按日期多档导出并合并成汇总文件</span>
|
||
</el-radio>
|
||
<el-radio value="采购订单列表" border class="mode-card">
|
||
<span class="m-title">仅采购订单列表</span>
|
||
<span class="m-desc">按固定列导出全部采购订单明细</span>
|
||
</el-radio>
|
||
</el-radio-group>
|
||
<div class="tip">
|
||
两张报表都走金蝶云星空 WebAPI(账密登录,不开浏览器),一次登录共用会话。
|
||
{{ form.mode === '采购订单列表' ? '该模式不需要仓库/日期设置。' : '' }}
|
||
</div>
|
||
</el-form>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 02 登录与系统 -->
|
||
<section class="sec">
|
||
<div class="sec-head">
|
||
<span class="sec-badge">02</span>
|
||
<span class="sec-name">ERP 登录</span>
|
||
<span class="sec-line" />
|
||
<span class="sec-tag">{{ form.erp_system }}</span>
|
||
</div>
|
||
<div class="sec-body">
|
||
<el-form label-position="top">
|
||
<div class="grid">
|
||
<el-form-item label="ERP 系统">
|
||
<el-radio-group v-model="form.erp_system" :disabled="running">
|
||
<el-radio-button value="新版">新版</el-radio-button>
|
||
<el-radio-button value="旧版">旧版</el-radio-button>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
<el-form-item label="登录账号">
|
||
<el-input v-model="form.erp_username" placeholder="ERP 登录账号"
|
||
:disabled="running" clearable />
|
||
</el-form-item>
|
||
<el-form-item label="登录密码">
|
||
<el-input v-model="form.erp_password" type="password" show-password
|
||
placeholder="仅保存在本机,下次免填" :disabled="running" />
|
||
</el-form-item>
|
||
</div>
|
||
<div class="tip">
|
||
新版 <b>criterion.erp.37du.co</b> / 旧版 <b>erp.37du.co</b>,两套账号不通用
|
||
(旧版请填旧系统账号)。密码只存本机,不会出现在日志里。
|
||
</div>
|
||
</el-form>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 03 查询范围(仅物料收发汇总) -->
|
||
<section v-show="form.mode !== '采购订单列表'" class="sec">
|
||
<div class="sec-head">
|
||
<span class="sec-badge">03</span>
|
||
<span class="sec-name">查询范围</span>
|
||
<span class="sec-line" />
|
||
<span class="sec-tag">已选 {{ (form.stock_codes || []).length || '全部' }} 个仓库</span>
|
||
</div>
|
||
<div class="sec-body">
|
||
<el-form label-position="top">
|
||
<el-form-item label="查询组织">
|
||
<el-select v-model="form.org_name" filterable allow-create default-first-option
|
||
:reserve-keyword="false" placeholder="选择或输入组织" :disabled="running" class="wide">
|
||
<el-option v-for="o in orgOptions" :key="o" :value="o" :label="o" />
|
||
</el-select>
|
||
<div class="tip">
|
||
候选按 ERP 系统切换:新版=金七象;旧版=石桥铺会馆。也可直接输入其它组织(格式
|
||
<b>编码 名称</b>)。
|
||
</div>
|
||
</el-form-item>
|
||
<el-form-item label="日期选项(多选,逐档导出)">
|
||
<el-select v-model="form.date_options" multiple filterable allow-create default-first-option
|
||
:reserve-keyword="false" placeholder="勾选预设,或输入自定义区间后回车"
|
||
:disabled="running" class="wide">
|
||
<el-option v-for="d in DATE_PRESETS" :key="d" :value="d" :label="d" />
|
||
</el-select>
|
||
<div class="tip">N天 = 今天往前推 N 天;自定义区间格式 <b>2026-01-01~2026-09-15</b>(输入后回车)。</div>
|
||
</el-form-item>
|
||
<el-form-item label="仓库编码(多选,或关系)">
|
||
<el-select v-model="form.stock_codes" multiple filterable allow-create default-first-option
|
||
:reserve-keyword="false" placeholder="选择或输入仓库编码" :disabled="running" class="wide">
|
||
<el-option v-for="w in stockOptions" :key="w.code" :value="w.code"
|
||
:label="w.code + ' ' + w.name" />
|
||
</el-select>
|
||
<div class="tip">
|
||
候选按 ERP 系统切换:新版=五个三方仓;旧版=03010127 代管仓。留空 = 不限仓库(仅按组织过滤)。
|
||
</div>
|
||
</el-form-item>
|
||
</el-form>
|
||
</div>
|
||
</section>
|
||
|
||
<!-- 04 保存目录 -->
|
||
<section class="sec">
|
||
<div class="sec-head">
|
||
<span class="sec-badge">04</span>
|
||
<span class="sec-name">保存位置</span>
|
||
<span class="sec-line" />
|
||
</div>
|
||
<div class="sec-body">
|
||
<el-form label-position="top">
|
||
<el-form-item label="保存目录">
|
||
<div class="dir-ctrl">
|
||
<el-input v-model="form.save_dir" class="dir-input" :disabled="running" clearable
|
||
placeholder="留空 = 桌面\采购计划报表_今天日期" />
|
||
<el-button class="dir-btn" :disabled="running || picking" :loading="picking"
|
||
@click="pickDir">选择</el-button>
|
||
</div>
|
||
<div class="tip">两张报表输出到同一目录;物料收发汇总会额外生成一份多档合并的汇总文件。</div>
|
||
</el-form-item>
|
||
</el-form>
|
||
</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>
|
||
<div class="help-body">
|
||
<div class="hb-line"><b>① 登录</b>:用这里填的账号密码直连金蝶云星空 WebAPI
|
||
(<b>AuthService.ValidateUser</b>),不开浏览器、不需要手动登录;一次登录两张报表共用会话。</div>
|
||
<div class="hb-line"><b>② 物料收发汇总表</b>:走分页报表接口
|
||
<b>StockReportQueryService.GetReportData</b>,按日期档逐档取数并落 xlsx
|
||
(说明行 + 表头 + 数据 + 合计),最后合并成「物料收发汇总表_日期.xlsx」。
|
||
仓库按编码直接过滤,不再下载全部仓库。</div>
|
||
<div class="hb-line"><b>③ 采购订单列表</b>:走 <b>ExecuteBillQuery</b> 分页取明细,
|
||
列结构与历史「按列表引出数据」完全一致(新版 22 列 / 旧版 17 列,末行合计)。
|
||
新版只导「金七象 + 标准采购订单 + 未作废」;旧版导「石桥铺会馆 + 未作废」全类型。</div>
|
||
<div class="hb-line"><b>④ 耗时参考</b>:物料收发汇总单档约 10~30 秒(行数越多越慢);
|
||
采购订单新版约 2 万行、旧版约 11.7 万行(约 2 分钟)。</div>
|
||
<div class="hb-line"><b>⑤ 注意</b>:报表过滤方案必须是<b>共享方案</b>(当前为「API专用(共享)」);
|
||
换组织/仓库口径需同步调整后端 <b>config.REPORT_ORG_ID</b> 与 <b>PO_FILTER_STRING</b>。</div>
|
||
</div>
|
||
</details>
|
||
|
||
<!-- 操作区 -->
|
||
<div class="actions">
|
||
<el-button type="primary" class="btn-run" :loading="running" @click="start">
|
||
{{ running ? '执行中 ' + progress + '%' : '一键执行' }}
|
||
</el-button>
|
||
<el-button v-if="running" type="danger" plain :loading="stopping"
|
||
@click="forceStop">强制停止</el-button>
|
||
<span class="spacer" />
|
||
<el-button :disabled="running" @click="restoreLastFields">恢复上次参数</el-button>
|
||
<el-button :disabled="running" @click="saveNow(true)">保存配置</el-button>
|
||
<el-button text :disabled="running" @click="resetDefaults">恢复默认</el-button>
|
||
</div>
|
||
|
||
<!-- 运行态:只留一行文字,进度与日志由壳子展示 -->
|
||
<div v-if="running" class="runline">
|
||
<span class="pulse" />
|
||
<span>正在执行,日志与进度实时显示在工作台下方「运行日志」区</span>
|
||
<span class="pct">{{ progress }}%</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup>
|
||
import { computed, nextTick, ref, watch } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import { usePluginUI } from './usePluginUI'
|
||
|
||
const DATE_PRESETS = ['60D', '30D', '15D', '7D', '3D']
|
||
|
||
// 组织候选:按 ERP 系统区分(新版只有金七象;旧版只有石桥铺会馆)
|
||
const ORG_OPTIONS = {
|
||
'新版': ['99.01 重庆金七象供应链管理有限公司'],
|
||
'旧版': ['99.01.07.01.01 石桥铺会馆'],
|
||
}
|
||
|
||
// 仓库候选:按 ERP 系统区分(新版=五个三方仓;旧版=代管仓),值与显示名分开
|
||
const STOCK_OPTIONS = {
|
||
'新版': [
|
||
{ code: '0101010101', name: '重庆运营总仓' },
|
||
{ code: '0101010201', name: '重庆美得三方仓' },
|
||
{ code: '0101020201', name: '成都美得三方仓' },
|
||
{ code: '0101030201', name: '长沙乐行三方仓' },
|
||
{ code: '0101040201', name: '西安美得三方仓' },
|
||
],
|
||
'旧版': [
|
||
{ code: '03010127', name: '代管仓' },
|
||
],
|
||
}
|
||
|
||
// 新旧系统各自的默认查询组织(与后端 config.ORG_NAME / ORG_NAME_OLD 保持一致)
|
||
const ORG_DEFAULTS = {
|
||
'新版': '99.01 重庆金七象供应链管理有限公司',
|
||
'旧版': '99.01.07.01.01 石桥铺会馆',
|
||
}
|
||
|
||
// 新旧系统各自的默认仓库编码(旧版 = 03010127 代管仓)
|
||
const STOCK_DEFAULTS = {
|
||
'新版': STOCK_OPTIONS['新版'].map((w) => w.code),
|
||
'旧版': 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) || '新版'
|
||
return {
|
||
mode: '两个都导',
|
||
erp_system: sys,
|
||
erp_username: '',
|
||
erp_password: '',
|
||
org_name: ORG_DEFAULTS[sys],
|
||
stock_codes: [...STOCK_DEFAULTS[sys]],
|
||
date_options: [...DATE_PRESETS],
|
||
scheme_name: '',
|
||
save_dir: '',
|
||
material_columns: '',
|
||
}
|
||
}
|
||
|
||
const {
|
||
form, loaded, notice, lastSavedAt, running, progress, stopping,
|
||
saveNow, resetDefaults, restoreLastFields,
|
||
schemeSel, schemeOptions, onSchemeChange, saveSchemeAs, removeScheme,
|
||
run, forceStop,
|
||
} = usePluginUI({
|
||
defaults: DEFAULTS,
|
||
validate() {
|
||
if (!form.erp_username.trim() || !form.erp_password) {
|
||
ElMessage.warning('请先填写 ERP 登录账号和密码')
|
||
return false
|
||
}
|
||
if (form.mode !== '采购订单列表') {
|
||
if (!(form.date_options || []).length) {
|
||
ElMessage.warning('请至少选择一个日期选项')
|
||
return false
|
||
}
|
||
if (!(form.org_name || '').trim()) {
|
||
ElMessage.warning('请填写查询组织')
|
||
return false
|
||
}
|
||
if (colRows.value.some((r) => !String(r.title || '').trim() || !String(r.field || '').trim())) {
|
||
ElMessage.warning('导出列里有「表头文字」或「接口字段」为空,请先在 05 区补全')
|
||
return false
|
||
}
|
||
}
|
||
return true
|
||
},
|
||
})
|
||
|
||
function start() {
|
||
run()
|
||
}
|
||
|
||
// 调用壳子本机接口打开原生「选择文件夹」对话框(仅返回路径)
|
||
const picking = ref(false)
|
||
async function pickDir() {
|
||
picking.value = true
|
||
try {
|
||
const r = await fetch('/api/dialog/directory', {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json' },
|
||
body: JSON.stringify({ title: '选择保存目录', current: form.save_dir || '' }),
|
||
})
|
||
const d = await r.json().catch(() => ({}))
|
||
if (!r.ok) throw new Error(d.detail || d.error || ('HTTP ' + r.status))
|
||
if (d.path) form.save_dir = d.path
|
||
} catch (e) {
|
||
ElMessage.warning('打开文件夹选择失败:' + e.message)
|
||
} finally {
|
||
picking.value = false
|
||
}
|
||
}
|
||
|
||
// ---- 导出列:可视化编辑(底层仍以 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['新版'])
|
||
|
||
function sameArray(a, b) {
|
||
if (!a || !b || a.length !== b.length) return false
|
||
const s = new Set(a)
|
||
return b.every((x) => s.has(x))
|
||
}
|
||
|
||
// 切换 ERP 系统:组织/仓库未自定义时自动带出本系统默认,并剔除不属于该系统的仓库编码
|
||
watch(() => form.erp_system, (sys) => {
|
||
if (!loaded.value || running.value) return
|
||
const orgOther = sys === '新版' ? ORG_DEFAULTS['旧版'] : ORG_DEFAULTS['新版']
|
||
if (!form.org_name || form.org_name === orgOther || !orgOptions.value.includes(form.org_name)) {
|
||
form.org_name = ORG_DEFAULTS[sys]
|
||
}
|
||
const validCodes = (STOCK_OPTIONS[sys] || []).map((w) => w.code)
|
||
const cur = form.stock_codes || []
|
||
const kept = cur.filter((c) => validCodes.includes(c))
|
||
if (!kept.length || sameArray(cur, STOCK_DEFAULTS[sys === '新版' ? '旧版' : '新版'])) {
|
||
form.stock_codes = [...STOCK_DEFAULTS[sys]]
|
||
} else {
|
||
form.stock_codes = kept
|
||
}
|
||
loadColumnRows() // 新旧系统的标准列不同,切系统后重载列编辑表
|
||
})
|
||
</script>
|
||
|
||
<style scoped>
|
||
/* 插件差异样式:只用壳子 token,不写字面色值;左右内边距由壳子提供 */
|
||
/* 执行模式:三张卡片一行(窄屏自动换行) */
|
||
.mode-group { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); width: 100%; }
|
||
.mode-group :deep(.el-radio) {
|
||
height: auto;
|
||
width: 100%;
|
||
margin: 0;
|
||
padding: 10px 14px;
|
||
align-items: flex-start;
|
||
white-space: normal;
|
||
}
|
||
.mode-group :deep(.el-radio__input) { margin-top: 2px; }
|
||
.mode-group :deep(.el-radio__label) { display: block; line-height: 1.5; white-space: normal; }
|
||
.m-title { display: block; font-weight: 600; }
|
||
.m-desc { display: block; font-size: 12px; opacity: 0.65; }
|
||
|
||
/* 保存目录:输入框撑满 + 右侧选择按钮 */
|
||
.dir-ctrl { display: flex; align-items: center; gap: var(--space-2); width: 100%; }
|
||
.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>
|