WEB/src/views/warehouses/index.vue
2026-07-08 18:11:22 +08:00

652 lines
23 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="warehouses-container">
<div class="main-content">
<div class="toolbar">
<div class="toolbar-left">
<el-button size="small" type="primary" @click="openSignDialog('apply')">
<el-icon><Plus /></el-icon> 发起签约
</el-button>
<el-button size="small" type="warning" @click="openSignDialog('preview')">
<el-icon><Search /></el-icon> 预览签约
</el-button>
<el-button size="small" @click="loadList">
<el-icon><Refresh /></el-icon> 刷新
</el-button>
</div>
<div class="toolbar-right">
<el-input
v-model="queryForm.keyword"
placeholder="搜索仓库名或备注"
clearable
size="small"
style="width: 200px"
@keyup.enter="handleSearch"
>
<template #prefix>
<el-icon><Search /></el-icon>
</template>
</el-input>
</div>
</div>
<div class="upper-wrapper">
<upper-table
ref="tableRef"
default-align="center"
:data="list"
:columns="columns"
:loading="loading"
:pagination="pagination"
@current-change="handleRowClick"
@page-change="handlePageChange"
@page-size-change="handleSizeChange"
>
<template #column-counterparty_name="{ row }">
<span>{{ row.warehouse_name || row.remask || row.counterparty_name }}</span>
<span
v-if="(row.warehouse_name || row.remask) && row.counterparty_name && (row.warehouse_name || 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-store_use_status="{ row }">
<el-tag size="small" :type="row.store_use_status === 1 ? 'success' : 'info'" effect="light">
{{ row.store_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 }">
<el-button
size="small"
type="primary"
link
@click.stop="handleRename(row)"
>修改备注</el-button>
<el-button
v-if="row.needs_my_confirm"
size="small"
type="warning"
link
@click.stop="handleConfirmSign(row)"
>确认签约</el-button>
<el-button
v-if="row.store_use_status === 1 && row.auth_status !== 1"
size="small"
type="danger"
link
@click.stop="handleUnbind(row, 0)"
>禁用</el-button>
<el-button
v-else-if="row.store_use_status === 0 && row.auth_status !== 1"
size="small"
type="success"
link
@click.stop="handleUnbind(row, 1)"
>启用</el-button>
<span v-else class="text-muted">—</span>
</template>
</upper-table>
</div>
<div class="lower-level" v-if="selectedRow">
<div class="detail-header">
<el-tabs v-model="activeTab" class="detail-tab">
<el-tab-pane label="签约详情" name="details" />
<el-tab-pane label="操作日志" name="logs" />
</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.warehouse_name || 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="warning" effect="plain" style="margin-left:6px">货主方</el-tag>
</el-descriptions-item>
<el-descriptions-item label="仓库ID">{{ selectedRow.warehouse_id }}</el-descriptions-item>
<el-descriptions-item label="使用状态">
<el-tag size="small" :type="selectedRow.store_use_status === 1 ? 'success' : 'info'" effect="light">
{{ selectedRow.store_use_status === 1 ? '启用' : '禁用' }}
</el-tag>
</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>
<div v-else class="log-placeholder">
<el-empty description="操作日志开发中" :image-size="40" />
</div>
</div>
</div>
<div class="lower-level empty" v-else>
<el-empty description="请选择数据查看详情" :image-size="60" />
</div>
</div>
<!-- 发起签约弹窗 -->
<el-dialog
v-model="signDialog.visible"
:title="signDialog.title"
width="480px"
align-center
:close-on-click-modal="false"
@close="resetSignDialog"
>
<template v-if="signDialog.step === 1">
<!-- 发起签约:填对方主体ID -->
<el-form v-if="signDialog.signAction === 'apply'" :model="signForm" label-width="100px" size="small">
<el-form-item label="对方主体ID" required>
<el-input-number v-model.number="signForm.counterparty_id" placeholder="请输入对方主体ID" style="width: 100%" :controls="false" />
</el-form-item>
<el-form-item label="通用名备注">
<el-input v-model="signForm.remask" placeholder="给对方主体的通用名称(可选)" />
</el-form-item>
</el-form>
<!-- 预览签约:填仓库ID -->
<el-form v-else :model="signForm" label-width="100px" size="small">
<el-form-item label="仓库ID" required>
<el-input-number v-model.number="signForm.warehouse_id" placeholder="请输入仓库ID" style="width: 100%" :controls="false" />
</el-form-item>
</el-form>
</template>
<!-- 预览结果 / 提交结果 -->
<template v-else-if="signDialog.step === 2">
<div class="sign-preview">
<!-- 预览模式:展示双方主体信息 -->
<template v-if="signDialog.signMode === 'preview'">
<el-descriptions :column="1" border size="small">
<el-descriptions-item label="己方(货主)">
{{ signDialog.currentSubject?.company_name || '—' }}
<el-tag size="small" type="warning" effect="plain" style="margin-left:6px">货主方</el-tag>
</el-descriptions-item>
<el-descriptions-item label="对方(仓库)">
{{ signDialog.counterparty?.company_name || '—' }}
<el-tag size="small" type="primary" effect="plain" style="margin-left:6px">仓库方</el-tag>
</el-descriptions-item>
</el-descriptions>
<div class="sign-tip">
<el-alert type="info" :closable="false" show-icon>
<template #default>请确认签约信息,确认无误后点击「确认提交」。</template>
</el-alert>
</div>
</template>
<!-- 提交后:展示合同信息 -->
<template v-else>
<el-descriptions :column="2" border size="small">
<el-descriptions-item label="签约ID">{{ signDialog.contract?.id || '—' }}</el-descriptions-item>
<el-descriptions-item label="签约状态">
<el-tag size="small" :type="getAuthStatusType(signDialog.contract?.auth_status)">
{{ signDialog.contract?.auth_status_label || '—' }}
</el-tag>
</el-descriptions-item>
<el-descriptions-item label="仓库">{{ signDialog.contract?.warehouse_name || signDialog.contract?.counterparty_name || '—' }}</el-descriptions-item>
<el-descriptions-item label="货主">{{ signDialog.contract?.store_name || '—' }}</el-descriptions-item>
<el-descriptions-item label="备注">{{ signDialog.contract?.remask || '—' }}</el-descriptions-item>
<el-descriptions-item label="面单余额">{{ signDialog.contract?.print_quantity ?? '—' }}</el-descriptions-item>
</el-descriptions>
<div class="sign-tip">
<el-alert
v-if="signDialog.signMode === 'initiate'"
type="info" :closable="false" show-icon
>
<template #default>已提交申请,等待对方确认。</template>
</el-alert>
<el-alert
v-else-if="signDialog.signMode === 'already_exists'"
type="warning" :closable="false" show-icon
>
<template #default>对方已发起签约申请,等待处理。</template>
</el-alert>
<el-alert
v-else-if="signDialog.signMode === 'already_confirmed'"
type="success" :closable="false" show-icon
>
<template #default>该签约已完成,无需重复提交。</template>
</el-alert>
</div>
</template>
</div>
</template>
<template #footer>
<div class="dialog-footer">
<!-- Step 1: 填写信息 -->
<template v-if="signDialog.step === 1">
<el-button size="small" @click="signDialog.visible = false">取消</el-button>
<el-button size="small" type="primary" :loading="signDialog.loading" @click="doPreviewSign">
预览
</el-button>
</template>
<!-- Step 2: 预览结果 -->
<template v-else-if="signDialog.step === 2">
<el-button size="small" @click="goBackToStep1">返回</el-button>
<el-button
v-if="signDialog.signMode === 'preview' && signDialog.signAction === 'apply'"
size="small"
type="primary"
:loading="signDialog.loading"
@click="doSubmitSign"
>确认提交</el-button>
<el-button v-else size="small" @click="signDialog.visible = false">关闭</el-button>
</template>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Search, Plus, Refresh } from '@element-plus/icons-vue'
import {
storeWarehouseList,
storeWarehouseSign,
storeWarehouseConfirmSign,
storeWarehouseUnbind,
storeWarehouseRename
} from '@/api/storeWarehouse.store/storeWarehouse'
import UpperTable from '@/components/UpperTable/index.vue'
// ─── 列表列配置 ─────────────────────────────────────────────────────────────
const columns = [
{ prop: 'counterparty_name', label: '签约仓库', minWidth: 140 },
{ prop: 'auth_status', label: '签约状态', width: 100 },
{ prop: 'needs_my_confirm', label: '待确认', width: 90 },
{ prop: 'store_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: 280, fixed: 'right' }
]
// ─── 当前主体信息(从列表接口返回) ────────────────────────────────────────
const currentSubject = ref<{ store_id?: number; company_name?: string; role?: string }>({})
// ─── 列表状态 ──────────────────────────────────────────────────────────────
const loading = ref(false)
const list = ref<any[]>([])
const selectedRow = ref<any>(null)
const tableRef = ref<any>(null)
const activeTab = ref('details')
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
const queryForm = reactive({ keyword: '' })
// ─── 加载列表 ──────────────────────────────────────────────────────────────
async function loadList() {
loading.value = true
try {
const params: any = {
page: pagination.currentPage,
page_size: pagination.pageSize
}
if (queryForm.keyword) params.keyword = queryForm.keyword
const res = await storeWarehouseList(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 (e) {
ElMessage.error('获取列表失败')
} finally {
loading.value = false
}
}
function isExpired(dateStr: string): boolean {
if (!dateStr) return false
const d = new Date(dateStr)
if (isNaN(d.getTime())) return false
return d < new Date()
}
function handleSearch() {
pagination.currentPage = 1
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 getAuthStatusType(status: number): string {
const map: Record<number, string> = { 1: 'warning', 2: 'success', 3: 'danger', 4: 'info', 5: 'danger' }
return map[status] || 'info'
}
function getAuthStatusLabel(status: number): string {
const map: Record<number, string> = { 1: '待审核', 2: '已通过', 3: '已拒绝', 4: '已解除', 5: '已过期' }
return map[status] || '未知'
}
// ─── 启用/禁用 ─────────────────────────────────────────────────────────────
async function handleUnbind(row: any, targetStatus: number) {
const action = targetStatus === 1 ? '启用' : '禁用'
try {
await ElMessageBox.confirm(`确认${action}该签约关系?`, '提示', { type: 'warning' })
} catch {
return
}
try {
await storeWarehouseUnbind({ id: row.id, store_use_status: targetStatus })
ElMessage.success(`${action}成功`)
loadList()
} catch (e) {
ElMessage.error(`${action}失败`)
}
}
// ─── 修改备注 ──────────────────────────────────────────────────────────────
async function handleRename(row: any) {
try {
const { value } = await ElMessageBox.prompt('请输入新的备注名', '修改备注', {
confirmButtonText: '确定',
cancelButtonText: '取消',
inputValue: row.remask || ''
})
if (value != null) {
await storeWarehouseRename({ id: row.id, remask: value })
ElMessage.success('备注修改成功')
loadList()
}
} catch {
// 用户取消
}
}
// ─── 发起签约 ──────────────────────────────────────────────────────────────
const signDialog = reactive({
visible: false,
title: '发起签约',
step: 1,
loading: false,
signAction: 'apply' as string,
signMode: '' as string,
contract: null as any,
currentSubject: null as any,
counterparty: null as any
})
const signForm = reactive({
counterparty_id: undefined as number | undefined,
warehouse_id: undefined as number | undefined,
remask: ''
})
function openSignDialog(action: 'apply' | 'preview' = 'apply') {
signDialog.visible = true
signDialog.step = 1
signDialog.signAction = action
signDialog.title = action === 'preview' ? '预览签约' : '发起签约'
signDialog.signMode = ''
signDialog.contract = null
signDialog.currentSubject = null
signDialog.counterparty = null
signForm.counterparty_id = undefined
signForm.warehouse_id = undefined
signForm.remask = ''
}
function resetSignDialog() {
signForm.counterparty_id = undefined
signForm.warehouse_id = undefined
signForm.remask = ''
signDialog.step = 1
signDialog.loading = false
}
async function doPreviewSign() {
const isPreviewOnly = signDialog.signAction === 'preview'
if (isPreviewOnly && !signForm.warehouse_id) {
ElMessage.warning('请输入仓库ID')
return
}
if (!isPreviewOnly && !signForm.counterparty_id) {
ElMessage.warning('请输入对方主体ID')
return
}
signDialog.loading = true
try {
// 第一步:拉取预览
const params: any = isPreviewOnly
? { action: 'preview', warehouse_id: signForm.warehouse_id }
: { action: 'preview', warehouse_id: signForm.counterparty_id }
const res = await storeWarehouseSign(params) as any
if (res?.data) {
const d = res.data
signDialog.signMode = d.mode || ''
signDialog.contract = d.contract || null
signDialog.currentSubject = d.current_subject || null
signDialog.counterparty = d.counterparty || null
signDialog.step = 2
signDialog.title = '签约预览'
}
} catch (e) {
ElMessage.error('获取预览失败')
} finally {
signDialog.loading = false
}
}
async function doSubmitSign() {
if (!signForm.counterparty_id) {
ElMessage.warning('缺少对方主体ID')
return
}
signDialog.loading = true
try {
await storeWarehouseSign({
counterparty_id: signForm.counterparty_id,
remask: signForm.remask
})
ElMessage.success('签约申请已提交')
signDialog.visible = false
loadList()
} catch (e) {
ElMessage.error('提交签约失败')
} finally {
signDialog.loading = false
}
}
function goBackToStep1() {
signDialog.step = 1
signDialog.signMode = ''
signDialog.contract = null
signDialog.currentSubject = null
signDialog.counterparty = null
}
async function handleConfirmSign(row: any) {
try {
await ElMessageBox.confirm(
`确认与「${row.warehouse_name || row.remask || row.counterparty_name}」的签约关系?`,
'确认签约',
{ type: 'warning' }
)
} catch {
return
}
try {
await storeWarehouseConfirmSign({ id: row.id })
ElMessage.success('签约已确认')
loadList()
} catch (e) {
ElMessage.error('确认签约失败')
}
}
// ─── 初始化 ────────────────────────────────────────────────────────────────
onMounted(() => {
loadList()
})
</script>
<style scoped lang="scss">
.warehouses-container {
display: flex;
height: 100%;
.main-content {
flex: 1;
display: flex;
flex-direction: column;
min-width: 0;
padding: 12px;
overflow: hidden;
}
.toolbar {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px;
flex-shrink: 0;
gap: 12px;
&-left {
display: flex;
align-items: center;
gap: 6px;
}
&-right {
display: flex;
align-items: center;
}
}
.upper-wrapper {
flex: 1;
min-height: 0;
overflow: hidden;
}
.lower-level {
margin-top: 8px;
border: 1px solid #ebeef5;
border-radius: 4px;
flex-shrink: 0;
display: flex;
flex-direction: column;
&.empty {
border: none;
}
.detail-header {
padding: 0 12px;
border-bottom: 1px solid #ebeef5;
flex-shrink: 0;
}
.detail-container {
padding: 12px;
overflow: auto;
max-height: 260px;
}
.log-placeholder {
padding: 20px 0;
}
}
.text-danger {
color: #f56c6c;
font-weight: 500;
}
.real-name {
font-size: 12px;
color: #c0c4cc;
}
.sign-preview {
.sign-tip {
margin-top: 16px;
}
}
.policy-form-scroll {
max-height: 400px;
overflow-y: auto;
}
.policy-json-editor {
.policy-json-label {
margin-bottom: 6px;
font-size: 13px;
font-weight: 500;
}
.policy-json-error {
color: #f56c6c;
font-size: 12px;
margin-top: 4px;
}
.policy-json-tip {
color: #c0c4cc;
font-size: 12px;
margin-top: 6px;
}
}
:deep(.el-descriptions__label) {
width: 110px;
}
}
</style>