- 新增 router/view-glob.ts,动态菜单兜底的全量 glob 表改为按需动态加载, 入口 chunk 由 465KB 降至 393KB;Sidebar / TaskView 用 utils/path 的 resolveRoutePath 替换 path-browserify 静态引用 - 新增 utils/perf-probe 轻量探针(?perf=1 或 localStorage 开启),输出导航耗时、 资源分类统计、长任务与硬件信息;移除 text-rendering: optimizeLegibility, breadcrumb 过渡由 all 改为 opacity/transform,降低弱 CPU 与非 Chrome 内核开销 - Navbar 工单角标轮询在后台标签页跳过,通过 visibilitychange 回到前台补刷一次 - 库存详情、货位、条码、入库日志、出库日志与明细、收货日志、盘点记录等 详情面板由 el-table 迁移到 UpperTable,统一展开行、分页、选择与列插槽 - 11 处模板配置及内嵌表格开启行选择;转储、转退货、批量复核弹窗改用 SelectedTags 展示已选项并支持逐个移除,移除最后一个后自动关闭 - ImagesUpload 重构为「图库 + 上传区」面板,支持多选、最多 20 张、 单张 10MB 校验与数量提示 - 新增《跨浏览器性能-分析与优化清单》文档
1042 lines
33 KiB
Vue
1042 lines
33 KiB
Vue
<template>
|
||
<div class="order-sub-container" :style="{ height: containerHeight }">
|
||
<scan-box
|
||
ref="scanBox"
|
||
width="220px"
|
||
: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"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="upper-wrapper">
|
||
<upper-table
|
||
ref="upperTable"
|
||
title="快递策略"
|
||
default-align="center"
|
||
table-id="setting-storeExpressBindingPolicy"
|
||
:data="tableData"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="pagination"
|
||
:show-index="true"
|
||
:show-actions="true"
|
||
:show-selection="true"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
row-key="id"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadList"
|
||
>
|
||
<template #column-is_enabled="{ row }">
|
||
<span :class="getStatusTextClass(formatPolicyStatus(row.is_enabled).type)">
|
||
{{ formatPolicyStatus(row.is_enabled).text }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-store_ids="{ row }">
|
||
<span>{{ Array.isArray(row.store_names) && row.store_names.length ? row.store_names.join(',') : '不限' }}</span>
|
||
</template>
|
||
|
||
<template #column-weight_type="{ row }">
|
||
<span>{{ WEIGHT_TYPE_MAP[row.weight_type] ?? row.weight_type ?? '--' }}</span>
|
||
</template>
|
||
|
||
<template #column-shop_name="{ row }">
|
||
<span>{{ Array.isArray(row.shop_name) ? row.shop_name.join(',') || '不限' : (row.shop_name || '不限') }}</span>
|
||
</template>
|
||
|
||
<template #column-regions="{ row }">
|
||
<span>{{ Array.isArray(row.regions) ? row.regions.join(',') || '不限' : (row.regions || '不限') }}</span>
|
||
</template>
|
||
|
||
<template #column-exclude_regions="{ row }">
|
||
<span>{{ Array.isArray(row.exclude_regions) ? row.exclude_regions.join(',') || '不限' : (row.exclude_regions || '不限') }}</span>
|
||
</template>
|
||
|
||
<template #column-min_weight_g="{ row }">
|
||
<span>{{ row.min_weight_g != null ? row.min_weight_g : '不限' }}</span>
|
||
</template>
|
||
|
||
<template #column-max_weight_g="{ row }">
|
||
<span>{{ row.max_weight_g != null ? row.max_weight_g : '不限' }}</span>
|
||
</template>
|
||
|
||
<template #column-prohibited_type_id="{ row }">
|
||
<span>{{ Array.isArray(row.prohibited_type_names) && row.prohibited_type_names.length ? row.prohibited_type_names.join(',') : '不限' }}</span>
|
||
</template>
|
||
|
||
<template #column-actions="{ row }">
|
||
<div class="wave-operation-actions">
|
||
<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>
|
||
</div>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无策略数据,可调整左侧筛选条件</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
</div>
|
||
|
||
<el-dialog
|
||
v-model="dialogVisible"
|
||
class="policy-form-dialog"
|
||
width="min(720px, 94vw)"
|
||
align-center
|
||
append-to-body
|
||
:show-close="false"
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
@close="resetForm"
|
||
>
|
||
<div class="task-panel">
|
||
<header class="task-panel__head">
|
||
<div class="task-panel__titles">
|
||
<h2>{{ dialogMode === 'create' ? '新增策略' : '编辑策略' }}</h2>
|
||
<p>按快递 / 店铺 / 地区 / 重量段配置运单可绑定的快递策略</p>
|
||
</div>
|
||
<button class="task-panel__close" type="button" aria-label="关闭" @click="dialogVisible = false">
|
||
<svg viewBox="0 0 12 12" fill="none">
|
||
<path d="M1 1L11 11M11 1L1 11" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
|
||
</svg>
|
||
</button>
|
||
</header>
|
||
|
||
<div class="task-panel__body">
|
||
<el-form
|
||
ref="formRef"
|
||
:model="formData"
|
||
:rules="rules"
|
||
class="task-panel__form task-panel__form--wide"
|
||
>
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label is-required">策略名称</span>
|
||
<el-form-item prop="custom_name">
|
||
<el-input
|
||
v-model="formData.custom_name"
|
||
placeholder="请输入策略名称"
|
||
maxlength="100"
|
||
show-word-limit
|
||
/>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label is-required">快递编码</span>
|
||
<el-form-item prop="express_code">
|
||
<el-select v-model="formData.express_code" placeholder="请选择快递" filterable style="width: 100%">
|
||
<el-option
|
||
v-for="item in expressOptions"
|
||
:key="item.code"
|
||
:label="`${item.name} (${item.code})`"
|
||
:value="item.code"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">店铺名称</span>
|
||
<el-form-item prop="shop_name">
|
||
<div class="tag-input-wrapper">
|
||
<div class="tag-list" v-if="formData.shopNameList.length">
|
||
<el-tag
|
||
v-for="(item, idx) in formData.shopNameList"
|
||
:key="idx"
|
||
closable
|
||
size="small"
|
||
@close="formData.shopNameList.splice(idx, 1)"
|
||
>{{ item }}</el-tag>
|
||
</div>
|
||
<div class="tag-input-row">
|
||
<el-input
|
||
v-model="shopNameInput"
|
||
placeholder="输入店铺名称,回车添加"
|
||
maxlength="100"
|
||
@keyup.enter="addShopName"
|
||
/>
|
||
<el-button size="small" @click="addShopName" :disabled="!shopNameInput.trim()">添加</el-button>
|
||
</div>
|
||
</div>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">限定货主ID</span>
|
||
<el-form-item prop="store_ids">
|
||
<el-select
|
||
v-model="formData.storeIdsList"
|
||
placeholder="请选择货主"
|
||
multiple
|
||
filterable
|
||
clearable
|
||
collapse-tags
|
||
collapse-tags-tooltip
|
||
style="width: 100%"
|
||
>
|
||
<el-option
|
||
v-for="item in storeOptions"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">违禁品类型</span>
|
||
<el-form-item prop="prohibited_type_id">
|
||
<el-select
|
||
v-model="formData.prohibited_type_id"
|
||
placeholder="请选择违禁品类型"
|
||
multiple
|
||
filterable
|
||
clearable
|
||
collapse-tags
|
||
collapse-tags-tooltip
|
||
style="width: 100%"
|
||
>
|
||
<el-option
|
||
v-for="item in prohibitedOptions"
|
||
:key="item.value"
|
||
:label="item.label"
|
||
:value="item.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">重量段类型</span>
|
||
<el-form-item prop="weight_type">
|
||
<el-select v-model="formData.weight_type" placeholder="请选择重量段类型" style="width: 100%">
|
||
<el-option label="常规" :value="0" />
|
||
<el-option label="轻货" :value="1" />
|
||
<el-option label="重货" :value="2" />
|
||
<el-option label="冷链" :value="3" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">最小重量(g)</span>
|
||
<el-form-item prop="min_weight_g">
|
||
<el-input-number
|
||
v-model="formData.min_weight_g"
|
||
:min="0"
|
||
placeholder="不限制"
|
||
:controls="false"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">最大重量(g)</span>
|
||
<el-form-item prop="max_weight_g">
|
||
<el-input-number
|
||
v-model="formData.max_weight_g"
|
||
:min="0"
|
||
placeholder="不限制"
|
||
:controls="false"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">限定地区</span>
|
||
<el-form-item prop="regions">
|
||
<div class="tag-input-wrapper">
|
||
<div class="tag-list" v-if="formData.regionsList.length">
|
||
<el-tag
|
||
v-for="(item, idx) in formData.regionsList"
|
||
:key="idx"
|
||
closable
|
||
size="small"
|
||
@close="formData.regionsList.splice(idx, 1)"
|
||
>{{ item }}</el-tag>
|
||
</div>
|
||
<div class="tag-input-row">
|
||
<el-input
|
||
v-model="regionInput"
|
||
placeholder="输入省/市名,回车添加"
|
||
maxlength="50"
|
||
@keyup.enter="addRegion"
|
||
/>
|
||
<el-button size="small" @click="addRegion" :disabled="!regionInput.trim()">添加</el-button>
|
||
</div>
|
||
</div>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">排除地区</span>
|
||
<el-form-item prop="exclude_regions">
|
||
<div class="tag-input-wrapper">
|
||
<div class="tag-list" v-if="formData.excludeRegionsList.length">
|
||
<el-tag
|
||
v-for="(item, idx) in formData.excludeRegionsList"
|
||
:key="idx"
|
||
closable
|
||
size="small"
|
||
@close="formData.excludeRegionsList.splice(idx, 1)"
|
||
>{{ item }}</el-tag>
|
||
</div>
|
||
<div class="tag-input-row">
|
||
<el-input
|
||
v-model="excludeRegionInput"
|
||
placeholder="输入省/市名,回车添加"
|
||
maxlength="50"
|
||
@keyup.enter="addExcludeRegion"
|
||
/>
|
||
<el-button size="small" @click="addExcludeRegion" :disabled="!excludeRegionInput.trim()">添加</el-button>
|
||
</div>
|
||
</div>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">
|
||
优先级
|
||
<el-tooltip content="优先级越大越优先匹配,命中后将不再匹配其他策略" placement="top">
|
||
<el-icon class="task-panel__label-icon"><QuestionFilled /></el-icon>
|
||
</el-tooltip>
|
||
</span>
|
||
<el-form-item prop="priority">
|
||
<el-input-number
|
||
v-model="formData.priority"
|
||
:min="0"
|
||
:max="9999"
|
||
placeholder="请输入优先级"
|
||
style="width: 100%"
|
||
/>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">状态</span>
|
||
<el-form-item prop="is_enabled">
|
||
<el-select v-model="formData.is_enabled" placeholder="请选择状态" style="width: 100%">
|
||
<el-option label="启用" :value="1" />
|
||
<el-option label="禁用" :value="0" />
|
||
</el-select>
|
||
</el-form-item>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label">备注</span>
|
||
<el-form-item prop="remark">
|
||
<el-input
|
||
v-model="formData.remark"
|
||
type="textarea"
|
||
:rows="3"
|
||
placeholder="请输入备注(选填)"
|
||
maxlength="200"
|
||
show-word-limit
|
||
/>
|
||
</el-form-item>
|
||
</div>
|
||
</el-form>
|
||
|
||
<!-- 提示条:对齐「手工录入运单号」的 .task-panel__form-tip -->
|
||
<p class="task-panel__form-tip">
|
||
策略按优先级从大到小匹配,命中后不再匹配其它策略;店铺名称、限定地区、重量段留空表示不限制。
|
||
</p>
|
||
</div>
|
||
|
||
<footer class="task-panel__foot">
|
||
<span class="task-panel__hint">提交前请确认快递与适用条件无误</span>
|
||
<div class="task-panel__actions">
|
||
<el-button size="small" @click="dialogVisible = false">取消</el-button>
|
||
<el-button size="small" type="primary" :loading="saving" @click="submitForm">保存</el-button>
|
||
</div>
|
||
</footer>
|
||
</div>
|
||
</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 '@/components/ToolbarButtonGroup/index.vue'
|
||
import { getStatusTextClass } from '@/utils/statusText'
|
||
import type { ToolbarButtonConfig } from '@/components/ToolbarButtonGroup/types'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
import {
|
||
storeExpressBindingPolicyAdd,
|
||
storeExpressBindingPolicyDel,
|
||
storeExpressBindingPolicyEdit,
|
||
storeExpressBindingPolicyList
|
||
} from '@/api/storeexpressbindingpolicy/storeExpressBindingPolicy'
|
||
import { expressIndexGetExpressList } from '@/api/setting.express/express'
|
||
import { getProhibitedType } from '@/api/stock/stock'
|
||
import { loadStores } from '@/api/index/index'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
import { useUserStore } from '@/stores/modules/user'
|
||
import {
|
||
buildPolicyListPayload,
|
||
formatPolicyStatus,
|
||
normalizeStoreExpressBindingPolicyScanConditionToWhere,
|
||
storeExpressBindingPolicyColumns,
|
||
storeExpressBindingPolicyScanFields,
|
||
WEIGHT_TYPE_MAP,
|
||
type StoreExpressBindingPolicyRecord
|
||
} from './storeExpressBindingPolicy-config'
|
||
|
||
const settingsStore = useSettingsStore()
|
||
const userStore = useUserStore()
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(storeExpressBindingPolicyScanFields)))
|
||
|
||
const containerHeight = computed(() =>
|
||
'100%' /* 高度由布局层(.app-router-page 的 flex:1)提供,不再自己算 vh */
|
||
)
|
||
|
||
const columns = storeExpressBindingPolicyColumns
|
||
const loading = ref(false)
|
||
const saving = ref(false)
|
||
const tableData = ref<StoreExpressBindingPolicyRecord[]>([])
|
||
const expressOptions = ref<{ code: string; name: string }[]>([])
|
||
const prohibitedOptions = ref<{ value: number; label: string }[]>([])
|
||
const storeOptions = ref<{ value: number; label: string }[]>([])
|
||
const queryTime = ref(0)
|
||
const tableSize = ref<'small' | 'default' | 'large'>('small')
|
||
const currentConditionRaw = ref<any>(null)
|
||
|
||
const toolbarButtons: ToolbarButtonConfig[] = [
|
||
{ key: 'refresh', label: '刷新', category: 'refresh', size: 'small', loadingKey: 'loading', action: 'loadList' },
|
||
{ key: 'create', label: '新增策略', category: 'action', size: 'small', action: 'openCreate' },
|
||
]
|
||
|
||
const buttonLoadingMap = computed(() => ({ loading: loading.value }))
|
||
const buttonDisabledMap = computed(() => ({}))
|
||
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> = {
|
||
loadList: () => { void loadList() },
|
||
openCreate: () => openCreate()
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||
const handler = toolbarActionMap[action]
|
||
if (!handler) return
|
||
safeInvoke(() => handler())
|
||
}
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
|
||
const dialogVisible = ref(false)
|
||
const dialogMode = ref<'create' | 'edit'>('create')
|
||
const formRef = ref<FormInstance>()
|
||
const formData = reactive({
|
||
id: undefined as number | undefined,
|
||
custom_name: '',
|
||
express_code: '',
|
||
prohibited_type_id: [] as number[],
|
||
weight_type: 0 as number,
|
||
shopNameList: [] as string[],
|
||
storeIdsList: [] as number[],
|
||
regionsList: [] as string[],
|
||
excludeRegionsList: [] as string[],
|
||
min_weight_g: undefined as number | undefined,
|
||
max_weight_g: undefined as number | undefined,
|
||
priority: 0,
|
||
is_enabled: 1 as number,
|
||
remark: ''
|
||
})
|
||
|
||
const shopNameInput = ref('')
|
||
const regionInput = ref('')
|
||
const excludeRegionInput = ref('')
|
||
|
||
const rules: FormRules = {
|
||
custom_name: [{ required: true, message: '请输入自定义名称', trigger: 'blur' }],
|
||
express_code: [{ required: true, message: '请输入快递编码', trigger: 'blur' }]
|
||
}
|
||
|
||
const isSuccess = (res: any) => res && [0, 1, 200].includes(res.code)
|
||
|
||
async function loadList() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const where = normalizeStoreExpressBindingPolicyScanConditionToWhere(currentConditionRaw.value)
|
||
const res: any = await storeExpressBindingPolicyList(
|
||
buildPolicyListPayload({
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize,
|
||
where
|
||
})
|
||
)
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '获取策略列表失败')
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
return
|
||
}
|
||
const data = res?.data || {}
|
||
tableData.value = data.list || []
|
||
pagination.total = Number(data.pagination?.total ?? data.total ?? 0)
|
||
} catch {
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
ElMessage.error('获取策略列表失败')
|
||
} finally {
|
||
queryTime.value = Date.now() - start
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function handleConditionChange(condition: any) {
|
||
currentConditionRaw.value = condition
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleSubmit() {
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleConditionClear() {
|
||
currentConditionRaw.value = null
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
currentConditionRaw.value = null
|
||
pagination.currentPage = 1
|
||
if (scanBox.value?.reset) {
|
||
scanBox.value.reset()
|
||
} else if (scanBox.value?.clear) {
|
||
scanBox.value.clear()
|
||
}
|
||
loadList()
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
loadList()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function resetForm() {
|
||
formData.id = undefined
|
||
formData.custom_name = ''
|
||
formData.express_code = ''
|
||
formData.prohibited_type_id = []
|
||
formData.weight_type = 0
|
||
formData.shopNameList = []
|
||
formData.storeIdsList = []
|
||
formData.regionsList = []
|
||
formData.excludeRegionsList = []
|
||
formData.min_weight_g = undefined
|
||
formData.max_weight_g = undefined
|
||
formData.priority = 0
|
||
formData.is_enabled = 1
|
||
formData.remark = ''
|
||
shopNameInput.value = ''
|
||
regionInput.value = ''
|
||
excludeRegionInput.value = ''
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
function addShopName() {
|
||
const val = shopNameInput.value.trim()
|
||
if (!val) return
|
||
if (!formData.shopNameList.includes(val)) {
|
||
formData.shopNameList.push(val)
|
||
}
|
||
shopNameInput.value = ''
|
||
}
|
||
|
||
function addRegion() {
|
||
const val = regionInput.value.trim()
|
||
if (!val) return
|
||
if (!formData.regionsList.includes(val)) {
|
||
formData.regionsList.push(val)
|
||
}
|
||
regionInput.value = ''
|
||
}
|
||
|
||
function addExcludeRegion() {
|
||
const val = excludeRegionInput.value.trim()
|
||
if (!val) return
|
||
if (!formData.excludeRegionsList.includes(val)) {
|
||
formData.excludeRegionsList.push(val)
|
||
}
|
||
excludeRegionInput.value = ''
|
||
}
|
||
|
||
function openCreate() {
|
||
dialogMode.value = 'create'
|
||
dialogVisible.value = true
|
||
resetForm()
|
||
}
|
||
|
||
function openEdit(row: StoreExpressBindingPolicyRecord) {
|
||
if (!row.id) return
|
||
dialogMode.value = 'edit'
|
||
dialogVisible.value = true
|
||
formData.id = row.id
|
||
formData.custom_name = row.custom_name || ''
|
||
formData.express_code = row.express_code || ''
|
||
formData.prohibited_type_id = Array.isArray(row.prohibited_type_id) ? row.prohibited_type_id.map((v: any) => Number(v)).filter((v: number) => !isNaN(v)) : []
|
||
formData.weight_type = Number(row.weight_type ?? 0)
|
||
formData.shopNameList = Array.isArray(row.shop_name) ? row.shop_name.filter((s: any) => s != null && String(s).trim()) : []
|
||
formData.storeIdsList = Array.isArray(row.store_ids) ? row.store_ids.map((v: any) => Number(v)).filter((v: number) => !isNaN(v)) : []
|
||
formData.regionsList = Array.isArray(row.regions) ? row.regions.filter((s: any) => s != null && String(s).trim()) : []
|
||
formData.excludeRegionsList = Array.isArray(row.exclude_regions) ? row.exclude_regions.filter((s: any) => s != null && String(s).trim()) : []
|
||
formData.min_weight_g = row.min_weight_g != null ? Number(row.min_weight_g) : undefined
|
||
formData.max_weight_g = row.max_weight_g != null ? Number(row.max_weight_g) : undefined
|
||
formData.priority = Number(row.priority ?? 0)
|
||
formData.is_enabled = Number(row.is_enabled ?? 1)
|
||
formData.remark = row.remark || ''
|
||
shopNameInput.value = ''
|
||
regionInput.value = ''
|
||
excludeRegionInput.value = ''
|
||
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 buildPayload = (base: Record<string, unknown> = {}) => {
|
||
const p: Record<string, unknown> = { ...base }
|
||
p.custom_name = formData.custom_name.trim()
|
||
p.express_code = formData.express_code.trim()
|
||
p.prohibited_type_id = formData.prohibited_type_id.length ? formData.prohibited_type_id : undefined
|
||
p.weight_type = formData.weight_type
|
||
p.shop_name = formData.shopNameList.length ? formData.shopNameList : undefined
|
||
p.store_ids = formData.storeIdsList.length ? formData.storeIdsList : undefined
|
||
// 限定地区/排除地区无数据时传空数组(而非 undefined),确保后端能清除已有地区
|
||
p.regions = formData.regionsList.length ? formData.regionsList : []
|
||
p.exclude_regions = formData.excludeRegionsList.length ? formData.excludeRegionsList : []
|
||
p.min_weight_g = formData.min_weight_g
|
||
p.max_weight_g = formData.max_weight_g
|
||
p.priority = formData.priority
|
||
p.is_enabled = formData.is_enabled
|
||
p.remark = formData.remark.trim() || undefined
|
||
return p
|
||
}
|
||
|
||
if (dialogMode.value === 'create') {
|
||
const payload = buildPayload()
|
||
// 创建人账户ID(兼容 creatorId;后端也会注入,此处显式传入保证传参完整)
|
||
const creatorId = Number(userStore.user?.id)
|
||
if (Number.isInteger(creatorId) && creatorId > 0) {
|
||
payload.creator_id = creatorId
|
||
}
|
||
const res: any = await storeExpressBindingPolicyAdd(payload)
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '新增失败')
|
||
return
|
||
}
|
||
ElMessage.success('新增成功')
|
||
} else {
|
||
if (!formData.id) return
|
||
const payload = buildPayload({ id: formData.id })
|
||
const res: any = await storeExpressBindingPolicyEdit(payload)
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '更新失败')
|
||
return
|
||
}
|
||
ElMessage.success('更新成功')
|
||
}
|
||
dialogVisible.value = false
|
||
loadList()
|
||
} catch {
|
||
ElMessage.error('保存失败')
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
|
||
function handleDelete(row: StoreExpressBindingPolicyRecord) {
|
||
if (!row.id) return
|
||
const name = row.custom_name || String(row.id)
|
||
ElMessageBox.confirm(`确认删除策略「${name}」吗?`, '提示', { type: 'warning', buttonSize: 'small' })
|
||
.then(async () => {
|
||
const res: any = await storeExpressBindingPolicyDel({ id: row.id as number })
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '删除失败')
|
||
return
|
||
}
|
||
ElMessage.success('删除成功')
|
||
if (tableData.value.length === 1 && pagination.currentPage > 1) {
|
||
pagination.currentPage -= 1
|
||
}
|
||
loadList()
|
||
})
|
||
.catch(() => undefined)
|
||
}
|
||
|
||
async function loadExpressOptions() {
|
||
try {
|
||
const res: any = await expressIndexGetExpressList({})
|
||
if (isSuccess(res)) {
|
||
expressOptions.value = (res?.data || []).map((item: any) => ({
|
||
code: item.code,
|
||
name: item.name
|
||
}))
|
||
}
|
||
} catch {
|
||
expressOptions.value = []
|
||
}
|
||
}
|
||
|
||
async function loadProhibitedOptions() {
|
||
try {
|
||
const res: any = await getProhibitedType()
|
||
if (isSuccess(res) && Array.isArray(res?.data)) {
|
||
prohibitedOptions.value = res.data
|
||
.map((item: any) => {
|
||
if (item && typeof item === 'object') {
|
||
if (item.value != null && item.label != null) {
|
||
return { value: Number(item.value), label: String(item.label) }
|
||
}
|
||
if (item.id != null && item.name != null) {
|
||
return { value: Number(item.id), label: String(item.name) }
|
||
}
|
||
}
|
||
return null
|
||
})
|
||
.filter((x:any): x is { value: number; label: string } => x != null)
|
||
}
|
||
// 同步到 ScanBox 字段选项
|
||
const prohibitedField = availableFieldsRef.find((f: any) => f.value === 'prohibited_type_id')
|
||
if (prohibitedField) {
|
||
prohibitedField.options = prohibitedOptions.value.map((item) => ({
|
||
label: item.label,
|
||
value: item.value
|
||
}))
|
||
}
|
||
} catch {
|
||
prohibitedOptions.value = []
|
||
}
|
||
}
|
||
|
||
async function loadStoreOptions() {
|
||
try {
|
||
const res: any = await loadStores()
|
||
if (res && res.stores && Array.isArray(res.stores)) {
|
||
storeOptions.value = res.stores.map((item: any) => ({
|
||
value: Number(item.value ?? item.id),
|
||
label: String(item.label ?? item.name ?? '')
|
||
}))
|
||
}
|
||
} catch {
|
||
storeOptions.value = []
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadList()
|
||
loadExpressOptions()
|
||
loadProhibitedOptions()
|
||
loadStoreOptions()
|
||
})
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@use "@/styles/list-page.scss";
|
||
@use "@/styles/status-text.scss";
|
||
|
||
.wave-operation-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 4px;
|
||
}
|
||
|
||
.tag-input-wrapper {
|
||
width: 100%;
|
||
|
||
.tag-list {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 6px;
|
||
margin-bottom: 8px;
|
||
}
|
||
|
||
.tag-input-row {
|
||
display: flex;
|
||
gap: 8px;
|
||
|
||
.el-input {
|
||
flex: 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* 新增 / 编辑策略:面板结构 / 尺寸对齐「手工录入运单号」(ManualWaybillForm) */
|
||
.task-panel {
|
||
background: #fff;
|
||
color: #303133;
|
||
|
||
&__head {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
gap: 12px;
|
||
padding: 16px;
|
||
}
|
||
|
||
&__titles {
|
||
flex: 1;
|
||
min-width: 0;
|
||
|
||
h2 {
|
||
margin: 0;
|
||
font-size: 18px;
|
||
line-height: 24px;
|
||
font-weight: 400;
|
||
color: #303133;
|
||
}
|
||
|
||
p {
|
||
margin: 4px 0 0;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
}
|
||
}
|
||
|
||
&__close {
|
||
width: 24px;
|
||
height: 24px;
|
||
flex: none;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border: none;
|
||
border-radius: 4px;
|
||
background: transparent;
|
||
color: #909399;
|
||
cursor: pointer;
|
||
transition: color 0.2s;
|
||
|
||
svg {
|
||
width: 12px;
|
||
height: 12px;
|
||
}
|
||
|
||
&:hover {
|
||
color: #409eff;
|
||
}
|
||
}
|
||
|
||
&__body {
|
||
padding: 12px 16px 0;
|
||
}
|
||
|
||
&__form {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
|
||
/* 表单行内嵌 el-form-item:占满剩余宽度,去掉默认间距 */
|
||
:deep(.el-form-item) {
|
||
flex: 1;
|
||
min-width: 0;
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
:deep(.el-form-item__content) {
|
||
margin-left: 0 !important;
|
||
width: 100%;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
:deep(.el-form-item__error) {
|
||
position: static;
|
||
padding-top: 4px;
|
||
}
|
||
}
|
||
|
||
/* 部分标签较长(如「最小重量(g)」),单独放宽标签列,避免换行 */
|
||
&__form--wide {
|
||
.task-panel__field-label {
|
||
flex: 0 0 96px;
|
||
width: 96px;
|
||
}
|
||
}
|
||
|
||
&__field {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 16px;
|
||
min-height: 40px;
|
||
padding: 8px 12px;
|
||
border: 1px solid #ebeef5;
|
||
border-radius: 4px;
|
||
background: #fafafa;
|
||
|
||
/* 输入行:去掉灰色容器,与静态信息行区分 */
|
||
&--input {
|
||
align-items: flex-start;
|
||
min-height: 0;
|
||
/* 右 0 让输入框右边顶到容器右边缘 */
|
||
padding: 4px 0 0 12px;
|
||
border: none;
|
||
border-radius: 0;
|
||
background: transparent;
|
||
|
||
.task-panel__field-label {
|
||
padding-top: 7px;
|
||
|
||
&.is-required::before {
|
||
top: 7px;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/* 标签列固定宽度 + 必填星号绝对定位前缀 */
|
||
&__field-label {
|
||
position: relative;
|
||
flex: 0 0 88px;
|
||
width: 88px;
|
||
padding-left: 10px;
|
||
box-sizing: border-box;
|
||
font-size: 12px;
|
||
line-height: 20px;
|
||
color: #606266;
|
||
text-align: left;
|
||
white-space: nowrap;
|
||
|
||
&.is-required::before {
|
||
content: '*';
|
||
position: absolute;
|
||
left: 0;
|
||
top: 0;
|
||
line-height: 20px;
|
||
color: #f56c6c;
|
||
}
|
||
}
|
||
|
||
&__label-icon {
|
||
margin-left: 2px;
|
||
vertical-align: middle;
|
||
cursor: help;
|
||
}
|
||
|
||
&__field-value {
|
||
font-size: 13px;
|
||
font-weight: 500;
|
||
color: #303133;
|
||
text-align: right;
|
||
word-break: break-all;
|
||
}
|
||
|
||
&__form-tip {
|
||
margin: 8px 0 0;
|
||
padding: 8px 12px;
|
||
border-radius: 4px;
|
||
background: #f4f4f5;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
}
|
||
|
||
&__foot {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
padding: 16px;
|
||
}
|
||
|
||
&__hint {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
|
||
&__actions {
|
||
display: flex;
|
||
align-items: center;
|
||
/* 与工具栏按钮组(OrderToolbarButtonGroup)保持一致:gap 6px */
|
||
gap: 6px;
|
||
|
||
:deep(.el-button) {
|
||
margin-left: 0;
|
||
margin-right: 0;
|
||
}
|
||
}
|
||
}
|
||
</style>
|
||
|
||
<style lang="scss">
|
||
/* el-dialog 会被 append 到 body:去掉默认头/内边距,统一交给面板 */
|
||
.el-dialog.policy-form-dialog {
|
||
padding: 0;
|
||
overflow: hidden;
|
||
|
||
.el-dialog__header {
|
||
display: none;
|
||
}
|
||
|
||
.el-dialog__body {
|
||
padding: 0;
|
||
}
|
||
}
|
||
</style>
|