2915 lines
100 KiB
Vue
2915 lines
100 KiB
Vue
<template>
|
||
<div class="order-sub-container" :style="{ height: containerHeight }">
|
||
<scan-box
|
||
ref="scanBox"
|
||
cache-key="store-stores"
|
||
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"
|
||
/>
|
||
</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="store-stores-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.store_name || row.remask || row.counterparty_name }}</span>
|
||
<span
|
||
v-if="(row.store_name || row.remask) && row.counterparty_name && (row.store_name || 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-needs_my_confirm="{ row }">
|
||
<el-tag v-if="row.auth_status === 1" 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-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-actions="{ row }">
|
||
<div class="wave-operation-actions">
|
||
<el-button
|
||
v-if="row.auth_status === 1"
|
||
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
|
||
size="small"
|
||
type="warning"
|
||
link
|
||
@click.stop="openAdjustBalanceDialog(row)"
|
||
>调整余额</el-button>
|
||
<el-button
|
||
size="small"
|
||
type="primary"
|
||
link
|
||
@click.stop="openCreateUserDialog(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
|
||
size="small"
|
||
type="success"
|
||
link
|
||
@click.stop="handleGenerateBindCode(row)"
|
||
>加群授权</el-button>
|
||
<el-button
|
||
v-if="row.current_subject_role === 'warehouse'"
|
||
size="small"
|
||
type="warning"
|
||
link
|
||
@click.stop="openQimenDialog(row)"
|
||
>接口配置</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-tab-pane label="余额变动" name="balanceLogs" />
|
||
<el-tab-pane label="操作日志" name="logs" />
|
||
</el-tabs>
|
||
</div>
|
||
|
||
<div class="detail-container">
|
||
<div v-if="activeTab === 'balanceLogs'" class="balance-log-panel store-detail-pane">
|
||
<div class="balance-log-toolbar">
|
||
<div class="balance-log-toolbar__left">
|
||
<el-button size="small" @click="loadBalanceLogs">刷新</el-button>
|
||
<el-select
|
||
v-model="balanceLogFilter"
|
||
size="small"
|
||
placeholder="流水类型"
|
||
style="width: 130px"
|
||
clearable
|
||
@change="handleBalanceLogFilterChange"
|
||
>
|
||
<el-option label="充值" value="recharge" />
|
||
<el-option label="消费" value="consumption" />
|
||
</el-select>
|
||
<el-date-picker
|
||
v-model="balanceLogDateRange"
|
||
type="datetimerange"
|
||
size="small"
|
||
range-separator="至"
|
||
start-placeholder="开始时间"
|
||
end-placeholder="结束时间"
|
||
value-format="YYYY-MM-DD HH:mm:ss"
|
||
style="width: 380px"
|
||
@change="handleBalanceLogFilterChange"
|
||
/>
|
||
<el-button
|
||
v-if="hasPermission('storeWarehouse.store.exportPrintQuantityLogs')"
|
||
size="small"
|
||
type="primary"
|
||
:loading="exportLoading"
|
||
@click="handleExportBalanceLogs"
|
||
>导出</el-button>
|
||
</div>
|
||
</div>
|
||
<el-table
|
||
v-loading="balanceLogLoading"
|
||
:data="balanceLogList"
|
||
border
|
||
size="small"
|
||
height="100%"
|
||
class="balance-log-table"
|
||
empty-text="暂无余额变动记录"
|
||
>
|
||
<el-table-column type="index" label="#" width="58" :index="computeBalanceLogIndex" align="center" />
|
||
<el-table-column prop="created_at" label="变动时间" min-width="160">
|
||
<template #default="{ row }">
|
||
{{ formatDate(getBalanceLogTime(row)) || '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="变动前" min-width="90" align="right">
|
||
<template #default="{ row }">
|
||
{{ getBalanceLogBefore(row) ?? '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="变动后" min-width="90" align="right">
|
||
<template #default="{ row }">
|
||
{{ getBalanceLogAfter(row) ?? '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="变动值" min-width="90" align="right">
|
||
<template #default="{ row }">
|
||
<span :class="getBalanceLogDeltaClass(getBalanceLogDelta(row))">{{ formatBalanceLogDelta(getBalanceLogDelta(row)) }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="变动类型" min-width="120">
|
||
<template #default="{ row }">
|
||
{{ row.change_type_label || getBalanceLogChangeType(row) || '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="业务类型" min-width="120">
|
||
<template #default="{ row }">
|
||
{{ row.business_type_label || getBalanceLogBusinessType(row) || '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="业务ID" min-width="100" align="right">
|
||
<template #default="{ row }">
|
||
{{ getBalanceLogBusinessId(row) ?? '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作人" min-width="120">
|
||
<template #default="{ row }">
|
||
{{ getBalanceLogOperator(row) || '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="原因" min-width="220" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ getBalanceLogReason(row) || '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<div class="balance-log-pagination">
|
||
<el-pagination
|
||
background
|
||
layout="total, sizes, prev, pager, next, jumper"
|
||
:total="balanceLogPagination.total"
|
||
:current-page="balanceLogPagination.currentPage"
|
||
:page-size="balanceLogPagination.pageSize"
|
||
:page-sizes="[10, 20, 50, 100]"
|
||
@current-change="handleBalanceLogPageChange"
|
||
@size-change="handleBalanceLogSizeChange"
|
||
/>
|
||
</div>
|
||
</div>
|
||
<KeepAlive v-else>
|
||
<component
|
||
:is="activeComponent"
|
||
class="store-detail-pane"
|
||
:id="selectedRow?.id"
|
||
:row="selectedRow"
|
||
:getAuthStatusType="getAuthStatusType"
|
||
:getAuthStatusLabel="getAuthStatusLabel"
|
||
:formatDate="formatDate"
|
||
/>
|
||
</KeepAlive>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="no-selection" v-else :style="lowerPaneStyle">
|
||
<div class="empty-tip">
|
||
<p>请从上方列表中选择一项查看详情</p>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
|
||
<!-- 签约策略配置弹窗 -->
|
||
<el-dialog
|
||
v-model="policyDialog.visible"
|
||
:title="`策略配置 — ${policyDialog.contractRow?.store_name || 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="货主">{{ policyDialog.contractRow?.store_name || policyDialog.contractRow?.counterparty_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="isExpressSelectField(field)"
|
||
v-model="policyDialog.formData[field.key]"
|
||
clearable
|
||
filterable
|
||
:placeholder="field.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?.store_name || qimenDialog.contractRow?.remask || qimenDialog.contractRow?.counterparty_name || ''}`"
|
||
width="80%"
|
||
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.filter(c => !['self_app_key', 'qimen_customer_id', 'qimen_warehouse_code', 'callback_url'].includes(c.prop))"
|
||
:key="col.prop"
|
||
:prop="col.prop"
|
||
:label="col.label"
|
||
:min-width="col.minWidth"
|
||
:width="col.width"
|
||
/>
|
||
<el-table-column label="货主编码" min-width="150">
|
||
<template #default="{ row }">
|
||
<div class="appkey-cell">
|
||
<span class="appkey-text">{{ row.qimen_customer_id || '—' }}</span>
|
||
<el-button
|
||
v-if="row.qimen_customer_id"
|
||
size="small"
|
||
type="primary"
|
||
link
|
||
@click="copyText(row.qimen_customer_id)"
|
||
>
|
||
复制
|
||
</el-button>
|
||
</div>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="qimen_warehouse_code" label="仓库编码" width="110" />
|
||
<el-table-column prop="callback_url" label="回调地址" min-width="200" />
|
||
<el-table-column prop="self_app_key" label="APPKEY" min-width="200">
|
||
<template #default="{ row }">
|
||
<div class="appkey-cell">
|
||
<span class="appkey-text">{{ row.self_app_key || '—' }}</span>
|
||
<el-button
|
||
v-if="row.self_app_key"
|
||
size="small"
|
||
type="primary"
|
||
link
|
||
@click="copyText(row.self_app_key)"
|
||
>
|
||
复制
|
||
</el-button>
|
||
</div>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="APPSECRET" min-width="130">
|
||
<template #default="{ row }">
|
||
<div class="appsecret-cell">
|
||
<template v-if="visibleSecrets[row.id || row.interface_type_id]">
|
||
<span class="appsecret-text">{{ row.self_app_secret || '—' }}</span>
|
||
<el-button
|
||
v-if="row.self_app_secret"
|
||
size="small"
|
||
type="primary"
|
||
link
|
||
@click="copyText(row.self_app_secret)"
|
||
>
|
||
复制
|
||
</el-button>
|
||
</template>
|
||
<el-button
|
||
v-else-if="row.self_app_secret"
|
||
size="small"
|
||
type="warning"
|
||
link
|
||
@click="toggleSecret(row)"
|
||
>
|
||
显示
|
||
</el-button>
|
||
<span v-else>—</span>
|
||
</div>
|
||
</template>
|
||
</el-table-column>
|
||
<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="140" align="center" fixed="right">
|
||
<template #default="{ row }">
|
||
<el-button size="small" type="primary" link @click="openQimenForm(row)">编辑</el-button>
|
||
<el-button
|
||
v-if="row.interface_code === 'QM_WMS'"
|
||
size="small"
|
||
type="success"
|
||
link
|
||
@click="copyQmWmsConfig(row)"
|
||
>复制配置</el-button>
|
||
<el-button
|
||
v-if="row.interface_code === 'OPEN_API'"
|
||
size="small"
|
||
type="success"
|
||
link
|
||
@click="copyOpenApiConfig(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="ERP" required>
|
||
<el-select
|
||
v-model="qimenForm.qimen_app_key"
|
||
filterable
|
||
clearable
|
||
placeholder="请选择ERP"
|
||
style="width:100%"
|
||
>
|
||
<el-option
|
||
v-for="opt in qimenAppOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="货主编码" required>
|
||
<el-input v-model="qimenForm.qimen_customer_id" placeholder="奇门货主编码(必填)">
|
||
<template #append>
|
||
<el-button @click="generateQimenCustomerCode">随机生成</el-button>
|
||
</template>
|
||
</el-input>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="仓库编码" required>
|
||
<el-input v-model="qimenForm.qimen_warehouse_code" placeholder="奇门仓库编码">
|
||
<template #append>
|
||
<el-button @click="generateQimenWarehouseCode">随机生成</el-button>
|
||
</template>
|
||
</el-input>
|
||
</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>
|
||
<el-col :span="24">
|
||
<el-form-item label="回调地址">
|
||
<div class="callback-url-row">
|
||
<el-input v-model="qimenForm.callback_url" placeholder="API 回调通知 URL(可选),订单状态变更时将推送至此地址" maxlength="500" show-word-limit style="flex:1" />
|
||
<el-button size="small" type="primary" link @click="openCallbackDoc">
|
||
<el-icon><Link /></el-icon> 调试文档
|
||
</el-button>
|
||
</div>
|
||
</el-form-item>
|
||
</el-col>
|
||
</template>
|
||
<!-- 其他类型或未选类型时显示所有奇门字段(向后兼容)-->
|
||
<template v-else-if="!qimenForm.interface_code && qimenDialog.editingConfig">
|
||
<el-col :span="12">
|
||
<el-form-item label="ERP">
|
||
<el-select
|
||
v-model="qimenForm.qimen_app_key"
|
||
filterable
|
||
clearable
|
||
placeholder="请选择ERP(如适用)"
|
||
style="width:100%"
|
||
>
|
||
<el-option
|
||
v-for="opt in qimenAppOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="货主编码">
|
||
<el-input v-model="qimenForm.qimen_customer_id" placeholder="奇门货主编码(如适用)">
|
||
<template #append>
|
||
<el-button @click="generateQimenCustomerCode">随机生成</el-button>
|
||
</template>
|
||
</el-input>
|
||
</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"
|
||
>
|
||
<div v-loading="adjustBalanceDialog.fetchLoading">
|
||
<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"
|
||
>
|
||
<span
|
||
v-if="item.type === 'display'"
|
||
class="adjust-balance-display-value"
|
||
>{{ formatAdjustBalanceDisplayQty(adjustBalanceForm[item.prop]) }}</span>
|
||
<div v-else-if="item.type === 'number'" class="adjust-balance-number-field">
|
||
<el-input-number
|
||
v-model="adjustBalanceForm[item.prop]"
|
||
:placeholder="item.placeholder"
|
||
:style="{ width: '100%' }"
|
||
controls-position="right"
|
||
/>
|
||
<div
|
||
v-if="item.prop === 'target_quantity' && adjustBalanceDeltaHint.text"
|
||
class="adjust-balance-delta-hint"
|
||
:class="`is-${adjustBalanceDeltaHint.kind}`"
|
||
>
|
||
{{ adjustBalanceDeltaHint.text }}
|
||
</div>
|
||
</div>
|
||
<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>
|
||
</div>
|
||
|
||
<template #footer>
|
||
<el-button @click="adjustBalanceDialog.visible = false">取消</el-button>
|
||
<el-button
|
||
type="primary"
|
||
:loading="adjustBalanceDialog.loading"
|
||
:disabled="adjustBalanceDialog.fetchLoading"
|
||
@click="submitAdjustBalance"
|
||
>
|
||
确认设置
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 代开户弹窗 -->
|
||
<el-dialog
|
||
v-model="openAccountDialog.visible"
|
||
title="仓库代货主一键开户"
|
||
width="720px"
|
||
align-center
|
||
:close-on-click-modal="false"
|
||
@close="resetOpenAccountDialog"
|
||
>
|
||
<el-form
|
||
ref="openAccountFormRef"
|
||
:model="openAccountForm"
|
||
:rules="openAccountFormRules"
|
||
label-width="120px"
|
||
size="small"
|
||
class="open-account-form-grid"
|
||
>
|
||
<el-row :gutter="16">
|
||
<el-col v-for="item in openAccountFormItems" :key="item.prop" :span="12">
|
||
<el-form-item :label="item.label" :prop="item.prop" :required="item.required">
|
||
<el-input-number
|
||
v-if="item.type === 'number'"
|
||
v-model="openAccountForm[item.prop]"
|
||
:placeholder="item.placeholder"
|
||
:min="0"
|
||
:precision="0"
|
||
style="width:100%"
|
||
controls-position="right"
|
||
/>
|
||
<el-date-picker
|
||
v-else-if="item.type === 'date'"
|
||
v-model="openAccountForm[item.prop]"
|
||
type="date"
|
||
:placeholder="item.placeholder"
|
||
value-format="YYYY-MM-DD"
|
||
style="width:100%"
|
||
/>
|
||
<div v-else-if="item.prop === 'username'" class="username-field-row">
|
||
<el-input
|
||
v-model="openAccountForm[item.prop]"
|
||
:placeholder="item.placeholder"
|
||
style="flex:1"
|
||
/>
|
||
<el-button size="small" @click="generateRandomUsername">
|
||
<el-icon><Refresh /></el-icon> 随机生成
|
||
</el-button>
|
||
</div>
|
||
<el-input
|
||
v-else
|
||
v-model="openAccountForm[item.prop]"
|
||
:placeholder="item.placeholder"
|
||
:maxlength="item.prop === 'company_name' ? 200 : item.prop === 'apply_reason' ? 2000 : item.prop === 'store_remask' || item.prop === 'warehouse_remask' ? 50 : undefined"
|
||
show-word-limit
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button size="small" @click="openAccountDialog.visible = false">取消</el-button>
|
||
<el-button size="small" type="primary" :loading="openAccountDialog.loading" @click="submitOpenAccount">
|
||
确认开户
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 创建用户弹窗(storeWarehouse.store.createUser) -->
|
||
<el-dialog
|
||
v-model="createUserDialog.visible"
|
||
title="创建用户"
|
||
width="480px"
|
||
destroy-on-close
|
||
align-center
|
||
@close="resetCreateUserDialog"
|
||
>
|
||
<el-form
|
||
ref="createUserFormRef"
|
||
:model="createUserForm"
|
||
:rules="createUserFormRules"
|
||
label-width="80px"
|
||
size="small"
|
||
>
|
||
<el-row :gutter="20">
|
||
<el-col v-for="item in createUserFormItems" :key="item.prop" :span="item.span ?? 24">
|
||
<el-form-item :label="item.label" :prop="item.prop">
|
||
<el-input
|
||
v-if="item.type === 'display'"
|
||
:model-value="createUserForm[item.prop]"
|
||
readonly
|
||
/>
|
||
<el-input
|
||
v-else
|
||
v-model="createUserForm[item.prop]"
|
||
:placeholder="item.placeholder"
|
||
clearable
|
||
/>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
</el-form>
|
||
<template #footer>
|
||
<el-button size="small" @click="createUserDialog.visible = false">取消</el-button>
|
||
<el-button size="small" type="primary" :loading="createUserDialog.loading" @click="submitCreateUser">
|
||
确认创建
|
||
</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<!-- 余额变动导出进度弹窗 -->
|
||
<AsyncExportProgressDialog
|
||
:visible="exportDialogVisible"
|
||
title="导出面单余额变更日志"
|
||
:loading="exportLoading"
|
||
:progress-percent="exportProgressPercent"
|
||
:progress-status="exportProgressStatus"
|
||
:status-label="exportStatusLabel"
|
||
:task-id="exportTaskProgress.taskId"
|
||
:message="exportTaskProgress.message"
|
||
:error="exportTaskProgress.error"
|
||
:update-time="exportTaskProgress.updateTime"
|
||
@update:visible="exportDialogVisible = $event"
|
||
/>
|
||
|
||
<!-- 签约货主列表导出(功能表单:storeWarehouse.store.export + exportTaskProgress) -->
|
||
<StoreExportDialog
|
||
v-model:visible="listExportDialogVisible"
|
||
:conditions="currentCondition"
|
||
@success="loadList"
|
||
@loading-change="listExportLoading = $event"
|
||
/>
|
||
|
||
<!-- 生成加群授权码弹窗 -->
|
||
<el-dialog
|
||
v-model="bindCodeDialog.visible"
|
||
title="生成加群授权码"
|
||
width="460px"
|
||
align-center
|
||
:close-on-click-modal="false"
|
||
@close="resetBindCodeDialog"
|
||
>
|
||
<div v-loading="bindCodeDialog.loading" style="padding: 10px 0">
|
||
<el-descriptions :column="1" size="small" border style="margin-bottom: 20px">
|
||
<el-descriptions-item label="货主名称">
|
||
{{ bindCodeDialog.storeName }}
|
||
</el-descriptions-item>
|
||
</el-descriptions>
|
||
|
||
<div v-if="bindCodeDialog.code" class="bind-code-display">
|
||
<div class="bind-code-label">授权码(5分钟有效)</div>
|
||
<div class="bind-code-row">
|
||
<span class="bind-code-value">{{ bindCodeDialog.code }}</span>
|
||
<el-button size="small" type="primary" @click="copyBindCode">一键复制</el-button>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
<template #footer>
|
||
<el-button size="small" @click="bindCodeDialog.visible = false">关闭</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, reactive, onMounted, computed, watch } from 'vue'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import { Plus, Refresh, QuestionFilled, Link } from '@element-plus/icons-vue'
|
||
import { storeWarehouseList, storeWarehouseUnbind,
|
||
storeWarehouseRename, storeWarehouseGetPolicyConfig, storeWarehouseGetPolicyConfigFields,
|
||
storeWarehouseSavePolicyConfig, saveApiConfig, storeWarehouseDeleteQimenConfig,
|
||
storeWarehouseAdjustPrintQuantity, storeWarehouseQueryPrintQuantityLogs, listApiConfig,
|
||
storeWarehouseOpenAccount, storeWarehouseConfirmSign,
|
||
storeWarehouseExportPrintQuantityLogs,
|
||
storeWarehouseExportPrintQuantityLogsTaskProgress,
|
||
storeWarehouseCreateUser
|
||
} from '@/api/storeWarehouse.store/storeWarehouse'
|
||
import { listInterfaceTypes, getExpressList, getPlatformList, getQimenAppList, loadStores } from '@/api/index/index'
|
||
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 Detail from './component/detail.vue'
|
||
import Log from './component/log.vue'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
import { useUserStore } from '@/stores/modules/user'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import { useAsyncExportTask } from '@/composables/useAsyncExportTask'
|
||
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
import { columns as defaultColumns, availableFields as defaultAvailableFields, presetTree as defaultPresetTree, qimenFormDefault, qimenFormItems, qimenTableColumns, adjustBalanceDialogDefault, adjustBalanceFormDefault, adjustBalanceFormItems, openAccountDialogDefault, openAccountFormDefault, openAccountFormItems, createUserDialogDefault, createUserFormDefault, createUserFormItems, storeToolbarButtons } from './store-config.ts'
|
||
import { inboxBindCode } from '@/api/inbox/inbox'
|
||
import StoreExportDialog from './component/ExportDialog.vue'
|
||
|
||
// ─── 列表 ───────────────────────────────────────────────────────────────────
|
||
const settingsStore = useSettingsStore()
|
||
const userStore = useUserStore()
|
||
const hasPermission = (perm: string) => userStore.checkPermission(perm)
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() => shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)')
|
||
|
||
const {
|
||
splitStackRef,
|
||
beginSplitDrag,
|
||
lowerPaneStyle,
|
||
upperPaneStyle,
|
||
} = useVerticalSplitPane({ defaultLowerPercent: 40 })
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden',
|
||
}))
|
||
|
||
const detailVisible = ref(true)
|
||
|
||
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('balanceLogs')
|
||
const componentMap: Record<string, any> = {
|
||
details: Detail,
|
||
logs: Log
|
||
}
|
||
const activeComponent = computed(() => componentMap[activeTab.value] || componentMap.details)
|
||
|
||
const balanceLogLoading = ref(false)
|
||
const balanceLogList = ref<any[]>([])
|
||
const balanceLogPagination = reactive({
|
||
currentPage: 1,
|
||
pageSize: 20,
|
||
total: 0
|
||
})
|
||
|
||
/** 余额变动筛选:''=无, 'recharge'=充值(增加), 'consumption'=消费(减少) */
|
||
const balanceLogFilter = ref('')
|
||
|
||
/** 余额变动时间范围筛选 */
|
||
const balanceLogDateRange = ref<string[] | null>(null)
|
||
|
||
function handleBalanceLogFilterChange() {
|
||
balanceLogPagination.currentPage = 1
|
||
void loadBalanceLogs()
|
||
}
|
||
|
||
// ─── 余额变动导出 ────────────────────────────────────────────────────────────
|
||
function buildBalanceLogExportPayload() {
|
||
const storeId = selectedStoreId.value
|
||
if (storeId === undefined || storeId === null) return null
|
||
const whereFilter: Record<string, any> = {}
|
||
if (balanceLogFilter.value === 'recharge') {
|
||
whereFilter.change_quantity = { operator: 'gt', value: 0 }
|
||
} else if (balanceLogFilter.value === 'consumption') {
|
||
whereFilter.change_quantity = { operator: 'lt', value: 0 }
|
||
}
|
||
if (balanceLogDateRange.value && balanceLogDateRange.value.length === 2) {
|
||
whereFilter.created_at = {
|
||
operator: 'between',
|
||
value: balanceLogDateRange.value
|
||
}
|
||
}
|
||
const payload: Record<string, any> = { store_id: storeId }
|
||
if (Object.keys(whereFilter).length > 0) {
|
||
payload.where = whereFilter
|
||
}
|
||
return payload
|
||
}
|
||
|
||
const {
|
||
exportLoading,
|
||
exportDialogVisible,
|
||
exportTaskProgress,
|
||
exportProgressPercent,
|
||
exportProgressStatus,
|
||
exportStatusLabel,
|
||
submitExportTaskWithMode
|
||
} = useAsyncExportTask({
|
||
storageKey: 'store:stores:balanceLogExportTaskId',
|
||
submitExport: (payload) => storeWarehouseExportPrintQuantityLogs(payload as any),
|
||
queryProgress: (params) => storeWarehouseExportPrintQuantityLogsTaskProgress(params as any)
|
||
})
|
||
|
||
async function handleExportBalanceLogs() {
|
||
const payload = buildBalanceLogExportPayload()
|
||
if (!payload) {
|
||
ElMessage.warning('请先选择一个货主')
|
||
return
|
||
}
|
||
await submitExportTaskWithMode(payload, undefined)
|
||
}
|
||
|
||
const selectedStoreId = computed<number | string | undefined>(() => {
|
||
return resolveStoreIdFromRow(selectedRow.value)
|
||
})
|
||
|
||
watch(
|
||
() => activeTab.value,
|
||
(tab) => {
|
||
if (tab !== 'balanceLogs') return
|
||
balanceLogPagination.currentPage = 1
|
||
void loadBalanceLogs()
|
||
}
|
||
)
|
||
|
||
watch(
|
||
() => selectedRow.value?.id,
|
||
() => {
|
||
if (activeTab.value !== 'balanceLogs') return
|
||
balanceLogPagination.currentPage = 1
|
||
void loadBalanceLogs()
|
||
}
|
||
)
|
||
|
||
// 全局控制所有行的面单余额显示/隐藏
|
||
const balanceVisible = ref(false)
|
||
const toggleBalance = () => {
|
||
balanceVisible.value = !balanceVisible.value
|
||
}
|
||
|
||
function toggleDetailVisible() {
|
||
detailVisible.value = !detailVisible.value
|
||
}
|
||
|
||
const toolbarButtons = storeToolbarButtons
|
||
|
||
const buttonLoadingMap = computed(() => ({
|
||
loading: loading.value,
|
||
listExportLoading: listExportLoading.value
|
||
}))
|
||
|
||
const buttonDisabledMap = computed(() => ({}))
|
||
|
||
const buttonLabelMap = computed(() => ({
|
||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情',
|
||
balanceToggleLabel: balanceVisible.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
|
||
}
|
||
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
loadList: () => {
|
||
void loadList()
|
||
},
|
||
openOpenAccountDialog: () => openOpenAccountDialog(),
|
||
openExportDialog: () => {
|
||
listExportDialogVisible.value = true
|
||
},
|
||
toggleBalance: () => toggleBalance(),
|
||
toggleDetailVisible: () => toggleDetailVisible()
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||
const handler = toolbarActionMap[action]
|
||
if (!handler) return
|
||
safeInvoke(() => handler())
|
||
}
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
|
||
const columns = ref(defaultColumns)
|
||
const availableFields = reactive(defaultAvailableFields)
|
||
const presetTree = ref<any[]>(defaultPresetTree)
|
||
|
||
const currentCondition = ref<any>({ use_status: 1 })
|
||
const listExportDialogVisible = ref(false)
|
||
const listExportLoading = ref(false)
|
||
|
||
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 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
|
||
}
|
||
} catch (e) {
|
||
ElMessage.error('获取列表失败')
|
||
} finally {
|
||
queryTime.value = Date.now() - startTime
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function handleConditionChange(condition: any) {
|
||
const where: any = {}
|
||
if (condition) {
|
||
Object.keys(condition).forEach(k => {
|
||
const c = condition[k]
|
||
// 处理 ScanBox 规范格式:{ value, operator, type }
|
||
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 handleSortChange(_sort: { prop: string; order: string }) {
|
||
// 预留排序事件处理
|
||
}
|
||
|
||
function handleSelectionChange(rows: any[]) {
|
||
selectionRows.value = rows || []
|
||
}
|
||
|
||
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
|
||
if (activeTab.value === 'balanceLogs') {
|
||
balanceLogPagination.currentPage = 1
|
||
void loadBalanceLogs()
|
||
}
|
||
}
|
||
|
||
function resolveStoreIdFromRow(row: any): number | string | undefined {
|
||
if (!row || typeof row !== 'object') return undefined
|
||
const candidates = [row.store_id, row.storeId, row.counterparty_id, row.counterpartyId]
|
||
for (const candidate of candidates) {
|
||
if (candidate === null || candidate === undefined || candidate === '') continue
|
||
return candidate
|
||
}
|
||
return undefined
|
||
}
|
||
|
||
function toFiniteNumber(value: unknown): number | undefined {
|
||
if (value === null || value === undefined || value === '') return undefined
|
||
const n = Number(value)
|
||
return Number.isFinite(n) ? n : undefined
|
||
}
|
||
|
||
function getBalanceLogTime(row: any): string {
|
||
return String(row?.created_at || row?.create_time || row?.createdAt || row?.change_time || row?.updated_at || '')
|
||
}
|
||
|
||
function getBalanceLogBefore(row: any): number | undefined {
|
||
return (
|
||
toFiniteNumber(row?.balance_before) ??
|
||
toFiniteNumber(row?.before_quantity) ??
|
||
toFiniteNumber(row?.before_print_quantity) ??
|
||
toFiniteNumber(row?.old_quantity) ??
|
||
toFiniteNumber(row?.print_quantity_before) ??
|
||
toFiniteNumber(row?.previous_quantity)
|
||
)
|
||
}
|
||
|
||
function getBalanceLogAfter(row: any): number | undefined {
|
||
return (
|
||
toFiniteNumber(row?.balance_after) ??
|
||
toFiniteNumber(row?.after_quantity) ??
|
||
toFiniteNumber(row?.after_print_quantity) ??
|
||
toFiniteNumber(row?.new_quantity) ??
|
||
toFiniteNumber(row?.print_quantity_after) ??
|
||
toFiniteNumber(row?.current_quantity)
|
||
)
|
||
}
|
||
|
||
function getBalanceLogDelta(row: any): number | undefined {
|
||
const direct =
|
||
toFiniteNumber(row?.change_quantity) ??
|
||
toFiniteNumber(row?.delta_quantity) ??
|
||
toFiniteNumber(row?.quantity_delta) ??
|
||
toFiniteNumber(row?.diff_quantity)
|
||
if (direct !== undefined) return direct
|
||
const before = getBalanceLogBefore(row)
|
||
const after = getBalanceLogAfter(row)
|
||
if (before === undefined || after === undefined) return undefined
|
||
return after - before
|
||
}
|
||
|
||
function getBalanceLogOperator(row: any): string {
|
||
return String(
|
||
row?.operator_name ||
|
||
row?.creator_name ||
|
||
row?.created_by_name ||
|
||
row?.operator ||
|
||
row?.user_name ||
|
||
row?.operator_id ||
|
||
row?.created_by ||
|
||
''
|
||
)
|
||
}
|
||
|
||
function getBalanceLogReason(row: any): string {
|
||
return String(row?.reason || row?.change_reason || row?.remark || row?.memo || '')
|
||
}
|
||
|
||
function getBalanceLogChangeType(row: any): string {
|
||
return String(row?.change_type || row?.type || row?.log_type || '')
|
||
}
|
||
|
||
function getBalanceLogBusinessType(row: any): string {
|
||
return String(row?.business_type || row?.biz_type || '')
|
||
}
|
||
|
||
function getBalanceLogBusinessId(row: any): number | string | undefined {
|
||
const candidate = row?.business_id ?? row?.biz_id
|
||
if (candidate === null || candidate === undefined || candidate === '') return undefined
|
||
return candidate
|
||
}
|
||
|
||
function getQimenErpDisplay(config: any): string {
|
||
return String(config?.erp_name || config?.erpName || config?.qimen_app_key || '').trim()
|
||
}
|
||
|
||
function getEditingQimenCustomerId(): string {
|
||
return String(qimenDialog.editingConfig?.qimen_customer_id || '').trim()
|
||
}
|
||
|
||
function getBalanceLogDeltaClass(delta: number | undefined): string {
|
||
if (delta === undefined) return ''
|
||
if (delta > 0) return 'text-up'
|
||
if (delta < 0) return 'text-down'
|
||
return 'text-flat'
|
||
}
|
||
|
||
function formatBalanceLogDelta(delta: number | undefined): string {
|
||
if (delta === undefined) return '—'
|
||
if (delta > 0) return `+${delta}`
|
||
return String(delta)
|
||
}
|
||
|
||
function computeBalanceLogIndex(index: number): number {
|
||
return (balanceLogPagination.currentPage - 1) * balanceLogPagination.pageSize + index + 1
|
||
}
|
||
|
||
async function loadBalanceLogs() {
|
||
if (!selectedRow.value) {
|
||
balanceLogList.value = []
|
||
balanceLogPagination.total = 0
|
||
return
|
||
}
|
||
|
||
const storeId = selectedStoreId.value
|
||
if (storeId === undefined || storeId === null || String(storeId).trim() === '') {
|
||
balanceLogList.value = []
|
||
balanceLogPagination.total = 0
|
||
ElMessage.warning('当前记录缺少 store_id,无法查询余额变动')
|
||
return
|
||
}
|
||
|
||
balanceLogLoading.value = true
|
||
try {
|
||
// 构建 where 筛选条件
|
||
const whereFilter: Record<string, any> = {}
|
||
if (balanceLogFilter.value === 'recharge') {
|
||
// 充值:change_quantity > 0
|
||
whereFilter.change_quantity = { operator: 'gt', value: 0 }
|
||
} else if (balanceLogFilter.value === 'consumption') {
|
||
// 消费:change_quantity < 0
|
||
whereFilter.change_quantity = { operator: 'lt', value: 0 }
|
||
}
|
||
// 时间范围筛选
|
||
if (balanceLogDateRange.value && balanceLogDateRange.value.length === 2) {
|
||
whereFilter.created_at = {
|
||
operator: 'between',
|
||
value: balanceLogDateRange.value
|
||
}
|
||
}
|
||
|
||
const requestData: {
|
||
store_id: number | string
|
||
pagination: { page: number; page_size: number }
|
||
where?: Record<string, any>
|
||
} = {
|
||
store_id: storeId,
|
||
pagination: {
|
||
page: balanceLogPagination.currentPage,
|
||
page_size: balanceLogPagination.pageSize
|
||
}
|
||
}
|
||
if (Object.keys(whereFilter).length > 0) {
|
||
requestData.where = whereFilter
|
||
}
|
||
|
||
const res = (await storeWarehouseQueryPrintQuantityLogs(requestData)) as any
|
||
|
||
const payload = res?.data || {}
|
||
const nested = payload?.data && typeof payload.data === 'object' ? payload.data : null
|
||
const rowsRaw = payload?.list || payload?.records || payload?.logs || nested?.list || nested?.records || nested || []
|
||
const rows = Array.isArray(rowsRaw) ? rowsRaw : []
|
||
balanceLogList.value = rows
|
||
|
||
const paginationRaw = payload?.pagination || nested?.pagination || {}
|
||
const total = toFiniteNumber(paginationRaw?.total) ?? toFiniteNumber(payload?.total) ?? toFiniteNumber(nested?.total) ?? 0
|
||
const current = toFiniteNumber(paginationRaw?.page) ?? balanceLogPagination.currentPage
|
||
const pageSize =
|
||
toFiniteNumber(paginationRaw?.page_size) ??
|
||
toFiniteNumber(paginationRaw?.pageSize) ??
|
||
balanceLogPagination.pageSize
|
||
|
||
balanceLogPagination.total = total
|
||
balanceLogPagination.currentPage = current
|
||
balanceLogPagination.pageSize = pageSize
|
||
} catch {
|
||
balanceLogList.value = []
|
||
balanceLogPagination.total = 0
|
||
ElMessage.error('获取余额变动列表失败')
|
||
} finally {
|
||
balanceLogLoading.value = false
|
||
}
|
||
}
|
||
|
||
function handleBalanceLogPageChange(page: number) {
|
||
balanceLogPagination.currentPage = page
|
||
void loadBalanceLogs()
|
||
}
|
||
|
||
function handleBalanceLogSizeChange(size: number) {
|
||
balanceLogPagination.pageSize = size
|
||
balanceLogPagination.currentPage = 1
|
||
void loadBalanceLogs()
|
||
}
|
||
|
||
// ─── 状态辅助 ────────────────────────────────────────────────────────────────
|
||
function getAuthStatusType(status: number) {
|
||
const map: Record<number, string> = { 1: 'warning', 2: 'success', 3: 'danger', 4: 'info', 5: 'danger' }
|
||
return (map[status] || 'info') as any
|
||
}
|
||
|
||
function getAuthStatusLabel(status: number) {
|
||
const map: Record<number, string> = { 1: '待审核', 2: '已通过', 3: '已拒绝', 4: '已解除', 5: '已过期' }
|
||
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 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()
|
||
if (selectedRow.value && selectedRow.value.id === row.id && res.data?.contract) {
|
||
Object.assign(selectedRow.value, res.data.contract)
|
||
}
|
||
} else {
|
||
ElMessage.error(res?.message || '确认签约失败')
|
||
}
|
||
} catch {
|
||
ElMessage.error('确认签约失败')
|
||
}
|
||
}
|
||
|
||
// ─── 禁用/启用 ────────────────────────────────────────────────────────────────
|
||
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('操作失败')
|
||
}
|
||
}
|
||
|
||
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 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 isExpressSelectField(field: any) {
|
||
if (!field) return false
|
||
const key = String(field.key || '').trim()
|
||
if (key === 'default_express_code') return true
|
||
const name = String(field.name || field.label || '').trim()
|
||
// 兼容后端动态字段:名称同时包含“出库单”与“快递”(如“出库单默认快递”),避免误伤 flag 类快递开关字段
|
||
return name.includes('出库单') && name.includes('快递')
|
||
}
|
||
|
||
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({ systemOnly: 'true' }),
|
||
getPlatformList({ systemOnly: 'true' })
|
||
])
|
||
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 qimenAppOptions = ref<Array<{ label: string; value: string }>>([])
|
||
|
||
/** 新增时可选的接口类型 */
|
||
const selectableTypes = computed(() => qimenDialog.availableTypes)
|
||
|
||
const qimenForm = reactive<Record<string, any>>({ ...qimenFormDefault })
|
||
const visibleSecrets = reactive<Record<string | number, boolean>>({})
|
||
|
||
function toggleSecret(row: any) {
|
||
const key = row.id || row.interface_type_id
|
||
visibleSecrets[key] = !visibleSecrets[key]
|
||
}
|
||
|
||
// ─── 面单余额调整 ─────────────────────────────────────────────────────────
|
||
const adjustBalanceDialog = reactive({ ...adjustBalanceDialogDefault })
|
||
const adjustBalanceForm = reactive<Record<string, any>>({ ...adjustBalanceFormDefault })
|
||
|
||
/** 目标余额相对当前余额的增减提示 */
|
||
const adjustBalanceDeltaHint = computed(() => {
|
||
if (adjustBalanceDialog.fetchLoading) {
|
||
return { text: '', kind: 'neutral' as const }
|
||
}
|
||
const curN = parsePrintQuantity(adjustBalanceForm.current_print_quantity)
|
||
const tgtRaw = adjustBalanceForm.target_quantity
|
||
const tgtN = parsePrintQuantity(tgtRaw)
|
||
if (tgtRaw === undefined || tgtRaw === null || tgtRaw === '') {
|
||
return { text: '', kind: 'neutral' as const }
|
||
}
|
||
if (tgtN === undefined) {
|
||
return { text: '', kind: 'neutral' as const }
|
||
}
|
||
if (curN === undefined) {
|
||
return {
|
||
text: '提交后将把面单余额覆盖为上述目标值(当前余额未加载,无法计算增减)',
|
||
kind: 'neutral' as const
|
||
}
|
||
}
|
||
const delta = tgtN - curN
|
||
if (delta === 0) {
|
||
return { text: '与当前面单余额一致,无增减', kind: 'same' as const }
|
||
}
|
||
if (delta > 0) {
|
||
return { text: `相对当前余额将增加 ${delta}`, kind: 'up' as const }
|
||
}
|
||
return { text: `相对当前余额将减少 ${Math.abs(delta)}`, kind: 'down' as const }
|
||
})
|
||
|
||
function formatAdjustBalanceDisplayQty(value: unknown) {
|
||
if (value === null || value === undefined || value === '') {
|
||
return '—'
|
||
}
|
||
const n = Number(value)
|
||
return Number.isFinite(n) ? String(n) : '—'
|
||
}
|
||
|
||
function parsePrintQuantity(value: unknown): number | undefined {
|
||
if (value === null || value === undefined || value === '') {
|
||
return undefined
|
||
}
|
||
const n = Number(value)
|
||
return Number.isFinite(n) ? n : undefined
|
||
}
|
||
|
||
/** 调用 storeWarehouse.store.list,按签约 id 拉取最新一行(含 print_quantity) */
|
||
async function fetchLatestContractRowById(contractId: number): Promise<any | null> {
|
||
const filterAttempts: Record<string, unknown>[] = [
|
||
{ keyword: currentCondition.value?.keyword },
|
||
{}
|
||
]
|
||
|
||
const pageSize = 200
|
||
const maxPages = 40
|
||
|
||
for (const filters of filterAttempts) {
|
||
let page = 1
|
||
while (page <= maxPages) {
|
||
const res = (await storeWarehouseList({
|
||
page,
|
||
page_size: pageSize,
|
||
...filters
|
||
} as any)) as any
|
||
const payload = res?.data
|
||
const rows = Array.isArray(payload?.list) ? payload.list : []
|
||
|
||
const hit = rows.find((r: any) => Number(r?.id) === Number(contractId))
|
||
if (hit) {
|
||
return hit
|
||
}
|
||
|
||
if (rows.length === 0) {
|
||
break
|
||
}
|
||
|
||
const reportedTotal = Number(payload?.pagination?.total ?? payload?.total)
|
||
const noMore =
|
||
rows.length < pageSize ||
|
||
(Number.isFinite(reportedTotal) && page * pageSize >= reportedTotal)
|
||
if (noMore) {
|
||
break
|
||
}
|
||
|
||
page += 1
|
||
}
|
||
}
|
||
|
||
return null
|
||
}
|
||
|
||
async function openAdjustBalanceDialog(row: any) {
|
||
adjustBalanceDialog.contractRow = row
|
||
adjustBalanceDialog.visible = true
|
||
adjustBalanceDialog.fetchLoading = true
|
||
Object.assign(adjustBalanceForm, adjustBalanceFormDefault)
|
||
|
||
try {
|
||
const fresh = await fetchLatestContractRowById(Number(row.id))
|
||
if (fresh) {
|
||
adjustBalanceDialog.contractRow = fresh
|
||
const pq = parsePrintQuantity(fresh.print_quantity)
|
||
adjustBalanceForm.current_print_quantity = pq
|
||
adjustBalanceForm.target_quantity = pq
|
||
} else {
|
||
ElMessage.warning('未能从列表接口获取该签约的最新数据,已使用表格当前行数据')
|
||
const pq = parsePrintQuantity(row.print_quantity)
|
||
adjustBalanceForm.current_print_quantity = pq
|
||
adjustBalanceForm.target_quantity = pq
|
||
}
|
||
} catch {
|
||
ElMessage.error('获取最新面单余额失败')
|
||
const pq = parsePrintQuantity(row.print_quantity)
|
||
adjustBalanceForm.current_print_quantity = pq
|
||
adjustBalanceForm.target_quantity = pq
|
||
} finally {
|
||
adjustBalanceDialog.fetchLoading = false
|
||
}
|
||
}
|
||
|
||
function resetAdjustBalanceDialog() {
|
||
adjustBalanceDialog.contractRow = null
|
||
adjustBalanceDialog.fetchLoading = false
|
||
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
|
||
}
|
||
}
|
||
|
||
// ─── 代开户 ────────────────────────────────────────────────────────────────────
|
||
const openAccountDialog = reactive({ ...openAccountDialogDefault })
|
||
const openAccountForm = reactive<Record<string, any>>({ ...openAccountFormDefault })
|
||
const openAccountFormRef = ref<any>(null)
|
||
|
||
const openAccountFormRules: Record<string, any> = {
|
||
username: [{ required: true, message: '请输入登录账号', trigger: 'blur' }],
|
||
company_name: [
|
||
{ required: true, message: '请输入公司全称', trigger: 'blur' },
|
||
{ max: 200, message: '公司全称不能超过200字符', trigger: 'blur' }
|
||
],
|
||
contact_person: [
|
||
{ required: true, message: '请输入联系人姓名', trigger: 'blur' },
|
||
{ max: 50, message: '联系人姓名不能超过50字符', trigger: 'blur' }
|
||
],
|
||
apply_reason: [{ max: 2000, message: '申请原因不能超过2000字符', trigger: 'blur' }],
|
||
store_remask: [{ max: 50, message: '货主备注名不能超过50字符', trigger: 'blur' }],
|
||
warehouse_remask: [{ max: 50, message: '仓库备注名不能超过50字符', trigger: 'blur' }]
|
||
}
|
||
|
||
function generateRandomUsername() {
|
||
const prefix = 'user'
|
||
const chars = 'abcdefghijklmnopqrstuvwxyz0123456789'
|
||
let suffix = ''
|
||
for (let i = 0; i < 8; i++) {
|
||
suffix += chars.charAt(Math.floor(Math.random() * chars.length))
|
||
}
|
||
openAccountForm.username = `${prefix}${suffix}`
|
||
}
|
||
|
||
function openOpenAccountDialog() {
|
||
resetOpenAccountDialog()
|
||
// 默认授权开始日期为当天
|
||
const today = new Date()
|
||
openAccountForm.auth_start = today.toISOString().slice(0, 10)
|
||
openAccountDialog.visible = true
|
||
}
|
||
|
||
function resetOpenAccountDialog() {
|
||
Object.assign(openAccountDialog, openAccountDialogDefault)
|
||
Object.assign(openAccountForm, openAccountFormDefault)
|
||
openAccountFormRef.value?.clearValidate?.()
|
||
}
|
||
|
||
async function submitOpenAccount() {
|
||
if (!openAccountFormRef.value) return
|
||
try {
|
||
await openAccountFormRef.value.validate()
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
openAccountDialog.loading = true
|
||
try {
|
||
const payload: Record<string, any> = {
|
||
username: openAccountForm.username.trim(),
|
||
company_name: openAccountForm.company_name.trim(),
|
||
contact_person: openAccountForm.contact_person.trim()
|
||
}
|
||
// 仅提交非空值
|
||
const optionalFields = [
|
||
'password', 'real_name', 'business_license', 'contact_phone',
|
||
'legal_person', 'contact_email', 'address', 'industry', 'logo_url',
|
||
'domain', 'auth_start', 'auth_end', 'apply_reason', 'store_remask', 'warehouse_remask'
|
||
]
|
||
for (const field of optionalFields) {
|
||
const val = openAccountForm[field]
|
||
if (val !== undefined && val !== null && String(val).trim() !== '') {
|
||
payload[field] = typeof val === 'string' ? val.trim() : val
|
||
}
|
||
}
|
||
if (openAccountForm.print_quantity > 0) {
|
||
payload.print_quantity = openAccountForm.print_quantity
|
||
}
|
||
// 默认申请原因
|
||
if (!payload.apply_reason) {
|
||
payload.apply_reason = '仓库代开户'
|
||
}
|
||
|
||
const res = await storeWarehouseOpenAccount(payload as any) as any
|
||
if (res?.flag === 'success' || res?.code === 200 || res?.code === 1) {
|
||
ElMessage.success(res?.message || '开户成功')
|
||
openAccountDialog.visible = false
|
||
loadList()
|
||
} else {
|
||
ElMessage.error(res?.message || '开户失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '开户失败')
|
||
} finally {
|
||
openAccountDialog.loading = false
|
||
}
|
||
}
|
||
|
||
// ─── 创建用户(storeWarehouse.store.createUser) ──────────────────────────────
|
||
const createUserDialog = reactive({ ...createUserDialogDefault })
|
||
const createUserForm = reactive<Record<string, any>>({ ...createUserFormDefault })
|
||
const createUserFormRef = ref<any>(null)
|
||
|
||
const createUserFormRules: Record<string, any> = {
|
||
username: [
|
||
{ required: true, message: '请输入用户名', trigger: 'blur' },
|
||
{
|
||
pattern: /^[a-zA-Z0-9_]{3,50}$/,
|
||
message: '用户名需为3-50位字母、数字或下划线',
|
||
trigger: 'blur'
|
||
}
|
||
]
|
||
}
|
||
|
||
function openCreateUserDialog(row: any) {
|
||
resetCreateUserDialog()
|
||
createUserForm.store_id = Number(row.store_id ?? row.counterparty_id)
|
||
createUserForm.store_label = String(row.counterparty_name ?? row.remask ?? '') || `货主 ${row.store_id}`
|
||
createUserDialog.visible = true
|
||
}
|
||
|
||
function resetCreateUserDialog() {
|
||
Object.assign(createUserDialog, createUserDialogDefault)
|
||
Object.assign(createUserForm, createUserFormDefault)
|
||
createUserFormRef.value?.clearValidate?.()
|
||
}
|
||
|
||
async function submitCreateUser() {
|
||
if (!createUserFormRef.value) return
|
||
try {
|
||
await createUserFormRef.value.validate()
|
||
} catch {
|
||
return
|
||
}
|
||
const storeId = Number(createUserForm.store_id)
|
||
if (!Number.isFinite(storeId) || storeId <= 0) {
|
||
ElMessage.warning('缺少货主信息,无法创建用户')
|
||
return
|
||
}
|
||
createUserDialog.loading = true
|
||
try {
|
||
const res: any = await storeWarehouseCreateUser({
|
||
username: String(createUserForm.username ?? '').trim(),
|
||
store_id: storeId
|
||
})
|
||
const data = res?.data ?? res
|
||
if (res?.flag === 'success' || res?.code === 200 || res?.code === 1) {
|
||
const created = Boolean(data?.created)
|
||
const password = data?.password
|
||
createUserDialog.visible = false
|
||
if (created && password) {
|
||
// 仅本次新建账号时返回初始明文密码
|
||
const username = String(data?.username ?? createUserForm.username ?? '').trim()
|
||
const copyText = `地址:https://wms.wms.gztbyc.com/\n账号:${username}\n密码:${password}`
|
||
ElMessageBox.alert(
|
||
copyText,
|
||
'创建成功',
|
||
{ confirmButtonText: '复制并关闭', type: 'success' }
|
||
).then(() => {
|
||
navigator.clipboard?.writeText(copyText).catch(() => {})
|
||
}).catch(() => {})
|
||
} else {
|
||
ElMessage.success(created ? '创建成功' : '账号已存在,已为货主授权')
|
||
}
|
||
loadList()
|
||
} else {
|
||
ElMessage.error(res?.message || '创建用户失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '创建用户失败')
|
||
} finally {
|
||
createUserDialog.loading = false
|
||
}
|
||
}
|
||
|
||
function openQimenDialog(row: any) {
|
||
qimenDialog.contractRow = row
|
||
qimenDialog.formVisible = false
|
||
qimenDialog.editingConfig = null
|
||
qimenDialog.list = []
|
||
qimenDialog.visible = true
|
||
void loadQimenAppOptions()
|
||
loadQimenConfigs()
|
||
}
|
||
|
||
function resetQimenDialog() {
|
||
qimenDialog.contractRow = null
|
||
qimenDialog.formVisible = false
|
||
qimenDialog.editingConfig = null
|
||
qimenDialog.list = []
|
||
qimenDialog.availableTypes = []
|
||
qimenDialog.selectableTypes = []
|
||
qimenAppOptions.value = []
|
||
}
|
||
|
||
function mapQimenAppOptions(rawList: any[]) {
|
||
const result: Array<{ label: string; value: string }> = []
|
||
const seen = new Set<string>()
|
||
for (const item of rawList || []) {
|
||
const appKey = String(item?.app_key ?? item?.qimen_app_key ?? item?.value ?? '').trim()
|
||
if (!appKey || seen.has(appKey)) continue
|
||
const appName = String(item?.app_name ?? item?.name ?? item?.label ?? '').trim()
|
||
result.push({
|
||
value: appKey,
|
||
label: appName ? `${appName}(${appKey})` : appKey
|
||
})
|
||
seen.add(appKey)
|
||
}
|
||
return result
|
||
}
|
||
|
||
async function loadQimenAppOptions() {
|
||
try {
|
||
const res: any = await getQimenAppList({})
|
||
const payload = res?.data
|
||
const listRaw =
|
||
res?.list ||
|
||
res?.records ||
|
||
(Array.isArray(res) ? res : null) ||
|
||
(Array.isArray(payload) ? payload : null) ||
|
||
payload?.list ||
|
||
payload?.records ||
|
||
payload?.data?.list ||
|
||
payload?.data?.records ||
|
||
payload?.data ||
|
||
[]
|
||
const rows = Array.isArray(listRaw) ? listRaw : []
|
||
qimenAppOptions.value = mapQimenAppOptions(rows)
|
||
} catch {
|
||
qimenAppOptions.value = []
|
||
}
|
||
}
|
||
|
||
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 || []).map((item: any) => ({
|
||
...item,
|
||
erp_display: getQimenErpDisplay(item)
|
||
}))
|
||
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 randomAlphaNum(length = 12): string {
|
||
const chars = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz23456789'
|
||
let result = ''
|
||
for (let i = 0; i < length; i += 1) {
|
||
const idx = Math.floor(Math.random() * chars.length)
|
||
result += chars[idx]
|
||
}
|
||
return result
|
||
}
|
||
|
||
function generateQimenCustomerCode() {
|
||
qimenForm.qimen_customer_id = `ST_${randomAlphaNum(10)}`
|
||
}
|
||
|
||
function generateQimenWarehouseCode() {
|
||
qimenForm.qimen_warehouse_code = `WH_${randomAlphaNum(10)}`
|
||
}
|
||
|
||
async function copyText(text: string) {
|
||
try {
|
||
if (navigator?.clipboard?.writeText) {
|
||
await navigator.clipboard.writeText(text)
|
||
} else {
|
||
const input = document.createElement('textarea')
|
||
input.value = text
|
||
input.style.position = 'fixed'
|
||
input.style.opacity = '0'
|
||
document.body.appendChild(input)
|
||
input.focus()
|
||
input.select()
|
||
document.execCommand('copy')
|
||
document.body.removeChild(input)
|
||
}
|
||
ElMessage.success('已复制')
|
||
} catch {
|
||
ElMessage.error('复制失败')
|
||
}
|
||
}
|
||
|
||
async function copyEditingQimenCustomerId() {
|
||
const customerId = getEditingQimenCustomerId()
|
||
if (!customerId) {
|
||
ElMessage.warning('暂无可复制的货主编码')
|
||
return
|
||
}
|
||
|
||
try {
|
||
if (navigator?.clipboard?.writeText) {
|
||
await navigator.clipboard.writeText(customerId)
|
||
} else {
|
||
const input = document.createElement('textarea')
|
||
input.value = customerId
|
||
input.style.position = 'fixed'
|
||
input.style.opacity = '0'
|
||
document.body.appendChild(input)
|
||
input.focus()
|
||
input.select()
|
||
document.execCommand('copy')
|
||
document.body.removeChild(input)
|
||
}
|
||
ElMessage.success('货主编码已复制')
|
||
} catch {
|
||
ElMessage.error('复制货主编码失败')
|
||
}
|
||
}
|
||
|
||
function copyQmWmsConfig(row: any) {
|
||
const customerId = String(row.qimen_customer_id || '').trim()
|
||
const warehouseCode = String(row.qimen_warehouse_code || '').trim()
|
||
if (!customerId && !warehouseCode) {
|
||
ElMessage.warning('暂无可复制的奇门配置')
|
||
return
|
||
}
|
||
const lines: string[] = []
|
||
if (customerId) lines.push(`货主编码:${customerId}`)
|
||
if (warehouseCode) lines.push(`仓库编码:${warehouseCode}`)
|
||
copyText(lines.join('\n'))
|
||
}
|
||
|
||
function copyOpenApiConfig(row: any) {
|
||
const baseApi = String(import.meta.env.VITE_APP_BASE_API || '').replace(/\/+$/, '')
|
||
const lines: string[] = []
|
||
lines.push('【OPEN_API 接口配置信息】')
|
||
lines.push('')
|
||
if (row.app_name) lines.push(`应用名称:${row.app_name}`)
|
||
if (row.self_app_key) lines.push(`APPKEY:${row.self_app_key}`)
|
||
if (row.self_app_secret) lines.push(`APPSECRET:${row.self_app_secret}`)
|
||
if (row.callback_url) lines.push(`回调地址:${row.callback_url}`)
|
||
lines.push('')
|
||
lines.push('开发文档:')
|
||
lines.push(` 接口文档 ${baseApi}/docs/api/openapi`)
|
||
lines.push(` 回调测试 ${baseApi}/docs/api/openapi/callback-test`)
|
||
lines.push('')
|
||
lines.push('请妥善保管以上信息,用于 API 对接。')
|
||
copyText(lines.join('\n'))
|
||
}
|
||
|
||
function openCallbackDoc() {
|
||
const baseApi = String(import.meta.env.VITE_APP_BASE_API || '').replace(/\/+$/, '')
|
||
window.open(`${baseApi}/docs/api/openapi/callback-test`, '_blank')
|
||
}
|
||
|
||
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 类型必须选择ERP')
|
||
return
|
||
}
|
||
if (!qimenForm.qimen_customer_id?.trim()) {
|
||
ElMessage.warning('奇门备山 QM_WMS 类型必须填写货主编码')
|
||
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: Record<string, any> = {
|
||
id: qimenDialog.contractRow?.id as number,
|
||
interface_type_id: resolvedTypeId,
|
||
app_name: qimenForm.app_name.trim()
|
||
}
|
||
// QM_WMS 类型额外传奇门字段
|
||
if (isQmWms) {
|
||
payload.qimen_app_key = qimenForm.qimen_app_key.trim()
|
||
payload.qimen_customer_id = qimenForm.qimen_customer_id.trim()
|
||
payload.qimen_warehouse_code = qimenForm.qimen_warehouse_code.trim()
|
||
}
|
||
// 回调地址(所有类型)
|
||
if (qimenForm.callback_url?.trim()) {
|
||
payload.callback_url = qimenForm.callback_url.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('删除失败')
|
||
}
|
||
}
|
||
|
||
// ─── 生成加群授权码 ────────────────────────────────────────────────────────────
|
||
const bindCodeDialog = reactive({
|
||
visible: false,
|
||
loading: false,
|
||
storeName: '',
|
||
code: '',
|
||
contractRow: null as any
|
||
})
|
||
|
||
function resetBindCodeDialog() {
|
||
bindCodeDialog.contractRow = null
|
||
bindCodeDialog.storeName = ''
|
||
bindCodeDialog.code = ''
|
||
}
|
||
|
||
async function handleGenerateBindCode(row: any) {
|
||
bindCodeDialog.contractRow = row
|
||
bindCodeDialog.storeName = row.store_name || row.remask || row.counterparty_name || ''
|
||
bindCodeDialog.code = ''
|
||
bindCodeDialog.visible = true
|
||
bindCodeDialog.loading = true
|
||
try {
|
||
const storeId = row.store_id || row.id
|
||
const res = await inboxBindCode({ storeId }) as any
|
||
if (res?.data?.code) {
|
||
bindCodeDialog.code = res.data.code
|
||
ElMessage.success('授权码生成成功')
|
||
} else if (res?.code === 200 && res?.data) {
|
||
bindCodeDialog.code = res.data.code || res.data
|
||
} else {
|
||
ElMessage.error(res?.message || '生成授权码失败')
|
||
}
|
||
} catch {
|
||
ElMessage.error('生成授权码失败')
|
||
} finally {
|
||
bindCodeDialog.loading = false
|
||
}
|
||
}
|
||
|
||
function copyBindCode() {
|
||
if (!bindCodeDialog.code) {
|
||
ElMessage.warning('暂无可复制的授权码')
|
||
return
|
||
}
|
||
copyText(`授权:${bindCodeDialog.code}`)
|
||
}
|
||
|
||
// ─── 初始化 ───────────────────────────────────────────────────────────────────
|
||
|
||
async function loadStoreOptions() {
|
||
try {
|
||
const res = await loadStores() as any
|
||
if (res?.code === 200 || res?.code === 1 || res?.code === 20000 || res?.flag === 'success') {
|
||
const stores = res?.stores || res?.data?.stores || res?.data || []
|
||
const field = availableFields.find((f: any) => f.value === 'store_id')
|
||
if (field) {
|
||
field.options = stores.map((item: any) => {
|
||
const id = item?.store_id ?? item?.id ?? item?.value
|
||
const name = item?.store_name ?? item?.name ?? item?.label ?? String(id)
|
||
return { label: name, value: id }
|
||
})
|
||
}
|
||
}
|
||
} catch (e) {
|
||
console.error('加载货主列表失败', e)
|
||
}
|
||
}
|
||
|
||
onMounted(() => {
|
||
loadList()
|
||
loadStoreOptions()
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
@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;
|
||
|
||
:deep(.store-detail-pane) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
min-width: 0;
|
||
width: 100%;
|
||
overflow: hidden;
|
||
display: flex;
|
||
flex-direction: column;
|
||
}
|
||
}
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 13px;
|
||
line-height: 1.5;
|
||
max-width: 360px;
|
||
color: #909399;
|
||
}
|
||
|
||
.real-name {
|
||
color: #999;
|
||
font-size: 12px;
|
||
}
|
||
|
||
.wave-operation-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 4px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
// ─── 加群授权码弹窗样式 ────────────────────────────────────────────────────────
|
||
.bind-code-display {
|
||
text-align: center;
|
||
padding: 16px;
|
||
background: #f5f7fa;
|
||
border-radius: 8px;
|
||
border: 1px dashed #dcdfe6;
|
||
}
|
||
|
||
.bind-code-label {
|
||
font-size: 13px;
|
||
color: #909399;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
.bind-code-row {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
gap: 16px;
|
||
}
|
||
|
||
.bind-code-value {
|
||
font-size: 32px;
|
||
font-weight: 700;
|
||
font-family: 'Courier New', Courier, monospace;
|
||
letter-spacing: 6px;
|
||
color: #303133;
|
||
user-select: all;
|
||
}
|
||
|
||
.text-muted {
|
||
color: #c0c4cc;
|
||
}
|
||
|
||
.text-warning {
|
||
color: #e6a23c;
|
||
font-weight: 600;
|
||
}
|
||
|
||
.text-up {
|
||
color: var(--el-color-success);
|
||
font-weight: 600;
|
||
}
|
||
|
||
.text-down {
|
||
color: var(--el-color-danger);
|
||
font-weight: 600;
|
||
}
|
||
|
||
.text-flat {
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
.balance-log-panel {
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
min-height: 0;
|
||
|
||
.balance-log-toolbar {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 8px;
|
||
|
||
&__left {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
}
|
||
|
||
&__meta {
|
||
display: inline-flex;
|
||
gap: 14px;
|
||
color: var(--el-text-color-secondary);
|
||
font-size: 12px;
|
||
}
|
||
}
|
||
|
||
.balance-log-table {
|
||
flex: 1;
|
||
min-height: 0;
|
||
}
|
||
|
||
.balance-log-pagination {
|
||
margin-top: 10px;
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
}
|
||
|
||
.open-account-form-grid {
|
||
.el-row {
|
||
width: 100%;
|
||
}
|
||
.el-form-item {
|
||
margin-bottom: 18px;
|
||
}
|
||
.username-field-row {
|
||
display: flex;
|
||
width: 100%;
|
||
gap: 6px;
|
||
align-items: center;
|
||
}
|
||
}
|
||
|
||
.appkey-cell {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
.appkey-text {
|
||
font-family: monospace;
|
||
font-size: 12px;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
flex: 1;
|
||
}
|
||
}
|
||
|
||
.callback-url-row {
|
||
display: flex;
|
||
width: 100%;
|
||
gap: 8px;
|
||
align-items: flex-start;
|
||
}
|
||
|
||
.appsecret-cell {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
.appsecret-text {
|
||
font-family: monospace;
|
||
font-size: 12px;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
flex: 1;
|
||
}
|
||
}
|
||
}
|
||
|
||
.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;
|
||
}
|
||
|
||
.adjust-balance-display-value {
|
||
font-size: 14px;
|
||
line-height: 32px;
|
||
color: var(--el-text-color-primary);
|
||
}
|
||
|
||
.adjust-balance-number-field {
|
||
width: 100%;
|
||
}
|
||
|
||
.adjust-balance-delta-hint {
|
||
margin-top: 8px;
|
||
font-size: 13px;
|
||
line-height: 1.45;
|
||
|
||
&.is-up {
|
||
color: var(--el-color-success);
|
||
}
|
||
|
||
&.is-down {
|
||
color: var(--el-color-danger);
|
||
}
|
||
|
||
&.is-same {
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
|
||
&.is-neutral {
|
||
color: var(--el-text-color-secondary);
|
||
}
|
||
}
|
||
</style> |