This commit is contained in:
liufumingren 2026-06-02 09:16:01 +08:00
parent 79a872dea7
commit 7dde297f52

View File

@ -414,7 +414,7 @@
<el-col :span="12">
<el-form-item label="打印模板">
<el-select
v-model="formData.template_url"
v-model="templateSelectValue"
filterable
clearable
:loading="printTemplateLoading"
@ -425,7 +425,7 @@
<el-option
v-for="item in templateOptions"
:key="item.value"
:label="item.label || item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
@ -524,6 +524,7 @@ type MonthlyAccountOption = { value: string; label: string }
type TemplateOption = {
value: string
label: string
templateUrl: string
templateId: string | null
brandCode: string
raw: Record<string, any>
@ -608,6 +609,7 @@ const shopOptions = ref<ShopOption[]>([])
const dialogExpressOptions = ref<ExpressOption[]>([])
const customExpressOptions = ref<ExpressOption[]>([])
const templateOptions = ref<TemplateOption[]>([])
const templateSelectValue = ref('')
const selectedShopId = ref<number | string | undefined>(undefined)
const useCustomExpressCode = ref(false)
const printTemplateLoading = ref(false)
@ -1083,6 +1085,7 @@ async function loadPrintPlatformTemplateOptions(sourceExpressCode?: string, sour
const expressCode = String(sourceExpressCode ?? formData.sys_express_code ?? '').trim().toUpperCase()
if (!expressCode) {
templateOptions.value = []
templateSelectValue.value = ''
formData.template_url = ''
formData.template_id = null
formData.brandno = ''
@ -1100,6 +1103,7 @@ async function loadPrintPlatformTemplateOptions(sourceExpressCode?: string, sour
})
if (!isSuccess(res)) {
templateOptions.value = []
templateSelectValue.value = ''
formData.template_url = ''
formData.template_id = null
formData.brandno = ''
@ -1111,8 +1115,20 @@ async function loadPrintPlatformTemplateOptions(sourceExpressCode?: string, sour
: []
const nextOptions = templateList
.map((item: any) => ({
value: String(item?.standard_template_url || '').trim(),
label: String(item?.standard_template_name || item?.standard_template_url || '').trim(),
value: (() => {
const templateUrl = String(item?.standard_template_url || '').trim()
const templateId = String(item?.standard_template_id || '').trim()
return templateUrl || (templateId ? `ID:${templateId}` : '')
})(),
label: (() => {
const templateName = String(item?.standard_template_name || '').trim()
const templateUrl = String(item?.standard_template_url || '').trim()
const templateId = String(item?.standard_template_id || '').trim()
const identity = templateUrl || templateId
if (!templateName) return identity || '--'
return identity ? `${templateName}(${identity})` : templateName
})(),
templateUrl: String(item?.standard_template_url || '').trim(),
templateId: String(item?.standard_template_id || '').trim() || null,
brandCode: String(item?.brand_code || '').trim(),
raw: item || {}
@ -1123,20 +1139,30 @@ async function loadPrintPlatformTemplateOptions(sourceExpressCode?: string, sour
formData.brandno = fallbackBrandCode
const currentTemplateUrl = String(formData.template_url || '').trim()
if (!currentTemplateUrl) {
const currentTemplateId = String(formData.template_id || '').trim()
if (!currentTemplateUrl && !currentTemplateId) {
templateSelectValue.value = ''
formData.template_id = null
return
}
const matchedOption = nextOptions.find((item: TemplateOption) => item.value === currentTemplateUrl)
const matchedOption = nextOptions.find(
(item: TemplateOption) =>
item.templateUrl === currentTemplateUrl ||
(!!currentTemplateId && item.templateId === currentTemplateId)
)
if (!matchedOption) {
templateSelectValue.value = ''
formData.template_url = ''
formData.template_id = null
return
}
templateSelectValue.value = matchedOption.value
formData.template_url = matchedOption.templateUrl
formData.template_id = matchedOption.templateId
formData.brandno = matchedOption.brandCode || fallbackBrandCode
} catch {
templateOptions.value = []
templateSelectValue.value = ''
formData.template_url = ''
formData.template_id = null
formData.brandno = ''
@ -1147,13 +1173,16 @@ async function loadPrintPlatformTemplateOptions(sourceExpressCode?: string, sour
}
function handleTemplateChange(value: string | number | undefined) {
const templateUrl = String(value ?? '').trim()
if (!templateUrl) {
const templateValue = String(value ?? '').trim()
if (!templateValue) {
templateSelectValue.value = ''
formData.template_url = ''
formData.template_id = null
formData.brandno = ''
return
}
const matched = templateOptions.value.find((item) => item.value === templateUrl)
const matched = templateOptions.value.find((item) => item.value === templateValue)
formData.template_url = matched?.templateUrl || ''
formData.template_id = matched?.templateId ?? null
formData.brandno = matched?.brandCode || ''
}
@ -1607,6 +1636,7 @@ async function handleExpressCodeChange() {
}
formData.template_url = ''
formData.template_id = null
templateSelectValue.value = ''
formData.brandno = ''
templateOptions.value = []
applyAddressRaw(undefined)
@ -1647,6 +1677,7 @@ async function handlePlatformCodeChange(value: string | number | undefined) {
formData.sys_express_code = ''
formData.template_url = ''
formData.template_id = null
templateSelectValue.value = ''
formData.brandno = ''
customExpressOptions.value = []
templateOptions.value = []
@ -1674,6 +1705,7 @@ async function handleShopChange(value: string | number | undefined) {
formData.sys_express_code = ''
formData.template_url = ''
formData.template_id = null
templateSelectValue.value = ''
formData.brandno = ''
customExpressOptions.value = []
templateOptions.value = []
@ -1716,6 +1748,7 @@ function resetForm() {
useCustomExpressCode.value = false
serviceValueMap.value = {}
templateOptions.value = []
templateSelectValue.value = ''
formRef.value?.clearValidate()
}
@ -1731,6 +1764,7 @@ async function openCreate() {
selectedAddressKey.value = ''
shopOptions.value = []
templateOptions.value = []
templateSelectValue.value = ''
}
async function openEdit(row: ExpressInterfaceRecord) {
@ -1748,6 +1782,7 @@ async function openEdit(row: ExpressInterfaceRecord) {
selectedSiteKey.value = ''
selectedAddressKey.value = ''
templateOptions.value = []
templateSelectValue.value = ''
applyExpressInterfaceRowToForm(formData, row)
if (formData.is_system_express_code === 0 || String(formData.is_system_express_code) === '0') {
useCustomExpressCode.value = true