重构产品价和红线价功能

This commit is contained in:
wuweihua
2026-10-18 14:16:27 +08:00
parent db6f5e882a
commit 60d4614695
84 changed files with 6753 additions and 2843 deletions
+169 -334
View File
@@ -5,9 +5,16 @@
:closable="false"
show-icon
class="mb16"
title="导入前须先选择生效时间;产品与国家明细均按此时间落库,上一版产品/明细失效时间设为该时间。多国家价表用「全部导入」,单国专线成本价用「按国家导入」。相同产品代码+生效日期不覆盖主数据。"
title="已生效展示当前生效版本产品。待生效、已失效按版本展示;待生效可启动或删除整版。建价请点「新建产品价格」。"
/>
<el-tabs v-model="statusTab" class="catalog-tabs" @tab-change="onTabChange">
<el-tab-pane label="已生效" name="effect" />
<el-tab-pane label="待生效" name="pending" />
<el-tab-pane label="已失效" name="expired" />
</el-tabs>
<div v-show="statusTab === 'effect'">
<basic-table
ref="tableRef"
:extra-params="extraParams"
@@ -15,37 +22,11 @@
:search-columns="searchColumns"
:query="queryList"
row-key="productId"
:selection="true"
:selection="false"
>
<template #toolbar="{ selection }">
<template #toolbar>
<el-col :span="1.5">
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['price:product:add']">新建产品</el-button>
</el-col>
<el-col :span="1.5">
<el-dropdown @command="handleImportCommand">
<el-button type="info" plain icon="Upload" v-hasPermi="['price:product:import']">
导入 Excel<el-icon class="el-icon--right"><arrow-down /></el-icon>
</el-button>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item command="all">全部导入(多国家价表)</el-dropdown-item>
<el-dropdown-item command="country">按国家导入(单国专线成本价)</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="Delete"
:disabled="!selection.length"
@click="handleBatchDelete(selection)"
v-hasPermi="['price:product:remove']"
>批量删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button plain icon="Clock" @click="expiredRef.open()" v-hasPermi="['price:product:list']">失效价格</el-button>
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['price:product:add']">新建产品价格</el-button>
</el-col>
</template>
@@ -58,167 +39,104 @@
</template>
<template #col-action="{ row }">
<el-button link type="primary" title="价格" icon="Document" @click="excelFileRef.open(row)" v-hasPermi="['price:product:query']"></el-button>
<el-button link type="primary" title="产品明细" icon="View" @click="countryRef.open(row)" v-hasPermi="['price:product:query']"></el-button>
<el-button link type="primary" title="附加费" icon="Money" @click="surchargeRef.open(row)" v-hasPermi="['price:surcharge:query']"></el-button>
<el-button title="编辑" link type="primary" icon="Edit" @click="handleUpdate(row)" v-hasPermi="['price:product:edit']"></el-button>
</template>
</basic-table>
</div>
<product-form-dialog ref="formRef" @success="() => tableRef.refresh()" />
<product-excel-file-drawer ref="excelFileRef" />
<div v-show="statusTab === 'pending'">
<el-row class="mb12">
<el-col :span="1.5">
<el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['price:product:add']">新建产品价格</el-button>
</el-col>
</el-row>
<el-table v-loading="versionLoading" :data="versionRows" border empty-text="暂无待生效版本" @row-click="openVersionProducts">
<el-table-column label="版本号" prop="versionNo" width="120" />
<el-table-column label="生效时间" prop="effectiveTime" min-width="170" />
<el-table-column label="失效时间" prop="expireTime" min-width="170" />
<el-table-column label="状态" width="100" align="center">
<template #default="{ row }">{{ versionStatusText(row.status) }}</template>
</el-table-column>
<el-table-column label="产品数" prop="productCount" width="90" align="center" />
<el-table-column label="明细行数" prop="detailCount" width="100" align="center" />
<el-table-column label="操作" width="360" align="center" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click.stop="onEditVersion(row)" v-hasPermi="['price:product:edit']">编辑</el-button>
<el-button link type="primary" @click.stop="openVersionProducts(row)">查看产品</el-button>
<el-button link type="primary" @click.stop="openExcel(row)" v-hasPermi="['price:product:query']">查看附件</el-button>
<el-button link type="success" @click.stop="onStartVersion(row)" v-hasPermi="['price:product:edit']">启动</el-button>
<el-button link type="danger" @click.stop="onDeleteVersion(row)" v-hasPermi="['price:product:remove']">删除</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="versionTotal > 0"
:total="versionTotal"
v-model:page="versionQuery.pageNum"
v-model:limit="versionQuery.pageSize"
@pagination="loadVersions"
/>
</div>
<div v-show="statusTab === 'expired'">
<el-table v-loading="versionLoading" :data="versionRows" border empty-text="暂无失效版本" @row-click="openVersionProducts">
<el-table-column label="版本号" prop="versionNo" width="120" />
<el-table-column label="生效时间" prop="effectiveTime" min-width="170" />
<el-table-column label="失效时间" prop="expireTime" min-width="170" />
<el-table-column label="状态" width="100" align="center">
<template #default="{ row }">{{ versionStatusText(row.status) }}</template>
</el-table-column>
<el-table-column label="产品数" prop="productCount" width="90" align="center" />
<el-table-column label="明细行数" prop="detailCount" width="100" align="center" />
<el-table-column label="操作" width="220" align="center" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click.stop="openVersionProducts(row)">查看产品</el-button>
<el-button link type="primary" @click.stop="openExcel(row)" v-hasPermi="['price:product:query']">查看附件</el-button>
</template>
</el-table-column>
</el-table>
<pagination
v-show="versionTotal > 0"
:total="versionTotal"
v-model:page="versionQuery.pageNum"
v-model:limit="versionQuery.pageSize"
@pagination="loadVersions"
/>
</div>
<catalog-version-excel-drawer ref="excelRef" :list-fn="listProductVersionExcelFiles" />
<product-country-drawer ref="countryRef" />
<product-surcharge-drawer ref="surchargeRef" @success="() => tableRef.refresh()" />
<product-expired-drawer ref="expiredRef" @view-country="(row) => countryRef.open(row)" />
<excel-import-dialog
ref="importRef"
title="产品 Excel 导入"
width="560px"
:show-update-support="false"
template-url="/templates/product/product-import-all-template.xlsx"
template-file-name="产品多国家价表导入模板"
:import-desc="allImportDesc"
:before-submit="validateImportEffectiveDate"
:submit-handler="runImportAllAsync"
@success="() => tableRef.refresh()"
>
<template #extra>
<el-form label-width="90px">
<el-form-item label="生效时间" required>
<el-date-picker
v-model="importEffectiveDate"
type="datetime"
format="YYYY-MM-DD HH:00"
value-format="YYYY-MM-DD HH:00:00"
popper-class="product-import-hour-picker"
placeholder="请选择生效时间"
style="width: 100%"
@change="onImportEffectiveTimeChange"
/>
</el-form-item>
</el-form>
</template>
</excel-import-dialog>
<excel-import-dialog
ref="countryImportRef"
title="按国家导入"
width="560px"
:show-update-support="false"
:before-submit="validateCountryImport"
:import-desc="countryImportDesc"
template-url="/templates/product/product-import-country-template.xlsx"
template-file-name="产品按国家导入模板"
:submit-handler="runImportCountryAsync"
@success="() => tableRef.refresh()"
>
<template #extra>
<el-form label-width="90px">
<el-form-item label="生效时间" required>
<el-date-picker
v-model="importEffectiveDate"
type="datetime"
format="YYYY-MM-DD HH:00"
value-format="YYYY-MM-DD HH:00:00"
popper-class="product-import-hour-picker"
placeholder="请选择生效时间"
style="width: 100%"
@change="onImportEffectiveTimeChange"
/>
</el-form-item>
<el-form-item label="目的国家" required>
<el-select v-model="importCountryCode" filterable clearable placeholder="请选择国家" style="width: 100%">
<el-option
v-for="item in regionOptions"
:key="item.countryCode2"
:label="regionLabel(item)"
:value="item.countryCode2"
/>
</el-select>
</el-form-item>
</el-form>
</template>
</excel-import-dialog>
<el-dialog
v-model="importProgressVisible"
title="正在导入产品"
width="420px"
:close-on-click-modal="false"
:close-on-press-escape="false"
:show-close="false"
append-to-body
>
<div class="import-progress">
<el-progress :percentage="importProgressPercent" :status="importProgressStatus" />
<div class="import-progress-msg">{{ importProgressMessage }}</div>
</div>
</el-dialog>
<catalog-version-products-drawer ref="versionProductsRef" :list-fn="listProduct" @view="(row) => countryRef.open(row)" />
<catalog-activate-dialog ref="activateRef" :load-versions="loadAllVersions" :activate-fn="activateProductVersion" @success="onActivated" />
</div>
</template>
<script setup name="PriceProduct">
import ExcelImportDialog from '@/components/ExcelImportDialog'
import ProductFormDialog from './components/ProductFormDialog.vue'
import ProductExcelFileDrawer from './components/ProductExcelFileDrawer.vue'
import ProductCountryDrawer from './components/ProductCountryDrawer.vue'
import ProductSurchargeDrawer from './components/ProductSurchargeDrawer.vue'
import ProductExpiredDrawer from './components/ProductExpiredDrawer.vue'
import { listProduct, delProduct, importProductExcelAsync, importProductCountryExcelAsync } from '@/api/price/product'
import { listRegionOptions } from '@/api/data/region'
import CatalogVersionProductsDrawer from '../components/CatalogVersionProductsDrawer.vue'
import CatalogVersionExcelDrawer from '../components/CatalogVersionExcelDrawer.vue'
import CatalogActivateDialog from '../components/CatalogActivateDialog.vue'
import { listProduct, listProductVersions, activateProductVersion, deleteProductVersion, listProductVersionExcelFiles } from '@/api/price/product'
const { proxy } = getCurrentInstance()
const { bms_product_effect_status } = useDict('bms_product_effect_status')
const extraParams = { statusGroup: 'active' }
const statusTab = ref('effect')
const extraParams = reactive({ statusGroup: 'effect' })
const versionProductsRef = ref()
const activateRef = ref()
const versionLoading = ref(false)
const versionRows = ref([])
const versionTotal = ref(0)
const versionQuery = reactive({ pageNum: 1, pageSize: 10 })
const tableRef = ref()
const formRef = ref()
const excelFileRef = ref()
const countryRef = ref()
const surchargeRef = ref()
const expiredRef = ref()
const importRef = ref()
const countryImportRef = ref()
const importCountryCode = ref('')
const importEffectiveDate = ref('')
function pad2(n) {
return String(n).padStart(2, '0')
}
function formatImportHour(d) {
if (!d || Number.isNaN(d.getTime())) return undefined
return d.getFullYear() + '-' + pad2(d.getMonth() + 1) + '-' + pad2(d.getDate())
+ ' ' + pad2(d.getHours()) + ':00:00'
}
function normalizeImportToHour(val) {
if (val == null || val === '') return val
if (val instanceof Date) return formatImportHour(val)
const s = String(val).trim().replace('T', ' ')
const m = s.match(/^(\d{4}-\d{2}-\d{2})[ ](\d{2})/)
if (m) return m[1] + ' ' + m[2] + ':00:00'
if (/^\d{4}-\d{2}-\d{2}$/.test(s)) return s + ' 00:00:00'
return formatImportHour(new Date(s.replace(/-/g, '/'))) || val
}
function onImportEffectiveTimeChange(val) {
importEffectiveDate.value = normalizeImportToHour(val) || ''
}
const regionOptions = ref([])
const importProgressVisible = ref(false)
const importProgressPercent = ref(0)
const importProgressMessage = ref('')
const importProgressStatus = ref(undefined)
const allImportDesc = [
'适用多国家价表(B2C 小包价表等),按目录 sheet 匹配国家导入。',
'必选生效时间:产品与 product_country 明细均按此时间计费;上一版产品/明细失效时间设为该时间。',
'请在弹窗底部下载模板,按模板格式整理后上传。相同产品代码+生效日期不覆盖主数据。'
]
const countryImportDesc = [
'选择目的国家后上传专线成本价表,目录中的产品都会记到该国家。',
'必选生效时间:产品与 product_country 明细均按此时间计费;上一版产品/明细失效时间设为该时间。',
'邮编、赔偿标准等 sheet 不导入。可在弹窗底部下载模板。'
]
const excelRef = ref()
const columns = [
{ prop: 'productCode', label: '产品代码', minWidth: 110 },
@@ -232,20 +150,12 @@ const columns = [
{ prop: 'surchargeCount', label: '附加费数', width: 90, align: 'center' },
{ prop: 'status', label: '状态', width: 90, align: 'center', slot: 'status' },
{ prop: 'updateNote', label: '更新内容', minWidth: 160, showOverflowTooltip: true },
{ prop: 'action', label: '操作', width: 240, fixed: 'right', slot: 'action' }
{ prop: 'action', label: '操作', width: 120, fixed: 'right', slot: 'action' }
]
const searchColumns = [
{ prop: 'productCode', label: '产品代码', component: 'input', placeholder: '产品代码' },
{ prop: 'productName', label: '产品名称', component: 'input', placeholder: '产品名称' },
{
prop: 'status',
label: '状态',
component: 'select',
dict: 'bms_product_effect_status',
placeholder: '请选择状态',
width: '160px'
}
{ prop: 'productName', label: '产品名称', component: 'input', placeholder: '产品名称' }
]
function queryList(params) {
@@ -258,177 +168,102 @@ function queryList(params) {
}
function handleAdd() {
formRef.value.open()
proxy.$router.push({ path: '/price/product-create/index' })
}
function handleUpdate(row) {
formRef.value.open(row)
}
function isPendingProduct(row) {
if (!row) return false
if (String(row.status) === '0') return true
// fallback: effective in future and not expired
if (!row.effectiveDate) return false
const eff = new Date(String(row.effectiveDate).replace(/-/g, '/')).getTime()
if (Number.isNaN(eff) || eff <= Date.now()) return false
if (row.expireDate) {
const exp = new Date(String(row.expireDate).replace(/-/g, '/')).getTime()
if (!Number.isNaN(exp) && exp <= Date.now()) return false
}
return true
}
function handleBatchDelete(selection) {
const rows = (selection || []).filter(r => r && r.productId != null)
if (!rows.length) {
proxy.$modal.msgWarning('请先勾选产品')
function openExcel(row) {
if (!row || row.psvId == null) {
proxy.$modal.msgWarning('该行没有版本,无法查看附件')
return
}
const pending = rows.filter(isPendingProduct)
const blocked = rows.filter(r => !isPendingProduct(r))
if (!pending.length) {
proxy.$modal.msgWarning('仅待生效产品可删除,当前勾选无待生效记录')
excelRef.value && excelRef.value.open(row)
}
function onTabChange(name) {
if (name === 'pending' || name === 'expired') {
versionQuery.pageNum = 1
loadVersions()
return
}
if (blocked.length) {
const tip = blocked.map(r => r.productCode || r.productId).join('、')
proxy.$modal.msgWarning('已跳过非待生效产品:' + tip)
extraParams.statusGroup = 'effect'
nextTick(() => tableRef.value && tableRef.value.refresh())
}
function versionStatusText(status) {
const map = { '0': '草稿', '1': '已生效', '2': '已失效', '3': '待生效' }
return map[String(status)] || status || '-'
}
function loadVersions() {
versionLoading.value = true
const params = {
pageNum: versionQuery.pageNum,
pageSize: versionQuery.pageSize
}
const codes = pending.map(r => r.productCode || r.productId).join('、')
const ids = pending.map(r => r.productId)
proxy.$modal.confirm(
'确认删除已选待生效产品(' + pending.length + '个):'
+ codes
+ '?删除后产品及国家/重量段明细将一并清除,且不可恢复。'
).then(() => delProduct(ids)).then(() => {
tableRef.value.refresh()
if (statusTab.value === 'pending') params.statusGroup = 'pending'
else params.status = '2'
listProductVersions(params).then(res => {
versionRows.value = res.rows || []
versionTotal.value = res.total || 0
}).finally(() => { versionLoading.value = false })
}
function loadAllVersions() {
return listProductVersions({ pageNum: 1, pageSize: 500 }).then(res => res.rows || [])
}
function openVersionProducts(row) {
versionProductsRef.value && versionProductsRef.value.open(row)
}
function onEditVersion(row) {
if (!row || row.psvId == null) return
proxy.$router.push({
path: '/price/product-create/index',
query: {
psvId: row.psvId,
versionNo: row.versionNo || undefined
}
})
}
function onStartVersion(row) {
if (row && row.psvId != null) {
activateRef.value && activateRef.value.open(row)
return
}
loadAllVersions().then(list => {
const pending = (list || []).filter(v => v && (String(v.status) === '0' || String(v.status) === '3'))
if (!pending.length) {
proxy.$modal.msgWarning('当前没有可启动的待生效版本')
return
}
pending.sort((a, b) => (Number(b.versionSeq) || 0) - (Number(a.versionSeq) || 0))
const draft = pending.find(v => String(v.status) === '0')
activateRef.value && activateRef.value.open(draft || pending[0])
})
}
function onDeleteVersion(row) {
if (!row || row.psvId == null) return
proxy.$modal.confirm('确认硬删除该待生效版本?版本、产品、明细将从数据库真删除,且不可恢复。').then(() => deleteProductVersion(row.psvId)).then(() => {
loadVersions()
proxy.$modal.msgSuccess('删除成功')
}).catch(() => {})
}
function handleImportCommand(command) {
if (command === 'country') {
handleCountryImport()
return
}
handleImport()
function onActivated() {
if (statusTab.value === 'pending' || statusTab.value === 'expired') loadVersions()
else if (tableRef.value) tableRef.value.refresh()
}
function handleImport() {
importEffectiveDate.value = ''
importRef.value.open()
}
function regionLabel(item) {
const name = item.countryNameCn || item.countryNameEn || ''
const code = item.countryCode2 || ''
return name && code ? name + ' (' + code + ')' : (name || code)
}
function loadRegionOptions() {
if (regionOptions.value.length) return
listRegionOptions().then(res => {
regionOptions.value = res.data || []
})
}
function handleCountryImport() {
importCountryCode.value = ''
importEffectiveDate.value = ''
loadRegionOptions()
countryImportRef.value.open()
}
function validateImportEffectiveDate() {
if (!importEffectiveDate.value) {
return '请先选择生效时间'
}
return ''
}
function validateCountryImport() {
const effErr = validateImportEffectiveDate()
if (effErr) return effErr
if (!importCountryCode.value) {
return '请先选择目的国家'
}
return ''
}
function applyImportProgress(t) {
importProgressPercent.value = Math.min(100, Number(t.percent) || 0)
if (t.status === 'PENDING') importProgressMessage.value = '排队中…'
else if (t.status === 'RUNNING') {
const m = t.message || ''
if (m === 'parsing excel') importProgressMessage.value = '正在解析价表…'
else if (m === 'finishing') importProgressMessage.value = '收尾中…'
else if (m === 'queued') importProgressMessage.value = '排队中…'
else if (m.indexOf('importing ') === 0) {
const rest = m.slice('importing '.length)
importProgressMessage.value = '正在导入产品 ' + rest
} else importProgressMessage.value = m || '正在导入…'
} else if (t.status === 'SUCCESS') {
importProgressMessage.value = t.message || '导入完成'
importProgressStatus.value = 'success'
} else if (t.status === 'FAIL') {
importProgressMessage.value = t.error || t.message || '导入失败'
importProgressStatus.value = 'exception'
}
}
async function runImportWithProgress(runner) {
importProgressVisible.value = true
importProgressPercent.value = 0
importProgressMessage.value = '上传并解析中…'
importProgressStatus.value = undefined
try {
const { task } = await runner(applyImportProgress)
importProgressPercent.value = 100
importProgressStatus.value = 'success'
return (task && task.message) ? task.message : '导入完成'
} catch (e) {
importProgressStatus.value = 'exception'
const tip = (e && e.task && e.task.error) || (e && e.message) || '导入失败'
importProgressMessage.value = tip
await new Promise(resolve => setTimeout(resolve, 600))
throw e
} finally {
importProgressVisible.value = false
}
}
async function runImportAllAsync(uploadFile) {
const raw = uploadFile && (uploadFile.raw || uploadFile)
if (!raw) {
throw new Error('请先选择文件')
}
if (!importEffectiveDate.value) {
throw new Error('请先选择生效时间')
}
const eff = importEffectiveDate.value
return runImportWithProgress((onProgress) => importProductExcelAsync(raw, eff, onProgress))
}
async function runImportCountryAsync(uploadFile) {
const raw = uploadFile && (uploadFile.raw || uploadFile)
if (!raw) {
throw new Error('请先选择文件')
}
if (!importEffectiveDate.value) {
throw new Error('请先选择生效时间')
}
if (!importCountryCode.value) {
throw new Error('请先选择目的国家')
}
const code = importCountryCode.value
const eff = importEffectiveDate.value
return runImportWithProgress((onProgress) => importProductCountryExcelAsync(raw, code, eff, onProgress))
}
</script>
<style scoped>
.mb16 { margin-bottom: 16px; }
.mb12 { margin-bottom: 12px; }
.catalog-tabs { margin-bottom: 8px; }
.import-progress { padding: 8px 4px 4px; }
.import-progress-msg {
margin-top: 12px;