2304 lines
77 KiB
Vue
2304 lines
77 KiB
Vue
<template>
|
||
<div class="order-sub-container" :style="{ height: containerHeight }">
|
||
<scan-box
|
||
ref="scanBox"
|
||
width="250px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:preset-tree="presetTree"
|
||
:available-fields="availableFieldsRef"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
@submit="handleSubmit"
|
||
/>
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<order-toolbar-button-group
|
||
:buttons="toolbarButtons"
|
||
:resolve-disabled="resolveButtonDisabled"
|
||
:resolve-loading="resolveButtonLoading"
|
||
:resolve-label="resolveButtonLabel"
|
||
:layout-key="toolbarLayoutKey"
|
||
@action="handleToolbarButtonClick"
|
||
/>
|
||
<!-- <span v-if="viewMode === 'warehouse' && warehouseContextHint" class="toolbar-hint">
|
||
{{ warehouseContextHint }}
|
||
</span> -->
|
||
</div>
|
||
<div class="toolbar-right">
|
||
<el-radio-group
|
||
v-model="viewMode"
|
||
class="view-mode-toggle"
|
||
size="small"
|
||
@change="onViewModeChange"
|
||
>
|
||
<el-radio-button label="paged">分页列表</el-radio-button>
|
||
<el-radio-button label="warehouse">按仓库 + 平台(全量)</el-radio-button>
|
||
</el-radio-group>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="split-stack" ref="splitStackRef">
|
||
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
|
||
<upper-table
|
||
ref="upperTable"
|
||
:title="viewMode === 'paged' ? '快递接口配置' : '快递接口(按仓库+平台)'"
|
||
table-id="setting-express-interface-list"
|
||
:enable-column-config="true"
|
||
:data="list"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="pagination"
|
||
:show-pagination="viewMode === 'paged'"
|
||
:show-index="true"
|
||
:show-actions="true"
|
||
:show-selection="true"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
row-key="id"
|
||
@current-change="handleRowClick"
|
||
@selection-change="handleSelectionChange"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
>
|
||
<template #column-actions="{ row }">
|
||
<div class="wave-operation-actions">
|
||
<template v-if="!isExternalSharedInterface(row)">
|
||
<el-button link type="primary" size="small" @click.stop="openEdit(row)">编辑</el-button>
|
||
<el-button link type="danger" size="small" @click.stop="handleDelete(row)">删除</el-button>
|
||
</template>
|
||
<span v-else class="action-disabled-text">--</span>
|
||
</div>
|
||
</template>
|
||
<template #empty>
|
||
<div class="empty-tip">
|
||
{{ viewMode === 'warehouse' ? '请选择平台编码后查询,或在左侧添加筛选条件' : '暂无快递接口配置,可调整左侧筛选条件' }}
|
||
</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
|
||
<template v-if="detailVisible">
|
||
<div
|
||
class="pane-resizer"
|
||
title="拖动调整列表与详情区域高度"
|
||
@mousedown="beginSplitDrag"
|
||
/>
|
||
<div v-if="selectedRow" class="lower-level" :class="tableSize" :style="lowerPaneStyle">
|
||
<div class="detail-header">
|
||
<span class="detail-title">配置明细</span>
|
||
<span class="detail-sub">字段与接口返回单条记录一致</span>
|
||
</div>
|
||
<div class="detail-container">
|
||
<el-descriptions :column="2" border size="small">
|
||
<el-descriptions-item
|
||
v-for="key in detailKeys"
|
||
:key="key"
|
||
:label="fieldLabel(key)"
|
||
:span="isWideKey(key) ? 2 : 1"
|
||
>
|
||
{{ detailValue(key) }}
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
<div v-if="selectedRow.express" class="express-relation">
|
||
<div class="express-relation__title">关联快递</div>
|
||
<el-descriptions :column="2" border size="small">
|
||
<el-descriptions-item label="快递名称">
|
||
{{ selectedRow.express.name || '--' }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="快递编码">
|
||
{{ selectedRow.express.code || selectedRow.express_code || '--' }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="快递平台">
|
||
{{ selectedRow.express.platform ?? '--' }}
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div v-else class="no-selection" :style="lowerPaneStyle">
|
||
<div class="empty-tip">在表格中点击一行可查看配置详情</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
|
||
<el-dialog
|
||
v-model="dialogVisible"
|
||
:title="dialogMode === 'create' ? '新增快递接口配置' : '编辑快递接口配置'"
|
||
:width="dialogMode === 'edit' ? '1160px' : '1080px'"
|
||
align-center
|
||
class="config-dialog"
|
||
:class="{ 'config-dialog--edit': dialogMode === 'edit' }"
|
||
@close="resetForm"
|
||
>
|
||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="128px" class="dialog-form">
|
||
|
||
|
||
<div class="form-section">
|
||
<div class="form-section-title">基础配置</div>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12">
|
||
<el-form-item label="配置名称" prop="name">
|
||
<el-input v-model="formData.name" placeholder="如 申通-快手" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<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="请选择平台"
|
||
@change="handlePlatformCodeChange"
|
||
>
|
||
<el-option
|
||
v-for="item in platformOptions"
|
||
:key="item.code"
|
||
:label="item.label || item.name"
|
||
:value="item.code"
|
||
/>
|
||
</el-select>
|
||
</div>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="店铺名称">
|
||
<div class="shop-select-row">
|
||
<el-select
|
||
v-model="selectedShopId"
|
||
class="shop-select"
|
||
filterable
|
||
clearable
|
||
:loading="shopLoading"
|
||
:disabled="!formData.platform_code"
|
||
:placeholder="formData.platform_code ? '请选择店铺' : '请先选择平台编码'"
|
||
@change="handleShopChange"
|
||
>
|
||
<el-option
|
||
v-for="item in shopOptions"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
<el-button
|
||
type="success"
|
||
plain
|
||
:loading="authLoading"
|
||
:disabled="!formData.platform_code"
|
||
@click="handleAuthorizeFromSelection"
|
||
>
|
||
新增授权店铺
|
||
</el-button>
|
||
</div>
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
<el-col :span="12">
|
||
<el-form-item label="已签约快递" prop="sys_express_code">
|
||
<div class="signed-express-row">
|
||
<el-select
|
||
v-model="formData.sys_express_code"
|
||
class="signed-express-select"
|
||
filterable
|
||
clearable
|
||
:loading="shopExpressLoading"
|
||
:disabled="!selectedShopId"
|
||
placeholder="请选择已签约快递"
|
||
@change="handleExpressCodeChange"
|
||
>
|
||
<el-option
|
||
v-for="item in dialogExpressOptions"
|
||
:key="item.code"
|
||
:label="item.label || item.name"
|
||
:value="item.sysExpressCode || item.code"
|
||
/>
|
||
</el-select>
|
||
<el-switch
|
||
v-model="useCustomExpressCode"
|
||
inline-prompt
|
||
active-text="自定义"
|
||
inactive-text="默认"
|
||
@change="handleCustomExpressSwitchChange"
|
||
/>
|
||
</div>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col v-if="useCustomExpressCode" :span="12">
|
||
<el-form-item label="自定义快递编码" prop="express_code">
|
||
<el-select
|
||
v-model="formData.express_code"
|
||
filterable
|
||
clearable
|
||
:loading="customExpressLoading"
|
||
placeholder="请选择自定义快递编码"
|
||
>
|
||
<el-option
|
||
v-for="item in customExpressOptions"
|
||
:key="item.code"
|
||
:label="item.label || item.name"
|
||
:value="item.code"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col v-for="field in flatServiceFields" v-if="selectedSite" :key="field.key" :span="12">
|
||
<el-form-item
|
||
class="service-field-item"
|
||
:required="field.required"
|
||
>
|
||
<template #label>
|
||
<span
|
||
class="service-field-label"
|
||
:title="serviceFieldLabel(field)"
|
||
>
|
||
{{ serviceFieldLabel(field) }}
|
||
</span>
|
||
</template>
|
||
<el-select
|
||
v-if="field.renderAs === 'select'"
|
||
v-model="serviceValueMap[field.key]"
|
||
clearable
|
||
filterable
|
||
:placeholder="`请选择${field.attrName}`"
|
||
@change="handleServiceValueChange"
|
||
>
|
||
<el-option
|
||
v-for="opt in field.options"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value"
|
||
/>
|
||
</el-select>
|
||
<el-input-number
|
||
v-else-if="field.renderAs === 'number'"
|
||
v-model="serviceValueMap[field.key]"
|
||
:min="field.min"
|
||
:max="field.max"
|
||
style="width: 100%"
|
||
@change="handleServiceValueChange"
|
||
/>
|
||
<el-input
|
||
v-else
|
||
v-model="serviceValueMap[field.key]"
|
||
:placeholder="field.attrName ? `请输入${field.attrName}` : '请输入'"
|
||
@input="handleServiceValueChange"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</div>
|
||
|
||
<div class="form-section">
|
||
<div class="form-section-title">发件信息</div>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12">
|
||
<el-form-item label="发件人" prop="sender_name" required>
|
||
<el-input v-model="formData.sender_name" placeholder="请输入发件人,最长 50 字符" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="发件电话" prop="sender_tel" required>
|
||
<el-input v-model="formData.sender_tel" placeholder="请输入发件电话,最长 11 字符" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col v-if="dialogSiteOptions.length > 0" :span="24">
|
||
<el-form-item label="网点">
|
||
<el-select
|
||
v-model="selectedSiteKey"
|
||
filterable
|
||
clearable
|
||
placeholder="请选择网点"
|
||
@change="handleSiteChange"
|
||
>
|
||
<el-option
|
||
v-for="item in dialogSiteOptions"
|
||
:key="item.key"
|
||
:label="item.label"
|
||
:value="item.key"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col v-if="dialogAddressOptions.length > 0" :span="24">
|
||
<el-form-item label="网点地址">
|
||
<el-select
|
||
v-model="selectedAddressKey"
|
||
filterable
|
||
clearable
|
||
placeholder="请选择网点地址"
|
||
@change="handleAddressChange"
|
||
>
|
||
<el-option
|
||
v-for="item in dialogAddressOptions"
|
||
:key="item.key"
|
||
:label="item.label"
|
||
:value="item.key"
|
||
/>
|
||
</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="省市区">
|
||
<el-row :gutter="8" class="region-display-row">
|
||
<el-col :span="8">
|
||
<el-input
|
||
v-model="formData.province_name"
|
||
readonly
|
||
placeholder="省"
|
||
/>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-input
|
||
v-model="formData.city_name"
|
||
readonly
|
||
placeholder="市"
|
||
/>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-input
|
||
v-model="formData.district_name"
|
||
readonly
|
||
placeholder="区/县"
|
||
/>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</div>
|
||
|
||
<div class="form-section form-section--last">
|
||
<div class="form-section-title">接口参数</div>
|
||
<el-row :gutter="16">
|
||
<el-col :span="12">
|
||
<el-form-item label="权重">
|
||
<el-input-number v-model="formData.weight" :min="0" :precision="0" :step="1" style="width: 100%" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="重量类型">
|
||
<el-select v-model="formData.weight_type" clearable placeholder="请选择重量类型">
|
||
<el-option :value="0" label="普通" />
|
||
<el-option :value="2" label="重货" />
|
||
<el-option :value="3" label="轻货" />
|
||
<el-option :value="4" label="生鲜" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="验视人">
|
||
<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" v-if="formData.can_use_count !== undefined">
|
||
<el-form-item label="可用单量">
|
||
<el-input :model-value="String(formData.can_use_count)" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12" v-if="dialogMode === 'edit'">
|
||
<el-form-item label="可用面单数量">
|
||
<el-input :model-value="String(formData.quantity ?? 0)" disabled />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="打印模板">
|
||
<el-select
|
||
v-model="templateSelectValue"
|
||
filterable
|
||
clearable
|
||
:loading="printTemplateLoading"
|
||
:disabled="!activeTemplateExpressCode"
|
||
placeholder="请选择打印模板"
|
||
@change="handleTemplateChange"
|
||
>
|
||
<el-option
|
||
v-for="item in templateOptions"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
: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-col :span="12">
|
||
<el-form-item label="是否启用">
|
||
<el-switch
|
||
v-model="formData.is_enabled"
|
||
:active-value="1"
|
||
:inactive-value="0"
|
||
active-text="是"
|
||
inactive-text="否"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
|
||
</el-row>
|
||
</div>
|
||
|
||
<!-- <div v-if="dialogMode === 'edit'" class="form-section form-section--last">
|
||
<div class="form-section-title">扩展数据(ext_data)</div>
|
||
<el-form-item label="扩展 JSON">
|
||
<el-input
|
||
:model-value="editExtDataDisplay"
|
||
type="textarea"
|
||
:rows="8"
|
||
readonly
|
||
placeholder="无扩展数据"
|
||
class="ext-data-preview"
|
||
/>
|
||
</el-form-item>
|
||
</div> -->
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button @click="dialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="saving" @click="submitForm">保存</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, onMounted, reactive, ref } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import type { FormInstance, FormRules } from 'element-plus'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
import {
|
||
getPrintPlatformTemplateList,
|
||
getPlatformOauthLink,
|
||
getShopList,
|
||
getShopExpressList
|
||
} from '@/api/index/index'
|
||
import { expressIndexGetExpressList as getExpressList } from '@/api/setting.express/express'
|
||
import {
|
||
expressInterfaceCreate,
|
||
expressInterfaceDelete,
|
||
expressInterfaceList,
|
||
expressInterfaceListByWarehousePlatformCode,
|
||
expressInterfaceUpdate,
|
||
getPrintPlatformList
|
||
} from '@/api/setting.expressinterface/expressInterface'
|
||
import { useUserStore } from '@/stores/modules/user'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import {
|
||
expressInterfaceColumns,
|
||
expressInterfaceFieldLabels,
|
||
expressInterfaceListFieldOrder,
|
||
expressInterfaceScanFields,
|
||
expressInterfaceWarehouseColumns,
|
||
extractPlainWhereValue,
|
||
formatExpressInterfaceCell,
|
||
formatExpressInterfaceData,
|
||
formatExpressInterfaceNumber,
|
||
parseExpressInterfaceWarehouseListResponse,
|
||
normalizeScanConditionToWhere,
|
||
defaultExpressInterfaceForm,
|
||
applyExpressInterfaceRowToForm,
|
||
formatExpressInterfaceFormDisplayValue,
|
||
buildExpressInterfaceCreatePayload,
|
||
buildExpressInterfaceUpdatePayload,
|
||
expressInterfaceAddressDisplayKeys,
|
||
resolveExpressInterfaceAddress
|
||
} from './express-interface-config'
|
||
|
||
type ExpressOption = { code: string; name: string; label?: string; sysExpressCode?: string; providerid?: string }
|
||
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
|
||
templateUrl: string
|
||
templateId: string | null
|
||
brandCode: string
|
||
raw: Record<string, any>
|
||
}
|
||
type ServiceFlatField = {
|
||
key: string
|
||
serviceCode: string
|
||
serviceName: string
|
||
attrCode: string
|
||
attrName: string
|
||
attrType: 'enum' | 'number' | 'string'
|
||
renderAs: 'select' | 'number' | 'input'
|
||
required: boolean
|
||
options: Array<{ label: string; value: string }>
|
||
min?: number
|
||
max?: number
|
||
}
|
||
type SiteOption = {
|
||
key: string
|
||
label: string
|
||
raw: Record<string, any>
|
||
branch_code?: string
|
||
branch_name?: string
|
||
quantity?: string | number
|
||
allocated_quantity?: string | number
|
||
recycled_quantity?: string | number
|
||
cancel_quantity?: string | number
|
||
services?: ServiceOption[]
|
||
addresses?: AddressOption[]
|
||
}
|
||
type ExpressInterfaceRecord = Record<string, any>
|
||
|
||
const userStore = useUserStore()
|
||
const settingsStore = useSettingsStore()
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(expressInterfaceScanFields)))
|
||
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() =>
|
||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||
)
|
||
|
||
const {
|
||
splitStackRef,
|
||
beginSplitDrag,
|
||
lowerPaneStyle,
|
||
upperPaneStyle
|
||
} = useVerticalSplitPane({ defaultLowerPercent: 38 })
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden'
|
||
}))
|
||
|
||
// ─── 工具栏按钮配置 ──────────────────────────────────────────────────────────
|
||
const toolbarButtons: ToolbarButtonConfig[] = [
|
||
{ key: 'refresh', label: '刷新', category: 'refresh', size: 'small', loadingKey: 'loading', action: 'loadData' },
|
||
{ key: 'columnConfig',label: '字段设置', category: 'setting', size: 'small', action: 'openColumnConfigPanel' },
|
||
{ key: 'create', label: '新增接口配置', category: 'action', size: 'small', action: 'openCreate' },
|
||
{ key: 'copy', label: '复制', category: 'action', size: 'small', disabledKey: 'noSelection',action: 'handleCopySelected' },
|
||
]
|
||
|
||
const buttonLoadingMap = computed(() => ({
|
||
loading: loading.value
|
||
}))
|
||
|
||
const buttonDisabledMap = computed(() => ({
|
||
noSelection: selectedRows.value.length === 0
|
||
}))
|
||
|
||
const buttonLabelMap = computed(() => ({}))
|
||
|
||
const toolbarLayoutKey = computed(() =>
|
||
JSON.stringify({
|
||
loading: buttonLoadingMap.value,
|
||
disabled: buttonDisabledMap.value,
|
||
labels: buttonLabelMap.value
|
||
})
|
||
)
|
||
|
||
function resolveButtonLoading(loadingKey?: string) {
|
||
if (!loadingKey) return false
|
||
return Boolean((buttonLoadingMap.value as Record<string, boolean>)[loadingKey])
|
||
}
|
||
|
||
function resolveButtonDisabled(disabledKey?: string) {
|
||
if (!disabledKey) return false
|
||
return Boolean((buttonDisabledMap.value as Record<string, boolean>)[disabledKey])
|
||
}
|
||
|
||
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
|
||
if (!dynamicLabelKey) return defaultLabel
|
||
return (buttonLabelMap.value as Record<string, string>)[dynamicLabelKey] || defaultLabel
|
||
}
|
||
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
loadData: () => { void loadData() },
|
||
openColumnConfigPanel: () => openColumnConfigPanel(),
|
||
openCreate: () => openCreate(),
|
||
handleCopySelected: () => { void handleCopySelected() }
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||
const handler = toolbarActionMap[action]
|
||
if (!handler) return
|
||
safeInvoke(() => handler())
|
||
}
|
||
|
||
const viewMode = ref<'paged' | 'warehouse'>('paged')
|
||
const loading = ref(false)
|
||
const saving = ref(false)
|
||
const authLoading = ref(false)
|
||
const shopLoading = ref(false)
|
||
const shopExpressLoading = ref(false)
|
||
const customExpressLoading = ref(false)
|
||
const queryTime = ref(0)
|
||
const tableSize = ref<'small' | 'default' | 'large'>('small')
|
||
const detailVisible = ref(false)
|
||
|
||
const list = ref<ExpressInterfaceRecord[]>([])
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const currentConditionRaw = ref<any>(null)
|
||
const selectedId = ref<number | null>(null)
|
||
const selectedRows = ref<ExpressInterfaceRecord[]>([])
|
||
|
||
function handleSelectionChange(rows: ExpressInterfaceRecord[]) {
|
||
selectedRows.value = rows || []
|
||
}
|
||
|
||
async function handleCopySelected() {
|
||
if (selectedRows.value.length === 0) {
|
||
ElMessage.warning('请先勾选需要复制的记录')
|
||
return
|
||
}
|
||
const headers = ['配置名称', '可用面单数量', '已回收面单', '已取消面单', '已分配面单']
|
||
const lines = [headers.join('\t')]
|
||
selectedRows.value.forEach((row) => {
|
||
const name = String(row.name ?? '--').trim()
|
||
const quantity = row.quantity ?? 0
|
||
const recycled = row.recycled_quantity ?? 0
|
||
const cancel = row.cancel_quantity ?? 0
|
||
const allocated = row.allocated_quantity ?? 0
|
||
lines.push([name, quantity, recycled, cancel, allocated].join('\t'))
|
||
})
|
||
const text = lines.join('\n')
|
||
try {
|
||
if (navigator.clipboard?.writeText) {
|
||
await navigator.clipboard.writeText(text)
|
||
} else {
|
||
const textarea = document.createElement('textarea')
|
||
textarea.value = text
|
||
textarea.style.position = 'fixed'
|
||
textarea.style.opacity = '0'
|
||
document.body.appendChild(textarea)
|
||
textarea.select()
|
||
document.execCommand('copy')
|
||
document.body.removeChild(textarea)
|
||
}
|
||
ElMessage.success(`已复制 ${selectedRows.value.length} 条记录`)
|
||
} catch {
|
||
ElMessage.error('复制失败,请重试')
|
||
}
|
||
}
|
||
|
||
const columns = computed(() =>
|
||
viewMode.value === 'paged' ? expressInterfaceColumns : expressInterfaceWarehouseColumns
|
||
)
|
||
|
||
const expressOptions = ref<ExpressOption[]>([])
|
||
const platformOptions = ref<PlatformOption[]>([])
|
||
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)
|
||
const activeTemplateExpressCode = computed(() =>
|
||
String(formData.sys_express_code || '').trim()
|
||
)
|
||
const serviceValueMap = ref<Record<string, any>>({})
|
||
const shopExpressSitesMap = ref<Record<string, SiteOption[]>>({})
|
||
const selectedSiteKey = ref<string>('')
|
||
const selectedAddressKey = ref<string>('')
|
||
const SERVICE_EMPTY_ENUM_TOKEN = '__SERVICE_EMPTY_ENUM__'
|
||
const EXCLUDED_SERVICE_PATTERN = /保价|子母单/
|
||
|
||
function shouldExcludeService(item: ServiceOption) {
|
||
const name = String(item?.name || item?.raw?.service_name || '').trim()
|
||
const desc = String(item?.raw?.service_desc || '').trim()
|
||
const code = String(item?.code || item?.raw?.service_code || '').trim()
|
||
return EXCLUDED_SERVICE_PATTERN.test(name) || EXCLUDED_SERVICE_PATTERN.test(desc) || EXCLUDED_SERVICE_PATTERN.test(code)
|
||
}
|
||
|
||
const dialogServiceOptions = computed<ServiceOption[]>(() => {
|
||
const site = selectedSite.value
|
||
if (!site || !Array.isArray(site.services)) return []
|
||
return site.services.filter((item) => !shouldExcludeService(item))
|
||
})
|
||
|
||
function parseTypeDesc(raw: unknown) {
|
||
if (typeof raw !== 'string') return undefined
|
||
const text = raw.trim()
|
||
if (!text) return undefined
|
||
try {
|
||
return JSON.parse(text)
|
||
} catch {
|
||
return undefined
|
||
}
|
||
}
|
||
|
||
function toServiceOptionValue(rawValue: unknown) {
|
||
const v = String(rawValue ?? '')
|
||
return v === '' ? SERVICE_EMPTY_ENUM_TOKEN : v
|
||
}
|
||
|
||
function toServicePayloadValue(viewValue: unknown) {
|
||
if (viewValue === SERVICE_EMPTY_ENUM_TOKEN) return ''
|
||
return viewValue
|
||
}
|
||
|
||
function serviceFieldLabel(field: ServiceFlatField) {
|
||
return field.attrName && field.attrName !== '值'
|
||
? `${field.serviceName}-${field.attrName}`
|
||
: field.serviceName
|
||
}
|
||
|
||
const flatServiceFields = computed<ServiceFlatField[]>(() => {
|
||
const fields: ServiceFlatField[] = []
|
||
dialogServiceOptions.value.forEach((service) => {
|
||
const attrs = Array.isArray(service.raw?.attributes) && service.raw.attributes.length > 0
|
||
? service.raw.attributes
|
||
: [{ attribute_code: 'value', attribute_name: '值', attribute_type: 'string' }]
|
||
|
||
attrs.forEach((attr: any, index: number) => {
|
||
const attrCode = String(attr?.attribute_code || `value_${index}`)
|
||
const attrName = String(attr?.attribute_name || '值')
|
||
const attrTypeRaw = String(attr?.attribute_type || 'string').toLowerCase()
|
||
const attrType: 'enum' | 'number' | 'string' =
|
||
attrTypeRaw === 'enum' ? 'enum' : attrTypeRaw === 'number' ? 'number' : 'string'
|
||
const parsed = parseTypeDesc(attr?.type_desc)
|
||
const options: Array<{ label: string; value: string }> = []
|
||
let min: number | undefined
|
||
let max: number | undefined
|
||
let renderAs: 'select' | 'number' | 'input' = 'input'
|
||
|
||
if (attrType === 'number' && parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
||
const minRaw = (parsed as any).min
|
||
const maxRaw = (parsed as any).max
|
||
if (minRaw !== undefined && Number.isFinite(Number(minRaw))) min = Number(minRaw)
|
||
if (maxRaw !== undefined && Number.isFinite(Number(maxRaw))) max = Number(maxRaw)
|
||
renderAs = 'number'
|
||
} else if (parsed && typeof parsed === 'object' && !Array.isArray(parsed)) {
|
||
const entries = Object.entries(parsed as Record<string, any>)
|
||
if (entries.some(([k]) => String(k).trim() === '')) {
|
||
return
|
||
}
|
||
entries.forEach(([k, v]) => {
|
||
options.push({ label: String(v), value: toServiceOptionValue(k) })
|
||
})
|
||
if (options.length > 0) {
|
||
renderAs = 'select'
|
||
}
|
||
}
|
||
|
||
fields.push({
|
||
key: `${service.code}__${attrCode}`,
|
||
serviceCode: service.code,
|
||
serviceName: service.name,
|
||
attrCode,
|
||
attrName,
|
||
attrType,
|
||
renderAs,
|
||
required: !!service.raw?.required,
|
||
options,
|
||
min,
|
||
max
|
||
})
|
||
})
|
||
})
|
||
return fields
|
||
})
|
||
|
||
const dialogSiteOptions = computed<SiteOption[]>(() => {
|
||
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 (
|
||
shopExpressSitesMap.value[selectedSignedCode] ||
|
||
shopExpressSitesMap.value[selectedSysCode] ||
|
||
[]
|
||
)
|
||
})
|
||
|
||
const selectedSite = computed<SiteOption | null>(() => {
|
||
if (!selectedSiteKey.value) return null
|
||
return dialogSiteOptions.value.find((item) => item.key === selectedSiteKey.value) || null
|
||
})
|
||
|
||
const dialogAddressOptions = computed<AddressOption[]>(() => {
|
||
const site = selectedSite.value
|
||
if (!site || !Array.isArray(site.addresses)) return []
|
||
return site.addresses
|
||
})
|
||
|
||
const selectedAddress = computed<AddressOption | null>(() => {
|
||
if (!selectedAddressKey.value) return 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
|
||
if (sid === undefined || sid === null || sid === '') return ''
|
||
return `未填仓库 ID 时默认使用登录上下文(store_id / 仓库:${sid})`
|
||
})
|
||
|
||
const selectedRow = computed(
|
||
() => list.value.find((r) => Number(r.id) === selectedId.value) || null
|
||
)
|
||
|
||
const detailKeys = computed(() => {
|
||
if (!selectedRow.value) return []
|
||
const keys = Object.keys(selectedRow.value).filter(
|
||
(k) => k !== 'express' && !k.startsWith('express_')
|
||
)
|
||
const ordered = expressInterfaceListFieldOrder.filter((k) => keys.includes(k))
|
||
const rest = keys.filter((k) => !expressInterfaceListFieldOrder.includes(k as any)).sort()
|
||
return [...ordered, ...rest]
|
||
})
|
||
|
||
const dialogVisible = ref(false)
|
||
const dialogMode = ref<'create' | 'edit'>('create')
|
||
const formRef = ref<FormInstance>()
|
||
const formData = reactive<ExpressInterfaceRecord>({ ...defaultExpressInterfaceForm })
|
||
const editExpressRelation = ref<Record<string, any> | null>(null)
|
||
|
||
const editExtDataDisplay = computed(() =>
|
||
formatExpressInterfaceFormDisplayValue('ext_data', formData.ext_data)
|
||
)
|
||
|
||
const rules = computed<FormRules>(() => {
|
||
return {
|
||
name: [{ required: true, message: '请输入配置名称', trigger: 'blur' }],
|
||
sender_name: [
|
||
{
|
||
required: true,
|
||
validator: (_rule, value, callback) => {
|
||
if (value === null || value === undefined || String(value).trim() === '') {
|
||
callback(new Error('请输入发件人'))
|
||
return
|
||
}
|
||
callback()
|
||
},
|
||
trigger: 'blur'
|
||
}
|
||
],
|
||
sender_tel: [
|
||
{
|
||
required: true,
|
||
validator: (_rule, value, callback) => {
|
||
if (value === null || value === undefined || String(value).trim() === '') {
|
||
callback(new Error('请输入发件电话'))
|
||
return
|
||
}
|
||
callback()
|
||
},
|
||
trigger: 'blur'
|
||
}
|
||
],
|
||
sys_express_code: [
|
||
{
|
||
validator: (_rule, value, callback) => {
|
||
if (!selectedShopId.value || dialogExpressOptions.value.length === 0) {
|
||
callback()
|
||
return
|
||
}
|
||
if (value === null || value === undefined || String(value).trim() === '') {
|
||
callback(new Error('请选择自定义快递编码'))
|
||
return
|
||
}
|
||
callback()
|
||
},
|
||
trigger: 'change'
|
||
}
|
||
],
|
||
express_code: [
|
||
{
|
||
validator: (_rule, value, callback) => {
|
||
if (!useCustomExpressCode.value) {
|
||
callback()
|
||
return
|
||
}
|
||
if (value === null || value === undefined || String(value).trim() === '') {
|
||
callback(new Error('请选择快递编码'))
|
||
return
|
||
}
|
||
callback()
|
||
},
|
||
trigger: 'change'
|
||
}
|
||
],
|
||
platform_code: [{ required: true, message: '请选择平台编码', trigger: 'change' }]
|
||
}
|
||
})
|
||
|
||
const isSuccess = (res: any) => res && [0, 1, 200].includes(res.code)
|
||
|
||
const senderNameFieldKeys = ['sender_name', 'senderName', 'contact_name', 'name', 'send_name']
|
||
const senderTelFieldKeys = [
|
||
'sender_tel',
|
||
'sender_phone',
|
||
'sender_mobile',
|
||
'contact_mobile',
|
||
'contact_tel',
|
||
'contact_phone',
|
||
'phone_number',
|
||
'mobile_phone',
|
||
'telephone',
|
||
'tel',
|
||
'phone',
|
||
'mobile'
|
||
]
|
||
|
||
const showRegionField = computed(() => {
|
||
return !!selectedSite.value
|
||
})
|
||
|
||
function pickFirstExistingString(source: Record<string, any>, keys: string[]) {
|
||
for (const key of keys) {
|
||
if (!Object.prototype.hasOwnProperty.call(source, key)) continue
|
||
const value = source[key]
|
||
if (value === null || value === undefined) continue
|
||
const text = String(value).trim()
|
||
if (text) return text
|
||
}
|
||
return ''
|
||
}
|
||
|
||
function fieldLabel(key: string) {
|
||
return expressInterfaceFieldLabels[key] || key
|
||
}
|
||
|
||
function detailValue(key: string) {
|
||
if (!selectedRow.value) return '--'
|
||
return formatExpressInterfaceFormDisplayValue(key, selectedRow.value[key])
|
||
}
|
||
|
||
function isWideKey(key: string) {
|
||
return detailValue(key).length > 80
|
||
}
|
||
|
||
function openColumnConfigPanel() {
|
||
upperTable.value?.openColumnConfig?.()
|
||
}
|
||
|
||
function syncSelectOptions() {
|
||
const expressField = availableFieldsRef.find((f: any) => f.value === 'express_code')
|
||
if (expressField) {
|
||
expressField.options = expressOptions.value.map((item) => ({
|
||
label: item.label || item.name,
|
||
value: item.code
|
||
}))
|
||
}
|
||
const platformField = availableFieldsRef.find((f: any) => f.value === 'platform_code')
|
||
if (platformField) {
|
||
platformField.options = platformOptions.value.map((item) => ({
|
||
label: item.label || item.name,
|
||
value: item.code
|
||
}))
|
||
}
|
||
}
|
||
|
||
async function loadPagedList(where: Record<string, unknown>) {
|
||
const res: any = await expressInterfaceList({
|
||
pagination: {
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize
|
||
},
|
||
where
|
||
})
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '获取快递接口配置失败')
|
||
list.value = []
|
||
pagination.total = 0
|
||
return
|
||
}
|
||
const data = res?.data || {}
|
||
list.value = formatExpressInterfaceData(data.list || [])
|
||
pagination.total = Number(data.total || 0)
|
||
const page = Number(data.page)
|
||
const pageSize = Number(data.page_size)
|
||
if (Number.isFinite(page) && page > 0) pagination.currentPage = page
|
||
if (Number.isFinite(pageSize) && pageSize > 0) pagination.pageSize = pageSize
|
||
}
|
||
|
||
async function loadWarehouseList(where: Record<string, unknown>) {
|
||
const platformCode = String(extractPlainWhereValue(where, 'platform_code') || '').trim()
|
||
if (!platformCode) {
|
||
ElMessage.warning('按仓库+平台查询时,请在左侧筛选中选择「平台编码」')
|
||
list.value = []
|
||
pagination.total = 0
|
||
return
|
||
}
|
||
const payload: Record<string, any> = { platform_code: platformCode }
|
||
const warehouseId = extractPlainWhereValue(where, 'warehouse_id')
|
||
if (warehouseId != null && warehouseId !== '' && Number(warehouseId) > 0) {
|
||
payload.warehouse_id = Number(warehouseId)
|
||
}
|
||
const res: any = await expressInterfaceListByWarehousePlatformCode(payload)
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '按仓库与平台查询失败')
|
||
list.value = []
|
||
pagination.total = 0
|
||
return
|
||
}
|
||
const rawList = parseExpressInterfaceWarehouseListResponse(res)
|
||
list.value = formatExpressInterfaceData(rawList)
|
||
pagination.total = list.value.length
|
||
}
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const where = normalizeScanConditionToWhere(currentConditionRaw.value)
|
||
if (viewMode.value === 'warehouse') {
|
||
await loadWarehouseList(where)
|
||
} else {
|
||
await loadPagedList(where)
|
||
}
|
||
if (selectedId.value && !list.value.some((r) => Number(r.id) === selectedId.value)) {
|
||
selectedId.value = null
|
||
}
|
||
selectedRows.value = []
|
||
} catch {
|
||
list.value = []
|
||
pagination.total = 0
|
||
ElMessage.error('加载快递接口配置失败')
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Date.now() - start
|
||
}
|
||
}
|
||
|
||
function onViewModeChange() {
|
||
selectedId.value = null
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionChange(condition: any) {
|
||
currentConditionRaw.value = condition
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleSubmit() {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionClear() {
|
||
currentConditionRaw.value = null
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
currentConditionRaw.value = null
|
||
pagination.currentPage = 1
|
||
if (scanBox.value?.reset) {
|
||
scanBox.value.reset()
|
||
} else if (scanBox.value?.clear) {
|
||
scanBox.value.clear()
|
||
}
|
||
loadData()
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
loadData()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleRowClick(row: ExpressInterfaceRecord | null) {
|
||
selectedId.value = row?.id != null ? Number(row.id) : null
|
||
}
|
||
|
||
async function loadExpressOptions() {
|
||
try {
|
||
const res: any = await getExpressList({ systemOnly: true })
|
||
if (!isSuccess(res)) {
|
||
expressOptions.value = []
|
||
return
|
||
}
|
||
expressOptions.value = (res?.data || []).map((item: any) => ({
|
||
code: item.express_code || item.code,
|
||
name: item.express_name || item.name,
|
||
label: item.label || item.name
|
||
}))
|
||
} catch {
|
||
expressOptions.value = []
|
||
}
|
||
}
|
||
|
||
async function loadPlatformOptions() {
|
||
try {
|
||
const res: any = await getPrintPlatformList({})
|
||
if (!isSuccess(res)) {
|
||
platformOptions.value = []
|
||
return
|
||
}
|
||
platformOptions.value = (res?.data || []).map((item: any) => ({
|
||
code: item.platform_code || item.code,
|
||
name: item.platform_name || item.name,
|
||
label: item.label || item.platform_name || item.name
|
||
}))
|
||
} catch {
|
||
platformOptions.value = []
|
||
}
|
||
}
|
||
|
||
async function loadPrintPlatformTemplateOptions(sourceExpressCode?: string, sourcePlatformCode?: string, sourceShopId?: string | number) {
|
||
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 = ''
|
||
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,
|
||
shopId: sourceShopId ?? selectedShopId.value ?? formData.shop_id,
|
||
shop_id: sourceShopId ?? selectedShopId.value ?? formData.shop_id
|
||
})
|
||
if (!isSuccess(res)) {
|
||
templateOptions.value = []
|
||
templateSelectValue.value = ''
|
||
formData.template_url = ''
|
||
formData.template_id = null
|
||
formData.brandno = ''
|
||
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: (() => {
|
||
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 || {}
|
||
}))
|
||
.filter((item: TemplateOption) => !!item.value)
|
||
templateOptions.value = nextOptions
|
||
const fallbackBrandCode = nextOptions[0]?.brandCode || ''
|
||
formData.brandno = fallbackBrandCode
|
||
|
||
const currentTemplateUrl = String(formData.template_url || '').trim()
|
||
const currentTemplateId = String(formData.template_id || '').trim()
|
||
if (!currentTemplateUrl && !currentTemplateId) {
|
||
templateSelectValue.value = ''
|
||
formData.template_id = null
|
||
return
|
||
}
|
||
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 = ''
|
||
ElMessage.error('获取打印模板列表失败')
|
||
} finally {
|
||
printTemplateLoading.value = false
|
||
}
|
||
}
|
||
|
||
function handleTemplateChange(value: string | number | undefined) {
|
||
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 === templateValue)
|
||
formData.template_url = matched?.templateUrl || ''
|
||
formData.template_id = matched?.templateId ?? null
|
||
formData.brandno = matched?.brandCode || ''
|
||
}
|
||
|
||
async function loadCustomExpressOptions(sourceExpressCode?: string) {
|
||
const expressCode = String(sourceExpressCode ?? formData.sys_express_code ?? '').trim().toUpperCase()
|
||
if (!expressCode) {
|
||
customExpressOptions.value = []
|
||
formData.express_code = ''
|
||
return
|
||
}
|
||
if (customExpressLoading.value) return
|
||
customExpressLoading.value = true
|
||
try {
|
||
const res: any = await getExpressList({
|
||
systemOnly: false,
|
||
express_code: expressCode
|
||
})
|
||
if (!isSuccess(res)) {
|
||
customExpressOptions.value = []
|
||
ElMessage.error(res?.message || '获取自定义快递编码列表失败')
|
||
return
|
||
}
|
||
const nextOptions = (res?.data || [])
|
||
.map((item: any) => ({
|
||
code: String(item?.sys_express_code || item?.code || item?.custom_code || item?.express_code || '').trim(),
|
||
name: String(item?.name || item?.express_name || item?.code || '').trim(),
|
||
label: String(item?.label || item?.name || item?.code || '').trim(),
|
||
sysExpressCode: String(item?.sys_express_code || '').trim()
|
||
}))
|
||
.filter((item: ExpressOption) => !!item.code)
|
||
customExpressOptions.value = nextOptions
|
||
|
||
const currentCustomCode = String(formData.express_code || '').trim()
|
||
if (!currentCustomCode) return
|
||
const exists = nextOptions.some((item: ExpressOption) => {
|
||
return String(item.sysExpressCode || item.code || '').trim() === currentCustomCode
|
||
})
|
||
if (!exists) {
|
||
formData.express_code = ''
|
||
}
|
||
} catch {
|
||
customExpressOptions.value = []
|
||
ElMessage.error('获取自定义快递编码列表失败')
|
||
} finally {
|
||
customExpressLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function loadShopOptions(platformCode?: string) {
|
||
const normalizedPlatformCode = String(platformCode || '').trim()
|
||
if (!normalizedPlatformCode) {
|
||
shopOptions.value = []
|
||
return
|
||
}
|
||
if (shopLoading.value) return
|
||
shopLoading.value = true
|
||
try {
|
||
const res: any = await getShopList({
|
||
platform_code: normalizedPlatformCode,
|
||
platformCode: normalizedPlatformCode,
|
||
code: normalizedPlatformCode
|
||
})
|
||
if (!isSuccess(res)) {
|
||
shopOptions.value = []
|
||
ElMessage.error(res?.message || '获取店铺列表失败')
|
||
return
|
||
}
|
||
const list = Array.isArray(res?.data?.list) ? res.data.list : []
|
||
shopOptions.value = list
|
||
.map((item: any) => {
|
||
const label = String(item?.shop_name || item?.name || item?.shop_title || '').trim()
|
||
const value = item?.shop_id ?? item?.id ?? item?.shopId
|
||
if (!label) return null
|
||
if (value === null || value === undefined || value === '') return null
|
||
return { value, label }
|
||
})
|
||
.filter((item: ShopOption | null): item is ShopOption => !!item)
|
||
} catch {
|
||
shopOptions.value = []
|
||
ElMessage.error('获取店铺列表失败')
|
||
} finally {
|
||
shopLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function loadShopExpressOptions(shopId: string | number) {
|
||
if (!shopId || shopExpressLoading.value) return
|
||
shopExpressLoading.value = true
|
||
try {
|
||
const res: any = await getShopExpressList({ shop_id: shopId, shopId: shopId })
|
||
if (!isSuccess(res)) {
|
||
dialogExpressOptions.value = []
|
||
ElMessage.error(res?.message || '获取店铺快递列表失败')
|
||
return
|
||
}
|
||
const list = Array.isArray(res?.data?.list) ? res.data.list : []
|
||
const siteMap: Record<string, SiteOption[]> = {}
|
||
dialogExpressOptions.value = list
|
||
.map((item: any) => {
|
||
const code = item?.wp_code || item?.express_code || item?.code
|
||
const sysExpressCode = String(item?.sys_express_code || item?.express_code || item?.code || '').trim()
|
||
const providerid = String(item?.providerid || item?.provider_id || item?.providerId || '').trim()
|
||
const name = item?.wp_name || item?.express_name || item?.name
|
||
const label = item?.label || name
|
||
if (code) {
|
||
const accounts = Array.isArray(item?.accounts) ? item.accounts : []
|
||
const mappedSites = accounts.map((acc: any, idx: number) => {
|
||
const shipAddresses = Array.isArray(acc?.ship_addresses) ? acc.ship_addresses : []
|
||
const addresses = (shipAddresses.length > 0 ? shipAddresses : [{}]).map((address: any, adx: number) => {
|
||
const raw = {
|
||
...(address || {}),
|
||
...(acc || {}),
|
||
branch_code: acc?.branch_code,
|
||
branch_name: acc?.branch_name
|
||
}
|
||
const addrText = pickFirstExistingString(raw, addressDisplayFieldKeys) || `地址${adx + 1}`
|
||
return {
|
||
key: `${String(acc?.branch_code || acc?.branch_name || 'addr')}-${adx}`,
|
||
label: addrText,
|
||
raw
|
||
}
|
||
})
|
||
const primaryAddress = (addresses[0]?.raw || {}) as Record<string, any>
|
||
|
||
const serviceUniq = new Map<string, ServiceOption>()
|
||
;(Array.isArray(acc?.services) ? acc.services : []).forEach((service: any) => {
|
||
const serviceCode = String(service?.service_code || '').trim()
|
||
if (!serviceCode || serviceUniq.has(serviceCode)) return
|
||
serviceUniq.set(serviceCode, {
|
||
code: serviceCode,
|
||
name: String(service?.service_name || serviceCode),
|
||
raw: service
|
||
})
|
||
})
|
||
|
||
const fallbackSenderTel =
|
||
String(
|
||
primaryAddress?.sender_tel ||
|
||
primaryAddress?.sender_phone ||
|
||
primaryAddress?.sender_mobile ||
|
||
primaryAddress?.contact_mobile ||
|
||
primaryAddress?.contact_tel ||
|
||
primaryAddress?.contact_phone ||
|
||
primaryAddress?.phone_number ||
|
||
primaryAddress?.mobile_phone ||
|
||
primaryAddress?.telephone ||
|
||
primaryAddress?.tel ||
|
||
primaryAddress?.phone ||
|
||
primaryAddress?.mobile ||
|
||
acc?.sender_tel ||
|
||
acc?.sender_phone ||
|
||
acc?.sender_mobile ||
|
||
acc?.contact_mobile ||
|
||
acc?.contact_tel ||
|
||
acc?.contact_phone ||
|
||
acc?.phone_number ||
|
||
acc?.mobile_phone ||
|
||
acc?.telephone ||
|
||
acc?.tel ||
|
||
acc?.phone ||
|
||
acc?.mobile ||
|
||
''
|
||
).trim()
|
||
|
||
const branchName = String(acc?.branch_name || '').trim()
|
||
const branchCode = String(acc?.branch_code || '').trim()
|
||
const quantity = acc?.quantity ?? '--'
|
||
const allocatedQuantity = acc?.allocated_quantity ?? '--'
|
||
const recycledQuantity = acc?.recycled_quantity ?? '--'
|
||
const cancelQuantity = acc?.cancel_quantity ?? '--'
|
||
const siteLabelParts = [branchName, branchCode ? `(${branchCode})` : ''].filter((s) => !!s)
|
||
const label =
|
||
`${siteLabelParts.join(' ')} | 数量:${quantity} 分配:${allocatedQuantity} 回收:${recycledQuantity} 取消:${cancelQuantity}`.trim() ||
|
||
`网点-${idx + 1}`
|
||
|
||
return {
|
||
key: `${branchCode || branchName || 'branch'}-${idx}`,
|
||
label,
|
||
raw: {
|
||
...(primaryAddress || {}),
|
||
...(acc || {}),
|
||
branch_code: acc?.branch_code,
|
||
branch_name: acc?.branch_name,
|
||
sender_tel: fallbackSenderTel
|
||
},
|
||
branch_code: acc?.branch_code,
|
||
branch_name: acc?.branch_name,
|
||
quantity,
|
||
allocated_quantity: allocatedQuantity,
|
||
recycled_quantity: recycledQuantity,
|
||
cancel_quantity: cancelQuantity,
|
||
services: Array.from(serviceUniq.values()),
|
||
addresses
|
||
}
|
||
})
|
||
siteMap[code] = mappedSites
|
||
if (sysExpressCode && sysExpressCode !== code) {
|
||
siteMap[sysExpressCode] = mappedSites
|
||
}
|
||
}
|
||
return { code, name, label, sysExpressCode, providerid }
|
||
})
|
||
.filter((item: ExpressOption) => !!item.code)
|
||
|
||
const currentSignedCode = String(formData.sys_express_code || '').trim()
|
||
const hasMatchedSignedCode = dialogExpressOptions.value.some(
|
||
(item) => String(item.sysExpressCode || item.code || '').trim() === currentSignedCode
|
||
)
|
||
if (!hasMatchedSignedCode) {
|
||
const currentSignedOrCustomCode = String(formData.sys_express_code || formData.express_code || '').trim()
|
||
if (currentSignedOrCustomCode) {
|
||
const matchedBySignedCode = dialogExpressOptions.value.find((item) => {
|
||
const optionValue = String(item.sysExpressCode || item.code || '').trim()
|
||
const wpCode = String(item.code || '').trim()
|
||
const sysCode = String(item.sysExpressCode || '').trim()
|
||
return (
|
||
optionValue === currentSignedOrCustomCode ||
|
||
sysCode === currentSignedOrCustomCode ||
|
||
wpCode === currentSignedOrCustomCode
|
||
)
|
||
})
|
||
if (matchedBySignedCode) {
|
||
formData.sys_express_code = String(
|
||
matchedBySignedCode.sysExpressCode || matchedBySignedCode.code || ''
|
||
).trim()
|
||
}
|
||
}
|
||
}
|
||
const selectedBySignedCode = dialogExpressOptions.value.find(
|
||
(item) => String(item.sysExpressCode || item.code || '').trim() === String(formData.sys_express_code || '').trim()
|
||
)
|
||
formData.providerid = String(selectedBySignedCode?.providerid || '').trim()
|
||
shopExpressSitesMap.value = siteMap
|
||
} catch {
|
||
dialogExpressOptions.value = []
|
||
shopExpressSitesMap.value = {}
|
||
ElMessage.error('获取店铺快递列表失败')
|
||
} finally {
|
||
shopExpressLoading.value = false
|
||
}
|
||
}
|
||
|
||
const addressDisplayFieldKeys = [...expressInterfaceAddressDisplayKeys]
|
||
|
||
function applyAddressRaw(raw?: Record<string, any>) {
|
||
if (!raw) {
|
||
formData.platform_shop_id = null
|
||
formData.province_name = ''
|
||
formData.city_name = ''
|
||
formData.district_name = ''
|
||
formData.address = ''
|
||
return
|
||
}
|
||
const platformShopId = String(raw?.platform_shop_id ?? '').trim()
|
||
formData.platform_shop_id = platformShopId || null
|
||
const mappedSenderTel = pickFirstExistingString(raw, senderTelFieldKeys)
|
||
if (mappedSenderTel) {
|
||
formData.sender_tel = mappedSenderTel
|
||
}
|
||
formData.province_name = String(raw?.province || '').trim()
|
||
formData.city_name = String(raw?.city || '').trim()
|
||
formData.district_name = String(raw?.district || '').trim()
|
||
formData.address = resolveExpressInterfaceAddress(raw)
|
||
}
|
||
|
||
function handleSiteChange(value: string) {
|
||
selectedSiteKey.value = value || ''
|
||
selectedAddressKey.value = ''
|
||
serviceValueMap.value = {}
|
||
syncExtDataByServiceSelection()
|
||
const site = selectedSite.value
|
||
if (!site) {
|
||
formData.site_code = ''
|
||
applyAddressRaw(undefined)
|
||
return
|
||
}
|
||
|
||
formData.site_code = String(site.branch_code || '').trim()
|
||
initializeAddressSelection()
|
||
}
|
||
|
||
function handleAddressChange(value: string) {
|
||
selectedAddressKey.value = value || ''
|
||
applyAddressRaw(selectedAddress.value?.raw || selectedSite.value?.raw)
|
||
}
|
||
|
||
function initializeAddressSelection(preferredAddress?: string) {
|
||
const addresses = dialogAddressOptions.value
|
||
if (!addresses.length) {
|
||
selectedAddressKey.value = ''
|
||
applyAddressRaw(selectedSite.value?.raw)
|
||
return
|
||
}
|
||
|
||
const normalizedPreferredAddress = String(preferredAddress || '').trim()
|
||
const compactPreferredAddress = normalizedPreferredAddress.replace(/\s+/g, '')
|
||
const matchedAddress = normalizedPreferredAddress
|
||
? addresses.find((item) => {
|
||
const text = pickFirstExistingString(item.raw, addressDisplayFieldKeys)
|
||
const normalizedText = String(text || '').trim()
|
||
const compactText = normalizedText.replace(/\s+/g, '')
|
||
return (
|
||
normalizedText === normalizedPreferredAddress ||
|
||
compactText === compactPreferredAddress ||
|
||
compactText.includes(compactPreferredAddress) ||
|
||
compactPreferredAddress.includes(compactText)
|
||
)
|
||
})
|
||
: null
|
||
const target = matchedAddress || addresses[0]
|
||
if (!target) return
|
||
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[],
|
||
preferredShipperno?: string
|
||
) {
|
||
const sites = dialogSiteOptions.value
|
||
if (!sites.length) {
|
||
selectedSiteKey.value = ''
|
||
selectedAddressKey.value = ''
|
||
formData.site_code = ''
|
||
applyAddressRaw(undefined)
|
||
return
|
||
}
|
||
|
||
const normalizedPreferredCode = String(preferredSiteCode || '').trim()
|
||
const normalizedPreferredAddress = String(preferredAddress || '').trim()
|
||
const compactPreferredAddress = normalizedPreferredAddress.replace(/\s+/g, '')
|
||
const matchedByCode = normalizedPreferredCode
|
||
? sites.find((item) => String(item.branch_code || '').trim() === normalizedPreferredCode)
|
||
: null
|
||
|
||
const matchedByAddress = !matchedByCode && compactPreferredAddress
|
||
? sites.find((site) => {
|
||
const addresses = Array.isArray(site.addresses) ? site.addresses : []
|
||
return addresses.some((addr) => {
|
||
const text = pickFirstExistingString(addr.raw, addressDisplayFieldKeys)
|
||
const compactText = String(text || '').trim().replace(/\s+/g, '')
|
||
return (
|
||
compactText === compactPreferredAddress ||
|
||
compactText.includes(compactPreferredAddress) ||
|
||
compactPreferredAddress.includes(compactText)
|
||
)
|
||
})
|
||
})
|
||
: null
|
||
|
||
const serviceCodes = Array.isArray(preferredServiceCodes)
|
||
? preferredServiceCodes.map((code) => String(code || '').trim()).filter((code) => !!code)
|
||
: []
|
||
let matchedByServices: SiteOption | null = null
|
||
if (!matchedByCode && !matchedByAddress && serviceCodes.length > 0) {
|
||
let bestScore = 0
|
||
for (const site of sites) {
|
||
const siteServiceCodes = new Set(
|
||
(Array.isArray(site.services) ? site.services : [])
|
||
.map((svc) => String(svc?.code || '').trim())
|
||
.filter((code) => !!code)
|
||
)
|
||
let score = 0
|
||
serviceCodes.forEach((code) => {
|
||
if (siteServiceCodes.has(code)) score += 1
|
||
})
|
||
if (score > bestScore) {
|
||
bestScore = score
|
||
matchedByServices = site
|
||
}
|
||
}
|
||
}
|
||
|
||
const target = matchedByCode || matchedByAddress || matchedByServices || sites[0]
|
||
if (!target) return
|
||
handleSiteChange(target.key)
|
||
initializeAddressSelection(preferredAddress)
|
||
initializeMonthlyAccountSelection(preferredShipperno, false)
|
||
}
|
||
|
||
function syncExtDataByServiceSelection() {
|
||
const expressCode = String(formData.express_code || '').trim()
|
||
if (!selectedShopId.value || !expressCode) {
|
||
formData.ext_data = undefined
|
||
return
|
||
}
|
||
|
||
const valueByService: Record<string, Record<string, any>> = {}
|
||
flatServiceFields.value.forEach((field) => {
|
||
const v = serviceValueMap.value[field.key]
|
||
if (v === undefined || v === null || String(v) === '') return
|
||
if (!valueByService[field.serviceCode]) valueByService[field.serviceCode] = {}
|
||
const bucket = valueByService[field.serviceCode] as Record<string, any>
|
||
bucket[field.attrCode] = toServicePayloadValue(v)
|
||
})
|
||
|
||
const serviceSelection: Record<string, any> = {}
|
||
Object.entries(valueByService).forEach(([serviceCode, attrValues]) => {
|
||
const entries = Object.entries(attrValues || {})
|
||
if (entries.length === 0) return
|
||
if (entries.length === 1) {
|
||
const firstEntry = entries[0]
|
||
if (!firstEntry) return
|
||
serviceSelection[serviceCode] = firstEntry[1]
|
||
return
|
||
}
|
||
serviceSelection[serviceCode] = attrValues
|
||
})
|
||
|
||
formData.ext_data = Object.keys(serviceSelection).length > 0 ? serviceSelection : undefined
|
||
}
|
||
|
||
async function handleExpressCodeChange() {
|
||
const selectedSignedExpress = dialogExpressOptions.value.find(
|
||
(item) =>
|
||
String(item.sysExpressCode || item.code || '').trim() === String(formData.sys_express_code || '').trim()
|
||
)
|
||
const currentExpressCode = String(
|
||
selectedSignedExpress?.sysExpressCode || formData.sys_express_code || ''
|
||
).trim()
|
||
selectedSiteKey.value = ''
|
||
selectedAddressKey.value = ''
|
||
formData.site_code = ''
|
||
formData.providerid = String(selectedSignedExpress?.providerid || '').trim()
|
||
formData.shipperno = ''
|
||
customExpressOptions.value = []
|
||
if (useCustomExpressCode.value) {
|
||
formData.express_code = ''
|
||
}
|
||
formData.template_url = ''
|
||
formData.template_id = null
|
||
templateSelectValue.value = ''
|
||
formData.brandno = ''
|
||
templateOptions.value = []
|
||
applyAddressRaw(undefined)
|
||
serviceValueMap.value = {}
|
||
syncExtDataByServiceSelection()
|
||
console.log('handleExpressCodeChange', { currentExpressCode, platformCode: formData.platform_code })
|
||
await loadPrintPlatformTemplateOptions(currentExpressCode, formData.sys_platform_code, selectedShopId.value ?? formData.shop_id)
|
||
if (!useCustomExpressCode.value || !currentExpressCode) return
|
||
await loadCustomExpressOptions(currentExpressCode)
|
||
}
|
||
|
||
function handleServiceValueChange() {
|
||
syncExtDataByServiceSelection()
|
||
}
|
||
|
||
async function handleCustomExpressSwitchChange(value: boolean) {
|
||
useCustomExpressCode.value = value
|
||
formData.is_system_express_code = value ? 0 : 1
|
||
if (!value) {
|
||
customExpressOptions.value = []
|
||
formRef.value?.clearValidate('express_code')
|
||
return
|
||
}
|
||
formData.express_code = ''
|
||
await loadCustomExpressOptions(formData.sys_express_code)
|
||
}
|
||
|
||
async function handlePlatformCodeChange(value: string | number | undefined) {
|
||
const platformCode = String(value ?? '').trim()
|
||
formData.platform_code = platformCode
|
||
selectedShopId.value = undefined
|
||
formData.shop_id = undefined
|
||
formData.shop_name = ''
|
||
formData.express_code = ''
|
||
formData.providerid = ''
|
||
formData.site_code = ''
|
||
formData.shipperno = ''
|
||
formData.sys_express_code = ''
|
||
formData.template_url = ''
|
||
formData.template_id = null
|
||
templateSelectValue.value = ''
|
||
formData.brandno = ''
|
||
customExpressOptions.value = []
|
||
templateOptions.value = []
|
||
selectedSiteKey.value = ''
|
||
selectedAddressKey.value = ''
|
||
applyAddressRaw(undefined)
|
||
serviceValueMap.value = {}
|
||
formData.ext_data = undefined
|
||
dialogExpressOptions.value = []
|
||
shopExpressSitesMap.value = {}
|
||
await loadShopOptions(platformCode)
|
||
}
|
||
|
||
async function handleShopChange(value: string | number | undefined) {
|
||
const target = value ?? undefined
|
||
selectedShopId.value = target
|
||
formData.shop_id = target
|
||
const current = shopOptions.value.find((item) => item.value === target)
|
||
formData.shop_name = current?.label || ''
|
||
formData.express_code = ''
|
||
formData.providerid = ''
|
||
serviceValueMap.value = {}
|
||
formData.ext_data = undefined
|
||
formData.shipperno = ''
|
||
formData.sys_express_code = ''
|
||
formData.template_url = ''
|
||
formData.template_id = null
|
||
templateSelectValue.value = ''
|
||
formData.brandno = ''
|
||
customExpressOptions.value = []
|
||
templateOptions.value = []
|
||
dialogExpressOptions.value = []
|
||
shopExpressSitesMap.value = {}
|
||
selectedSiteKey.value = ''
|
||
selectedAddressKey.value = ''
|
||
formData.site_code = ''
|
||
applyAddressRaw(undefined)
|
||
if (target === undefined || target === null || target === '') return
|
||
await loadShopExpressOptions(target)
|
||
}
|
||
|
||
function extractOauthUrl(res: any): string {
|
||
const data = res?.data
|
||
if (typeof data === 'string') return data
|
||
if (!data || typeof data !== 'object') return ''
|
||
const candidates = [
|
||
data.url,
|
||
data.link,
|
||
data.oauth_link,
|
||
data.authLink,
|
||
data.oauth_url,
|
||
data.oauthUrl,
|
||
data.redirect_url,
|
||
data.redirectUrl
|
||
]
|
||
const hit = candidates.find((item) => typeof item === 'string' && item.trim())
|
||
return hit ? String(hit).trim() : ''
|
||
}
|
||
|
||
function isExternalSharedInterface(row: ExpressInterfaceRecord | null | undefined) {
|
||
if (!row) return false
|
||
return row.is_share === 1 || row.is_share === true
|
||
}
|
||
|
||
function resetForm() {
|
||
Object.assign(formData, { ...defaultExpressInterfaceForm })
|
||
editExpressRelation.value = null
|
||
useCustomExpressCode.value = false
|
||
serviceValueMap.value = {}
|
||
templateOptions.value = []
|
||
templateSelectValue.value = ''
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
async function openCreate() {
|
||
dialogMode.value = 'create'
|
||
dialogVisible.value = true
|
||
resetForm()
|
||
selectedShopId.value = undefined
|
||
formData.shop_id = undefined
|
||
dialogExpressOptions.value = []
|
||
shopExpressSitesMap.value = {}
|
||
selectedSiteKey.value = ''
|
||
selectedAddressKey.value = ''
|
||
shopOptions.value = []
|
||
templateOptions.value = []
|
||
templateSelectValue.value = ''
|
||
}
|
||
|
||
async function openEdit(row: ExpressInterfaceRecord) {
|
||
if (isExternalSharedInterface(row)) {
|
||
ElMessage.warning('共享接口为外部接口,不支持编辑')
|
||
return
|
||
}
|
||
dialogMode.value = 'edit'
|
||
dialogVisible.value = true
|
||
selectedShopId.value = undefined
|
||
formData.shop_id = undefined
|
||
serviceValueMap.value = {}
|
||
dialogExpressOptions.value = []
|
||
shopExpressSitesMap.value = {}
|
||
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
|
||
} 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(formData.sys_express_code)
|
||
}
|
||
editExpressRelation.value =
|
||
row.express && typeof row.express === 'object' ? (row.express as Record<string, any>) : null
|
||
const platformCode = String(formData.platform_code || '').trim()
|
||
await loadShopOptions(platformCode)
|
||
const rowShopId =
|
||
row.shop_id ?? row.shopId ?? (formData.ext_data as Record<string, any> | undefined)?.shop_id
|
||
if (rowShopId !== undefined && rowShopId !== null && rowShopId !== '') {
|
||
selectedShopId.value = rowShopId
|
||
formData.shop_id = rowShopId
|
||
await loadShopExpressOptions(rowShopId)
|
||
const rowSiteCode = String(row.site_code || '').trim()
|
||
const extData = formData.ext_data as any
|
||
const extServiceValues =
|
||
extData && typeof extData === 'object'
|
||
? extData.service_values && typeof extData.service_values === 'object'
|
||
? extData.service_values
|
||
: extData
|
||
: null
|
||
const preferredServiceCodes =
|
||
extServiceValues && typeof extServiceValues === 'object'
|
||
? Object.keys(extServiceValues).map((key) => String(key || '').trim()).filter((key) => !!key)
|
||
: []
|
||
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> = {}
|
||
flatServiceFields.value.forEach((field) => {
|
||
serviceFieldCount[field.serviceCode] = (serviceFieldCount[field.serviceCode] || 0) + 1
|
||
})
|
||
flatServiceFields.value.forEach((field) => {
|
||
const svcValues = extServiceValues[field.serviceCode]
|
||
if (svcValues === undefined || svcValues === null) return
|
||
|
||
let resolvedValue: any
|
||
if (typeof svcValues === 'object' && !Array.isArray(svcValues)) {
|
||
if (Object.prototype.hasOwnProperty.call(svcValues, field.attrCode)) {
|
||
resolvedValue = svcValues[field.attrCode]
|
||
} else {
|
||
return
|
||
}
|
||
} else {
|
||
const onlyOneAttr = (serviceFieldCount[field.serviceCode] || 0) <= 1
|
||
if (!onlyOneAttr && field.attrCode !== 'value') return
|
||
resolvedValue = svcValues
|
||
}
|
||
|
||
patch[field.key] =
|
||
field.renderAs === 'select' ? toServiceOptionValue(resolvedValue) : resolvedValue
|
||
})
|
||
serviceValueMap.value = patch
|
||
}
|
||
} else if (formData.express_code) {
|
||
dialogExpressOptions.value = [
|
||
{
|
||
code: formData.sys_express_code || formData.express_code,
|
||
name: formData.sys_express_code || formData.express_code,
|
||
label: formData.sys_express_code || formData.express_code,
|
||
sysExpressCode: formData.sys_express_code || formData.express_code
|
||
}
|
||
]
|
||
}
|
||
await loadPrintPlatformTemplateOptions(formData.sys_express_code, formData.platform_code, selectedShopId.value ?? formData.shop_id)
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
async function handleAuthorizeFromSelection() {
|
||
const platformCode = String(formData.platform_code || '').trim()
|
||
if (!platformCode) {
|
||
ElMessage.warning('请先选择平台编码')
|
||
return
|
||
}
|
||
if (authLoading.value) return
|
||
|
||
authLoading.value = true
|
||
try {
|
||
const res: any = await getPlatformOauthLink({
|
||
code: platformCode,
|
||
platform_code: platformCode,
|
||
platformCode
|
||
})
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '获取授权链接失败')
|
||
return
|
||
}
|
||
const oauthUrl = extractOauthUrl(res)
|
||
if (!oauthUrl) {
|
||
ElMessage.error('未获取到有效的授权链接')
|
||
return
|
||
}
|
||
|
||
const win = window.open(oauthUrl, '_blank')
|
||
if (!win) {
|
||
window.location.href = oauthUrl
|
||
}
|
||
} catch {
|
||
ElMessage.error('获取授权链接失败')
|
||
} finally {
|
||
authLoading.value = false
|
||
}
|
||
}
|
||
|
||
async function submitForm() {
|
||
if (!formRef.value || saving.value) return
|
||
const valid = await formRef.value.validate().catch(() => false)
|
||
if (!valid) return
|
||
|
||
formData.is_system_express_code = useCustomExpressCode.value ? 0 : 1
|
||
syncExtDataByServiceSelection()
|
||
|
||
saving.value = true
|
||
try {
|
||
const res: any =
|
||
dialogMode.value === 'create'
|
||
? await expressInterfaceCreate(buildExpressInterfaceCreatePayload(formData))
|
||
: await expressInterfaceUpdate(buildExpressInterfaceUpdatePayload(formData))
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '保存失败')
|
||
return
|
||
}
|
||
ElMessage.success(dialogMode.value === 'create' ? '新增成功' : '更新成功')
|
||
dialogVisible.value = false
|
||
loadData()
|
||
} catch {
|
||
ElMessage.error('保存失败')
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
|
||
function handleDelete(row: ExpressInterfaceRecord) {
|
||
if (isExternalSharedInterface(row)) {
|
||
ElMessage.warning('共享接口为外部接口,不支持删除')
|
||
return
|
||
}
|
||
if (!row?.id) return
|
||
ElMessageBox.confirm(`确认删除配置「${row.name || row.id}」吗?`, '提示', { type: 'warning' })
|
||
.then(async () => {
|
||
const res: any = await expressInterfaceDelete({ id: row.id })
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '删除失败')
|
||
return
|
||
}
|
||
ElMessage.success('删除成功')
|
||
if (viewMode.value === 'paged' && list.value.length === 1 && pagination.currentPage > 1) {
|
||
pagination.currentPage -= 1
|
||
}
|
||
if (selectedId.value === Number(row.id)) {
|
||
selectedId.value = null
|
||
}
|
||
loadData()
|
||
})
|
||
.catch(() => undefined)
|
||
}
|
||
|
||
onMounted(async () => {
|
||
await Promise.all([loadExpressOptions(), loadPlatformOptions()])
|
||
syncSelectOptions()
|
||
loadData()
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@use "../../../order/orderManagement/styles/order-sub.scss";
|
||
|
||
.order-sub-container .main-content .lower-level .detail-container {
|
||
padding: 6px 10px;
|
||
overflow: auto;
|
||
flex: 1;
|
||
min-height: 0;
|
||
}
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
color: #909399;
|
||
padding: 16px;
|
||
}
|
||
|
||
.wave-operation-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 4px;
|
||
}
|
||
|
||
.action-disabled-text {
|
||
color: #c0c4cc;
|
||
}
|
||
|
||
.view-mode-toggle {
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.toolbar-hint {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary, #909399);
|
||
line-height: 1.4;
|
||
max-width: min(360px, 100%);
|
||
}
|
||
|
||
.express-relation {
|
||
margin-top: 12px;
|
||
|
||
&__title {
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
color: var(--el-text-color-regular);
|
||
margin-bottom: 8px;
|
||
}
|
||
}
|
||
|
||
:deep(.config-dialog .el-dialog__body) {
|
||
padding-top: 8px;
|
||
padding-bottom: 8px;
|
||
max-height: min(70vh, 640px);
|
||
overflow-y: auto;
|
||
overflow-x: hidden;
|
||
}
|
||
|
||
: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) {
|
||
font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
|
||
font-size: 12px;
|
||
}
|
||
|
||
.express-inline-desc {
|
||
margin-bottom: 4px;
|
||
}
|
||
|
||
.dialog-form {
|
||
padding-right: 0;
|
||
}
|
||
|
||
.form-section {
|
||
padding-bottom: 4px;
|
||
margin-bottom: 16px;
|
||
border-bottom: 1px dashed var(--el-border-color-lighter, #e4e7ed);
|
||
|
||
&--last {
|
||
margin-bottom: 0;
|
||
padding-bottom: 0;
|
||
border-bottom: none;
|
||
}
|
||
}
|
||
|
||
.form-section-title {
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
color: var(--el-text-color-regular, #606266);
|
||
margin-bottom: 12px;
|
||
padding-left: 2px;
|
||
}
|
||
|
||
.dialog-form :deep(.el-select),
|
||
.dialog-form :deep(.el-input),
|
||
.dialog-form :deep(.el-input-number) {
|
||
width: 100%;
|
||
}
|
||
|
||
.platform-select-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
width: 100%;
|
||
}
|
||
|
||
.platform-form-item :deep(.el-form-item__content) {
|
||
display: block;
|
||
}
|
||
|
||
.platform-form-item :deep(.el-form-item__error) {
|
||
position: relative;
|
||
top: 4px;
|
||
}
|
||
|
||
.platform-select {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.platform-select-row .el-button {
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.shop-select-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
width: 100%;
|
||
}
|
||
|
||
.shop-select {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.shop-select-row .el-button {
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.signed-express-row {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
width: 100%;
|
||
}
|
||
|
||
.signed-express-select {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
.action-disabled-text {
|
||
color: var(--el-text-color-placeholder, #a8abb2);
|
||
font-size: 12px;
|
||
}
|
||
|
||
.dialog-form :deep(.service-field-item .el-form-item__label) {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.service-field-label {
|
||
display: inline-block;
|
||
max-width: 100%;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
.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>
|