1681 lines
62 KiB
Vue
1681 lines
62 KiB
Vue
<template>
|
||
<div class="store-container">
|
||
<scan-box
|
||
ref="scanBox"
|
||
width="320px"
|
||
title="货主筛选"
|
||
:preset-tree="presetTree"
|
||
:available-fields="availableFields"
|
||
:initial-conditions="{ use_status: 1 }"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleReset"
|
||
/>
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<el-button size="small" type="primary" @click="openSignDialog">
|
||
<el-icon><Plus /></el-icon> 发起签约
|
||
</el-button>
|
||
<el-button size="small" @click="loadList">
|
||
<el-icon><Refresh /></el-icon> 刷新
|
||
</el-button>
|
||
<el-button size="small" :type="balanceVisible ? 'warning' : 'default'" @click="toggleBalance">
|
||
{{ balanceVisible ? '隐藏余额' : '显示余额' }}
|
||
</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"
|
||
:data="list"
|
||
:columns="columns"
|
||
:loading="loading"
|
||
:pagination="pagination"
|
||
show-selection
|
||
@current-change="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handleSizeChange"
|
||
>
|
||
<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-current_subject_role="{ row }">
|
||
<el-tag size="small" :type="row.current_subject_role === 'warehouse' ? 'primary' : 'warning'" effect="light">
|
||
{{ row.current_subject_role === 'warehouse' ? '仓库方' : '货主方' }}
|
||
</el-tag>
|
||
</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-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-is_auth_valid="{ row }">
|
||
<el-tag size="small" :type="row.is_auth_valid ? 'success' : 'warning'" effect="plain">
|
||
{{ row.is_auth_valid ? '有效' : '无效' }}
|
||
</el-tag>
|
||
</template>
|
||
<template #column-print_quantity="{ row }">
|
||
<span v-if="balanceVisible">{{ row.print_quantity ?? 0 }}</span>
|
||
<span v-else>***</span>
|
||
</template>
|
||
<template #column-remaining_days="{ row }">
|
||
<span :class="row.remaining_days <= 7 && row.remaining_days > 0 ? 'text-warning' : ''">
|
||
{{ row.remaining_days > 0 ? row.remaining_days + '天' : '—' }}
|
||
</span>
|
||
</template>
|
||
<template #column-has_qimen_config="{ row }">
|
||
<el-tag
|
||
size="small"
|
||
:type="row.has_qimen_config ? 'success' : 'info'"
|
||
effect="plain"
|
||
@click.stop="openQimenDialog(row)"
|
||
style="cursor:pointer"
|
||
>
|
||
{{ row.has_qimen_config ? '已配置' : '未配置' }}
|
||
</el-tag>
|
||
</template>
|
||
<template #column-apply_time="{ row }">
|
||
{{ formatDate(row.apply_time) }}
|
||
</template>
|
||
<template #column-actions="{ row }">
|
||
<el-button
|
||
size="small"
|
||
type="primary"
|
||
link
|
||
@click.stop="handleRename(row)"
|
||
>修改备注</el-button>
|
||
<el-button
|
||
size="small"
|
||
type="warning"
|
||
link
|
||
@click.stop="openAdjustBalanceDialog(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>
|
||
<el-button
|
||
size="small"
|
||
type="info"
|
||
link
|
||
@click.stop="openPolicyDialog(row)"
|
||
>策略配置</el-button>
|
||
<el-button
|
||
v-if="row.current_subject_role === 'warehouse'"
|
||
size="small"
|
||
type="warning"
|
||
link
|
||
@click.stop="openQimenDialog(row)"
|
||
>奇门配置</el-button>
|
||
</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">
|
||
<KeepAlive>
|
||
<component
|
||
:is="activeComponent"
|
||
:id="selectedRow?.id"
|
||
:row="selectedRow"
|
||
:getAuthStatusType="getAuthStatusType"
|
||
:getAuthStatusLabel="getAuthStatusLabel"
|
||
:formatDate="formatDate"
|
||
@view-detail="handleViewDetail"
|
||
/>
|
||
</KeepAlive>
|
||
</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"
|
||
>
|
||
<!-- Step 1: 发起 -->
|
||
<template v-if="signDialog.step === 1">
|
||
<el-form :model="signForm" label-width="100px" size="small">
|
||
<el-form-item v-for="item in signFormItems" :key="item.prop" :label="item.label" :required="item.required">
|
||
<el-input-number v-if="item.type === 'number'" v-model.number="signForm[item.prop]" :placeholder="item.placeholder" style="width: 100%" :controls="false" />
|
||
<el-input v-else v-model="signForm[item.prop]" :placeholder="item.placeholder" />
|
||
</el-form-item>
|
||
</el-form>
|
||
</template>
|
||
|
||
<!-- Step 2: 预览/确认 -->
|
||
<template v-else-if="signDialog.step === 2">
|
||
<div class="sign-preview">
|
||
<el-descriptions :column="1" border size="small">
|
||
<el-descriptions-item label="临时码">
|
||
<el-tag type="info" size="small">{{ signDialog.tempCode }}</el-tag>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item v-if="signDialog.contract" label="签约ID">
|
||
{{ signDialog.contract.id }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item v-if="signDialog.contract" label="货主">
|
||
{{ signDialog.contract.store_name }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item v-if="signDialog.contract" label="仓库">
|
||
{{ signDialog.contract.warehouse_name }}
|
||
</el-descriptions-item>
|
||
<el-descriptions-item v-if="signDialog.contract" label="签约状态">
|
||
<el-tag size="small" :type="getAuthStatusType(signDialog.contract.auth_status)">
|
||
{{ signDialog.contract.auth_status_label }}
|
||
</el-tag>
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
<div v-if="signDialog.mode === 'initiate'" class="sign-tip">
|
||
<el-alert type="info" :closable="false" show-icon>
|
||
<template #default>已生成临时码,点击「预览」可查看签约详情,点击「确认签约」立即生效。</template>
|
||
</el-alert>
|
||
</div>
|
||
<div v-else-if="signDialog.mode === 'confirm'" class="sign-tip">
|
||
<el-alert type="success" :closable="false" show-icon>
|
||
<template #default>签约已确认生效!</template>
|
||
</el-alert>
|
||
</div>
|
||
</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="doInitiateSign">
|
||
发起签约
|
||
</el-button>
|
||
</template>
|
||
<!-- Step 2 底部 -->
|
||
<template v-else-if="signDialog.step === 2">
|
||
<el-button size="small" @click="signDialog.visible = false">关闭</el-button>
|
||
<el-button
|
||
v-if="signDialog.mode === 'initiate'"
|
||
size="small"
|
||
:loading="signDialog.loading"
|
||
@click="doPreviewSign"
|
||
>预览</el-button>
|
||
<el-button
|
||
v-if="signDialog.mode !== 'confirm'"
|
||
size="small"
|
||
type="primary"
|
||
:loading="signDialog.loading"
|
||
@click="doConfirmSign"
|
||
>确认签约</el-button>
|
||
<el-button
|
||
v-if="signDialog.mode === 'confirm'"
|
||
size="small"
|
||
type="primary"
|
||
@click="handleSignSuccess"
|
||
>完成</el-button>
|
||
</template>
|
||
</div>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 详情弹窗 -->
|
||
<el-dialog
|
||
v-model="detailDialog.visible"
|
||
title="签约详情"
|
||
width="560px"
|
||
align-center
|
||
>
|
||
<el-descriptions v-if="detailDialog.row" :column="2" border size="small">
|
||
<template v-for="(field, idx) in detailPanel" :key="field.prop || idx">
|
||
<el-descriptions-item :label="field.label" :span="field.span || 1">
|
||
<template v-if="field.prop === 'current_subject_role'">
|
||
<el-tag size="small" :type="detailDialog.row.current_subject_role === 'warehouse' ? 'primary' : 'warning'" effect="light">
|
||
{{ detailDialog.row.current_subject_role === 'warehouse' ? '仓库方' : '货主方' }}
|
||
</el-tag>
|
||
</template>
|
||
<template v-else-if="field.prop === 'auth_status'">
|
||
<el-tag size="small" :type="getAuthStatusType(detailDialog.row.auth_status)" effect="light">
|
||
{{ detailDialog.row.auth_status_label || getAuthStatusLabel(detailDialog.row.auth_status) }}
|
||
</el-tag>
|
||
</template>
|
||
<template v-else-if="field.prop === 'use_status'">
|
||
<el-tag size="small" :type="detailDialog.row.use_status === 1 ? 'success' : 'info'" effect="light">
|
||
{{ detailDialog.row.use_status === 1 ? '启用' : '禁用' }}
|
||
</el-tag>
|
||
</template>
|
||
<template v-else-if="field.prop === 'is_auth_valid'">
|
||
<el-tag size="small" :type="detailDialog.row.is_auth_valid ? 'success' : 'warning'" effect="plain">
|
||
{{ detailDialog.row.is_auth_valid ? '有效' : '无效' }}
|
||
</el-tag>
|
||
</template>
|
||
<template v-else-if="field.prop === 'remaining_days'">
|
||
{{ detailDialog.row.remaining_days > 0 ? detailDialog.row.remaining_days + '天' : '—' }}
|
||
</template>
|
||
<template v-else-if="field.prop === 'auth_start' || field.prop === 'auth_end' || field.prop === 'apply_time' || field.prop === 'review_time'">
|
||
{{ formatDate(detailDialog.row[field.prop]) || '—' }}
|
||
</template>
|
||
<template v-else-if="field.prop === 'apply_reason' || field.prop === 'review_comment'">
|
||
{{ detailDialog.row[field.prop] || '—' }}
|
||
</template>
|
||
<template v-else-if="field.prop === 'qimen_config'">
|
||
<template v-if="detailDialog.row.qimen_config && Array.isArray(detailDialog.row.qimen_config) && detailDialog.row.qimen_config.length">
|
||
<div v-for="(cfg, idx2) in detailDialog.row.qimen_config" :key="cfg.id || idx2" style="margin-bottom:8px">
|
||
<div class="qimen-summary">
|
||
<strong>{{ cfg.app_name }}</strong>
|
||
<el-tag size="small" :type="cfg.is_enabled ? 'success' : 'info'" style="margin-left:6px">
|
||
{{ cfg.is_enabled ? '启用' : '停用' }}
|
||
</el-tag>
|
||
<span style="margin-left:8px;color:#999">{{ cfg.interface_name || cfg.interface_category || cfg.interface_code }}</span>
|
||
</div>
|
||
<div class="qimen-info">
|
||
<span>AppKey:{{ cfg.qimen_app_key }}</span>
|
||
<span style="margin-left:12px">客户ID:{{ cfg.qimen_customer_id }}</span>
|
||
<span style="margin-left:12px">仓库编码:{{ cfg.qimen_warehouse_code }}</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
<template v-else-if="detailDialog.row.qimen_config && typeof detailDialog.row.qimen_config === 'object'">
|
||
<div class="qimen-summary">
|
||
<strong>{{ detailDialog.row.qimen_config.app_name }}</strong>
|
||
<el-tag size="small" :type="detailDialog.row.qimen_config.is_enabled ? 'success' : 'info'" style="margin-left:6px">
|
||
{{ detailDialog.row.qimen_config.is_enabled ? '启用' : '停用' }}
|
||
</el-tag>
|
||
</div>
|
||
<div class="qimen-info">
|
||
<span>AppKey:{{ detailDialog.row.qimen_config.qimen_app_key }}</span>
|
||
<span style="margin-left:12px">客户ID:{{ detailDialog.row.qimen_config.qimen_customer_id }}</span>
|
||
<span style="margin-left:12px">仓库编码:{{ detailDialog.row.qimen_config.qimen_warehouse_code }}</span>
|
||
</div>
|
||
</template>
|
||
<span v-else style="color:#aaa">未配置</span>
|
||
</template>
|
||
<template v-else>
|
||
{{ detailDialog.row[field.prop] || '—' }}
|
||
</template>
|
||
</el-descriptions-item>
|
||
</template>
|
||
</el-descriptions>
|
||
<template #footer>
|
||
<el-button size="small" @click="detailDialog.visible = false">关闭</el-button>
|
||
<el-button
|
||
size="small"
|
||
type="info"
|
||
@click="() => { detailDialog.visible = false; openPolicyDialog(detailDialog.row) }"
|
||
>策略配置</el-button>
|
||
<el-button
|
||
v-if="detailDialog.row?.current_subject_role === 'warehouse'"
|
||
size="small"
|
||
type="primary"
|
||
@click="() => { detailDialog.visible = false; openQimenDialog(detailDialog.row) }"
|
||
>管理奇门配置</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 签约策略配置弹窗 -->
|
||
<el-dialog
|
||
v-model="policyDialog.visible"
|
||
:title="`策略配置 — ${policyDialog.contractRow?.remask || policyDialog.contractRow?.counterparty_name || ''}`"
|
||
width="560px"
|
||
align-center
|
||
:close-on-click-modal="false"
|
||
@close="resetPolicyDialog"
|
||
>
|
||
<div v-loading="policyDialog.loading">
|
||
<!-- 签约基本信息 -->
|
||
<el-descriptions :column="2" size="small" border style="margin-bottom:16px">
|
||
<el-descriptions-item label="签约ID">{{ policyDialog.contractRow?.id }}</el-descriptions-item>
|
||
<el-descriptions-item label="当前角色">
|
||
<el-tag size="small" :type="policyDialog.contractRow?.current_subject_role === 'warehouse' ? 'primary' : 'warning'" effect="light">
|
||
{{ policyDialog.contractRow?.current_subject_role === 'warehouse' ? '仓库方' : '货主方' }}
|
||
</el-tag>
|
||
</el-descriptions-item>
|
||
<el-descriptions-item label="货主">{{ policyDialog.contractRow?.store_name }}</el-descriptions-item>
|
||
<el-descriptions-item label="仓库">{{ policyDialog.contractRow?.warehouse_name }}</el-descriptions-item>
|
||
<el-descriptions-item label="面单余额">
|
||
<span :style="{ color: (policyDialog.contractRow?.print_quantity ?? 0) <= 0 ? '#f56c6c' : '' }">
|
||
{{ policyDialog.contractRow?.print_quantity ?? '—' }}
|
||
</span>
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
|
||
<!-- 结构化策略配置表单 -->
|
||
<template v-if="policyDialog.fields.length > 0">
|
||
<div class="policy-form-scroll">
|
||
<el-form :model="policyDialog.formData" label-width="140px" size="small" style="margin-top:4px">
|
||
<el-row :gutter="16">
|
||
<el-col v-for="field in policyDialog.fields" :key="field.key" :span="24">
|
||
<el-form-item>
|
||
<template #label>
|
||
<span>{{ field.name }}</span>
|
||
<el-tooltip v-if="field.description" :content="field.description" placement="top">
|
||
<el-icon style="margin-left:4px;cursor:pointer;color:#999;vertical-align:middle"><QuestionFilled /></el-icon>
|
||
</el-tooltip>
|
||
</template>
|
||
<!-- 默认快递:使用快递接口列表 -->
|
||
<el-select
|
||
v-if="field.key === 'default_express_code'"
|
||
v-model="policyDialog.formData[field.key]"
|
||
clearable
|
||
filterable
|
||
placeholder="请选择默认快递"
|
||
style="width:220px"
|
||
>
|
||
<el-option
|
||
v-for="opt in policyExpressOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value"
|
||
/>
|
||
</el-select>
|
||
<!-- 默认平台:使用平台列表 -->
|
||
<el-select
|
||
v-else-if="field.key === 'default_platform_code'"
|
||
v-model="policyDialog.formData[field.key]"
|
||
clearable
|
||
filterable
|
||
placeholder="请选择默认平台"
|
||
style="width:220px"
|
||
>
|
||
<el-option
|
||
v-for="opt in policyPlatformOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value"
|
||
/>
|
||
</el-select>
|
||
<!-- enum 类型 -->
|
||
<el-select v-else-if="field.type === 'enum'" v-model="policyDialog.formData[field.key]" clearable style="width:220px">
|
||
<template v-if="field.key === 'receive_mode'">
|
||
<el-option label="标准模式" value="standard" />
|
||
<el-option label="严格模式" value="strict" />
|
||
<el-option label="手动模式" value="manual" />
|
||
</template>
|
||
<template v-else-if="field.key === 'sku_visibility'">
|
||
<el-option label="全部可见" value="all" />
|
||
<el-option label="白名单" value="whitelist" />
|
||
<el-option label="黑名单" value="blacklist" />
|
||
</template>
|
||
<el-option
|
||
v-for="opt in field.options"
|
||
v-else
|
||
:key="getEnumOptionValue(opt)"
|
||
:label="getEnumOptionLabel(opt)"
|
||
:value="getEnumOptionValue(opt)"
|
||
/>
|
||
</el-select>
|
||
<!-- flag 类型 -->
|
||
<el-switch
|
||
v-else-if="field.type === 'flag'"
|
||
v-model="policyDialog.formData[field.key]"
|
||
:active-value="1"
|
||
:inactive-value="0"
|
||
active-text="是"
|
||
inactive-text="否"
|
||
/>
|
||
<!-- integer 类型 (支持可选小数精度) -->
|
||
<el-input-number
|
||
v-else-if="field.type === 'integer'"
|
||
v-model="policyDialog.formData[field.key]"
|
||
:min="field.min ?? 0"
|
||
:max="field.max ?? 1000000"
|
||
:precision="field.precision ?? 0"
|
||
:step="field.step ?? (field.precision ? 0.01 : 1)"
|
||
style="width:200px"
|
||
/>
|
||
<!-- string / 其他类型 -->
|
||
<el-input
|
||
v-else
|
||
v-model="policyDialog.formData[field.key]"
|
||
:maxlength="field.maxLength"
|
||
show-word-limit
|
||
type="input"
|
||
:rows="2"
|
||
:placeholder="field.description || ''"
|
||
style="width:100%"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form>
|
||
</div>
|
||
</template>
|
||
|
||
<!-- 降级:字段元信息加载失败时显示 JSON 编辑器 -->
|
||
<template v-else>
|
||
<div class="policy-json-editor">
|
||
<div class="policy-json-label">
|
||
策略配置(JSON)
|
||
<el-tooltip content="后端 policy_config 为自由结构 object,直接编辑 JSON 提交" placement="top">
|
||
<el-icon style="margin-left:4px;cursor:pointer;color:#999"><QuestionFilled /></el-icon>
|
||
</el-tooltip>
|
||
</div>
|
||
<el-input
|
||
v-model="policyDialog.jsonText"
|
||
type="textarea"
|
||
:rows="10"
|
||
placeholder='暂无策略配置,输入 JSON 对象后保存,例如:{"key": "value"}'
|
||
:class="{ 'is-error-textarea': policyDialog.jsonError }"
|
||
@blur="validatePolicyJson"
|
||
spellcheck="false"
|
||
style="font-family: monospace; font-size: 13px"
|
||
/>
|
||
<div v-if="policyDialog.jsonError" class="policy-json-error">{{ policyDialog.jsonError }}</div>
|
||
<div class="policy-json-tip">留空则清除策略配置;必须是合法的 JSON 对象 <code>{}</code></div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
|
||
<template #footer>
|
||
<el-button size="small" @click="policyDialog.visible = false">取消</el-button>
|
||
<el-button size="small" type="primary" :loading="policyDialog.saving" @click="submitPolicyConfig">保存策略</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 奇门接口配置管理弹窗 -->
|
||
<el-dialog
|
||
v-model="qimenDialog.visible"
|
||
:title="`接口配置管理 — ${qimenDialog.contractRow?.remask || qimenDialog.contractRow?.counterparty_name || ''}`"
|
||
width="820px"
|
||
align-center
|
||
:close-on-click-modal="false"
|
||
@close="resetQimenDialog"
|
||
>
|
||
<div v-if="!qimenDialog.formVisible">
|
||
<div style="display:flex;justify-content:flex-end;margin-bottom:10px">
|
||
<el-button size="small" type="primary" @click="openQimenForm(null)">
|
||
<el-icon><Plus /></el-icon> 新增配置
|
||
</el-button>
|
||
<el-button size="small" @click="loadQimenConfigs" style="margin-left:8px">
|
||
<el-icon><Refresh /></el-icon> 刷新
|
||
</el-button>
|
||
</div>
|
||
<el-table :data="qimenDialog.list" v-loading="qimenDialog.loading" size="small" border>
|
||
<el-table-column v-for="col in qimenTableColumns" :key="col.prop" :prop="col.prop" :label="col.label" :min-width="col.minWidth" :width="col.width" />
|
||
<el-table-column label="状态" width="70" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag size="small" :type="row.is_enabled ? 'success' : 'info'">
|
||
{{ row.is_enabled ? '启用' : '停用' }}
|
||
</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作" width="100" align="center" fixed="right">
|
||
<template #default="{ row }">
|
||
<el-button size="small" type="primary" link @click="openQimenForm(row)">编辑</el-button>
|
||
<el-button size="small" type="danger" link @click="handleDeleteQimenConfig(row)">删除</el-button>
|
||
</template>
|
||
</el-table-column>
|
||
<template #empty>
|
||
<el-empty description="暂无奇门配置" :image-size="50" />
|
||
</template>
|
||
</el-table>
|
||
</div>
|
||
|
||
<!-- 保存表单 -->
|
||
<div v-else>
|
||
<el-page-header @back="qimenDialog.formVisible = false" style="margin-bottom:16px">
|
||
<template #content>{{ qimenDialog.editingConfig ? '编辑配置' : '新增配置' }}</template>
|
||
</el-page-header>
|
||
<el-form :model="qimenForm" label-width="120px" size="small" class="qimen-form">
|
||
<el-row :gutter="12">
|
||
<!-- 接口类型选择 -->
|
||
<el-col :span="12">
|
||
<el-form-item label="接口类型" required>
|
||
<!-- 编辑模式:锁定 -->
|
||
<el-select
|
||
v-if="qimenDialog.editingConfig"
|
||
:model-value="qimenForm.interface_code"
|
||
disabled
|
||
style="width:100%"
|
||
>
|
||
<el-option
|
||
v-for="t in qimenDialog.availableTypes"
|
||
:key="t.interface_code"
|
||
:label="`${t.interface_name}(${t.interface_code})`"
|
||
:value="t.interface_code"
|
||
/>
|
||
<!-- 兼容历史数据中未收录的其他类型 -->
|
||
<el-option
|
||
v-if="qimenForm.interface_code && !qimenDialog.availableTypes.some(t => t.interface_code === qimenForm.interface_code)"
|
||
:label="`${qimenDialog.editingConfig?.interface_name || qimenForm.interface_code}(${qimenForm.interface_code})`"
|
||
:value="qimenForm.interface_code"
|
||
/>
|
||
</el-select>
|
||
<!-- 新增模式:从接口选项中选择,已配置类型标灰禁用 -->
|
||
<el-select
|
||
v-else
|
||
v-model="qimenForm.interface_code"
|
||
placeholder="请选择接口类型"
|
||
style="width:100%"
|
||
@change="handleInterfaceTypeChange"
|
||
>
|
||
<el-option
|
||
v-for="t in selectableTypes"
|
||
:key="t.interface_code"
|
||
:label="`${t.interface_name}(${t.interface_code})`"
|
||
:value="t.interface_code"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<!-- 类型标识 -->
|
||
<el-col :span="12">
|
||
<el-form-item label="类型标识">
|
||
<el-tag v-if="qimenForm.interface_code" type="info" size="small">{{ qimenForm.interface_code }}</el-tag>
|
||
<span v-else style="color:#c0c4cc;font-size:12px">选择接口类型后自动显示</span>
|
||
</el-form-item>
|
||
</el-col>
|
||
<!-- 应用名称(所有类型必填)-->
|
||
<el-col :span="24">
|
||
<el-form-item label="应用名称" required>
|
||
<el-input v-model="qimenForm.app_name" placeholder="请输入应用名称(必填)" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<!-- QM_WMS 专属字段 -->
|
||
<template v-if="qimenForm.interface_code === 'QM_WMS' || (!qimenForm.interface_code && qimenDialog.editingConfig?.interface_code === 'QM_WMS')">
|
||
<el-col :span="12">
|
||
<el-form-item label="奇门 AppKey" required>
|
||
<el-input v-model="qimenForm.qimen_app_key" placeholder="请输入奇门对方 AppKey" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="客户ID" required>
|
||
<el-input v-model="qimenForm.qimen_customer_id" placeholder="奇门客户ID / 货主编码" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="仓库编码" required>
|
||
<el-input v-model="qimenForm.qimen_warehouse_code" placeholder="奇门仓库编码" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="API 版本">
|
||
<el-input v-model="qimenForm.api_version" placeholder="默认 1.0" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</template>
|
||
<!-- OPEN_API 类型提示 -->
|
||
<template v-else-if="qimenForm.interface_code === 'OPEN_API'">
|
||
<el-col :span="24">
|
||
<el-alert type="info" :closable="false" style="margin-bottom:8px">
|
||
<template #default>OPEN_API 类型无需填写奇门字段,系统将自动生成 AppKey 与 AppSecret。</template>
|
||
</el-alert>
|
||
</el-col>
|
||
</template>
|
||
<!-- 其他类型或未选类型时显示所有奇门字段(向后兼容)-->
|
||
<template v-else-if="!qimenForm.interface_code && qimenDialog.editingConfig">
|
||
<el-col :span="12">
|
||
<el-form-item label="奇门 AppKey">
|
||
<el-input v-model="qimenForm.qimen_app_key" placeholder="奇门 AppKey(如适用)" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="客户ID">
|
||
<el-input v-model="qimenForm.qimen_customer_id" placeholder="奇门客户ID(如适用)" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="仓库编码">
|
||
<el-input v-model="qimenForm.qimen_warehouse_code" placeholder="奇门仓库编码(如适用)" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="API 版本">
|
||
<el-input v-model="qimenForm.api_version" placeholder="默认 1.0" />
|
||
</el-form-item>
|
||
</el-col>
|
||
</template>
|
||
<!-- 可选联系信息 -->
|
||
<el-col :span="12">
|
||
<el-form-item label="联系人">
|
||
<el-input v-model="qimenForm.contact_person" placeholder="可选" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="联系电话">
|
||
<el-input v-model="qimenForm.contact_phone" placeholder="可选" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="邮箱">
|
||
<el-input v-model="qimenForm.email" placeholder="可选" />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="是否启用">
|
||
<el-switch
|
||
v-model="qimenForm.is_enabled"
|
||
:active-value="1"
|
||
:inactive-value="0"
|
||
active-text="启用"
|
||
inactive-text="停用"
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form>
|
||
</div>
|
||
|
||
<template #footer>
|
||
<template v-if="!qimenDialog.formVisible">
|
||
<el-button size="small" @click="qimenDialog.visible = false">关闭</el-button>
|
||
</template>
|
||
<template v-else>
|
||
<el-button size="small" @click="qimenDialog.formVisible = false">返回</el-button>
|
||
<el-button size="small" type="primary" :loading="qimenDialog.formLoading" @click="submitQimenForm">
|
||
{{ qimenDialog.editingConfig ? '保存修改' : '确认新增' }}
|
||
</el-button>
|
||
</template>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 面单余额调整弹窗 -->
|
||
<el-dialog
|
||
v-model="adjustBalanceDialog.visible"
|
||
title="面单余额设置"
|
||
width="500px"
|
||
align-center
|
||
@close="resetAdjustBalanceDialog"
|
||
>
|
||
<el-form
|
||
:model="adjustBalanceForm"
|
||
label-width="120px"
|
||
label-position="right"
|
||
>
|
||
<el-form-item
|
||
v-for="item in adjustBalanceFormItems"
|
||
:key="item.prop"
|
||
:label="item.label"
|
||
:prop="item.prop"
|
||
:rules="item.rules"
|
||
>
|
||
<el-input-number
|
||
v-if="item.type === 'number'"
|
||
v-model="adjustBalanceForm[item.prop]"
|
||
:placeholder="item.placeholder"
|
||
:style="{ width: '100%' }"
|
||
controls-position="right"
|
||
/>
|
||
<el-input
|
||
v-else-if="item.type === 'textarea'"
|
||
v-model="adjustBalanceForm[item.prop]"
|
||
:placeholder="item.placeholder"
|
||
:rows="item.rows || 3"
|
||
type="textarea"
|
||
maxlength="500"
|
||
show-word-limit
|
||
/>
|
||
<el-input
|
||
v-else
|
||
v-model="adjustBalanceForm[item.prop]"
|
||
:placeholder="item.placeholder"
|
||
/>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<template #footer>
|
||
<el-button @click="adjustBalanceDialog.visible = false">取消</el-button>
|
||
<el-button
|
||
type="primary"
|
||
:loading="adjustBalanceDialog.loading"
|
||
@click="submitAdjustBalance"
|
||
>
|
||
确认设置
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, reactive, onMounted, computed } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { Search, Plus, Refresh, QuestionFilled } from '@element-plus/icons-vue'
|
||
import { storeWarehouseList, storeWarehouseSign, storeWarehouseUnbind,
|
||
storeWarehouseRename, storeWarehouseGetPolicyConfig, storeWarehouseGetPolicyConfigFields,
|
||
storeWarehouseSavePolicyConfig, saveApiConfig, storeWarehouseDeleteQimenConfig,
|
||
storeWarehouseAdjustPrintQuantity, listApiConfig
|
||
} from '@/api/storewarehouse.store/storeWarehouse'
|
||
import { listInterfaceTypes, getExpressList, getPlatformList } from '@/api/index/index'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import Detail from './component/detail.vue'
|
||
import Log from './component/log.vue'
|
||
import { columns as defaultColumns, availableFields as defaultAvailableFields, presetTree as defaultPresetTree, signDialogDefault, signFormDefault, qimenFormDefault, signFormItems, qimenFormItems, qimenTableColumns, detailPanel, adjustBalanceDialogDefault, adjustBalanceFormDefault, adjustBalanceFormItems } from './store-config'
|
||
|
||
// ─── 列表 ───────────────────────────────────────────────────────────────────
|
||
const loading = ref(false)
|
||
const list = ref<any[]>([])
|
||
const selectedRow = ref<any>(null)
|
||
const tableRef = ref<any>(null)
|
||
const scanBox = ref<any>(null)
|
||
|
||
const activeTab = ref('details')
|
||
const componentMap: Record<string, any> = {
|
||
details: Detail,
|
||
logs: Log
|
||
}
|
||
const activeComponent = computed(() => componentMap[activeTab.value] || componentMap.details)
|
||
|
||
// 全局控制所有行的面单余额显示/隐藏
|
||
const balanceVisible = ref(false)
|
||
const toggleBalance = () => {
|
||
balanceVisible.value = !balanceVisible.value
|
||
}
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const queryForm = reactive<{
|
||
keyword: string
|
||
auth_status: number | undefined
|
||
use_status: number | undefined
|
||
}>({ keyword: '', auth_status: undefined, use_status: undefined })
|
||
|
||
const columns = ref(defaultColumns)
|
||
const availableFields = reactive(defaultAvailableFields)
|
||
const presetTree = ref<any[]>(defaultPresetTree)
|
||
|
||
async function loadList() {
|
||
loading.value = true
|
||
try {
|
||
const params: any = {
|
||
page: pagination.currentPage,
|
||
page_size: pagination.pageSize,
|
||
...currentCondition.value
|
||
}
|
||
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 || pagination.currentPage
|
||
pagination.pageSize = payload.pagination?.pageSize || pagination.pageSize
|
||
}
|
||
} catch (e) {
|
||
ElMessage.error('获取列表失败')
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
const currentCondition = ref<any>({ use_status: 1 })
|
||
function handleConditionChange(condition: any) {
|
||
const where: any = {}
|
||
|
||
// 处理 ScanBox 的自定义筛选条件
|
||
if (condition) {
|
||
Object.keys(condition).forEach(k => {
|
||
const c = condition[k]
|
||
// ScanBox 传出的是 { value, operator } 或直接是值
|
||
if (c && typeof c === 'object' && c.value !== undefined) {
|
||
if (c.value !== '' && c.value !== null) {
|
||
where[k] = c.value
|
||
}
|
||
} else if (c !== '' && c !== null && c !== undefined) {
|
||
where[k] = c
|
||
}
|
||
})
|
||
}
|
||
|
||
currentCondition.value = where
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleSearch() {
|
||
pagination.currentPage = 1
|
||
loadList()
|
||
}
|
||
|
||
function handleReset() {
|
||
queryForm.keyword = ''
|
||
currentCondition.value = {}
|
||
if (scanBox.value?.reset) {
|
||
scanBox.value.reset()
|
||
} else {
|
||
// 降级处理:如果没有 scanBox 实例也应该能正常重置并加载
|
||
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) {
|
||
const map: Record<number, string> = { 1: 'warning', 2: 'success', 3: 'danger', 4: 'info' }
|
||
return (map[status] || 'info') as any
|
||
}
|
||
|
||
function getAuthStatusLabel(status: number) {
|
||
const map: Record<number, string> = { 1: '待审核', 2: '已通过', 3: '已拒绝', 4: '已终止' }
|
||
return map[status] || '未知'
|
||
}
|
||
|
||
function formatDate(dateStr: string | null | undefined) {
|
||
if (!dateStr) return ''
|
||
return new Date(dateStr).toLocaleString('zh-CN', { hour12: false }).replace(/\//g, '-')
|
||
}
|
||
|
||
// ─── 禁用/启用 ────────────────────────────────────────────────────────────────
|
||
async function handleUnbind(row: any, targetStatus: number) {
|
||
const actionLabel = targetStatus === 0 ? '禁用' : '启用'
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确认要${actionLabel}与「${row.counterparty_remask || row.counterparty_name}」的签约关系吗?`,
|
||
`${actionLabel}签约`,
|
||
{ type: targetStatus === 0 ? 'warning' : 'info', confirmButtonText: actionLabel, cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
try {
|
||
const res = await storeWarehouseUnbind({
|
||
id: row.id,
|
||
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('操作失败')
|
||
}
|
||
}
|
||
|
||
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()
|
||
if (selectedRow.value && selectedRow.value.id === row.id) {
|
||
selectedRow.value.remask = value
|
||
}
|
||
} else {
|
||
ElMessage.error(res?.message || '修改备注失败')
|
||
}
|
||
} catch {
|
||
// cancelled
|
||
}
|
||
}
|
||
|
||
// ─── 发起签约 ────────────────────────────────────────────────────────────────
|
||
const signDialog = reactive({ ...signDialogDefault })
|
||
const signForm = reactive<Record<string, any>>({ ...signFormDefault })
|
||
|
||
function openSignDialog() {
|
||
resetSignDialog()
|
||
signDialog.visible = true
|
||
}
|
||
|
||
function resetSignDialog() {
|
||
Object.assign(signDialog, signDialogDefault)
|
||
Object.assign(signForm, signFormDefault)
|
||
}
|
||
|
||
async function doInitiateSign() {
|
||
if (!signForm.counterparty_id) {
|
||
ElMessage.warning('请输入对方主体ID')
|
||
return
|
||
}
|
||
signDialog.loading = true
|
||
try {
|
||
const res = await storeWarehouseSign({
|
||
counterparty_id: signForm.counterparty_id,
|
||
remask: signForm.remask || undefined
|
||
}) as any
|
||
if (res?.flag === 'success' || res?.code === 200) {
|
||
signDialog.mode = res.data?.mode || 'initiate'
|
||
signDialog.tempCode = res.data?.temp_code || ''
|
||
signDialog.contract = res.data?.contract || null
|
||
signDialog.step = 2
|
||
signDialog.title = '签约预览'
|
||
} else {
|
||
ElMessage.error(res?.message || '发起签约失败')
|
||
}
|
||
} catch {
|
||
ElMessage.error('发起签约失败')
|
||
} finally {
|
||
signDialog.loading = false
|
||
}
|
||
}
|
||
|
||
async function doPreviewSign() {
|
||
if (!signDialog.tempCode) return
|
||
signDialog.loading = true
|
||
try {
|
||
const res = await storeWarehouseSign({ temp_code: signDialog.tempCode, action: 'preview' }) as any
|
||
if (res?.flag === 'success' || res?.code === 200) {
|
||
signDialog.mode = res.data?.mode || 'preview'
|
||
signDialog.contract = res.data?.contract || null
|
||
} else {
|
||
ElMessage.error(res?.message || '预览失败')
|
||
}
|
||
} catch {
|
||
ElMessage.error('预览失败')
|
||
} finally {
|
||
signDialog.loading = false
|
||
}
|
||
}
|
||
|
||
async function doConfirmSign() {
|
||
if (!signDialog.tempCode) return
|
||
signDialog.loading = true
|
||
try {
|
||
const res = await storeWarehouseSign({ temp_code: signDialog.tempCode, action: 'confirm' }) as any
|
||
if (res?.flag === 'success' || res?.code === 200) {
|
||
signDialog.mode = 'confirm'
|
||
signDialog.contract = res.data?.contract || null
|
||
signDialog.title = '签约成功'
|
||
} else {
|
||
ElMessage.error(res?.message || '确认签约失败')
|
||
}
|
||
} catch {
|
||
ElMessage.error('确认签约失败')
|
||
} finally {
|
||
signDialog.loading = false
|
||
}
|
||
}
|
||
|
||
function handleSignSuccess() {
|
||
signDialog.visible = false
|
||
loadList()
|
||
}
|
||
|
||
// ─── 详情 ────────────────────────────────────────────────────────────────────
|
||
const detailDialog = reactive({ visible: false, row: null as any })
|
||
|
||
function handleViewDetail(row: any) {
|
||
detailDialog.row = row
|
||
detailDialog.visible = true
|
||
}
|
||
|
||
// ─── 签约策略配置 ────────────────────────────────────────────────────────────
|
||
const policyDialog = reactive({
|
||
visible: false,
|
||
loading: false,
|
||
saving: false,
|
||
contractRow: null as any,
|
||
fields: [] as any[],
|
||
formData: {} as Record<string, any>,
|
||
jsonText: '',
|
||
jsonError: ''
|
||
})
|
||
const policyExpressOptions = ref<Array<{ label: string; value: string }>>([])
|
||
const policyPlatformOptions = ref<Array<{ label: string; value: string }>>([])
|
||
|
||
function normalizePolicyConfig(source: Record<string, any>, fields: any[] = []) {
|
||
const normalized: Record<string, any> = {}
|
||
const allowAllKeys = fields.length === 0
|
||
const fieldMap = new Map<string, any>(fields.map((f: any) => [f.key, f]))
|
||
Object.keys(source || {}).forEach((key) => {
|
||
if (!allowAllKeys && !fieldMap.has(key)) return
|
||
const field = fieldMap.get(key)
|
||
const value = source[key]
|
||
if (value === undefined || value === null || value === '') return
|
||
if (
|
||
field?.type === 'flag' ||
|
||
[
|
||
'auto_allocate_bin',
|
||
'allow_mix_batch',
|
||
'allow_temp_storage',
|
||
'storage_separation'
|
||
].includes(key)
|
||
) {
|
||
normalized[key] = Number(value) ? 1 : 0
|
||
return
|
||
}
|
||
if (field?.type === 'integer' || key === 'max_daily_inbound') {
|
||
const n = Number(value)
|
||
if (!Number.isNaN(n)) normalized[key] = Math.max(0, Math.trunc(n))
|
||
return
|
||
}
|
||
if ((field?.type === 'number' && field?.precision === 2) || key === 'print_recharge_price') {
|
||
const n = Number(value)
|
||
if (!Number.isNaN(n)) normalized[key] = Number(n.toFixed(2))
|
||
return
|
||
}
|
||
normalized[key] = value
|
||
})
|
||
return normalized
|
||
}
|
||
|
||
function resetPolicyDialog() {
|
||
policyDialog.contractRow = null
|
||
policyDialog.fields = []
|
||
policyDialog.formData = {}
|
||
policyDialog.jsonText = ''
|
||
policyDialog.jsonError = ''
|
||
}
|
||
|
||
function validatePolicyJson(): boolean {
|
||
const text = policyDialog.jsonText.trim()
|
||
if (!text) {
|
||
policyDialog.jsonError = ''
|
||
return true
|
||
}
|
||
try {
|
||
const parsed = JSON.parse(text)
|
||
if (typeof parsed !== 'object' || Array.isArray(parsed) || parsed === null) {
|
||
policyDialog.jsonError = '必须是 JSON 对象 {},不能是数组或 null'
|
||
return false
|
||
}
|
||
policyDialog.jsonError = ''
|
||
return true
|
||
} catch {
|
||
policyDialog.jsonError = 'JSON 格式有误,请检查后重新输入'
|
||
return false
|
||
}
|
||
}
|
||
|
||
function getEnumOptionValue(option: any) {
|
||
if (option && typeof option === 'object') {
|
||
return option.value ?? option.label ?? ''
|
||
}
|
||
return option
|
||
}
|
||
|
||
function getEnumOptionLabel(option: any) {
|
||
if (option && typeof option === 'object') {
|
||
return option.label ?? option.value ?? ''
|
||
}
|
||
return option
|
||
}
|
||
|
||
function normalizeOptionText(value: unknown) {
|
||
return String(value ?? '').trim()
|
||
}
|
||
|
||
function mapPolicyExpressOptions(rawList: any[]) {
|
||
const result: Array<{ label: string; value: string }> = []
|
||
const seen = new Set<string>()
|
||
for (const item of rawList || []) {
|
||
const code = normalizeOptionText(item?.express_code || item?.code || item?.express?.code)
|
||
if (!code || seen.has(code)) continue
|
||
const name = normalizeOptionText(item?.name || item?.express_name || item?.express?.name)
|
||
result.push({
|
||
value: code,
|
||
label: name ? `${code} - ${name}` : code
|
||
})
|
||
seen.add(code)
|
||
}
|
||
return result
|
||
}
|
||
|
||
function mapPolicyPlatformOptions(rawList: any[]) {
|
||
const result: Array<{ label: string; value: string }> = []
|
||
const seen = new Set<string>()
|
||
for (const item of rawList || []) {
|
||
const code = normalizeOptionText(item?.code || item?.platform_code)
|
||
if (!code || seen.has(code)) continue
|
||
const name = normalizeOptionText(item?.name || item?.platform_name)
|
||
result.push({
|
||
value: code,
|
||
label: name ? `${code} - ${name}` : code
|
||
})
|
||
seen.add(code)
|
||
}
|
||
return result
|
||
}
|
||
|
||
async function loadPolicySelectOptions() {
|
||
try {
|
||
const [expressRes, platformRes]: any = await Promise.all([
|
||
getExpressList({}),
|
||
getPlatformList({})
|
||
])
|
||
const expressRaw = expressRes?.data?.list || expressRes?.data || []
|
||
const platformRaw = platformRes?.data?.list || platformRes?.data || []
|
||
policyExpressOptions.value = mapPolicyExpressOptions(expressRaw)
|
||
policyPlatformOptions.value = mapPolicyPlatformOptions(platformRaw)
|
||
} catch {
|
||
policyExpressOptions.value = []
|
||
policyPlatformOptions.value = []
|
||
}
|
||
}
|
||
|
||
async function openPolicyDialog(row: any) {
|
||
policyDialog.contractRow = row
|
||
policyDialog.fields = []
|
||
policyDialog.formData = {}
|
||
policyDialog.jsonText = ''
|
||
policyDialog.jsonError = ''
|
||
policyDialog.visible = true
|
||
policyDialog.loading = true
|
||
try {
|
||
await loadPolicySelectOptions()
|
||
const [configRes, fieldsRes] = await Promise.all([
|
||
storeWarehouseGetPolicyConfig({ id: row.id }) as Promise<any>,
|
||
storeWarehouseGetPolicyConfigFields() as Promise<any>
|
||
])
|
||
// 加载字段元信息
|
||
const fieldList: any[] = Array.isArray(fieldsRes?.data) ? fieldsRes.data : []
|
||
policyDialog.fields = fieldList
|
||
// 用字段默认值初始化 formData
|
||
const defaults: Record<string, any> = {}
|
||
fieldList.forEach((f: any) => { defaults[f.key] = f.default ?? undefined })
|
||
// 用已保存的 policy_config 覆盖
|
||
const saved = configRes?.data?.policy_config
|
||
policyDialog.formData = { ...defaults, ...(saved && typeof saved === 'object' && !Array.isArray(saved) ? saved : {}) }
|
||
// 同步 JSON 文本(fallback)
|
||
if (saved && typeof saved === 'object') {
|
||
policyDialog.jsonText = JSON.stringify(saved, null, 2)
|
||
}
|
||
} catch {
|
||
ElMessage.error('加载策略配置失败')
|
||
} finally {
|
||
policyDialog.loading = false
|
||
}
|
||
}
|
||
|
||
async function submitPolicyConfig() {
|
||
policyDialog.saving = true
|
||
try {
|
||
let policy_config: Record<string, any> = {}
|
||
if (policyDialog.fields.length > 0) {
|
||
// 结构化表单模式:直接取 formData
|
||
const data: Record<string, any> = {}
|
||
policyDialog.fields.forEach((f: any) => {
|
||
const v = policyDialog.formData[f.key]
|
||
if (v !== undefined && v !== '') data[f.key] = v
|
||
})
|
||
policy_config = normalizePolicyConfig(data, policyDialog.fields)
|
||
} else {
|
||
// fallback JSON 模式
|
||
if (!validatePolicyJson()) { policyDialog.saving = false; return }
|
||
const text = policyDialog.jsonText.trim()
|
||
policy_config = text ? normalizePolicyConfig(JSON.parse(text), policyDialog.fields) : {}
|
||
}
|
||
const res = await storeWarehouseSavePolicyConfig({
|
||
id: policyDialog.contractRow?.id,
|
||
policy_config: policy_config as any
|
||
}) as any
|
||
if (res?.flag === 'success' || res?.code === 200) {
|
||
ElMessage.success('策略配置保存成功')
|
||
policyDialog.visible = false
|
||
loadList()
|
||
} else {
|
||
ElMessage.error(res?.message || '保存策略配置失败')
|
||
}
|
||
} catch {
|
||
ElMessage.error('保存策略配置失败')
|
||
} finally {
|
||
policyDialog.saving = false
|
||
}
|
||
}
|
||
|
||
// ─── 接口配置管理(奇门 / OPEN_API 等) ─────────────────────────────────────────
|
||
const qimenDialog = reactive({
|
||
visible: false,
|
||
loading: false,
|
||
contractRow: null as any,
|
||
list: [] as any[],
|
||
availableTypes: [] as any[], // 用于提交时解析 interface_type_id(来源:listInterfaceTypes)
|
||
selectableTypes: [] as any[], // 保留字段(兼容,实际下拉由 selectableLocalTypes 驱动)
|
||
total: 0,
|
||
contract: null as any,
|
||
formVisible: false,
|
||
formLoading: false,
|
||
editingConfig: null as any
|
||
})
|
||
|
||
/** 新增时可选的接口类型 */
|
||
const selectableTypes = computed(() => qimenDialog.availableTypes)
|
||
|
||
const qimenForm = reactive<Record<string, any>>({ ...qimenFormDefault })
|
||
|
||
// ─── 面单余额调整 ─────────────────────────────────────────────────────────
|
||
const adjustBalanceDialog = reactive({ ...adjustBalanceDialogDefault })
|
||
const adjustBalanceForm = reactive<Record<string, any>>({ ...adjustBalanceFormDefault })
|
||
|
||
function openAdjustBalanceDialog(row: any) {
|
||
adjustBalanceDialog.contractRow = row
|
||
Object.assign(adjustBalanceForm, adjustBalanceFormDefault)
|
||
adjustBalanceDialog.visible = true
|
||
}
|
||
|
||
function resetAdjustBalanceDialog() {
|
||
adjustBalanceDialog.contractRow = null
|
||
Object.assign(adjustBalanceForm, adjustBalanceFormDefault)
|
||
}
|
||
|
||
async function submitAdjustBalance() {
|
||
if (adjustBalanceForm.target_quantity === undefined || adjustBalanceForm.target_quantity === null) {
|
||
ElMessage.warning('请输入目标面单余额')
|
||
return
|
||
}
|
||
if (!adjustBalanceForm.reason?.trim()) {
|
||
ElMessage.warning('请输入调整原因')
|
||
return
|
||
}
|
||
|
||
adjustBalanceDialog.loading = true
|
||
try {
|
||
const res = await storeWarehouseAdjustPrintQuantity({
|
||
id: adjustBalanceDialog.contractRow.id,
|
||
target_quantity: adjustBalanceForm.target_quantity,
|
||
reason: adjustBalanceForm.reason.trim()
|
||
}) as any
|
||
|
||
if (res?.flag === 'success' || res?.code === 200) {
|
||
ElMessage.success('面单余额设置成功')
|
||
adjustBalanceDialog.visible = false
|
||
loadList() // 刷新列表
|
||
} else {
|
||
ElMessage.error(res?.message || '调整失败')
|
||
}
|
||
} catch {
|
||
ElMessage.error('调整失败')
|
||
} finally {
|
||
adjustBalanceDialog.loading = false
|
||
}
|
||
}
|
||
|
||
function openQimenDialog(row: any) {
|
||
qimenDialog.contractRow = row
|
||
qimenDialog.formVisible = false
|
||
qimenDialog.editingConfig = null
|
||
qimenDialog.list = []
|
||
qimenDialog.visible = true
|
||
loadQimenConfigs()
|
||
}
|
||
|
||
function resetQimenDialog() {
|
||
qimenDialog.contractRow = null
|
||
qimenDialog.formVisible = false
|
||
qimenDialog.editingConfig = null
|
||
qimenDialog.list = []
|
||
qimenDialog.availableTypes = []
|
||
qimenDialog.selectableTypes = []
|
||
}
|
||
|
||
async function loadQimenConfigs() {
|
||
if (!qimenDialog.contractRow) return
|
||
qimenDialog.loading = true
|
||
try {
|
||
// 并行获取已配置列表和全局接口类型列表
|
||
const [res, typesRes] = await Promise.all([
|
||
listApiConfig({ id: qimenDialog.contractRow.id }) as Promise<any>,
|
||
listInterfaceTypes() as Promise<any>
|
||
])
|
||
|
||
// listInterfaceTypes 接口返回 { list: [...], total, ... }
|
||
const serverTypes: any[] = Array.isArray(typesRes?.list) ? typesRes.list : []
|
||
|
||
// 以接口类型列表作为主数据源;对于历史数据中未出现在 serverTypes 的类型进行兜底补充
|
||
const typeMap = new Map<number, any>(serverTypes.map((t: any) => [t.id, t]))
|
||
|
||
if (res?.data) {
|
||
qimenDialog.list = res.data.list || []
|
||
qimenDialog.total = res.data.total || 0
|
||
qimenDialog.contract = res.data.contract || null
|
||
|
||
// 将已配置列表中未被 listInterfaceTypes 收录的历史类型追加进去(兜底)
|
||
;(res.data.list || []).forEach((item: any) => {
|
||
const tid = item.interface_type_id
|
||
if (tid && !typeMap.has(tid)) {
|
||
typeMap.set(tid, {
|
||
id: tid,
|
||
interface_code: item.interface_code || item.interface_category || '',
|
||
interface_name: item.interface_name || item.interface_code || `类型 ${tid}`
|
||
})
|
||
}
|
||
})
|
||
}
|
||
|
||
qimenDialog.availableTypes = Array.from(typeMap.values())
|
||
} catch {
|
||
ElMessage.error('加载接口配置列表失败')
|
||
} finally {
|
||
qimenDialog.loading = false
|
||
}
|
||
}
|
||
|
||
function handleInterfaceTypeChange(_code: string) {
|
||
// interface_code 已由 v-model 绑定自动更新,此处只做联动清空
|
||
qimenForm.qimen_app_key = ''
|
||
qimenForm.qimen_customer_id = ''
|
||
qimenForm.qimen_warehouse_code = ''
|
||
}
|
||
|
||
function openQimenForm(config: any) {
|
||
qimenDialog.editingConfig = config
|
||
if (config) {
|
||
Object.assign(qimenForm, qimenFormDefault, config)
|
||
// 从现有配置提取接口类型标识(用于表单条件渲染)
|
||
qimenForm.interface_code = config.interface_code || config.interface_category || ''
|
||
// is_enabled = 0 情况兼容
|
||
if (config.is_enabled !== undefined) qimenForm.is_enabled = config.is_enabled
|
||
} else {
|
||
Object.assign(qimenForm, qimenFormDefault)
|
||
// 若只有一个接口类型,自动选中
|
||
if (selectableTypes.value.length === 1) {
|
||
qimenForm.interface_code = selectableTypes.value[0]?.interface_code ?? ''
|
||
}
|
||
}
|
||
qimenDialog.formVisible = true
|
||
}
|
||
|
||
async function submitQimenForm() {
|
||
if (!qimenForm.interface_code) {
|
||
ElMessage.warning('请选择接口类型')
|
||
return
|
||
}
|
||
if (!qimenForm.app_name?.trim()) {
|
||
ElMessage.warning('请填写应用名称')
|
||
return
|
||
}
|
||
// QM_WMS 类型必填奇门字段
|
||
const isQmWms = qimenForm.interface_code === 'QM_WMS' ||
|
||
(!qimenForm.interface_code && qimenDialog.editingConfig?.interface_code === 'QM_WMS')
|
||
if (isQmWms) {
|
||
if (!qimenForm.qimen_app_key?.trim()) {
|
||
ElMessage.warning('奇门备山 QM_WMS 类型必须填写 AppKey')
|
||
return
|
||
}
|
||
if (!qimenForm.qimen_customer_id?.trim()) {
|
||
ElMessage.warning('奇门备山 QM_WMS 类型必须填写客户ID')
|
||
return
|
||
}
|
||
if (!qimenForm.qimen_warehouse_code?.trim()) {
|
||
ElMessage.warning('奇门备山 QM_WMS 类型必须填写仓库编码')
|
||
return
|
||
}
|
||
}
|
||
// 解析 interface_type_id:编辑时来自已有配置,新增时从 availableTypes 按 interface_code 反查
|
||
const resolvedTypeId: number | undefined =
|
||
qimenDialog.editingConfig?.interface_type_id ??
|
||
qimenDialog.availableTypes.find((t: any) => t.interface_code === qimenForm.interface_code)?.id
|
||
if (!resolvedTypeId) {
|
||
ElMessage.warning('无法解析接口类型ID,请稍后重试或刷新页面')
|
||
return
|
||
}
|
||
qimenDialog.formLoading = true
|
||
try {
|
||
// 仅提交 saveApiConfig 接口所要求的字段
|
||
const payload = {
|
||
id: qimenDialog.contractRow?.id as number,
|
||
interface_type_id: resolvedTypeId,
|
||
app_name: qimenForm.app_name.trim()
|
||
} as const
|
||
// QM_WMS 类型额外传奇门字段
|
||
if (isQmWms) {
|
||
;(payload as any).qimen_app_key = qimenForm.qimen_app_key.trim()
|
||
;(payload as any).qimen_customer_id = qimenForm.qimen_customer_id.trim()
|
||
;(payload as any).qimen_warehouse_code = qimenForm.qimen_warehouse_code.trim()
|
||
}
|
||
const res = await saveApiConfig(payload as any) as any
|
||
if (res?.flag === 'success' || res?.code === 200) {
|
||
const action = res.data?.action === 'create' ? '新增' : '更新'
|
||
ElMessage.success(`奇门配置${action}成功`)
|
||
qimenDialog.formVisible = false
|
||
await loadQimenConfigs()
|
||
loadList()
|
||
} else {
|
||
ElMessage.error(res?.message || '保存奇门配置失败')
|
||
}
|
||
} catch {
|
||
ElMessage.error('保存奇门配置失败')
|
||
} finally {
|
||
qimenDialog.formLoading = false
|
||
}
|
||
}
|
||
|
||
async function handleDeleteQimenConfig(config: any) {
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确认要删除奇门配置「${config.app_name}」吗?删除后签约关系将无奇门配置。`,
|
||
'删除奇门配置',
|
||
{ type: 'warning', confirmButtonText: '确认删除', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
try {
|
||
const res = await storeWarehouseDeleteQimenConfig({
|
||
id: qimenDialog.contractRow?.id,
|
||
interface_type_id: config.interface_type_id
|
||
}) as any
|
||
if (res?.flag === 'success' || res?.code === 200) {
|
||
ElMessage.success('删除成功')
|
||
await loadQimenConfigs()
|
||
loadList()
|
||
} else {
|
||
ElMessage.error(res?.message || '删除失败')
|
||
}
|
||
} catch {
|
||
ElMessage.error('删除失败')
|
||
}
|
||
}
|
||
|
||
// ─── 初始化 ───────────────────────────────────────────────────────────────────
|
||
onMounted(loadList)
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
.store-container {
|
||
display: flex;
|
||
height: calc(100vh - 100px);
|
||
width: 100%;
|
||
background-color: #f0f2f5;
|
||
padding: 0;
|
||
box-sizing: border-box;
|
||
|
||
.main-content {
|
||
flex: 1;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
padding: 10px;
|
||
gap: 10px;
|
||
|
||
.toolbar {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
padding: 8px 12px;
|
||
background: #fff;
|
||
border-radius: 4px;
|
||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
|
||
|
||
.toolbar-left, .toolbar-right {
|
||
display: flex;
|
||
gap: 8px;
|
||
align-items: center;
|
||
}
|
||
}
|
||
|
||
.upper-wrapper {
|
||
flex: 3;
|
||
min-height: 300px;
|
||
background: #fff;
|
||
border-radius: 4px;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.lower-level {
|
||
flex: 0 0 40%;
|
||
height: 40%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
border-top: 1px solid #ebeef5;
|
||
overflow: hidden;
|
||
background-color: #fff;
|
||
border-radius: 4px;
|
||
|
||
&.empty {
|
||
align-items: center;
|
||
justify-content: center;
|
||
}
|
||
|
||
.detail-header {
|
||
padding: 0 10px;
|
||
border-bottom: 1px solid #ebeef5;
|
||
background-color: #fafafa;
|
||
|
||
.detail-tab {
|
||
margin-bottom: -1px;
|
||
|
||
:deep(.el-tabs__header) {
|
||
margin: 0;
|
||
}
|
||
|
||
:deep(.el-tabs__item) {
|
||
height: 32px;
|
||
line-height: 32px;
|
||
font-size: 13px;
|
||
}
|
||
|
||
:deep(.el-tabs__nav-wrap::after) {
|
||
height: 1px;
|
||
}
|
||
}
|
||
}
|
||
|
||
.detail-container {
|
||
flex: 1;
|
||
overflow-y: auto;
|
||
padding: 10px;
|
||
}
|
||
}
|
||
}
|
||
|
||
.real-name {
|
||
color: #999;
|
||
font-size: 12px;
|
||
}
|
||
|
||
.text-warning {
|
||
color: #e6a23c;
|
||
font-weight: 600;
|
||
}
|
||
}
|
||
|
||
.sign-preview {
|
||
.sign-tip {
|
||
margin-top: 12px;
|
||
}
|
||
}
|
||
|
||
.qimen-summary {
|
||
display: flex;
|
||
align-items: center;
|
||
}
|
||
|
||
.qimen-info {
|
||
margin-top: 4px;
|
||
font-size: 12px;
|
||
color: #888;
|
||
}
|
||
|
||
.qimen-form {
|
||
.el-input-number {
|
||
width: 100%;
|
||
}
|
||
}
|
||
|
||
.policy-form-scroll {
|
||
max-height: 48vh;
|
||
overflow-y: auto;
|
||
overflow-x: hidden;
|
||
padding-right: 8px;
|
||
}
|
||
|
||
.policy-json-editor {
|
||
.policy-json-label {
|
||
display: flex;
|
||
align-items: center;
|
||
font-size: 13px;
|
||
color: #606266;
|
||
margin-bottom: 8px;
|
||
font-weight: 500;
|
||
}
|
||
.policy-json-tip {
|
||
margin-top: 6px;
|
||
font-size: 12px;
|
||
color: #aaa;
|
||
code {
|
||
background: #f5f5f5;
|
||
padding: 0 4px;
|
||
border-radius: 2px;
|
||
}
|
||
}
|
||
}
|
||
|
||
.policy-json-error {
|
||
color: #f56c6c;
|
||
font-size: 12px;
|
||
margin-top: 4px;
|
||
}
|
||
|
||
:deep(.is-error-textarea .el-textarea__inner) {
|
||
border-color: #f56c6c;
|
||
}
|
||
</style> |