新增打单产品分区管理功能,优化常规分区逻辑

This commit is contained in:
wuweihua
2026-11-18 19:01:40 +08:00
parent 4b766184b5
commit 0445c4fa21
19 changed files with 787 additions and 50 deletions
+18 -1
View File
@@ -17,7 +17,7 @@ export function getCountry(regionId) {
})
}
/** Delete all zones + postcodes for region(s); does not delete region */
/** Delete all REGULAR zones + postcodes for region(s); does not delete region */
export function delCountryZones(regionIds) {
return request({
url: '/price/zone/country/' + regionIds,
@@ -25,6 +25,23 @@ export function delCountryZones(regionIds) {
})
}
// ========== label product zones ==========
export function listLabelProduct(query) {
return request({
url: '/price/zone/label/product/list',
method: 'get',
params: query
})
}
export function delLabelProductZones(productId) {
return request({
url: '/price/zone/label/product/' + productId,
method: 'delete'
})
}
// ========== zone item ==========
export function listZone(query) {
@@ -0,0 +1,198 @@
<template>
<el-drawer v-model="visible" size="860px" append-to-body>
<template #header>
<div class="drawer-head">
<span class="drawer-title">打单产品分区</span>
<span v-if="product" class="drawer-sub">
当前:{{ product.productName || product.dictValue || product.productId }}
<template v-if="product.dictValue">({{ product.dictValue }})</template>
,共 {{ zoneList.length }} 个分区
</span>
</div>
</template>
<div v-loading="zoneLoading">
<div class="zone-toolbar">
<el-button
type="primary"
plain
icon="Plus"
size="small"
:disabled="!product"
@click="handleZoneAdd"
v-hasPermi="['price:zone:add']"
>新增分区</el-button>
<el-button
type="danger"
plain
icon="Delete"
size="small"
:disabled="!product"
@click="handleClearZones"
v-hasPermi="['price:zone:remove']"
>清空分区</el-button>
</div>
<el-table
:data="zoneList"
border
highlight-current-row
row-key="zoneId"
:empty-text="product ? '该产品暂无分区,可导入打单价卡同步或点击「新增分区」' : '请先选择产品'"
>
<el-table-column label="分区名称" align="center" min-width="200">
<template #default="{ row }">
<div class="zone-country-cell">
<div class="zone-title">{{ row.zoneName || row.zoneCode }}</div>
<el-button link type="primary" class="zone-click" @click="openPostcodeDrawer(row)" v-hasPermi="['price:zone:query']">分区点击</el-button>
</div>
</template>
</el-table-column>
<el-table-column label="国家编码" prop="countryCode" align="center" width="110" />
<el-table-column label="分区代码" prop="zoneCode" align="center" width="140" />
<el-table-column label="邮编数" prop="detailCount" align="center" width="100" />
<el-table-column label="排序" prop="zoneSort" align="center" width="80" />
<el-table-column label="操作" align="center" width="220" fixed="right">
<template #default="{ row }">
<el-button link type="primary" icon="View" @click="openPostcodeDrawer(row)" v-hasPermi="['price:zone:query']">明细</el-button>
<el-button link type="primary" icon="Edit" @click="handleZoneUpdate(row)" v-hasPermi="['price:zone:edit']">编辑</el-button>
<el-button link type="primary" icon="Delete" @click="handleZoneDelete(row.zoneId)" v-hasPermi="['price:zone:remove']">删除</el-button>
</template>
</el-table-column>
</el-table>
</div>
<zone-form-dialog ref="zoneFormRef" :country="formCountry" zone-type="LABEL" :product-id="product?.productId" @success="onZoneChanged" />
<postcode-drawer ref="postcodeDrawerRef" @changed="onZoneChanged" />
</el-drawer>
</template>
<script setup name="LabelZoneDrawer">
import {
delLabelProductZones,
listZone, addZone, updateZone, delZone
} from '@/api/price/zone'
import ZoneFormDialog from './ZoneFormDialog.vue'
import PostcodeDrawer from './PostcodeDrawer.vue'
const { proxy } = getCurrentInstance()
const emit = defineEmits(['changed'])
const visible = ref(false)
const product = ref(null)
const zoneList = ref([])
const zoneLoading = ref(false)
const zoneFormRef = ref()
const postcodeDrawerRef = ref()
const formCountry = computed(() => {
if (!product.value) return null
// ZoneFormDialog expects region fields; LABEL zones still carry regionId/countryCode from sync
const first = zoneList.value[0]
return {
regionId: first?.regionId || null,
countryCode2: first?.countryCode || '',
countryNameCn: product.value.productName || product.value.dictValue || ''
}
})
function open(row) {
product.value = row || null
visible.value = true
loadZoneList()
}
function reload() {
loadZoneList()
}
function loadZoneList() {
if (!product.value?.productId) {
zoneList.value = []
return
}
zoneLoading.value = true
listZone({ zoneType: 'LABEL', productId: product.value.productId, pageNum: 1, pageSize: 200 }).then(res => {
zoneList.value = res.rows || []
}).catch(() => {
zoneList.value = []
}).finally(() => {
zoneLoading.value = false
})
}
function handleZoneAdd() {
if (!formCountry.value?.regionId) {
proxy.$modal.msgWarning('该产品尚无国家分区主数据,请先通过打单价卡导入同步')
return
}
zoneFormRef.value.open()
}
function handleZoneUpdate(row) {
zoneFormRef.value.open(row)
}
function onZoneChanged() {
// ensure newly added zone is LABEL + product scoped
loadZoneList()
emit('changed')
}
function handleZoneDelete(zoneIds) {
proxy.$modal.confirm('是否确认删除分区编号为"' + zoneIds + '"的数据?将同时删除邮编明细。').then(() => {
return delZone(zoneIds)
}).then(() => {
proxy.$modal.msgSuccess('删除成功')
onZoneChanged()
}).catch(() => {})
}
function handleClearZones() {
if (!product.value?.productId) return
proxy.$modal.confirm('是否清空打单产品 productId="' + product.value.productId + '" 下的全部分区与邮编?').then(() => {
return delLabelProductZones(product.value.productId)
}).then(() => {
zoneList.value = []
proxy.$modal.msgSuccess('清空成功')
emit('changed')
}).catch(() => {})
}
function onProductCleared(productId) {
if (visible.value && String(product.value?.productId) === String(productId)) {
zoneList.value = []
}
}
function openPostcodeDrawer(row) {
postcodeDrawerRef.value.open(row)
}
defineExpose({ open, reload, onProductCleared })
</script>
<style scoped>
.drawer-head {
display: flex;
align-items: center;
gap: 12px;
flex-wrap: wrap;
}
.drawer-title { font-size: 16px; font-weight: 600; }
.drawer-sub { color: #909399; font-size: 13px; }
.zone-toolbar {
display: flex;
align-items: center;
margin-bottom: 12px;
}
.zone-country-cell {
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
padding: 4px 0;
}
.zone-title { font-weight: 500; }
.zone-click { padding: 0; height: auto; font-size: 12px; }
</style>
@@ -138,7 +138,7 @@ function loadZoneList(regionId) {
return
}
zoneLoading.value = true
listZone({ regionId, pageNum: 1, pageSize: 200 }).then(res => {
listZone({ zoneType: 'REGULAR', regionId, pageNum: 1, pageSize: 200 }).then(res => {
zoneList.value = res.rows || []
}).catch(() => {
zoneList.value = []
@@ -39,6 +39,16 @@ const props = defineProps({
country: {
type: Object,
default: null
},
/** REGULAR / LABEL,默认常规 */
zoneType: {
type: String,
default: 'REGULAR'
},
/** 打单产品 ID(LABEL 时必填) */
productId: {
type: [Number, String],
default: null
}
})
@@ -59,6 +69,8 @@ function open2(row) {
? { ...row }
: {
zoneId: undefined,
zoneType: props.zoneType || 'REGULAR',
productId: props.productId || undefined,
regionId: props.country?.regionId,
countryCode: props.country?.countryCode2 || undefined,
zoneCode: undefined,
@@ -80,6 +92,8 @@ function submitForm() {
.toString().trim().toUpperCase()
const payload = {
...form.value,
zoneType: form.value.zoneType || props.zoneType || 'REGULAR',
productId: props.zoneType === 'LABEL' ? (props.productId || form.value.productId) : null,
regionId: region?.regionId,
countryCode: code,
zoneName: form.value.zoneName || (cn ? (cn + '(' + form.value.zoneCode + ')') : form.value.zoneCode)
+80 -5
View File
@@ -1,14 +1,29 @@
<template>
<div class="app-container">
<el-tabs v-model="activeTab" class="mb16" @tab-change="onTabChange">
<el-tab-pane label="常规计费分区" name="regular" />
<el-tab-pane label="打单计费分区" name="label" />
</el-tabs>
<el-alert
v-if="activeTab === 'regular'"
type="info"
:closable="false"
show-icon
class="mb16"
title="国家来自 region;点击「分区」在抽屉中查看/维护国家分区,抽屉内点击「分区点击」查看邮编明细。导入 Excel 时需 sheet 名以「分区」结尾且能匹配国家表。"
title="常规计费按国家维护分区;点击「分区」维护邮编。导入 Excel 时 sheet 名需以「分区」结尾且能匹配国家表。"
/>
<el-alert
v-else
type="info"
:closable="false"
show-icon
class="mb16"
title="打单计费按产品维护分区;由打单价卡导入同步。计费时按渠道绑定产品 + 订单邮编匹配分区。"
/>
<basic-table
v-show="activeTab === 'regular'"
ref="countryTableRef"
:columns="countryColumns"
:search-columns="countrySearchColumns"
@@ -36,7 +51,22 @@
</template>
</basic-table>
<basic-table
v-show="activeTab === 'label'"
ref="labelTableRef"
:columns="labelColumns"
:search-columns="labelSearchColumns"
:query="queryLabelProductList"
row-key="productId"
>
<template #col-action="{ row }">
<el-button link type="primary" icon="List" @click.stop="openLabelZoneDrawer(row)" v-hasPermi="['price:zone:query']">分区</el-button>
<el-button link type="primary" icon="Delete" @click.stop="handleLabelDelete(row.productId)" v-hasPermi="['price:zone:remove']">清空</el-button>
</template>
</basic-table>
<zone-drawer ref="zoneDrawerRef" @changed="onZoneChanged" />
<label-zone-drawer ref="labelZoneDrawerRef" @changed="onLabelZoneChanged" />
<excel-import-dialog
ref="importRef"
@@ -51,13 +81,17 @@
<script setup name="PriceZone">
import ExcelImportDialog from '@/components/ExcelImportDialog'
import { listCountry, delCountryZones } from '@/api/price/zone'
import { listCountry, delCountryZones, listLabelProduct, delLabelProductZones } from '@/api/price/zone'
import ZoneDrawer from './components/ZoneDrawer.vue'
import LabelZoneDrawer from './components/LabelZoneDrawer.vue'
const { proxy } = getCurrentInstance()
const activeTab = ref('regular')
const countryTableRef = ref()
const labelTableRef = ref()
const zoneDrawerRef = ref()
const labelZoneDrawerRef = ref()
const importRef = ref()
const countrySearchColumns = [
@@ -75,11 +109,35 @@ const countryColumns = [
{ label: '操作', prop: 'action', align: 'center', width: 160, showInToolbar: false }
]
const labelSearchColumns = [
{ label: '产品名称', prop: 'productName', component: 'input', placeholder: '产品名称 / 字典值', width: '260px' }
]
const labelColumns = [
{ label: '产品编号', prop: 'productId', align: 'center', width: 110 },
{ label: '产品名称', prop: 'productName', align: 'center', minWidth: 180 },
{ label: '字典值', prop: 'dictValue', align: 'center', minWidth: 160 },
{ label: '分区数', prop: 'zoneCount', align: 'center', width: 90 },
{ label: '邮编数', prop: 'detailCount', align: 'center', width: 100 },
{ label: '操作', prop: 'action', align: 'center', width: 160, showInToolbar: false }
]
function queryCountryList(params) {
return listCountry(params)
}
/** 工具栏「为国家新增分区」:不传国家,抽屉内自行选择 */
function queryLabelProductList(params) {
return listLabelProduct(params)
}
function onTabChange() {
if (activeTab.value === 'regular') {
countryTableRef.value?.refresh?.()
} else {
labelTableRef.value?.refresh?.()
}
}
function handleAddZone() {
zoneDrawerRef.value.open()
}
@@ -88,13 +146,20 @@ function openZoneDrawer(row) {
zoneDrawerRef.value.open(row)
}
/** 抽屉内分区/邮编有变动 → 刷新国家表格的分区数/邮编数统计 */
function openLabelZoneDrawer(row) {
labelZoneDrawerRef.value.open(row)
}
function onZoneChanged() {
countryTableRef.value.refresh()
}
function onLabelZoneChanged() {
labelTableRef.value.refresh()
}
function handleCountryDelete(regionIds) {
proxy.$modal.confirm('是否清空国家 regionId="' + regionIds + '" 下的全部分区与邮编?(不会删除 region 国家主数据)').then(() => {
proxy.$modal.confirm('是否清空国家 regionId="' + regionIds + '" 下的全部常规分区与邮编?(不会删除 region 国家主数据)').then(() => {
return delCountryZones(regionIds)
}).then(() => {
countryTableRef.value.refresh()
@@ -103,6 +168,16 @@ function handleCountryDelete(regionIds) {
}).catch(() => {})
}
function handleLabelDelete(productId) {
proxy.$modal.confirm('是否清空打单产品 productId="' + productId + '" 下的全部分区与邮编?').then(() => {
return delLabelProductZones(productId)
}).then(() => {
labelTableRef.value.refresh()
labelZoneDrawerRef.value.onProductCleared(productId)
proxy.$modal.msgSuccess('清空成功')
}).catch(() => {})
}
function handleImport() {
importRef.value.open()
}