feat: 快递编码支持自定义 & 快递策略列表显示名称
- 移除 getExpressList 的 systemOnly 参数,快递编码下拉不再限定系统编码 (pendingOrder, exceptionOrder) - 新增货主快递绑定策略页面 (storeExpressBindingPolicy) - 策略列表快递编码列改为显示快递名称 (express_name) - 路由注册 storeExpressBindingPolicy 页面
This commit is contained in:
parent
6274ce1407
commit
cdde7183e4
@ -0,0 +1,63 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
const v = '1.0'
|
||||
|
||||
/** 分页查询店铺快递绑定策略 */
|
||||
export function storeExpressBindingPolicyList(data?: {
|
||||
page?: number
|
||||
pageSize?: number
|
||||
where?: Record<string, unknown>
|
||||
}) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'storeExpressBindingPolicy.list',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data: data || {}
|
||||
})
|
||||
}
|
||||
|
||||
/** 新增店铺快递绑定策略 */
|
||||
export function storeExpressBindingPolicyAdd(data: Record<string, unknown>) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'storeExpressBindingPolicy.add',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 编辑店铺快递绑定策略 */
|
||||
export function storeExpressBindingPolicyEdit(data: Record<string, unknown>) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'storeExpressBindingPolicy.edit',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data
|
||||
})
|
||||
}
|
||||
|
||||
/** 删除店铺快递绑定策略 */
|
||||
export function storeExpressBindingPolicyDel(data: { id: number }) {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'storeExpressBindingPolicy.del',
|
||||
v,
|
||||
timestamp: new Date().getTime()
|
||||
},
|
||||
data
|
||||
})
|
||||
}
|
||||
@ -68,4 +68,5 @@ export const componentMap: Record<string, any> = {
|
||||
'data/packingflow': () => import('@/views/data/packingflow/index.vue'),
|
||||
'system/setting/printcomputer/index':() => import('@/views/system/setting/printcomputer/index.vue'),
|
||||
'express/index':() => import('@/views/express/waybill/index.vue'),
|
||||
'system/setting/storeExpressBindingPolicy/index':() => import('@/views/system/setting/storeExpressBindingPolicy/index.vue'),
|
||||
};
|
||||
@ -712,7 +712,7 @@ async function loadFilterData() {
|
||||
async function loadOrderMetaOptions() {
|
||||
try {
|
||||
const [expressRes, platformRes] = await Promise.all([
|
||||
indexApi.getExpressList({ systemOnly: 'true' }),
|
||||
indexApi.getExpressList(),
|
||||
indexApi.getPlatformList({ systemOnly: 'true' })
|
||||
])
|
||||
const expressData: any = expressRes?.data
|
||||
|
||||
@ -957,7 +957,7 @@ function mapNameOptions(rawList: any[], nameKeys: string[]) {
|
||||
async function loadOrderMetaOptions() {
|
||||
try {
|
||||
const [expressRes, platformRes] = await Promise.all([
|
||||
indexApi.getExpressList({ systemOnly: 'true' }),
|
||||
indexApi.getExpressList(),
|
||||
indexApi.getPlatformList({ systemOnly: 'true' })
|
||||
])
|
||||
const expressData: any = expressRes?.data
|
||||
|
||||
709
src/views/system/setting/storeExpressBindingPolicy/index.vue
Normal file
709
src/views/system/setting/storeExpressBindingPolicy/index.vue
Normal file
@ -0,0 +1,709 @@
|
||||
<template>
|
||||
<div class="store-express-binding-policy-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-button size="small" type="primary" :loading="loading" @click="loadList">刷新</el-button>
|
||||
<el-button type="success" size="small" @click="openCreate">新增策略</el-button>
|
||||
</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"
|
||||
:loading="loading"
|
||||
:query-time="queryTime"
|
||||
row-key="id"
|
||||
@page-change="handlePageChange"
|
||||
@page-size-change="handlePageSizeChange"
|
||||
@refresh="loadList"
|
||||
>
|
||||
<template #column-is_enabled="{ row }">
|
||||
<el-tag :type="formatPolicyStatus(row.is_enabled).type" size="small">
|
||||
{{ formatPolicyStatus(row.is_enabled).text }}
|
||||
</el-tag>
|
||||
</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 }">
|
||||
<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">暂无策略数据,可调整左侧筛选条件</div>
|
||||
</template>
|
||||
</upper-table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<el-dialog
|
||||
v-model="dialogVisible"
|
||||
:title="dialogMode === 'create' ? '新增策略' : '编辑策略'"
|
||||
width="640px"
|
||||
align-center
|
||||
@close="resetForm"
|
||||
>
|
||||
<el-form ref="formRef" :model="formData" :rules="rules" label-width="100px">
|
||||
<el-form-item label="策略名称" prop="custom_name">
|
||||
<el-input v-model="formData.custom_name" placeholder="请输入策略名称" maxlength="100" show-word-limit />
|
||||
</el-form-item>
|
||||
<el-form-item label="快递编码" 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>
|
||||
<el-form-item label="包含店铺名称" 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>
|
||||
<el-form-item label="限定货主ID" prop="store_ids">
|
||||
<el-select
|
||||
v-model="formData.storeIdsList"
|
||||
placeholder="请选择货主"
|
||||
multiple
|
||||
filterable
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in storeOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="违禁品类型" prop="prohibited_type_id">
|
||||
<el-select
|
||||
v-model="formData.prohibited_type_id"
|
||||
placeholder="请选择违禁品类型"
|
||||
multiple
|
||||
filterable
|
||||
clearable
|
||||
style="width: 100%"
|
||||
>
|
||||
<el-option
|
||||
v-for="item in prohibitedOptions"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value"
|
||||
/>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="重量段类型" 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>
|
||||
<el-row :gutter="10">
|
||||
<el-col :span="12">
|
||||
<el-form-item label="最小重量(g)" prop="min_weight_g">
|
||||
<el-input-number
|
||||
v-model="formData.min_weight_g"
|
||||
:min="0"
|
||||
placeholder="不限制"
|
||||
:controls="false"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="最大重量(g)" prop="max_weight_g">
|
||||
<el-input-number
|
||||
v-model="formData.max_weight_g"
|
||||
:min="0"
|
||||
placeholder="不限制"
|
||||
:controls="false"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-form-item label="限定地区" 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>
|
||||
<el-form-item label="排除地区" 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>
|
||||
<el-form-item prop="priority">
|
||||
<template #label>
|
||||
<span>优先级 <el-tooltip content="优先级越大越优先匹配,命中后将不再匹配其他策略" placement="top"><el-icon style="vertical-align: middle; cursor: help;"><QuestionFilled /></el-icon></el-tooltip></span>
|
||||
</template>
|
||||
<el-input-number
|
||||
v-model="formData.priority"
|
||||
:min="0"
|
||||
:max="9999"
|
||||
placeholder="请输入优先级"
|
||||
style="width: 100%"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" 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>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input
|
||||
v-model="formData.remark"
|
||||
type="textarea"
|
||||
:rows="3"
|
||||
placeholder="请输入备注(选填)"
|
||||
maxlength="200"
|
||||
show-word-limit
|
||||
/>
|
||||
</el-form-item>
|
||||
</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 {
|
||||
storeExpressBindingPolicyAdd,
|
||||
storeExpressBindingPolicyDel,
|
||||
storeExpressBindingPolicyEdit,
|
||||
storeExpressBindingPolicyList
|
||||
} from '@/api/setting.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 {
|
||||
buildPolicyListPayload,
|
||||
formatPolicyStatus,
|
||||
normalizeStoreExpressBindingPolicyScanConditionToWhere,
|
||||
storeExpressBindingPolicyColumns,
|
||||
storeExpressBindingPolicyScanFields,
|
||||
WEIGHT_TYPE_MAP,
|
||||
type StoreExpressBindingPolicyRecord
|
||||
} from './storeExpressBindingPolicy-config'
|
||||
|
||||
const settingsStore = useSettingsStore()
|
||||
const scanBox = ref<any>(null)
|
||||
const upperTable = ref<any>(null)
|
||||
|
||||
const presetTree = ref<any[]>([])
|
||||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(storeExpressBindingPolicyScanFields)))
|
||||
|
||||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||||
const containerHeight = computed(() =>
|
||||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||||
)
|
||||
|
||||
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 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
|
||||
p.regions = formData.regionsList.length ? formData.regionsList : undefined
|
||||
p.exclude_regions = formData.excludeRegionsList.length ? formData.excludeRegionsList : undefined
|
||||
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()
|
||||
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' })
|
||||
.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): 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">
|
||||
.store-express-binding-policy-container {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
padding: 12px;
|
||||
box-sizing: border-box;
|
||||
|
||||
.main-content {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
|
||||
&-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
}
|
||||
|
||||
.upper-wrapper {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@ -0,0 +1,212 @@
|
||||
export type StoreExpressBindingPolicyRecord = {
|
||||
id?: number
|
||||
warehouse_id?: number
|
||||
custom_name?: string
|
||||
store_ids?: string | null
|
||||
express_code?: string
|
||||
express_name?: string
|
||||
prohibited_type_id?: number[] | null
|
||||
prohibited_type_names?: string[] | null
|
||||
weight_type?: number
|
||||
shop_name?: string[] | null
|
||||
store_ids?: string[] | null
|
||||
store_names?: string[] | null
|
||||
regions?: string[] | null
|
||||
exclude_regions?: string[] | null
|
||||
min_weight_g?: number | null
|
||||
max_weight_g?: number | null
|
||||
priority?: number
|
||||
is_enabled?: number
|
||||
remark?: string | null
|
||||
creator_id?: number | null
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
|
||||
export const WEIGHT_TYPE_MAP: Record<number, string> = {
|
||||
0: '常规',
|
||||
1: '轻货',
|
||||
2: '重货',
|
||||
3: '冷链'
|
||||
}
|
||||
|
||||
export const storeExpressBindingPolicyColumns = [
|
||||
{ prop: 'id', label: 'ID', width: '80', sortable: true },
|
||||
{ prop: 'custom_name', label: '策略名称', minWidth: '160', showOverflowTooltip: true },
|
||||
{ prop: 'express_name', label: '快递名称', minWidth: '120', showOverflowTooltip: true },
|
||||
{ prop: 'store_ids', label: '限定货主', minWidth: '160', showOverflowTooltip: true },
|
||||
{ prop: 'shop_name', label: '包含店铺名称', minWidth: '160', showOverflowTooltip: true },
|
||||
{ prop: 'prohibited_type_id', label: '违禁品类型', minWidth: '140', showOverflowTooltip: true },
|
||||
{ prop: 'weight_type', label: '重量段类型', width: '110' },
|
||||
{ prop: 'regions', label: '限定地区', minWidth: '140', showOverflowTooltip: true },
|
||||
{ prop: 'exclude_regions', label: '排除地区', minWidth: '140', showOverflowTooltip: true },
|
||||
{ prop: 'min_weight_g', label: '最小重量(g)', width: '120' },
|
||||
{ prop: 'max_weight_g', label: '最大重量(g)', width: '120' },
|
||||
{ prop: 'priority', label: '优先级', width: '90' },
|
||||
{ prop: 'is_enabled', label: '状态', width: '100' },
|
||||
{ prop: 'remark', label: '备注', minWidth: '160', showOverflowTooltip: true },
|
||||
{ prop: 'created_at', label: '创建时间', minWidth: '160' },
|
||||
{ prop: 'updated_at', label: '更新时间', minWidth: '160' },
|
||||
{ prop: 'actions', label: '操作', width: '180', fixed: 'right' }
|
||||
]
|
||||
|
||||
export const storeExpressBindingPolicyScanFields = [
|
||||
{
|
||||
value: 'quickWhere',
|
||||
label: '关键词',
|
||||
type: 'text',
|
||||
placeholder: '策略名称/快递编码',
|
||||
operators: ['contains', 'eq'],
|
||||
defaultOperator: 'eq'
|
||||
},
|
||||
{
|
||||
value: 'custom_name',
|
||||
label: '策略名称',
|
||||
type: 'text',
|
||||
placeholder: '请输入策略名称',
|
||||
operators: ['eq', 'contains', 'like'],
|
||||
defaultOperator: 'contains'
|
||||
},
|
||||
{
|
||||
value: 'express_code',
|
||||
label: '快递编码',
|
||||
type: 'text',
|
||||
placeholder: '请输入快递编码',
|
||||
operators: ['eq', 'contains', 'like'],
|
||||
defaultOperator: 'eq'
|
||||
},
|
||||
{
|
||||
value: 'prohibited_type_id',
|
||||
label: '违禁品类型',
|
||||
type: 'select',
|
||||
filterable: true,
|
||||
clearable: true,
|
||||
options: [] as { label: string; value: number }[]
|
||||
},
|
||||
{
|
||||
value: 'weight_type',
|
||||
label: '重量段类型',
|
||||
type: 'select',
|
||||
clearable: true,
|
||||
options: [
|
||||
{ label: '常规', value: 0 },
|
||||
{ label: '轻货', value: 1 },
|
||||
{ label: '重货', value: 2 },
|
||||
{ label: '冷链', value: 3 }
|
||||
]
|
||||
},
|
||||
{
|
||||
value: 'is_enabled',
|
||||
label: '状态',
|
||||
type: 'select',
|
||||
clearable: true,
|
||||
options: [
|
||||
{ label: '启用', value: '1' },
|
||||
{ label: '禁用', value: '0' }
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
function getFieldConfig(key: string, fields: typeof storeExpressBindingPolicyScanFields) {
|
||||
return fields.find((f) => f.value === key)
|
||||
}
|
||||
|
||||
function mapFieldType(type: string, value: unknown) {
|
||||
if (type === 'daterange' || Array.isArray(value)) return 'daterange'
|
||||
if (type === 'number' || typeof value === 'number') return 'number'
|
||||
return 'text'
|
||||
}
|
||||
|
||||
function processConditionValue(key: string, raw: any, fields: typeof storeExpressBindingPolicyScanFields) {
|
||||
if (key === 'quickWhere') {
|
||||
const val = raw?.value !== undefined ? raw.value : raw
|
||||
const text = val == null ? '' : String(val).trim()
|
||||
return text ? text : null
|
||||
}
|
||||
|
||||
const config = getFieldConfig(key, fields)
|
||||
const fieldType = config?.type || 'text'
|
||||
|
||||
if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
|
||||
const op = raw.operator || (fieldType === 'select' ? 'eq' : fieldType === 'number' ? 'eq' : 'contains')
|
||||
const type = raw.type || mapFieldType(fieldType, raw.value)
|
||||
|
||||
if (['isnull', 'isnotnull'].includes(op)) {
|
||||
return { operator: op, value: null, type }
|
||||
}
|
||||
|
||||
const val = raw.value !== undefined ? raw.value : raw
|
||||
if (val === null || val === undefined || val === '' || (Array.isArray(val) && val.length === 0)) {
|
||||
return null
|
||||
}
|
||||
|
||||
if (fieldType === 'select') {
|
||||
return { operator: op || 'eq', value: val, type: 'text' }
|
||||
}
|
||||
|
||||
return { operator: op, value: val, type }
|
||||
}
|
||||
|
||||
if (raw === null || raw === undefined || raw === '' || (Array.isArray(raw) && raw.length === 0)) {
|
||||
return null
|
||||
}
|
||||
|
||||
const simpleOp = fieldType === 'select' || fieldType === 'number' ? 'eq' : 'contains'
|
||||
return { operator: simpleOp, value: raw, type: mapFieldType(fieldType, raw) }
|
||||
}
|
||||
|
||||
/** 将 ScanBox 条件转为 list 接口 where */
|
||||
export function normalizeStoreExpressBindingPolicyScanConditionToWhere(
|
||||
condition: any,
|
||||
fields: typeof storeExpressBindingPolicyScanFields = storeExpressBindingPolicyScanFields
|
||||
): Record<string, unknown> {
|
||||
if (!condition) return {}
|
||||
|
||||
const conds =
|
||||
condition?.conditions && typeof condition.conditions === 'object'
|
||||
? condition.conditions
|
||||
: condition && typeof condition === 'object'
|
||||
? condition
|
||||
: null
|
||||
|
||||
if (!conds) return {}
|
||||
|
||||
const where: Record<string, unknown> = {}
|
||||
for (const key of Object.keys(conds)) {
|
||||
const result = processConditionValue(key, conds[key], fields)
|
||||
if (result == null) continue
|
||||
if (key === 'quickWhere' && typeof result === 'string') {
|
||||
where.quickWhere = result
|
||||
} else {
|
||||
where[key] = result
|
||||
}
|
||||
}
|
||||
return where
|
||||
}
|
||||
|
||||
export function formatPolicyStatus(isEnabled: number | string | undefined | null) {
|
||||
if (isEnabled === null || isEnabled === undefined) return { text: '--', type: 'info' as const }
|
||||
const val = Number(isEnabled)
|
||||
if (val === 1) return { text: '启用', type: 'success' as const }
|
||||
if (val === 0) return { text: '禁用', type: 'info' as const }
|
||||
return { text: String(isEnabled), type: 'info' as const }
|
||||
}
|
||||
|
||||
export function buildPolicyListPayload(options: {
|
||||
page: number
|
||||
pageSize: number
|
||||
where?: Record<string, unknown>
|
||||
}) {
|
||||
const payload: Record<string, unknown> = {
|
||||
page: options.page,
|
||||
pageSize: options.pageSize,
|
||||
pagination: {
|
||||
page: options.page,
|
||||
pageSize: options.pageSize
|
||||
}
|
||||
}
|
||||
if (options.where && Object.keys(options.where).length) {
|
||||
payload.where = options.where
|
||||
}
|
||||
return payload
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user