feat(express-interface): pick 产品编码 from the express product type list
- read product_types from index.getShopExpressList and keep it keyed by both wp_code and sys_express_code, mirroring the existing site option mapping - render 产品编码 as a filterable select labelled "名称(编码)" and keep storing the code; hide the field entirely when the express returns no product_types - clear a stale product_type when the express / platform / shop changes Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
9aa6e4ca0d
commit
e2e1aeaa95
@ -436,9 +436,21 @@
|
|||||||
<el-input v-model="formData.viewer" placeholder="可选,最长 50 字符" />
|
<el-input v-model="formData.viewer" placeholder="可选,最长 50 字符" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12">
|
<el-col v-if="dialogProductTypeOptions.length" :span="12">
|
||||||
<el-form-item label="产品编码">
|
<el-form-item label="产品编码">
|
||||||
<el-input v-model="formData.product_type" placeholder="请输入产品编码" />
|
<el-select
|
||||||
|
v-model="formData.product_type"
|
||||||
|
filterable
|
||||||
|
clearable
|
||||||
|
placeholder="请选择产品编码"
|
||||||
|
>
|
||||||
|
<el-option
|
||||||
|
v-for="item in dialogProductTypeOptions"
|
||||||
|
:key="item.code"
|
||||||
|
:label="item.label"
|
||||||
|
:value="item.code"
|
||||||
|
/>
|
||||||
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12" v-if="formData.can_use_count !== undefined">
|
<el-col :span="12" v-if="formData.can_use_count !== undefined">
|
||||||
@ -573,6 +585,7 @@ import {
|
|||||||
resolveExpressInterfaceAddress
|
resolveExpressInterfaceAddress
|
||||||
} from './express-interface-config'
|
} from './express-interface-config'
|
||||||
|
|
||||||
|
type ProductTypeOption = { code: string; name: string; label: string }
|
||||||
type ExpressOption = { code: string; name: string; label?: string; sysExpressCode?: string; providerid?: string }
|
type ExpressOption = { code: string; name: string; label?: string; sysExpressCode?: string; providerid?: string }
|
||||||
type PlatformOption = { code: string; name: string; label?: string }
|
type PlatformOption = { code: string; name: string; label?: string }
|
||||||
type ShopOption = { value: number | string; label: string }
|
type ShopOption = { value: number | string; label: string }
|
||||||
@ -770,6 +783,8 @@ const activeTemplateExpressCode = computed(() =>
|
|||||||
)
|
)
|
||||||
const serviceValueMap = ref<Record<string, any>>({})
|
const serviceValueMap = ref<Record<string, any>>({})
|
||||||
const shopExpressSitesMap = ref<Record<string, SiteOption[]>>({})
|
const shopExpressSitesMap = ref<Record<string, SiteOption[]>>({})
|
||||||
|
/** 已签约快递 → 产品编码列表(product_types),来源 index.getShopExpressList */
|
||||||
|
const shopExpressProductTypesMap = ref<Record<string, ProductTypeOption[]>>({})
|
||||||
const selectedSiteKey = ref<string>('')
|
const selectedSiteKey = ref<string>('')
|
||||||
const selectedAddressKey = ref<string>('')
|
const selectedAddressKey = ref<string>('')
|
||||||
const SERVICE_EMPTY_ENUM_TOKEN = '__SERVICE_EMPTY_ENUM__'
|
const SERVICE_EMPTY_ENUM_TOKEN = '__SERVICE_EMPTY_ENUM__'
|
||||||
@ -885,6 +900,21 @@ const dialogSiteOptions = computed<SiteOption[]>(() => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** 当前已选快递的产品编码下拉项;快递未返回 product_types(或为空)时为空数组,对应「产品编码」不展示 */
|
||||||
|
const dialogProductTypeOptions = computed<ProductTypeOption[]>(() => {
|
||||||
|
const selectedSignedCode = String(formData.sys_express_code || '').trim()
|
||||||
|
const selectedSignedExpress = dialogExpressOptions.value.find(
|
||||||
|
(item) => String(item.sysExpressCode || item.code || '').trim() === selectedSignedCode
|
||||||
|
)
|
||||||
|
const selectedSysCode = String(selectedSignedExpress?.sysExpressCode || formData.express_code || '').trim()
|
||||||
|
if (!selectedSignedCode && !selectedSysCode) return []
|
||||||
|
return (
|
||||||
|
shopExpressProductTypesMap.value[selectedSignedCode] ||
|
||||||
|
shopExpressProductTypesMap.value[selectedSysCode] ||
|
||||||
|
[]
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
const selectedSite = computed<SiteOption | null>(() => {
|
const selectedSite = computed<SiteOption | null>(() => {
|
||||||
if (!selectedSiteKey.value) return null
|
if (!selectedSiteKey.value) return null
|
||||||
return dialogSiteOptions.value.find((item) => item.key === selectedSiteKey.value) || null
|
return dialogSiteOptions.value.find((item) => item.key === selectedSiteKey.value) || null
|
||||||
@ -1429,11 +1459,13 @@ async function loadShopExpressOptions(shopId: string | number) {
|
|||||||
const res: any = await getShopExpressList({ shop_id: shopId, shopId: shopId })
|
const res: any = await getShopExpressList({ shop_id: shopId, shopId: shopId })
|
||||||
if (!isSuccess(res)) {
|
if (!isSuccess(res)) {
|
||||||
dialogExpressOptions.value = []
|
dialogExpressOptions.value = []
|
||||||
|
shopExpressProductTypesMap.value = {}
|
||||||
ElMessage.error(res?.message || '获取店铺快递列表失败')
|
ElMessage.error(res?.message || '获取店铺快递列表失败')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const list = Array.isArray(res?.data?.list) ? res.data.list : []
|
const list = Array.isArray(res?.data?.list) ? res.data.list : []
|
||||||
const siteMap: Record<string, SiteOption[]> = {}
|
const siteMap: Record<string, SiteOption[]> = {}
|
||||||
|
const productTypeMap: Record<string, ProductTypeOption[]> = {}
|
||||||
dialogExpressOptions.value = list
|
dialogExpressOptions.value = list
|
||||||
.map((item: any) => {
|
.map((item: any) => {
|
||||||
const code = item?.wp_code || item?.express_code || item?.code
|
const code = item?.wp_code || item?.express_code || item?.code
|
||||||
@ -1441,7 +1473,25 @@ async function loadShopExpressOptions(shopId: string | number) {
|
|||||||
const providerid = String(item?.providerid || item?.provider_id || item?.providerId || '').trim()
|
const providerid = String(item?.providerid || item?.provider_id || item?.providerId || '').trim()
|
||||||
const name = item?.wp_name || item?.express_name || item?.name
|
const name = item?.wp_name || item?.express_name || item?.name
|
||||||
const label = item?.label || name
|
const label = item?.label || name
|
||||||
|
const productTypes: ProductTypeOption[] = []
|
||||||
if (code) {
|
if (code) {
|
||||||
|
// 产品编码:快递返回 product_types 时按 code/name 归一化,供「产品编码」下拉使用
|
||||||
|
const productTypeUniq = new Map<string, ProductTypeOption>()
|
||||||
|
;(Array.isArray(item?.product_types) ? item.product_types : []).forEach((productType: Record<string, unknown>) => {
|
||||||
|
const productCode = String(productType?.code ?? '').trim()
|
||||||
|
if (!productCode || productTypeUniq.has(productCode)) return
|
||||||
|
const productName = String(productType?.name ?? '').trim()
|
||||||
|
productTypeUniq.set(productCode, {
|
||||||
|
code: productCode,
|
||||||
|
name: productName || productCode,
|
||||||
|
label: productName && productName !== productCode ? `${productName}(${productCode})` : productCode
|
||||||
|
})
|
||||||
|
})
|
||||||
|
productTypes.push(...productTypeUniq.values())
|
||||||
|
productTypeMap[code] = productTypes
|
||||||
|
if (sysExpressCode && sysExpressCode !== code) {
|
||||||
|
productTypeMap[sysExpressCode] = productTypes
|
||||||
|
}
|
||||||
const accounts = Array.isArray(item?.accounts) ? item.accounts : []
|
const accounts = Array.isArray(item?.accounts) ? item.accounts : []
|
||||||
const mappedSites = accounts.map((acc: any, idx: number) => {
|
const mappedSites = accounts.map((acc: any, idx: number) => {
|
||||||
const shipAddresses = Array.isArray(acc?.ship_addresses) ? acc.ship_addresses : []
|
const shipAddresses = Array.isArray(acc?.ship_addresses) ? acc.ship_addresses : []
|
||||||
@ -1570,9 +1620,11 @@ async function loadShopExpressOptions(shopId: string | number) {
|
|||||||
)
|
)
|
||||||
formData.providerid = String(selectedBySignedCode?.providerid || '').trim()
|
formData.providerid = String(selectedBySignedCode?.providerid || '').trim()
|
||||||
shopExpressSitesMap.value = siteMap
|
shopExpressSitesMap.value = siteMap
|
||||||
|
shopExpressProductTypesMap.value = productTypeMap
|
||||||
} catch {
|
} catch {
|
||||||
dialogExpressOptions.value = []
|
dialogExpressOptions.value = []
|
||||||
shopExpressSitesMap.value = {}
|
shopExpressSitesMap.value = {}
|
||||||
|
shopExpressProductTypesMap.value = {}
|
||||||
ElMessage.error('获取店铺快递列表失败')
|
ElMessage.error('获取店铺快递列表失败')
|
||||||
} finally {
|
} finally {
|
||||||
shopExpressLoading.value = false
|
shopExpressLoading.value = false
|
||||||
@ -1770,6 +1822,8 @@ async function handleExpressCodeChange() {
|
|||||||
selectedSiteKey.value = ''
|
selectedSiteKey.value = ''
|
||||||
selectedAddressKey.value = ''
|
selectedAddressKey.value = ''
|
||||||
formData.site_code = ''
|
formData.site_code = ''
|
||||||
|
// 产品编码随快递变化,切换快递后旧编码不再适用
|
||||||
|
formData.product_type = ''
|
||||||
formData.providerid = String(selectedSignedExpress?.providerid || '').trim()
|
formData.providerid = String(selectedSignedExpress?.providerid || '').trim()
|
||||||
formData.shipperno = ''
|
formData.shipperno = ''
|
||||||
customExpressOptions.value = []
|
customExpressOptions.value = []
|
||||||
@ -1817,6 +1871,7 @@ async function handlePlatformCodeChange(value: string | number | undefined) {
|
|||||||
formData.site_code = ''
|
formData.site_code = ''
|
||||||
formData.shipperno = ''
|
formData.shipperno = ''
|
||||||
formData.sys_express_code = ''
|
formData.sys_express_code = ''
|
||||||
|
formData.product_type = ''
|
||||||
formData.template_url = ''
|
formData.template_url = ''
|
||||||
formData.template_id = null
|
formData.template_id = null
|
||||||
templateSelectValue.value = ''
|
templateSelectValue.value = ''
|
||||||
@ -1830,6 +1885,7 @@ async function handlePlatformCodeChange(value: string | number | undefined) {
|
|||||||
formData.ext_data = undefined
|
formData.ext_data = undefined
|
||||||
dialogExpressOptions.value = []
|
dialogExpressOptions.value = []
|
||||||
shopExpressSitesMap.value = {}
|
shopExpressSitesMap.value = {}
|
||||||
|
shopExpressProductTypesMap.value = {}
|
||||||
await loadShopOptions(platformCode)
|
await loadShopOptions(platformCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1845,6 +1901,7 @@ async function handleShopChange(value: string | number | undefined) {
|
|||||||
formData.ext_data = undefined
|
formData.ext_data = undefined
|
||||||
formData.shipperno = ''
|
formData.shipperno = ''
|
||||||
formData.sys_express_code = ''
|
formData.sys_express_code = ''
|
||||||
|
formData.product_type = ''
|
||||||
formData.template_url = ''
|
formData.template_url = ''
|
||||||
formData.template_id = null
|
formData.template_id = null
|
||||||
templateSelectValue.value = ''
|
templateSelectValue.value = ''
|
||||||
@ -1853,6 +1910,7 @@ async function handleShopChange(value: string | number | undefined) {
|
|||||||
templateOptions.value = []
|
templateOptions.value = []
|
||||||
dialogExpressOptions.value = []
|
dialogExpressOptions.value = []
|
||||||
shopExpressSitesMap.value = {}
|
shopExpressSitesMap.value = {}
|
||||||
|
shopExpressProductTypesMap.value = {}
|
||||||
selectedSiteKey.value = ''
|
selectedSiteKey.value = ''
|
||||||
selectedAddressKey.value = ''
|
selectedAddressKey.value = ''
|
||||||
formData.site_code = ''
|
formData.site_code = ''
|
||||||
@ -1902,6 +1960,7 @@ async function openCreate() {
|
|||||||
formData.shop_id = undefined
|
formData.shop_id = undefined
|
||||||
dialogExpressOptions.value = []
|
dialogExpressOptions.value = []
|
||||||
shopExpressSitesMap.value = {}
|
shopExpressSitesMap.value = {}
|
||||||
|
shopExpressProductTypesMap.value = {}
|
||||||
selectedSiteKey.value = ''
|
selectedSiteKey.value = ''
|
||||||
selectedAddressKey.value = ''
|
selectedAddressKey.value = ''
|
||||||
shopOptions.value = []
|
shopOptions.value = []
|
||||||
@ -1921,6 +1980,7 @@ async function openEdit(row: ExpressInterfaceRecord) {
|
|||||||
serviceValueMap.value = {}
|
serviceValueMap.value = {}
|
||||||
dialogExpressOptions.value = []
|
dialogExpressOptions.value = []
|
||||||
shopExpressSitesMap.value = {}
|
shopExpressSitesMap.value = {}
|
||||||
|
shopExpressProductTypesMap.value = {}
|
||||||
selectedSiteKey.value = ''
|
selectedSiteKey.value = ''
|
||||||
selectedAddressKey.value = ''
|
selectedAddressKey.value = ''
|
||||||
templateOptions.value = []
|
templateOptions.value = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user