liufumingren 12b26d5eb0 1
2026-09-02 09:00:09 +08:00

557 lines
19 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="order-sub-container" :style="{ height: containerHeight }">
<scan-box
ref="scanBox"
cache-key="shipper-signing"
width="220px"
title="货主筛选"
:auto-submit="false"
:preset-tree="presetTree"
:available-fields="availableFields"
:initial-conditions="{ use_status: 1 }"
@condition-change="handleConditionChange"
@reset="handleReset"
@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"
/>
<el-tag v-if="currentSubject.company_name" size="small" type="primary" effect="plain" style="margin-left:8px">
当前仓库:{{ currentSubject.company_name }}
</el-tag>
</div>
</div>
<div class="split-stack" ref="splitStackRef">
<div class="upper-wrapper" :style="detailVisible ? upperPaneStyle : upperPaneFullStyle">
<upper-table
ref="tableRef"
title="货主签约列表"
default-align="center"
:enable-column-config="true"
table-id="shipper-signing-list"
:data="list"
:columns="columns"
:table-size="tableSize"
:loading="loading"
:pagination="pagination"
:show-index="true"
:show-selection="true"
:show-actions="true"
:query-time="queryTime"
row-key="id"
@current-change="handleRowClick"
@row-click="handleRowClick"
@page-change="handlePageChange"
@page-size-change="handleSizeChange"
@sort-change="handleSortChange"
@selection-change="handleSelectionChange"
>
<template #column-counterparty_name="{ row }">
<span>{{ row.remask || row.counterparty_name }}</span>
<span v-if="row.remask && row.remask !== row.counterparty_name" class="real-name">({{ row.counterparty_name }})</span>
</template>
<template #column-auth_status="{ row }">
<el-tag size="small" :type="getAuthStatusType(row.auth_status)" effect="light">
{{ row.auth_status_label || getAuthStatusLabel(row.auth_status) }}
</el-tag>
</template>
<template #column-needs_my_confirm="{ row }">
<el-tag v-if="row.needs_my_confirm" size="small" type="warning" effect="dark">待我确认</el-tag>
<span v-else class="text-muted">—</span>
</template>
<template #column-use_status="{ row }">
<el-tag size="small" :type="row.use_status === 1 ? 'success' : 'info'" effect="light">
{{ row.use_status === 1 ? '启用' : '禁用' }}
</el-tag>
</template>
<template #column-auth_end="{ row }">
<span :class="{ 'text-danger': isExpired(row.auth_end) }">{{ row.auth_end || '—' }}</span>
</template>
<template #column-print_quantity="{ row }">
{{ row.print_quantity ?? '—' }}
</template>
<template #column-has_qimen_config="{ row }">
<el-tag size="small" :type="row.has_qimen_config ? 'success' : 'info'" effect="plain">
{{ row.has_qimen_config ? '已配置' : '未配置' }}
</el-tag>
</template>
<template #column-actions="{ row }">
<div class="wave-operation-actions">
<el-button
v-if="row.needs_my_confirm"
size="small"
type="warning"
link
@click.stop="handleConfirmSign(row)"
>确认签约</el-button>
<el-button
size="small"
type="primary"
link
@click.stop="handleRename(row)"
>修改备注</el-button>
<el-button
v-if="row.use_status === 1"
size="small"
type="danger"
link
@click.stop="handleUnbind(row, 0)"
>禁用</el-button>
<el-button
v-else
size="small"
type="success"
link
@click.stop="handleUnbind(row, 1)"
>启用</el-button>
</div>
</template>
<template #empty>
<div class="empty-tip">暂无签约货主数据</div>
</template>
</upper-table>
</div>
<template v-if="detailVisible">
<div
class="pane-resizer"
title="拖动调整列表与详情区域高度"
@mousedown="beginSplitDrag"
/>
<div class="lower-level" v-if="selectedRow" :style="lowerPaneStyle">
<div class="detail-header">
<el-tabs v-model="activeTab" class="detail-tab">
<el-tab-pane label="签约详情" name="details" />
</el-tabs>
</div>
<div class="detail-container">
<el-descriptions v-if="activeTab === 'details'" :column="2" border size="small">
<el-descriptions-item label="签约ID">{{ selectedRow.id }}</el-descriptions-item>
<el-descriptions-item label="签约状态">
<el-tag size="small" :type="getAuthStatusType(selectedRow.auth_status)" effect="light">
{{ selectedRow.auth_status_label || getAuthStatusLabel(selectedRow.auth_status) }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item label="签约货主">
{{ selectedRow.remask || selectedRow.counterparty_name || '—' }}
</el-descriptions-item>
<el-descriptions-item v-if="currentSubject.company_name" label="当前仓库">
{{ currentSubject.company_name }}
<el-tag size="small" type="primary" effect="plain" style="margin-left:6px">仓库方</el-tag>
</el-descriptions-item>
<el-descriptions-item label="货主ID">{{ selectedRow.store_id ?? '—' }}</el-descriptions-item>
<el-descriptions-item label="仓库ID">{{ selectedRow.warehouse_id ?? '—' }}</el-descriptions-item>
<el-descriptions-item label="使用状态">
<el-tag size="small" :type="selectedRow.use_status === 1 ? 'success' : 'info'" effect="light">
{{ selectedRow.use_status === 1 ? '启用' : '禁用' }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item label="待我确认">
<el-tag v-if="selectedRow.needs_my_confirm" size="small" type="warning" effect="dark">是</el-tag>
<span v-else>否</span>
</el-descriptions-item>
<el-descriptions-item label="授权截止">
<span :class="{ 'text-danger': isExpired(selectedRow.auth_end) }">{{ selectedRow.auth_end || '—' }}</span>
</el-descriptions-item>
<el-descriptions-item label="面单余额">{{ selectedRow.print_quantity ?? '—' }}</el-descriptions-item>
<el-descriptions-item label="奇门配置">
<el-tag size="small" :type="selectedRow.has_qimen_config ? 'success' : 'info'" effect="plain">
{{ selectedRow.has_qimen_config ? '已配置' : '未配置' }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item v-if="selectedRow.counterparty_name && selectedRow.remask" label="货主全称" :span="2">
{{ selectedRow.counterparty_name }}
</el-descriptions-item>
</el-descriptions>
</div>
</div>
<div class="no-selection" v-else :style="lowerPaneStyle">
<div class="empty-tip">
<p>请从上方列表中选择一项查看详情</p>
</div>
</div>
</template>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, computed } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { storeWarehouseWarehouseList } from '@/api/storeWarehouse.warehouse/storeWarehouse'
import { storeWarehouseUnbind, storeWarehouseRename, storeWarehouseConfirmSign } from '@/api/storeWarehouse.store/storeWarehouse'
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 { useSettingsStore } from '@/stores/modules/settings'
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
import { safeInvoke } from '@/utils/safe-invoke'
const settingsStore = useSettingsStore()
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
const containerHeight = computed(() => shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)')
const {
splitStackRef,
beginSplitDrag,
lowerPaneStyle,
upperPaneStyle,
} = useVerticalSplitPane({ defaultLowerPercent: 35 })
const upperPaneFullStyle = computed(() => ({
flex: '1 1 auto',
minHeight: '0',
overflow: 'hidden',
}))
const detailVisible = ref(true)
const toolbarButtons: ToolbarButtonConfig[] = [
{ key: 'refresh', label: '刷新', category: 'refresh', size: 'small', loadingKey: 'loading', action: 'loadList' },
{
key: 'toggleDetail',
label: '显示详情',
dynamicLabelKey: 'detailToggleLabel',
category: 'setting',
size: 'small',
action: 'toggleDetailVisible'
},
]
// ─── 工具栏状态管理 ──────────────────────────────────────────────────────────
const buttonLoadingMap = computed(() => ({
loading: loading.value
}))
const buttonDisabledMap = computed(() => ({}))
const buttonLabelMap = computed(() => ({
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
}))
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
}
function toggleDetailVisible() {
detailVisible.value = !detailVisible.value
}
const toolbarActionMap: Record<string, () => void> = {
loadList: () => { void loadList() },
toggleDetailVisible: () => toggleDetailVisible()
}
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
const handler = toolbarActionMap[action]
if (!handler) return
safeInvoke(() => handler())
}
const columns = [
{ prop: 'counterparty_name', label: '签约货主', minWidth: 140 },
{ prop: 'auth_status', label: '签约状态', width: 100 },
{ prop: 'needs_my_confirm', label: '待确认', width: 90 },
{ prop: 'use_status', label: '使用状态', width: 90 },
{ prop: 'print_quantity', label: '面单余额', width: 100 },
{ prop: 'has_qimen_config', label: '奇门配置', width: 100 },
{ prop: 'auth_end', label: '授权截止', width: 120 },
{ prop: 'actions', label: '操作', width: 200, fixed: 'right' }
]
const availableFields = [
{
label: '关键词',
value: 'keyword',
type: 'text',
group: '基础信息',
placeholder: '搜索货主名或备注'
},
{
label: '签约状态',
value: 'auth_status',
type: 'select',
options: [
{ label: '待审核', value: 1 },
{ label: '已通过', value: 2 },
{ label: '已拒绝', value: 3 },
{ label: '已解除', value: 4 }
]
},
{
label: '使用状态',
value: 'use_status',
type: 'select',
options: [
{ label: '全部', value: undefined },
{ label: '启用', value: 1 },
{ label: '禁用', value: 0 }
]
}
]
const presetTree: any[] = []
const currentSubject = ref<{ store_id?: number; company_name?: string; role?: string }>({})
const loading = ref(false)
const queryTime = ref(0)
const tableSize = ref<'small' | 'default' | 'large'>('small')
const list = ref<any[]>([])
const selectionRows = ref<any[]>([])
const selectedRow = ref<any>(null)
const tableRef = ref<any>(null)
const scanBox = ref<any>(null)
const activeTab = ref('details')
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
const currentCondition = ref<any>({ use_status: 1 })
async function loadList() {
loading.value = true
const startTime = Date.now()
try {
const params: any = {
page: pagination.currentPage,
page_size: pagination.pageSize,
...currentCondition.value
}
const res = await storeWarehouseWarehouseList(params) as any
if (res?.data) {
const payload = res.data
list.value = payload.list || []
pagination.total = payload.pagination?.total || payload.total || 0
pagination.currentPage = payload.pagination?.page || payload.page || pagination.currentPage
pagination.pageSize = payload.pagination?.pageSize || payload.page_size || pagination.pageSize
if (payload.current_subject) {
currentSubject.value = payload.current_subject
}
}
} catch {
ElMessage.error('获取货主签约列表失败')
} finally {
queryTime.value = Date.now() - startTime
loading.value = false
}
}
function isExpired(dateStr: string | null): boolean {
if (!dateStr) return false
const d = new Date(dateStr)
if (isNaN(d.getTime())) return false
return d < new Date()
}
function handleConditionChange(condition: any) {
const where: any = {}
if (condition) {
Object.keys(condition).forEach(k => {
const c = condition[k]
if (c && typeof c === 'object' && !Array.isArray(c) && c.value !== undefined) {
if (c.value !== '' && c.value !== null && c.value !== undefined) {
where[k] = c.value
}
} else if (c !== '' && c !== null && c !== undefined) {
where[k] = c
}
})
}
currentCondition.value = where
pagination.currentPage = 1
loadList()
}
function handleSubmit() {
pagination.currentPage = 1
loadList()
}
function handleConditionClear() {
currentCondition.value = {}
pagination.currentPage = 1
loadList()
}
function handleReset() {
currentCondition.value = {}
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 handleSizeChange(size: number) {
pagination.pageSize = size
pagination.currentPage = 1
loadList()
}
function handleRowClick(row: any) {
selectedRow.value = row
}
function handleSortChange(_sort: { prop: string; order: string }) {
// 预留排序事件处理
}
function handleSelectionChange(rows: any[]) {
selectionRows.value = rows || []
}
function getAuthStatusType(status: number): string {
const map: Record<number, string> = { 1: 'warning', 2: 'success', 3: 'danger', 4: 'info' }
return map[status] || 'info'
}
function getAuthStatusLabel(status: number): string {
const map: Record<number, string> = { 1: '待审核', 2: '已通过', 3: '已拒绝', 4: '已解除' }
return map[status] || '未知'
}
// ─── 操作 ────────────────────────────────────────────────────────────────────
async function handleConfirmSign(row: any) {
try {
await ElMessageBox.confirm(
`确认与「${row.store_name || row.remask || row.counterparty_name}」的签约关系?`,
'确认签约',
{ type: 'warning' }
)
} catch { return }
try {
const res = await storeWarehouseConfirmSign({ id: row.id })
if (res?.flag === 'success' || res?.code === 200 || res?.data?.mode === 'confirm') {
ElMessage.success('签约已确认')
loadList()
} else {
ElMessage.error(res?.message || '确认签约失败')
}
} catch { ElMessage.error('确认签约失败') }
}
async function handleRename(row: any) {
try {
const { value } = await ElMessageBox.prompt('请输入新的备注名称', '修改备注', {
confirmButtonText: '确定',
cancelButtonText: '取消',
inputValue: row.remask || row.counterparty_name,
})
const res = await storeWarehouseRename({ id: row.id, remask: value }) as any
if (res?.flag === 'success' || res?.code === 200) {
ElMessage.success('修改备注成功')
loadList()
} else {
ElMessage.error(res?.message || '修改备注失败')
}
} catch { /* cancelled */ }
}
async function handleUnbind(row: any, targetStatus: number) {
const actionLabel = targetStatus === 0 ? '禁用' : '启用'
try {
await ElMessageBox.confirm(
`确认要${actionLabel}与「${row.store_name || row.remask || row.counterparty_name}」的签约关系吗?`,
`${actionLabel}签约`,
{ type: targetStatus === 0 ? 'warning' : 'info', confirmButtonText: actionLabel, cancelButtonText: '取消' }
)
} catch { return }
try {
const res = await storeWarehouseUnbind({ id: row.id, warehouse_use_status: targetStatus }) as any
if (res?.flag === 'success' || res?.code === 200) {
ElMessage.success(`${actionLabel}成功`)
loadList()
} else {
ElMessage.error(res?.message || `${actionLabel}失败`)
}
} catch { ElMessage.error('操作失败') }
}
onMounted(() => {
loadList()
})
</script>
<style scoped lang="scss">
@use "../../order/orderManagement/styles/order-sub.scss";
.order-sub-container .main-content .lower-level .detail-container {
padding: 6px 10px;
display: flex;
flex-direction: column;
box-sizing: border-box;
overflow: auto;
flex: 1;
min-height: 0;
}
.empty-tip {
text-align: center;
font-size: 13px;
color: #909399;
padding: 16px;
}
.real-name {
color: #999;
font-size: 12px;
}
.wave-operation-actions {
display: flex;
align-items: center;
justify-content: center;
gap: 4px;
flex-wrap: wrap;
}
.text-muted {
color: #c0c4cc;
}
.text-danger {
color: #f56c6c;
}
</style>