672 lines
17 KiB
Vue
672 lines
17 KiB
Vue
<template>
|
||
<div class="encoding-sub-container">
|
||
<!-- <scan-box
|
||
ref="scanBox"
|
||
cache-key="encoding:platformCode"
|
||
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"
|
||
/> -->
|
||
|
||
<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="encoding-platform"
|
||
@action="handleToolbarButtonClick"
|
||
/>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="upper-wrapper">
|
||
<upper-table
|
||
ref="upperTable"
|
||
title="平台编码列表"
|
||
default-align="center"
|
||
table-id="encoding-platform-code"
|
||
:data="tableData"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="pagination"
|
||
:show-index="true"
|
||
:show-selection="false"
|
||
:loading="loading"
|
||
:query-time="queryTime"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@refresh="loadList"
|
||
>
|
||
<template #column-actions="{ row }">
|
||
<div class="encoding-operation-actions">
|
||
<el-button link type="primary" size="small" @click="openEdit(row)">编辑</el-button>
|
||
<el-button link type="danger" size="small" @click="handleDelete(row)">删除</el-button>
|
||
</div>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无平台编码数据</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 新增 / 编辑平台编码:面板结构 / 尺寸对齐「手工录入运单号」(ManualWaybillForm) -->
|
||
<el-dialog
|
||
v-model="dialogVisible"
|
||
class="platform-code-dialog"
|
||
width="min(560px, 92vw)"
|
||
align-center
|
||
append-to-body
|
||
:show-close="false"
|
||
@close="resetForm"
|
||
>
|
||
<div class="task-panel">
|
||
<header class="task-panel__head">
|
||
<div class="task-panel__titles">
|
||
<h2>{{ dialogMode === 'create' ? '新增平台编码' : '编辑平台编码' }}</h2>
|
||
<p>{{ dialogMode === 'create' ? '填写业务编码并选择对应平台' : '修改后立即生效' }}</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">
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label is-required">业务编码</span>
|
||
<div class="task-panel__field-control">
|
||
<el-form-item prop="code">
|
||
<el-input v-model="formData.code" size="default" placeholder="如 DY" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label is-required">业务名称</span>
|
||
<div class="task-panel__field-control">
|
||
<el-form-item prop="name">
|
||
<el-input v-model="formData.name" size="default" placeholder="如 抖音(仓管家映射)" />
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="task-panel__field task-panel__field--input">
|
||
<span class="task-panel__field-label is-required">平台</span>
|
||
<div class="task-panel__field-control">
|
||
<el-form-item prop="platform_code">
|
||
<el-select
|
||
v-model="formData.platform_code"
|
||
size="default"
|
||
placeholder="请选择平台"
|
||
filterable
|
||
style="width: 100%"
|
||
@change="handlePlatformChange"
|
||
>
|
||
<el-option
|
||
v-for="item in platformOptions"
|
||
:key="item.code"
|
||
:label="item.label || item.name"
|
||
:value="item.code"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</div>
|
||
</div>
|
||
</el-form>
|
||
|
||
<!-- 提示条:对齐「手工录入运单号」的 .task-panel__form-tip -->
|
||
<p class="task-panel__form-tip">
|
||
{{ dialogMode === 'create'
|
||
? '业务编码用于对接平台接口,建议使用平台简称缩写(如 DY);提交后该编码将用于平台订单同步。'
|
||
: '修改平台后会同步更新该编码的对应关系,保存后立即生效。' }}
|
||
</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 { onMounted, reactive, ref } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import type { FormInstance, FormRules } from 'element-plus'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
import { getPlatformList } from '@/api/index/index'
|
||
import {
|
||
settingPlatformCreate,
|
||
settingPlatformDelete,
|
||
settingPlatformList,
|
||
settingPlatformUpdate
|
||
} from '@/api/setting.platform/platform'
|
||
import {
|
||
buildWhereConditions,
|
||
platformAvailableFields,
|
||
platformColumns
|
||
} from '../encoding-config'
|
||
|
||
type PlatformOption = {
|
||
code: string
|
||
name: string
|
||
label?: string
|
||
}
|
||
|
||
type PlatformRecord = {
|
||
id?: number
|
||
code: string
|
||
name: string
|
||
platform_code: string
|
||
platform_name?: string
|
||
label?: string
|
||
}
|
||
|
||
const scanBox = ref<any>(null)
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(platformAvailableFields)))
|
||
const columns = platformColumns
|
||
|
||
const loading = ref(false)
|
||
const saving = ref(false)
|
||
|
||
// ---- toolbar 按钮配置(分类排序,对齐 waveOrder) ----
|
||
const toolbarButtons: ToolbarButtonConfig[] = [
|
||
{ key: 'refresh', label: '刷新', category: 'refresh', size: 'small', action: 'loadData' },
|
||
{ key: 'create', label: '新增平台编码', category: 'action', size: 'small', action: 'openCreate' }
|
||
]
|
||
|
||
function resolveButtonDisabled(_key?: string): boolean {
|
||
return false
|
||
}
|
||
|
||
function resolveButtonLoading(key?: string): boolean {
|
||
if (key === 'loading') return loading.value
|
||
return false
|
||
}
|
||
|
||
function resolveButtonLabel(defaultLabel: string, _dynamicLabelKey?: string): string {
|
||
return defaultLabel
|
||
}
|
||
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
loadData: loadList,
|
||
openCreate
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: string) {
|
||
toolbarActionMap[action]?.()
|
||
}
|
||
const tableData = ref<PlatformRecord[]>([])
|
||
const platformOptions = ref<PlatformOption[]>([])
|
||
const queryTime = ref(0)
|
||
const tableSize = ref('small')
|
||
|
||
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<PlatformRecord>({
|
||
id: undefined,
|
||
code: '',
|
||
name: '',
|
||
platform_code: ''
|
||
})
|
||
|
||
const rules: FormRules = {
|
||
code: [{ required: true, message: '请输入业务编码', trigger: 'blur' }],
|
||
name: [{ required: true, message: '请输入业务名称', trigger: 'blur' }],
|
||
platform_code: [{ required: true, message: '请选择平台', trigger: 'change' }]
|
||
}
|
||
|
||
const isSuccess = (res: any) => res && [0, 1, 200].includes(res.code)
|
||
|
||
function buildListPayload() {
|
||
const raw = scanBox.value?.getConditions?.() || {}
|
||
const where = buildWhereConditions(raw)
|
||
const keyword = String(where.keyword?.value ?? raw.keyword ?? '').trim()
|
||
delete where.keyword
|
||
|
||
const payload: Record<string, any> = {
|
||
pagination: {
|
||
page: pagination.currentPage,
|
||
pageSize: pagination.pageSize
|
||
}
|
||
}
|
||
if (keyword) {
|
||
payload.keyword = keyword
|
||
}
|
||
if (Object.keys(where).length) {
|
||
payload.where = where
|
||
}
|
||
return payload
|
||
}
|
||
|
||
function syncPresetTree(list: PlatformRecord[]) {
|
||
presetTree.value = list.map((item) => ({
|
||
label: item.name || item.code,
|
||
id: item.id,
|
||
code: item.code,
|
||
children: []
|
||
}))
|
||
}
|
||
|
||
function fillPlatformScanOptions(raw: any[]) {
|
||
const field = availableFieldsRef.find((f: any) => f.value === 'platform_code')
|
||
if (!field) return
|
||
field.options = (raw || []).map((item: any) => ({
|
||
label: item.label || item.platform_name || item.name,
|
||
value: item.platform_code || item.code
|
||
}))
|
||
}
|
||
|
||
async function loadList() {
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
const res: any = await settingPlatformList(buildListPayload())
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '获取平台编码失败')
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
presetTree.value = []
|
||
return
|
||
}
|
||
const data = res?.data || {}
|
||
tableData.value = data.list || []
|
||
pagination.total = Number(data.pagination?.total ?? data.total ?? 0)
|
||
syncPresetTree(tableData.value)
|
||
} catch {
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
presetTree.value = []
|
||
ElMessage.error('获取平台编码失败')
|
||
} finally {
|
||
queryTime.value = Date.now() - start
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
async function loadPlatformOptions() {
|
||
try {
|
||
const res: any = await getPlatformList()
|
||
if (!isSuccess(res)) {
|
||
platformOptions.value = []
|
||
return
|
||
}
|
||
const raw = res?.data || []
|
||
platformOptions.value = raw.map((item: any) => ({
|
||
code: item.platform_code || item.code,
|
||
name: item.platform_name || item.name,
|
||
label: item.label || item.platform_name || item.name
|
||
}))
|
||
fillPlatformScanOptions(raw)
|
||
} catch {
|
||
platformOptions.value = []
|
||
}
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
loadList()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleConditionChange() {
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleConditionClear() {
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
pagination.currentPage = 1
|
||
scanBox.value?.reset?.()
|
||
loadList()
|
||
}
|
||
|
||
function handlePlatformChange(code: string) {
|
||
const target = platformOptions.value.find((item) => item.code === code)
|
||
if (!target) return
|
||
if (!formData.name) {
|
||
formData.name = target.name || target.label || ''
|
||
}
|
||
}
|
||
|
||
function resetForm() {
|
||
formData.id = undefined
|
||
formData.code = ''
|
||
formData.name = ''
|
||
formData.platform_code = ''
|
||
formRef.value?.clearValidate()
|
||
}
|
||
|
||
function openCreate() {
|
||
dialogMode.value = 'create'
|
||
dialogVisible.value = true
|
||
resetForm()
|
||
}
|
||
|
||
function openEdit(row: PlatformRecord) {
|
||
dialogMode.value = 'edit'
|
||
dialogVisible.value = true
|
||
formData.id = row.id
|
||
formData.code = row.code
|
||
formData.name = row.name
|
||
formData.platform_code = row.platform_code
|
||
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 = {
|
||
id: formData.id as number,
|
||
code: formData.code,
|
||
name: formData.name,
|
||
platform_code: formData.platform_code
|
||
}
|
||
const res: any = dialogMode.value === 'create'
|
||
? await settingPlatformCreate({
|
||
code: payload.code,
|
||
name: payload.name,
|
||
platform_code: payload.platform_code
|
||
})
|
||
: await settingPlatformUpdate(payload)
|
||
if (!isSuccess(res)) {
|
||
ElMessage.error(res?.message || '保存失败')
|
||
return
|
||
}
|
||
ElMessage.success(dialogMode.value === 'create' ? '新增成功' : '更新成功')
|
||
dialogVisible.value = false
|
||
loadList()
|
||
} catch {
|
||
ElMessage.error('保存失败')
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
|
||
function handleDelete(row: PlatformRecord) {
|
||
if (!row.id) return
|
||
ElMessageBox.confirm(`确认删除平台编码「${row.code}」吗?`, '提示', { type: 'warning', buttonSize: 'small' })
|
||
.then(async () => {
|
||
const res: any = await settingPlatformDelete({ 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)
|
||
}
|
||
|
||
onMounted(async () => {
|
||
await loadPlatformOptions()
|
||
await loadList()
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
@use '../styles/encoding-sub.scss';
|
||
|
||
.encoding-operation-actions {
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
gap: 0 2px;
|
||
justify-content: center;
|
||
|
||
:deep(.el-button) {
|
||
font-size: 11px;
|
||
padding: 0 4px;
|
||
height: 20px;
|
||
margin-left: 0;
|
||
margin-right: 0;
|
||
}
|
||
|
||
:deep(.el-button + .el-button) {
|
||
margin-left: 0;
|
||
}
|
||
|
||
:deep(.el-button.is-link) {
|
||
padding: 0 4px;
|
||
height: 20px;
|
||
}
|
||
}
|
||
|
||
/* 新增 / 编辑平台编码:面板结构 / 尺寸对齐「批量修改平台信息」(UpdateOrderMetaForm) */
|
||
.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;
|
||
}
|
||
|
||
&__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;
|
||
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;
|
||
}
|
||
}
|
||
|
||
&__field-control {
|
||
flex: 1;
|
||
min-width: 0;
|
||
}
|
||
|
||
&__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;
|
||
}
|
||
}
|
||
}
|
||
|
||
/* 面板内嵌 el-form-item:去掉默认间距,错误提示改回文档流内展示 */
|
||
.task-panel__form {
|
||
:deep(.el-form-item) {
|
||
margin-bottom: 0;
|
||
}
|
||
|
||
:deep(.el-form-item__content) {
|
||
margin-left: 0;
|
||
line-height: 1.4;
|
||
}
|
||
|
||
:deep(.el-form-item__error) {
|
||
position: static;
|
||
padding-top: 4px;
|
||
}
|
||
}
|
||
</style>
|
||
|
||
<style lang="scss">
|
||
/* el-dialog 会被 append 到 body:去掉默认头/内边距,统一交给面板 */
|
||
.el-dialog.platform-code-dialog {
|
||
padding: 0;
|
||
overflow: hidden;
|
||
|
||
.el-dialog__header {
|
||
display: none;
|
||
}
|
||
|
||
.el-dialog__body {
|
||
padding: 0;
|
||
}
|
||
}
|
||
</style>
|