976 lines
30 KiB
Vue
976 lines
30 KiB
Vue
<template>
|
||
<div class="express-interface-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">
|
||
<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>
|
||
<el-button size="small" type="primary" :loading="loading" @click="loadData">刷新</el-button>
|
||
<el-button size="small" @click="openColumnConfigPanel">字段设置</el-button>
|
||
<el-tag size="small" type="info">共 {{ pagination.total }} 条</el-tag>
|
||
<span v-if="viewMode === 'warehouse' && warehouseContextHint" class="toolbar-hint">
|
||
{{ warehouseContextHint }}
|
||
</span>
|
||
</div>
|
||
<el-button type="success" size="small" @click="openCreate">新增接口配置</el-button>
|
||
</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"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
row-key="id"
|
||
@current-change="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadData"
|
||
>
|
||
<template #column-actions="{ 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>
|
||
<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="720px"
|
||
align-center
|
||
class="config-dialog"
|
||
@close="resetForm"
|
||
>
|
||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="120px" 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 label="快递编码" prop="express_code">
|
||
<el-select v-model="formData.express_code" filterable placeholder="请选择快递编码">
|
||
<el-option
|
||
v-for="item in expressOptions"
|
||
:key="item.code"
|
||
:label="item.label || item.name"
|
||
:value="item.code"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="平台编码" prop="platform_code">
|
||
<el-select v-model="formData.platform_code" filterable placeholder="请选择平台编码">
|
||
<el-option
|
||
v-for="item in platformOptions"
|
||
:key="item.code"
|
||
:label="item.label || item.name"
|
||
:value="item.code"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col v-if="dialogMode === 'edit'" :span="12">
|
||
<el-form-item label="平台接口ID" prop="express_platform_id">
|
||
<el-input-number v-model="formData.express_platform_id" :min="1" style="width: 100%" />
|
||
</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="发件人">
|
||
<el-input v-model="formData.sender_name" placeholder="可选" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="发件电话">
|
||
<el-input v-model="formData.sender_tel" placeholder="可选" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="24">
|
||
<el-form-item label="省市区">
|
||
<el-row :gutter="8" class="region-select-row">
|
||
<el-col :span="8">
|
||
<el-select
|
||
v-model="regionCodes.provinceCode"
|
||
filterable
|
||
clearable
|
||
placeholder="请选择省"
|
||
style="width: 100%"
|
||
@change="handleProvinceChange"
|
||
>
|
||
<el-option
|
||
v-for="item in provinceOptions"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-select
|
||
v-model="regionCodes.cityCode"
|
||
filterable
|
||
clearable
|
||
placeholder="请选择市"
|
||
style="width: 100%"
|
||
:disabled="!regionCodes.provinceCode"
|
||
@change="handleCityChange"
|
||
>
|
||
<el-option
|
||
v-for="item in cityOptions"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-select
|
||
v-model="regionCodes.districtCode"
|
||
filterable
|
||
clearable
|
||
placeholder="请选择区/县"
|
||
style="width: 100%"
|
||
:disabled="!regionCodes.cityCode"
|
||
@change="handleDistrictChange"
|
||
>
|
||
<el-option
|
||
v-for="item in districtOptions"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="站点编码">
|
||
<el-input v-model="formData.site_code" placeholder="可选" />
|
||
</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="24">
|
||
<el-form-item label="店铺名称">
|
||
<el-input v-model="formData.shop_name" placeholder="可选" />
|
||
</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="token">
|
||
<el-input v-model="formData.token" placeholder="可选" />
|
||
</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="客户端 ID">
|
||
<el-input v-model="formData.client_id" placeholder="可选,最长 50 字符" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="是否共享">
|
||
<el-radio-group v-model="formData.is_share">
|
||
<el-radio :label="0">否</el-radio>
|
||
<el-radio :label="1">是</el-radio>
|
||
</el-radio-group>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="共享记录 ID">
|
||
<el-input-number
|
||
v-model="formData.share_id"
|
||
:min="1"
|
||
placeholder="可选"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="可用单量">
|
||
<el-input-number
|
||
v-model="formData.can_use_count"
|
||
:min="0"
|
||
:precision="0"
|
||
:step="1"
|
||
placeholder="可选"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</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 { getExpressList, getPlatformList } from '@/api/index/index'
|
||
import {
|
||
expressInterfaceCreate,
|
||
expressInterfaceDelete,
|
||
expressInterfaceList,
|
||
expressInterfaceListByWarehousePlatformCode,
|
||
expressInterfaceUpdate
|
||
} 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,
|
||
expressInterfaceScanFields,
|
||
expressInterfaceWarehouseColumns,
|
||
extractPlainWhereValue,
|
||
formatExpressInterfaceCell,
|
||
formatExpressInterfaceData,
|
||
formatExpressInterfaceNumber,
|
||
normalizeScanConditionToWhere,
|
||
sortExpressInterfaceDetailKeys,
|
||
buildProvinceOptions,
|
||
buildCityOptions,
|
||
buildDistrictOptions,
|
||
resolveRegionCodesFromNames,
|
||
getCityNodes,
|
||
getDistrictNodes,
|
||
defaultExpressInterfaceForm,
|
||
buildExpressInterfaceCreatePayload,
|
||
buildExpressInterfaceUpdatePayload
|
||
} from './express-interface-config'
|
||
|
||
type ExpressOption = { code: string; name: string; label?: string }
|
||
type PlatformOption = { code: string; name: string; label?: string }
|
||
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 viewMode = ref<'paged' | 'warehouse'>('paged')
|
||
const loading = ref(false)
|
||
const saving = 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 columns = computed(() =>
|
||
viewMode.value === 'paged' ? expressInterfaceColumns : expressInterfaceWarehouseColumns
|
||
)
|
||
|
||
const expressOptions = ref<ExpressOption[]>([])
|
||
const platformOptions = ref<PlatformOption[]>([])
|
||
|
||
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_')
|
||
)
|
||
return sortExpressInterfaceDetailKeys(keys)
|
||
})
|
||
|
||
const dialogVisible = ref(false)
|
||
const dialogMode = ref<'create' | 'edit'>('create')
|
||
const formRef = ref<FormInstance>()
|
||
const formData = reactive<ExpressInterfaceRecord>({ ...defaultExpressInterfaceForm })
|
||
|
||
const rules = computed<FormRules>(() => {
|
||
const base: FormRules = {
|
||
name: [{ required: true, message: '请输入配置名称', trigger: 'blur' }],
|
||
express_code: [{ required: true, message: '请选择快递编码', trigger: 'change' }],
|
||
platform_code: [{ required: true, message: '请选择平台编码', trigger: 'change' }]
|
||
}
|
||
if (dialogMode.value === 'edit') {
|
||
base.express_platform_id = [{ required: true, message: '请输入平台接口ID', trigger: 'change' }]
|
||
}
|
||
return base
|
||
})
|
||
|
||
const regionCodes = reactive({
|
||
provinceCode: '',
|
||
cityCode: '',
|
||
districtCode: ''
|
||
})
|
||
|
||
const provinceOptions = computed(() => buildProvinceOptions())
|
||
const cityOptions = computed(() => buildCityOptions(regionCodes.provinceCode))
|
||
const districtOptions = computed(() => buildDistrictOptions(regionCodes.provinceCode, regionCodes.cityCode))
|
||
|
||
const isSuccess = (res: any) => res && [0, 1, 200].includes(res.code)
|
||
|
||
function resetRegionCodes() {
|
||
regionCodes.provinceCode = ''
|
||
regionCodes.cityCode = ''
|
||
regionCodes.districtCode = ''
|
||
}
|
||
|
||
function syncRegionCodesFromFormNames() {
|
||
const resolved = resolveRegionCodesFromNames({
|
||
province_name: formData.province_name,
|
||
city_name: formData.city_name,
|
||
district_name: formData.district_name
|
||
})
|
||
regionCodes.provinceCode = resolved.provinceCode
|
||
regionCodes.cityCode = resolved.cityCode
|
||
regionCodes.districtCode = resolved.districtCode
|
||
}
|
||
|
||
function handleProvinceChange(code: string) {
|
||
const province = buildProvinceOptions().find((item) => item.value === code)
|
||
formData.province_name = province?.label || ''
|
||
regionCodes.cityCode = ''
|
||
regionCodes.districtCode = ''
|
||
formData.city_name = ''
|
||
formData.district_name = ''
|
||
}
|
||
|
||
function handleCityChange(code: string) {
|
||
const city = getCityNodes(regionCodes.provinceCode).find((item) => item.code === code)
|
||
formData.city_name = city?.name || ''
|
||
regionCodes.districtCode = ''
|
||
formData.district_name = ''
|
||
}
|
||
|
||
function handleDistrictChange(code: string) {
|
||
const district = getDistrictNodes(regionCodes.provinceCode, regionCodes.cityCode).find(
|
||
(item) => item.code === code
|
||
)
|
||
formData.district_name = district?.name || ''
|
||
}
|
||
|
||
function fieldLabel(key: string) {
|
||
return expressInterfaceFieldLabels[key] || key
|
||
}
|
||
|
||
function detailValue(key: string) {
|
||
if (!selectedRow.value) return '--'
|
||
const v = selectedRow.value[key]
|
||
if (key === 'is_share') {
|
||
if (v === 1 || v === true) return '是'
|
||
if (v === 0 || v === false) return '否'
|
||
return '--'
|
||
}
|
||
if (['can_use_count', 'weight', 'express_platform_id', 'id', 'warehouse_id', 'share_id'].includes(key)) {
|
||
return formatExpressInterfaceNumber(v)
|
||
}
|
||
return formatExpressInterfaceCell(v)
|
||
}
|
||
|
||
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 data = res?.data || {}
|
||
list.value = formatExpressInterfaceData(data.list || [])
|
||
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
|
||
}
|
||
} 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 getPlatformList({ systemOnly: true })
|
||
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 = []
|
||
}
|
||
}
|
||
|
||
function resetForm() {
|
||
Object.assign(formData, { ...defaultExpressInterfaceForm })
|
||
resetRegionCodes()
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
function openCreate() {
|
||
dialogMode.value = 'create'
|
||
dialogVisible.value = true
|
||
resetForm()
|
||
}
|
||
|
||
function openEdit(row: ExpressInterfaceRecord) {
|
||
dialogMode.value = 'edit'
|
||
dialogVisible.value = true
|
||
formData.id = row.id
|
||
formData.name = row.name || ''
|
||
formData.express_code = row.express_code || ''
|
||
formData.platform_code = row.platform_code || ''
|
||
formData.express_platform_id = Number(row.express_platform_id || 1)
|
||
formData.sender_name = row.sender_name || ''
|
||
formData.sender_tel = row.sender_tel || ''
|
||
formData.weight = Number(row.weight || 1)
|
||
formData.token = row.token || ''
|
||
formData.site_code = row.site_code || ''
|
||
formData.shop_name = row.shop_name || ''
|
||
formData.province_name = row.province_name || ''
|
||
formData.city_name = row.city_name || ''
|
||
formData.district_name = row.district_name || ''
|
||
formData.product_type = row.product_type || ''
|
||
formData.viewer = row.viewer || ''
|
||
formData.client_id = row.client_id || ''
|
||
formData.is_share = row.is_share === 1 || row.is_share === true ? 1 : 0
|
||
formData.share_id = row.share_id != null && row.share_id !== '' ? Number(row.share_id) : undefined
|
||
formData.can_use_count =
|
||
row.can_use_count != null && row.can_use_count !== '' ? Number(row.can_use_count) : undefined
|
||
syncRegionCodesFromFormNames()
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
async function submitForm() {
|
||
if (!formRef.value || saving.value) return
|
||
const valid = await formRef.value.validate().catch(() => false)
|
||
if (!valid) return
|
||
|
||
saving.value = true
|
||
try {
|
||
const payload =
|
||
dialogMode.value === 'create'
|
||
? buildExpressInterfaceCreatePayload(formData)
|
||
: buildExpressInterfaceUpdatePayload(formData)
|
||
const res: any =
|
||
dialogMode.value === 'create'
|
||
? await expressInterfaceCreate(payload)
|
||
: await expressInterfaceUpdate(payload)
|
||
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 (!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">
|
||
.express-interface-container {
|
||
display: flex;
|
||
width: 100%;
|
||
background-color: #f0f2f5;
|
||
|
||
.main-content {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
padding: 10px;
|
||
overflow: hidden;
|
||
min-width: 0;
|
||
}
|
||
|
||
.toolbar {
|
||
padding: 5px 8px;
|
||
border-bottom: 1px solid #ebeef5;
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
gap: 12px;
|
||
flex-wrap: wrap;
|
||
background-color: #fff;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.toolbar-left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
flex-wrap: wrap;
|
||
min-width: 0;
|
||
}
|
||
|
||
.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%);
|
||
}
|
||
|
||
.split-stack {
|
||
flex: 1 1 auto;
|
||
min-height: 0;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.pane-resizer {
|
||
flex: 0 0 6px;
|
||
min-height: 6px;
|
||
background: #e4e7ed;
|
||
cursor: row-resize;
|
||
flex-shrink: 0;
|
||
|
||
&:hover {
|
||
background: #dcdfe6;
|
||
}
|
||
}
|
||
|
||
.upper-wrapper {
|
||
overflow: hidden;
|
||
}
|
||
|
||
.upper-wrapper :deep(.upper-table-container) {
|
||
height: 100%;
|
||
}
|
||
|
||
.lower-level {
|
||
display: flex;
|
||
flex-direction: column;
|
||
border-top: 1px solid #ebeef5;
|
||
overflow: hidden;
|
||
background-color: #fff;
|
||
|
||
.detail-header {
|
||
flex-shrink: 0;
|
||
padding: 8px 12px;
|
||
border-bottom: 1px solid #ebeef5;
|
||
background-color: #fafafa;
|
||
display: flex;
|
||
align-items: baseline;
|
||
gap: 10px;
|
||
}
|
||
|
||
.detail-title {
|
||
font-size: 13px;
|
||
font-weight: 600;
|
||
color: var(--el-text-color-primary);
|
||
}
|
||
|
||
.detail-sub {
|
||
font-size: 12px;
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
.detail-container {
|
||
flex: 1;
|
||
min-height: 0;
|
||
overflow: auto;
|
||
padding: 10px 12px;
|
||
}
|
||
}
|
||
|
||
.express-relation {
|
||
margin-top: 12px;
|
||
|
||
&__title {
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
color: var(--el-text-color-regular);
|
||
margin-bottom: 8px;
|
||
}
|
||
}
|
||
|
||
.no-selection {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
color: #909399;
|
||
background-color: #fff;
|
||
padding: 10px;
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
line-height: 1.5;
|
||
}
|
||
}
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
color: #909399;
|
||
padding: 16px;
|
||
}
|
||
}
|
||
|
||
.config-dialog :deep(.el-dialog__body) {
|
||
padding-top: 8px;
|
||
padding-bottom: 8px;
|
||
}
|
||
|
||
.dialog-form {
|
||
max-height: min(70vh, 640px);
|
||
overflow-y: auto;
|
||
padding-right: 4px;
|
||
}
|
||
|
||
.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%;
|
||
}
|
||
|
||
.region-select-row {
|
||
width: 100%;
|
||
}
|
||
</style>
|