This commit is contained in:
liufumingren 2026-05-25 08:57:20 +08:00
parent cb70b96229
commit 5547fc74b1
4 changed files with 330 additions and 28 deletions

View File

@ -180,6 +180,34 @@ export function getPlatformList(data?: Record<string, unknown>) {
} as any)
}
export function getPrintPlatformList(data?: Record<string, unknown>) {
return request({
url: '/system',
method: 'post',
params: {
method: 'index.getPrintPlatformList',
v: '1.0',
timestamp: new Date().getTime()
},
data: data ?? {},
isSystemApi: true
} as any)
}
export function getPrintPlatformTemplateList(data?: { platform_code?: string; express_code: string }) {
return request({
url: '/system',
method: 'post',
params: {
method: 'index.getPrintPlatformTemplateList',
v: '1.0',
timestamp: new Date().getTime()
},
data: data ?? ({} as any),
isSystemApi: true
} as any)
}
/** 获取平台授权链接(当前仅支持 PDD) */
export function getPlatformOauthLink(data?: {
code?: string

View File

@ -47,6 +47,8 @@ export type ExpressInterfaceCreateParams = {
platform_code: string
shop_id?: number
sys_express_code?: string
is_system_express_code?: number
is_hide_goods?: number
sender_name?: string
sender_tel?: string
weight?: number
@ -64,6 +66,7 @@ export type ExpressInterfaceCreateParams = {
address?: string
town_name?: string
site_code?: string
template_url?: string
product_type?: string
shop_name?: string
ext_data?: Record<string, any>

View File

@ -1,5 +1,5 @@
import pcasCodeData from 'china-division/dist/pcas-code.json'
import type { ExpressInterfaceCreateParams } from '@/api/setting.expressinterface/expressInterface'
import type { ExpressInterfaceCreateParams } from '@/api/setting.expressInterface/expressInterface'
/** setting.expressInterface.list 单条记录字段顺序(与接口返回一致) */
export const expressInterfaceListFieldOrder = [
@ -9,6 +9,7 @@ export const expressInterfaceListFieldOrder = [
'platform_code',
'express_code',
'sys_express_code',
'is_system_express_code',
'express_name',
'shop_name',
'sender_name',
@ -19,7 +20,9 @@ export const expressInterfaceListFieldOrder = [
'address',
'town_name',
'site_code',
'template_url',
'product_type',
'is_hide_goods',
'weight',
'weight_type',
'viewer',
@ -57,7 +60,10 @@ export const expressInterfaceFieldLabels: Record<string, string> = {
address: '详细地址',
town_name: '乡镇/街道',
site_code: '站点编码',
product_type: '快递产品类型',
template_url: '打印模板',
product_type: '产品编码',
is_hide_goods: '是否隐藏商品',
is_system_express_code: '是否系统快递编码',
shop_name: '店铺名称',
warehouse_id: '仓库ID',
ext_data: '扩展数据',
@ -428,6 +434,7 @@ export const defaultExpressInterfaceForm = {
name: '',
express_code: '',
sys_express_code: '',
is_system_express_code: 1,
platform_code: '',
express_name: '',
sender_name: '',
@ -442,8 +449,10 @@ export const defaultExpressInterfaceForm = {
shipperno: '',
can_use_count: undefined as number | undefined,
site_code: '',
template_url: '',
shop_name: '',
product_type: '',
is_hide_goods: 0,
address: '',
town_name: '',
ext_data: undefined as Record<string, any> | undefined,
@ -487,13 +496,20 @@ export function applyExpressInterfaceRowToForm(
row: Record<string, any>
) {
const ext = parseExpressInterfaceExtData(row.ext_data)
const rawExpressCode = toFormString(row.express_code)
const rawSysExpressCode = toFormString(row.sys_express_code)
const isCustomExpressCode = (toFormOptionalNumber(row.is_system_express_code) ?? 1) === 0
const signedExpressCode = rawSysExpressCode || rawExpressCode
const customExpressCode = isCustomExpressCode ? rawExpressCode : ''
Object.assign(form, {
id: row.id,
warehouse_id: toFormOptionalNumber(row.warehouse_id),
shop_id: toFormOptionalNumber(row.shop_id ?? row.shopId),
name: toFormString(row.name),
express_code: toFormString(row.express_code),
sys_express_code: toFormString(row.sys_express_code),
express_code: signedExpressCode,
sys_express_code: customExpressCode,
is_system_express_code: toFormOptionalNumber(row.is_system_express_code) ?? 1,
platform_code: toFormString(row.platform_code),
express_name: toFormString(row.express_name || row.express?.name),
sender_name: toFormString(row.sender_name),
@ -508,8 +524,10 @@ export function applyExpressInterfaceRowToForm(
shipperno: toFormString(row.shipperno),
can_use_count: toFormOptionalNumber(row.can_use_count),
site_code: toFormString(row.site_code),
template_url: toFormString(row.template_url ?? row.templateUrl),
shop_name: toFormString(row.shop_name),
product_type: toFormString(row.product_type),
is_hide_goods: toFormOptionalNumber(row.is_hide_goods) ?? 0,
address: toFormString(row.address),
town_name: toFormString(row.town_name),
province_name: toFormString(row.province_name),
@ -524,7 +542,7 @@ export function formatExpressInterfaceFormDisplayValue(
key: string,
val: unknown
): string {
if (key === 'is_share' || key === 'ispickup') {
if (key === 'is_share' || key === 'ispickup' || key === 'is_hide_goods') {
if (val === 1 || val === true) return '是'
if (val === 0 || val === false) return '否'
return '--'
@ -581,6 +599,7 @@ export function buildExpressInterfaceCreatePayload(
'address',
'town_name',
'site_code',
'template_url',
'product_type',
'shop_name'
] as const
@ -589,12 +608,23 @@ export function buildExpressInterfaceCreatePayload(
if (v !== undefined) payload[key] = v
}
const optionalNumbers = ['shop_id', 'weight', 'weight_type', 'share_id', 'ispickup', 'can_use_count'] as const
const optionalNumbers = [
'shop_id',
'is_system_express_code',
'is_hide_goods',
'weight',
'weight_type',
'share_id',
'ispickup',
'can_use_count'
] as const
for (const key of optionalNumbers) {
const n = omitOptionalNumber(form[key])
if (n === undefined) continue
const rounded =
key === 'shop_id' ||
key === 'is_system_express_code' ||
key === 'is_hide_goods' ||
key === 'weight' ||
key === 'weight_type' ||
key === 'ispickup' ||
@ -613,8 +643,14 @@ export function buildExpressInterfaceCreatePayload(
/** setting.expressInterface.update 请求体 */
export function buildExpressInterfaceUpdatePayload(form: Record<string, any>): Record<string, any> {
const sourceExpressCode = String(form.express_code || '').trim()
const customExpressCode = String(form.sys_express_code || '').trim()
const basePayload = buildExpressInterfaceCreatePayload(form)
return {
...buildExpressInterfaceCreatePayload(form),
...basePayload,
express_code: customExpressCode || sourceExpressCode,
sys_express_code: sourceExpressCode || undefined,
id: form.id
}
}

View File

@ -138,13 +138,13 @@
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item class="platform-form-item" label="平台编码" prop="platform_code">
<el-form-item class="platform-form-item" label="平台" prop="platform_code">
<div class="platform-select-row">
<el-select
v-model="formData.platform_code"
class="platform-select"
filterable
placeholder="请选择平台编码"
placeholder="请选择平台"
@change="handlePlatformCodeChange"
>
<el-option
@ -334,6 +334,24 @@
</el-select>
</el-form-item>
</el-col>
<el-col v-if="dialogMonthlyAccountOptions.length > 0" :span="24">
<el-form-item label="月结账号">
<el-select
v-model="formData.shipperno"
filterable
clearable
placeholder="请选择月结账号"
@change="handleMonthlyAccountChange"
>
<el-option
v-for="item in dialogMonthlyAccountOptions"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col v-if="dialogMode === 'create' || showRegionField" :span="24">
<el-form-item label="省市区">
@ -376,7 +394,7 @@
<el-col :span="12">
<el-form-item label="重量类型">
<el-select v-model="formData.weight_type" clearable placeholder="请选择重量类型">
<el-option :value="1" label="普通" />
<el-option :value="0" label="普通" />
<el-option :value="2" label="重货" />
<el-option :value="3" label="轻货" />
<el-option :value="4" label="生鲜" />
@ -388,6 +406,46 @@
<el-input v-model="formData.viewer" placeholder="可选,最长 50 字符" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品编码">
<el-input v-model="formData.product_type" placeholder="请输入产品编码" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="打印模板">
<el-select
v-model="formData.template_url"
filterable
clearable
:loading="printTemplateLoading"
:disabled="!formData.express_code"
placeholder="请选择打印模板"
>
<el-option
v-for="item in templateOptions"
:key="item.value"
:label="item.label || item.value"
:value="item.value"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="是否隐藏商品">
<div class="hide-goods-field">
<el-switch
v-model="formData.is_hide_goods"
:active-value="1"
:inactive-value="0"
active-text="是"
inactive-text="否"
/>
<div class="hide-goods-tip">
开启后,快递方接收到的商品名称将统一修改为:商品
</div>
</div>
</el-form-item>
</el-col>
</el-row>
</div>
@ -422,7 +480,8 @@ import ScanBox from '@/components/ScanBox/index.vue'
import UpperTable from '@/components/UpperTable/index.vue'
import {
getExpressList,
getPlatformList,
getPrintPlatformList,
getPrintPlatformTemplateList,
getPlatformOauthLink,
getShopList,
getShopExpressList
@ -433,7 +492,7 @@ import {
expressInterfaceList,
expressInterfaceListByWarehousePlatformCode,
expressInterfaceUpdate
} from '@/api/setting.expressinterface/expressInterface'
} from '@/api/setting.expressInterface/expressInterface'
import { useUserStore } from '@/stores/modules/user'
import { useSettingsStore } from '@/stores/modules/settings'
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
@ -460,6 +519,8 @@ type PlatformOption = { code: string; name: string; label?: string }
type ShopOption = { value: number | string; label: string }
type ServiceOption = { code: string; name: string; raw: Record<string, any> }
type AddressOption = { key: string; label: string; raw: Record<string, any> }
type MonthlyAccountOption = { value: string; label: string }
type TemplateOption = { value: string; label: string; raw: Record<string, any> }
type ServiceFlatField = {
key: string
serviceCode: string
@ -539,8 +600,10 @@ const platformOptions = ref<PlatformOption[]>([])
const shopOptions = ref<ShopOption[]>([])
const dialogExpressOptions = ref<ExpressOption[]>([])
const customExpressOptions = ref<ExpressOption[]>([])
const templateOptions = ref<TemplateOption[]>([])
const selectedShopId = ref<number | string | undefined>(undefined)
const useCustomExpressCode = ref(false)
const printTemplateLoading = ref(false)
const serviceValueMap = ref<Record<string, any>>({})
const shopExpressSitesMap = ref<Record<string, SiteOption[]>>({})
const selectedSiteKey = ref<string>('')
@ -666,6 +729,20 @@ const selectedAddress = computed<AddressOption | null>(() => {
return dialogAddressOptions.value.find((item) => item.key === selectedAddressKey.value) || null
})
const dialogMonthlyAccountOptions = computed<MonthlyAccountOption[]>(() => {
const site = selectedSite.value
const list = Array.isArray(site?.raw?.customer_code_list) ? site.raw.customer_code_list : []
const uniq = new Set<string>()
const options: MonthlyAccountOption[] = []
list.forEach((item: any) => {
const value = String(item ?? '').trim()
if (!value || uniq.has(value)) return
uniq.add(value)
options.push({ value, label: value })
})
return options
})
const warehouseContextHint = computed(() => {
const u = userStore.user || {}
const sid = u.store_id ?? u.warehouse_id
@ -977,7 +1054,7 @@ async function loadExpressOptions() {
async function loadPlatformOptions() {
try {
const res: any = await getPlatformList({ systemOnly: true })
const res: any = await getPrintPlatformList({})
if (!isSuccess(res)) {
platformOptions.value = []
return
@ -992,23 +1069,88 @@ async function loadPlatformOptions() {
}
}
async function loadCustomExpressOptions() {
async function loadPrintPlatformTemplateOptions(sourceExpressCode?: string, sourcePlatformCode?: string) {
const expressCode = String(sourceExpressCode ?? formData.express_code ?? '').trim().toUpperCase()
if (!expressCode) {
templateOptions.value = []
formData.template_url = ''
return
}
if (printTemplateLoading.value) return
printTemplateLoading.value = true
try {
const platformCode = String(sourcePlatformCode ?? formData.platform_code ?? '').trim().toUpperCase()
const res: any = await getPrintPlatformTemplateList({
platform_code: platformCode || undefined,
express_code: expressCode
})
if (!isSuccess(res)) {
templateOptions.value = []
formData.template_url = ''
ElMessage.error(res?.message || '获取打印模板列表失败')
return
}
const templateList = Array.isArray(res?.data?.standard_templates?.standard_template_do)
? res.data.standard_templates.standard_template_do
: []
const nextOptions = templateList
.map((item: any) => ({
value: String(item?.standard_template_url || '').trim(),
label: String(item?.standard_template_name || item?.standard_template_url || '').trim(),
raw: item || {}
}))
.filter((item: TemplateOption) => !!item.value)
templateOptions.value = nextOptions
const currentTemplateUrl = String(formData.template_url || '').trim()
if (!currentTemplateUrl) return
const exists = nextOptions.some((item: TemplateOption) => item.value === currentTemplateUrl)
if (!exists) {
formData.template_url = ''
}
} catch {
templateOptions.value = []
formData.template_url = ''
ElMessage.error('获取打印模板列表失败')
} finally {
printTemplateLoading.value = false
}
}
async function loadCustomExpressOptions(sourceExpressCode?: string) {
const expressCode = String(sourceExpressCode ?? formData.express_code ?? '').trim().toUpperCase()
if (!expressCode) {
customExpressOptions.value = []
formData.sys_express_code = ''
return
}
if (customExpressLoading.value) return
customExpressLoading.value = true
try {
const res: any = await getExpressList({})
const res: any = await getExpressList({
systemOnly: false,
express_code: expressCode
})
if (!isSuccess(res)) {
customExpressOptions.value = []
ElMessage.error(res?.message || '获取自定义快递编码列表失败')
return
}
customExpressOptions.value = (res?.data || [])
const nextOptions = (res?.data || [])
.map((item: any) => ({
code: String(item?.express_code || item?.code || '').trim(),
name: String(item?.express_name || item?.name || '').trim(),
label: String(item?.label || item?.express_name || item?.name || '').trim()
code: String(item?.code || item?.custom_code || item?.sys_express_code || item?.express_code || '').trim(),
name: String(item?.name || item?.express_name || item?.code || '').trim(),
label: String(item?.label || item?.name || item?.code || '').trim()
}))
.filter((item: ExpressOption) => !!item.code)
customExpressOptions.value = nextOptions
const currentCustomCode = String(formData.sys_express_code || '').trim()
if (!currentCustomCode) return
const exists = nextOptions.some((item: ExpressOption) => item.code === currentCustomCode)
if (!exists) {
formData.sys_express_code = ''
}
} catch {
customExpressOptions.value = []
ElMessage.error('获取自定义快递编码列表失败')
@ -1245,10 +1387,31 @@ function initializeAddressSelection(preferredAddress?: string) {
handleAddressChange(target.key)
}
function handleMonthlyAccountChange(value: string | number | undefined) {
formData.shipperno = String(value ?? '').trim()
}
function initializeMonthlyAccountSelection(preferredShipperno?: string, clearWhenEmpty = true) {
const options = dialogMonthlyAccountOptions.value
if (!options.length) {
if (clearWhenEmpty) {
formData.shipperno = ''
}
return
}
const preferred = String(preferredShipperno ?? formData.shipperno ?? '').trim()
const matched = preferred ? options.find((item) => item.value === preferred) : null
const first = options[0]
if (!first) return
formData.shipperno = matched ? matched.value : first.value
}
function initializeSiteSelection(
preferredSiteCode?: string,
preferredAddress?: string,
preferredServiceCodes?: string[]
preferredServiceCodes?: string[],
preferredShipperno?: string
) {
const sites = dialogSiteOptions.value
if (!sites.length) {
@ -1308,6 +1471,7 @@ function initializeSiteSelection(
if (!target) return
handleSiteChange(target.key)
initializeAddressSelection(preferredAddress)
initializeMonthlyAccountSelection(preferredShipperno, false)
}
function syncExtDataByServiceSelection() {
@ -1342,13 +1506,22 @@ function syncExtDataByServiceSelection() {
formData.ext_data = Object.keys(serviceSelection).length > 0 ? serviceSelection : undefined
}
function handleExpressCodeChange() {
async function handleExpressCodeChange() {
const currentExpressCode = String(formData.express_code || '').trim()
selectedSiteKey.value = ''
selectedAddressKey.value = ''
formData.site_code = ''
formData.shipperno = ''
formData.sys_express_code = ''
customExpressOptions.value = []
formData.template_url = ''
templateOptions.value = []
applyAddressRaw(undefined)
serviceValueMap.value = {}
syncExtDataByServiceSelection()
await loadPrintPlatformTemplateOptions(currentExpressCode, formData.platform_code)
if (!useCustomExpressCode.value || !currentExpressCode) return
await loadCustomExpressOptions(currentExpressCode)
}
function handleServiceValueChange() {
@ -1357,12 +1530,14 @@ function handleServiceValueChange() {
async function handleCustomExpressSwitchChange(value: boolean) {
useCustomExpressCode.value = value
formData.is_system_express_code = value ? 0 : 1
if (!value) {
formData.sys_express_code = ''
customExpressOptions.value = []
formRef.value?.clearValidate('sys_express_code')
return
}
await loadCustomExpressOptions()
await loadCustomExpressOptions(formData.express_code)
}
async function handlePlatformCodeChange(value: string | number | undefined) {
@ -1373,6 +1548,11 @@ async function handlePlatformCodeChange(value: string | number | undefined) {
formData.shop_name = ''
formData.express_code = ''
formData.site_code = ''
formData.shipperno = ''
formData.sys_express_code = ''
formData.template_url = ''
customExpressOptions.value = []
templateOptions.value = []
selectedSiteKey.value = ''
selectedAddressKey.value = ''
applyAddressRaw(undefined)
@ -1392,6 +1572,11 @@ async function handleShopChange(value: string | number | undefined) {
formData.express_code = ''
serviceValueMap.value = {}
formData.ext_data = undefined
formData.shipperno = ''
formData.sys_express_code = ''
formData.template_url = ''
customExpressOptions.value = []
templateOptions.value = []
dialogExpressOptions.value = []
shopExpressSitesMap.value = {}
selectedSiteKey.value = ''
@ -1430,6 +1615,7 @@ function resetForm() {
editExpressRelation.value = null
useCustomExpressCode.value = false
serviceValueMap.value = {}
templateOptions.value = []
formRef.value?.clearValidate()
}
@ -1444,6 +1630,7 @@ async function openCreate() {
selectedSiteKey.value = ''
selectedAddressKey.value = ''
shopOptions.value = []
templateOptions.value = []
}
async function openEdit(row: ExpressInterfaceRecord) {
@ -1460,10 +1647,17 @@ async function openEdit(row: ExpressInterfaceRecord) {
shopExpressSitesMap.value = {}
selectedSiteKey.value = ''
selectedAddressKey.value = ''
templateOptions.value = []
applyExpressInterfaceRowToForm(formData, row)
useCustomExpressCode.value = !!String(formData.sys_express_code || '').trim()
if (formData.is_system_express_code === 0 || String(formData.is_system_express_code) === '0') {
useCustomExpressCode.value = true
} else if (formData.is_system_express_code === 1 || String(formData.is_system_express_code) === '1') {
useCustomExpressCode.value = false
} else {
useCustomExpressCode.value = !!String(formData.sys_express_code || '').trim()
}
if (useCustomExpressCode.value) {
await loadCustomExpressOptions()
await loadCustomExpressOptions(formData.express_code)
}
editExpressRelation.value =
row.express && typeof row.express === 'object' ? (row.express as Record<string, any>) : null
@ -1487,7 +1681,12 @@ async function openEdit(row: ExpressInterfaceRecord) {
extServiceValues && typeof extServiceValues === 'object'
? Object.keys(extServiceValues).map((key) => String(key || '').trim()).filter((key) => !!key)
: []
initializeSiteSelection(rowSiteCode, String(row.address || '').trim(), preferredServiceCodes)
initializeSiteSelection(
rowSiteCode,
String(row.address || '').trim(),
preferredServiceCodes,
String(row.shipperno || formData.shipperno || '').trim()
)
if (extServiceValues && typeof extServiceValues === 'object') {
const patch: Record<string, any> = {}
const serviceFieldCount: Record<string, number> = {}
@ -1525,6 +1724,7 @@ async function openEdit(row: ExpressInterfaceRecord) {
}
]
}
await loadPrintPlatformTemplateOptions(formData.express_code, formData.platform_code)
formRef.value?.clearValidate()
}
@ -1569,6 +1769,7 @@ async function submitForm() {
const valid = await formRef.value.validate().catch(() => false)
if (!valid) return
formData.is_system_express_code = useCustomExpressCode.value ? 0 : 1
syncExtDataByServiceSelection()
saving.value = true
@ -1767,15 +1968,36 @@ onMounted(async () => {
}
}
.config-dialog :deep(.el-dialog__body) {
:deep(.config-dialog .el-dialog__body) {
padding-top: 8px;
padding-bottom: 8px;
max-height: min(70vh, 640px);
overflow-y: auto;
overflow-x: hidden;
}
.config-dialog--edit :deep(.el-dialog__body) {
max-height: min(82vh, 780px);
:deep(.config-dialog--edit.el-dialog) {
height: calc(100dvh - 32px);
max-height: calc(100dvh - 32px);
max-width: calc(100dvw - 32px);
margin: 16px auto !important;
display: flex;
flex-direction: column;
overflow: hidden;
}
:deep(.config-dialog--edit.el-dialog .el-dialog__header),
:deep(.config-dialog--edit.el-dialog .el-dialog__footer) {
flex: 0 0 auto;
}
:deep(.config-dialog--edit.el-dialog .el-dialog__body) {
flex: 1 1 auto;
min-height: 0;
max-height: none;
box-sizing: border-box;
overflow-y: auto;
overflow-x: hidden;
}
.ext-data-preview :deep(textarea) {
@ -1891,4 +2113,17 @@ onMounted(async () => {
.region-display-row {
width: 100%;
}
.hide-goods-field {
display: flex;
flex-direction: column;
gap: 6px;
width: 100%;
}
.hide-goods-tip {
font-size: 12px;
line-height: 1.4;
color: var(--el-text-color-secondary, #909399);
}
</style>