1443 lines
51 KiB
Vue
1443 lines
51 KiB
Vue
<template>
|
||
<div class="order-sub-container" :style="{ height: containerHeight }">
|
||
<scan-box
|
||
ref="scanBox"
|
||
cache-key="storage-stockout"
|
||
width="220px"
|
||
:tree-props="{ children: 'children', label: 'label' }"
|
||
:auto-submit="false"
|
||
:initial-conditions="initialConditions"
|
||
:preset-tree="presetTree"
|
||
:available-fields="availableFieldsRef"
|
||
@condition-change="handleConditionChange"
|
||
@reset="handleConditionReset"
|
||
@condition-clear="handleConditionClear"
|
||
@submit="handleSubmit"
|
||
/>
|
||
|
||
<div class="main-content">
|
||
<div class="toolbar">
|
||
<div class="toolbar-left">
|
||
<order-toolbar-button-group
|
||
:buttons="stockoutToolbarButtons"
|
||
: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="upperTable"
|
||
title="出库单列表"
|
||
default-align="center"
|
||
table-id="storage-stockout-list"
|
||
:enable-column-config="true"
|
||
:data="list"
|
||
:columns="columns"
|
||
:table-size="tableSize"
|
||
:pagination="pagination"
|
||
:show-index="true"
|
||
:show-actions="true"
|
||
:show-selection="true"
|
||
:loading="loading"
|
||
:queryTime="queryTime"
|
||
@current-change="handleRowClick"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
@sort-change="handleSortChange"
|
||
@refresh="loadData"
|
||
@selection-change="onSelectionChange"
|
||
>
|
||
<template #column-order_status="{ row }">
|
||
<span v-if="row.order_status" :class="getStatusTextClass(statusConfig[row.order_status as keyof typeof statusConfig]?.tagType || 'info')">
|
||
{{ statusConfig[row.order_status as keyof typeof statusConfig]?.text || row.order_status }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-sync_status="{ row }">
|
||
<span v-if="row.sync_status" :class="getStatusTextClass(syncStatusConfig[row.sync_status as keyof typeof syncStatusConfig]?.tagType || 'info')">
|
||
{{ syncStatusConfig[row.sync_status as keyof typeof syncStatusConfig]?.text || row.sync_status }}
|
||
</span>
|
||
</template>
|
||
|
||
<template #column-actions="{ row }">
|
||
<el-button
|
||
v-if="row.order_status === 'CREATED' || row.order_status === 'PENDING'"
|
||
type="success"
|
||
link
|
||
size="small"
|
||
:loading="row._stockoutLoading"
|
||
@click.stop="handleSingleRowStockout(row)"
|
||
>
|
||
一键出库
|
||
</el-button>
|
||
<el-button
|
||
v-if="row.order_status === 'CREATED' || row.order_status === 'PENDING'"
|
||
type="primary"
|
||
link
|
||
size="small"
|
||
@click.stop="openToOrderDialog(row)"
|
||
>
|
||
转销售订单
|
||
</el-button>
|
||
<!-- <el-button
|
||
v-if="row.order_status === 'CREATED' || row.order_status === 'PENDING'"
|
||
type="warning"
|
||
link
|
||
size="small"
|
||
@click.stop="openUpdateInfoDialog(row)"
|
||
>
|
||
修改
|
||
</el-button> -->
|
||
<el-button
|
||
v-if="row.order_status === 'CREATED' || row.order_status === 'PENDING'"
|
||
type="danger"
|
||
link
|
||
size="small"
|
||
:loading="row._cancelLoading"
|
||
@click.stop="handleSingleRowCancel(row)"
|
||
>
|
||
取消
|
||
</el-button>
|
||
</template>
|
||
|
||
<template #empty>
|
||
<div class="empty-tip">暂无出库单</div>
|
||
</template>
|
||
</upper-table>
|
||
</div>
|
||
|
||
<template v-if="detailVisible">
|
||
<div
|
||
class="pane-resizer"
|
||
title="拖动调整列表与详情区域高度"
|
||
@mousedown="beginSplitDrag"
|
||
/>
|
||
<div v-if="selectedStockoutId" class="lower-level" :class="tableSize" :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="product" />
|
||
<el-tab-pane label="操作日志" name="logs" />
|
||
</el-tabs>
|
||
</div>
|
||
|
||
<div class="detail-container">
|
||
<KeepAlive>
|
||
<component
|
||
:is="activeComponent"
|
||
:id="selectedStockoutId"
|
||
:row="selectedRow"
|
||
@refresh="loadData"
|
||
/>
|
||
</KeepAlive>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-else class="no-selection" :style="lowerPaneStyle">
|
||
<div class="empty-tip">
|
||
<p>请从上方列表中选择一项查看详情</p>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</div>
|
||
</div>
|
||
|
||
<batch-receiving-print-dialog
|
||
v-model="printDialogVisible"
|
||
:selection-rows="selectionRows"
|
||
business-type="STOCKOUT"
|
||
dialog-title="批量打印出库单"
|
||
queue-no-field="stockout_order_code"
|
||
document-label="出库单"
|
||
:fetch-print-data="fetchPrintData"
|
||
/>
|
||
|
||
<el-dialog
|
||
v-model="toOrderDialogVisible"
|
||
title="转为销售订单"
|
||
width="640px"
|
||
align-center
|
||
append-to-body
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
>
|
||
<div class="to-order-dialog">
|
||
<!-- <el-alert
|
||
type="info"
|
||
:closable="false"
|
||
show-icon
|
||
:title="`将出库单「${toOrderTargetRow?.stockout_order_code || toOrderTargetRow?.id || ''}」转为正式销售订单,转单成功后原出库单将置为已作废。`"
|
||
style="margin-bottom: 16px;"
|
||
/> -->
|
||
|
||
<el-form :model="toOrderForm" label-width="110px">
|
||
<el-form-item label="新订单号">
|
||
<el-input v-model="toOrderForm.delivery_order_code" placeholder="不填自动生成(SK 前缀)" clearable />
|
||
</el-form-item>
|
||
|
||
<el-divider content-position="left">收件人信息(可选)</el-divider>
|
||
|
||
<el-row :gutter="12">
|
||
<el-col :span="12">
|
||
<el-form-item label="姓名">
|
||
<el-input v-model="toOrderForm.receiverInfo.name" placeholder="收件人姓名" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="手机号">
|
||
<el-input v-model="toOrderForm.receiverInfo.mobile" placeholder="手机号" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="12">
|
||
<el-col :span="12">
|
||
<el-form-item label="电话">
|
||
<el-input v-model="toOrderForm.receiverInfo.tel" placeholder="固定电话(可选)" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="邮编">
|
||
<el-input v-model="toOrderForm.receiverInfo.zipCode" placeholder="邮编(可选)" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="12">
|
||
<el-col :span="8">
|
||
<el-form-item label="省份">
|
||
<el-input v-model="toOrderForm.receiverInfo.province" placeholder="省份" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="城市">
|
||
<el-input v-model="toOrderForm.receiverInfo.city" placeholder="城市" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="区县">
|
||
<el-input v-model="toOrderForm.receiverInfo.area" placeholder="区县" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-form-item label="乡镇">
|
||
<el-input v-model="toOrderForm.receiverInfo.town" placeholder="乡镇(可选)" clearable />
|
||
</el-form-item>
|
||
<el-form-item label="详细地址">
|
||
<el-input
|
||
v-model="toOrderForm.receiverInfo.detailAddress"
|
||
type="textarea"
|
||
:rows="2"
|
||
placeholder="详细地址(可选)"
|
||
clearable
|
||
/>
|
||
</el-form-item>
|
||
</el-form>
|
||
</div>
|
||
|
||
<template #footer>
|
||
<el-button @click="toOrderDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="toOrderLoading" @click="handleToOrderSubmit">确认转单</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<el-dialog
|
||
v-model="updateInfoDialogVisible"
|
||
title="修改出库单信息"
|
||
width="680px"
|
||
align-center
|
||
append-to-body
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
>
|
||
<div class="update-info-dialog">
|
||
<!-- <el-alert
|
||
type="info"
|
||
:closable="false"
|
||
show-icon
|
||
:title="`修改出库单「${updateInfoTargetRow?.stockout_order_code || updateInfoTargetRow?.id || ''}」的信息,留空的字段不修改。`"
|
||
style="margin-bottom: 16px;"
|
||
/> -->
|
||
|
||
<el-form :model="updateInfoForm" label-width="100px">
|
||
<el-divider content-position="left">收件人信息</el-divider>
|
||
<el-row :gutter="12">
|
||
<el-col :span="12">
|
||
<el-form-item label="姓名">
|
||
<el-input v-model="updateInfoForm.name" placeholder="收件人姓名" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="手机号">
|
||
<el-input v-model="updateInfoForm.mobile" placeholder="手机号" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="12">
|
||
<el-col :span="12">
|
||
<el-form-item label="电话">
|
||
<el-input v-model="updateInfoForm.tel" placeholder="固定电话(可选)" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="公司">
|
||
<el-input v-model="updateInfoForm.company" placeholder="收件人公司(可选)" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="12">
|
||
<el-col :span="12">
|
||
<el-form-item label="邮箱">
|
||
<el-input v-model="updateInfoForm.email" placeholder="电子邮箱(可选)" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="邮编">
|
||
<el-input v-model="updateInfoForm.zipCode" placeholder="邮编(可选)" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-row :gutter="12">
|
||
<el-col :span="12">
|
||
<el-form-item label="证件号">
|
||
<el-input v-model="updateInfoForm.receiver_id" placeholder="收件人证件号(可选)" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="12">
|
||
<el-form-item label="国家">
|
||
<el-input v-model="updateInfoForm.countryCode" placeholder="国家二字码(可选)" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-divider content-position="left">地址信息</el-divider>
|
||
<el-row :gutter="12">
|
||
<el-col :span="8">
|
||
<el-form-item label="省份">
|
||
<el-input v-model="updateInfoForm.province" placeholder="省份" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="城市">
|
||
<el-input v-model="updateInfoForm.city" placeholder="城市" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
<el-col :span="8">
|
||
<el-form-item label="区县">
|
||
<el-input v-model="updateInfoForm.area" placeholder="区县" clearable />
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-form-item label="乡镇">
|
||
<el-input v-model="updateInfoForm.town" placeholder="镇/街道(可选)" clearable />
|
||
</el-form-item>
|
||
<el-form-item label="详细地址">
|
||
<el-input v-model="updateInfoForm.detailAddress" type="textarea" :rows="2" placeholder="详细地址" clearable />
|
||
</el-form-item>
|
||
|
||
<el-divider content-position="left">快递与平台(可选)</el-divider>
|
||
<el-row :gutter="12">
|
||
<el-col :span="12">
|
||
<el-form-item label="快递">
|
||
<el-select
|
||
v-model="updateInfoForm.express_code"
|
||
placeholder="请选择快递"
|
||
clearable
|
||
filterable
|
||
style="width:100%"
|
||
>
|
||
<el-option
|
||
v-for="opt in updateInfoExpressOptions"
|
||
: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-select
|
||
v-model="updateInfoForm.source_platform_code"
|
||
placeholder="请选择来源平台"
|
||
clearable
|
||
filterable
|
||
style="width:100%"
|
||
@change="handleSourcePlatformChange"
|
||
>
|
||
<el-option
|
||
v-for="opt in updateInfoPlatformOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-col>
|
||
</el-row>
|
||
<el-form-item label="来源平台名称">
|
||
<el-input v-model="updateInfoForm.source_platform_name" placeholder="来源平台名称(自动带出,可修改)" clearable />
|
||
</el-form-item>
|
||
</el-form>
|
||
</div>
|
||
|
||
<template #footer>
|
||
<el-button @click="updateInfoDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="updateInfoLoading" @click="handleUpdateInfoSubmit">保存修改</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
|
||
<el-dialog
|
||
v-model="updateExpressDialogVisible"
|
||
title="更新快递公司与运单号"
|
||
width="520px"
|
||
align-center
|
||
append-to-body
|
||
destroy-on-close
|
||
:close-on-click-modal="false"
|
||
>
|
||
<div class="update-express-dialog">
|
||
<!-- <el-alert
|
||
type="info"
|
||
:closable="false"
|
||
show-icon
|
||
:title="`更新出库单「${updateExpressTargetRow?.stockout_order_code || updateExpressTargetRow?.id || ''}」的运单号。`"
|
||
style="margin-bottom: 16px;"
|
||
/> -->
|
||
<el-form :model="updateExpressForm" label-width="100px">
|
||
<el-form-item label="快递公司">
|
||
<el-select
|
||
v-model="updateExpressForm.express_code"
|
||
placeholder="选择快递公司编码(如 SF/STO/ZT)"
|
||
clearable
|
||
filterable
|
||
allow-create
|
||
default-first-option
|
||
style="width: 100%"
|
||
>
|
||
<el-option
|
||
v-for="opt in updateInfoExpressOptions"
|
||
:key="opt.value"
|
||
:label="opt.label"
|
||
:value="opt.value"
|
||
/>
|
||
</el-select>
|
||
<div class="update-express-tip">传编码即可,后端自动解析快递名称;清空表示置空</div>
|
||
</el-form-item>
|
||
<el-form-item label="运单号">
|
||
<el-input
|
||
v-model="updateExpressForm.waybill_codes"
|
||
type="textarea"
|
||
:rows="3"
|
||
placeholder="支持一单多运单,多个运单号用逗号、分号或换行分隔(可选)"
|
||
/>
|
||
<div class="update-express-tip">清空后提交空数组,将清空原有运单号</div>
|
||
</el-form-item>
|
||
</el-form>
|
||
</div>
|
||
|
||
<template #footer>
|
||
<el-button @click="updateExpressDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" :loading="updateExpressLoading" @click="handleUpdateExpressSubmit">确认更新</el-button>
|
||
</template>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { ref, reactive, onMounted, computed } from 'vue'
|
||
import { useRoute } from 'vue-router'
|
||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||
import ScanBox from '@/components/ScanBox/index.vue'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
import BatchReceivingPrintDialog from '@/components/BatchReceivingPrintDialog.vue'
|
||
import OrderToolbarButtonGroup from '@/views/order/orderManagement/component/OrderToolbarButtonGroup.vue'
|
||
import type { ToolbarButtonConfig } from '@/views/order/orderManagement/config/order-common-config'
|
||
import { getStatusTextClass } from '@/views/order/orderManagement/config/order-common-config'
|
||
import { safeInvoke } from '@/utils/safe-invoke'
|
||
import * as XLSX from 'xlsx'
|
||
import * as indexApi from '@/api/index/index'
|
||
import * as stockoutApi from '@/api/storage.stockout/stockout' //现有的对应API
|
||
import type { StockoutToOrderParams, StockoutUpdateInfoParams, StockoutUpdateExpressParams, StockoutConfirmResponse } from '@/api/storage.stockout/stockout'
|
||
import {
|
||
availableFields,
|
||
entryColums,
|
||
statusConfig,
|
||
syncStatusConfig,
|
||
stockoutToolbarButtons,
|
||
formatStockoutData,
|
||
formatStockoutListItems,
|
||
normalizeStockoutWaybillCodes,
|
||
splitStockoutWaybillCodes,
|
||
isSameStockoutWaybillCodes,
|
||
} from './stockout-config'
|
||
|
||
import stockoutdetail from './component/stockoutdetail.vue'
|
||
import product from './component/product.vue'
|
||
import log from './component/log.vue'
|
||
import { useVerticalSplitPane } from '@/composables/useVerticalSplitPane'
|
||
import { useSettingsStore } from '@/stores/modules/settings'
|
||
|
||
const settingsStore = useSettingsStore()
|
||
const shortcutExpanded = computed(() => settingsStore.shortcutExpanded)
|
||
const containerHeight = computed(() =>
|
||
shortcutExpanded.value ? 'calc(100vh - 150px)' : 'calc(100vh - 100px)'
|
||
)
|
||
|
||
const scanBox = ref<any>(null)
|
||
const upperTable = ref<any>(null)
|
||
|
||
const {
|
||
splitStackRef,
|
||
beginSplitDrag,
|
||
lowerPaneStyle,
|
||
upperPaneStyle
|
||
} = useVerticalSplitPane({ defaultLowerPercent: 40 })
|
||
|
||
const upperPaneFullStyle = computed(() => ({
|
||
flex: '1 1 auto',
|
||
minHeight: '0',
|
||
overflow: 'hidden'
|
||
}))
|
||
|
||
const detailVisible = ref(true)
|
||
|
||
function toggleDetailVisible() {
|
||
detailVisible.value = !detailVisible.value
|
||
}
|
||
|
||
function openColumnConfigPanel() {
|
||
upperTable.value?.openColumnConfig?.()
|
||
}
|
||
|
||
const route = useRoute()
|
||
|
||
// 初始条件(用于 URL 预设)
|
||
const initialConditions = ref<any>(null)
|
||
|
||
// 保存原始条件(可能包含 operator 等信息)
|
||
const currentConditionRaw = ref<any>(null)
|
||
|
||
const presetTree = ref<any[]>([])
|
||
const availableFieldsRef = reactive(JSON.parse(JSON.stringify(availableFields)))
|
||
|
||
const activeTab = ref('details')
|
||
|
||
const list = ref<any[]>([])
|
||
const loading = ref(false)
|
||
const exportLoading = ref(false)
|
||
const queryTime = ref(0)
|
||
|
||
const pagination = reactive({ currentPage: 1, pageSize: 20, total: 0 })
|
||
const tableSize = ref('small')
|
||
const columns = ref(entryColums)
|
||
|
||
const selectionRows = ref<any[]>([])
|
||
const hasSelection = ref(false)
|
||
const selectedStockoutId = ref<number | string | null>(null)
|
||
const printDialogVisible = ref(false)
|
||
|
||
// ── 转销售订单(storage.stockout.toOrder)──
|
||
const toOrderDialogVisible = ref(false)
|
||
const toOrderLoading = ref(false)
|
||
const toOrderTargetRow = ref<any>(null)
|
||
const toOrderForm = reactive({
|
||
delivery_order_code: '',
|
||
receiverInfo: {
|
||
name: '',
|
||
mobile: '',
|
||
tel: '',
|
||
province: '',
|
||
city: '',
|
||
area: '',
|
||
town: '',
|
||
detailAddress: '',
|
||
zipCode: ''
|
||
}
|
||
})
|
||
|
||
function resetToOrderForm() {
|
||
toOrderForm.delivery_order_code = ''
|
||
toOrderForm.receiverInfo = {
|
||
name: '',
|
||
mobile: '',
|
||
tel: '',
|
||
province: '',
|
||
city: '',
|
||
area: '',
|
||
town: '',
|
||
detailAddress: '',
|
||
zipCode: ''
|
||
}
|
||
}
|
||
|
||
function openToOrderDialog(row: any) {
|
||
toOrderTargetRow.value = row
|
||
resetToOrderForm()
|
||
// 回填当前行已有收货信息(storage.stockout.list 的 receiver_* → receiverInfo)
|
||
toOrderForm.receiverInfo.name = String(row?.receiver_name ?? '')
|
||
toOrderForm.receiverInfo.mobile = String(row?.receiver_mobile ?? '')
|
||
toOrderForm.receiverInfo.tel = String(row?.receiver_tel ?? '')
|
||
toOrderForm.receiverInfo.zipCode = String(row?.receiver_zip_code ?? '')
|
||
toOrderForm.receiverInfo.province = String(row?.receiver_province ?? '')
|
||
toOrderForm.receiverInfo.city = String(row?.receiver_city ?? '')
|
||
toOrderForm.receiverInfo.area = String(row?.receiver_area ?? '')
|
||
toOrderForm.receiverInfo.town = String(row?.receiver_town ?? '')
|
||
toOrderForm.receiverInfo.detailAddress = String(row?.receiver_detail_address ?? '')
|
||
toOrderDialogVisible.value = true
|
||
}
|
||
|
||
async function handleToOrderSubmit() {
|
||
const row = toOrderTargetRow.value
|
||
if (!row) return
|
||
|
||
const receiverInfo = toOrderForm.receiverInfo
|
||
const hasReceiver = Object.values(receiverInfo).some((v) => String(v || '').trim() !== '')
|
||
const payload: StockoutToOrderParams = { id: row.id }
|
||
const orderCode = toOrderForm.delivery_order_code.trim()
|
||
if (orderCode) payload.delivery_order_code = orderCode
|
||
if (hasReceiver) {
|
||
payload.receiverInfo = {}
|
||
for (const [k, v] of Object.entries(receiverInfo)) {
|
||
if (String(v || '').trim() !== '') {
|
||
;(payload.receiverInfo as Record<string, string>)[k] = v
|
||
}
|
||
}
|
||
}
|
||
|
||
toOrderLoading.value = true
|
||
try {
|
||
const res: any = await stockoutApi.stockoutToOrder(payload)
|
||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
|
||
const data = res?.data || res
|
||
const orderCodeText = data?.delivery_order_code || payload.delivery_order_code || ''
|
||
ElMessage.success(orderCodeText ? `转单成功,新订单号:${orderCodeText}` : '转单成功')
|
||
toOrderDialogVisible.value = false
|
||
loadData()
|
||
} else {
|
||
ElMessage.error(res?.message || '转单失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '转单失败')
|
||
} finally {
|
||
toOrderLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ── 修改出库单信息(storage.stockout.updateInfo)──
|
||
const updateInfoDialogVisible = ref(false)
|
||
const updateInfoLoading = ref(false)
|
||
const updateInfoTargetRow = ref<any>(null)
|
||
const updateInfoForm = reactive({
|
||
name: '',
|
||
tel: '',
|
||
mobile: '',
|
||
company: '',
|
||
email: '',
|
||
zipCode: '',
|
||
countryCode: '',
|
||
province: '',
|
||
city: '',
|
||
area: '',
|
||
town: '',
|
||
detailAddress: '',
|
||
receiver_id: '',
|
||
express_code: '',
|
||
source_platform_code: '',
|
||
source_platform_name: ''
|
||
})
|
||
|
||
function resetUpdateInfoForm() {
|
||
updateInfoForm.name = ''
|
||
updateInfoForm.tel = ''
|
||
updateInfoForm.mobile = ''
|
||
updateInfoForm.company = ''
|
||
updateInfoForm.email = ''
|
||
updateInfoForm.zipCode = ''
|
||
updateInfoForm.countryCode = ''
|
||
updateInfoForm.province = ''
|
||
updateInfoForm.city = ''
|
||
updateInfoForm.area = ''
|
||
updateInfoForm.town = ''
|
||
updateInfoForm.detailAddress = ''
|
||
updateInfoForm.receiver_id = ''
|
||
updateInfoForm.express_code = ''
|
||
updateInfoForm.source_platform_code = ''
|
||
updateInfoForm.source_platform_name = ''
|
||
}
|
||
|
||
function openUpdateInfoDialog(row: any) {
|
||
updateInfoTargetRow.value = row
|
||
resetUpdateInfoForm()
|
||
// 回填当前行已有数据(列表字段 receiver_* → 表单字段)
|
||
updateInfoForm.name = String(row?.receiver_name ?? '')
|
||
updateInfoForm.tel = String(row?.receiver_tel ?? '')
|
||
updateInfoForm.mobile = String(row?.receiver_mobile ?? '')
|
||
updateInfoForm.company = String(row?.receiver_company ?? '')
|
||
updateInfoForm.email = String(row?.receiver_email ?? '')
|
||
updateInfoForm.zipCode = String(row?.receiver_zip_code ?? '')
|
||
updateInfoForm.countryCode = String(row?.receiver_country_code ?? '')
|
||
updateInfoForm.province = String(row?.receiver_province ?? '')
|
||
updateInfoForm.city = String(row?.receiver_city ?? '')
|
||
updateInfoForm.area = String(row?.receiver_area ?? '')
|
||
updateInfoForm.town = String(row?.receiver_town ?? '')
|
||
updateInfoForm.detailAddress = String(row?.receiver_detail_address ?? '')
|
||
updateInfoForm.receiver_id = String(row?.receiver_id ?? '')
|
||
updateInfoForm.express_code = String(row?.express_code ?? '')
|
||
updateInfoForm.source_platform_code = String(row?.source_platform_code ?? '')
|
||
updateInfoForm.source_platform_name = String(row?.source_platform_name ?? '')
|
||
// 加载快递/平台下拉选项(后端编码列表),回填值自动选中对应编码选项
|
||
void loadUpdateInfoSelectOptions()
|
||
updateInfoDialogVisible.value = true
|
||
}
|
||
|
||
// ── 修改出库单信息下拉选项(快递 / 来源平台)──
|
||
const updateInfoExpressOptions = ref<Array<{ label: string; value: string }>>([])
|
||
const updateInfoPlatformOptions = ref<Array<{ label: string; value: string }>>([])
|
||
|
||
async function loadUpdateInfoSelectOptions() {
|
||
try {
|
||
const [expressRes, platformRes]: any = await Promise.all([
|
||
indexApi.getExpressList({ systemOnly: 'true' }),
|
||
indexApi.getPlatformList({ systemOnly: 'true' })
|
||
])
|
||
const expressRaw = expressRes?.data?.list || expressRes?.data || []
|
||
updateInfoExpressOptions.value = (Array.isArray(expressRaw) ? expressRaw : [])
|
||
.map((item: any) => {
|
||
const code = String(item?.express_code || item?.code || item?.express?.code || '').trim()
|
||
const name = String(item?.name || item?.express_name || item?.express?.name || '').trim()
|
||
return { value: code, label: name ? `${code} - ${name}` : code }
|
||
})
|
||
.filter((o) => !!o.value)
|
||
const platformRaw = platformRes?.data?.list || platformRes?.data || []
|
||
updateInfoPlatformOptions.value = (Array.isArray(platformRaw) ? platformRaw : [])
|
||
.map((item: any) => {
|
||
const code = String(item?.code || item?.platform_code || '').trim()
|
||
const name = String(item?.name || item?.platform_name || '').trim()
|
||
return { value: code, label: name ? `${code} - ${name}` : code }
|
||
})
|
||
.filter((o) => !!o.value)
|
||
} catch {
|
||
updateInfoExpressOptions.value = []
|
||
updateInfoPlatformOptions.value = []
|
||
}
|
||
}
|
||
|
||
/** 选中来源平台编码时自动带出平台名称 */
|
||
function handleSourcePlatformChange(val: string) {
|
||
if (!val) return
|
||
const opt = updateInfoPlatformOptions.value.find((o) => o.value === val)
|
||
if (opt) {
|
||
const sep = opt.label.indexOf(' - ')
|
||
updateInfoForm.source_platform_name = sep > -1 ? opt.label.slice(sep + 3) : opt.label
|
||
}
|
||
}
|
||
|
||
async function handleUpdateInfoSubmit() {
|
||
const row = updateInfoTargetRow.value
|
||
if (!row) return
|
||
|
||
// 只提交非空字段(未传入的字段后端不修改)
|
||
const payload: StockoutUpdateInfoParams = { id: row.id }
|
||
for (const [k, v] of Object.entries(updateInfoForm)) {
|
||
if (String(v || '').trim() !== '') {
|
||
;(payload as Record<string, any>)[k] = v
|
||
}
|
||
}
|
||
|
||
updateInfoLoading.value = true
|
||
try {
|
||
const res: any = await stockoutApi.stockoutUpdateInfo(payload)
|
||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
|
||
ElMessage.success('出库单信息修改成功')
|
||
updateInfoDialogVisible.value = false
|
||
loadData()
|
||
} else {
|
||
ElMessage.error(res?.message || '修改失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '修改失败')
|
||
} finally {
|
||
updateInfoLoading.value = false
|
||
}
|
||
}
|
||
|
||
/** 单行取消出库单(storage.stockout.cancel) */
|
||
async function handleSingleRowCancel(row: any) {
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定要取消出库单「${row.stockout_order_code || row.id}」吗?取消后将释放库存锁定。`,
|
||
'取消出库单',
|
||
{ type: 'warning', confirmButtonText: '确认取消', cancelButtonText: '返回' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
row._cancelLoading = true
|
||
try {
|
||
const res: any = await stockoutApi.stockoutCancel({ id: row.id })
|
||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
|
||
ElMessage.success('出库单已取消')
|
||
loadData()
|
||
} else {
|
||
ElMessage.error(res?.message || '取消失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '取消失败')
|
||
} finally {
|
||
row._cancelLoading = false
|
||
}
|
||
}
|
||
|
||
// ── 更新快递公司与运单号(storage.stockout.updateExpress)──
|
||
const updateExpressDialogVisible = ref(false)
|
||
const updateExpressLoading = ref(false)
|
||
const updateExpressTargetRow = ref<any>(null)
|
||
const updateExpressForm = reactive({
|
||
/** 快递公司编码(express_code,非运单号) */
|
||
express_code: '',
|
||
/** 运单号多行文本,提交时拆分为 waybill_codes 数组 */
|
||
waybill_codes: ''
|
||
})
|
||
|
||
function openUpdateExpressDialog() {
|
||
const rows = selectionRows.value
|
||
if (!rows.length) {
|
||
ElMessage.warning('请先选择要更新运单号的出库单')
|
||
return
|
||
}
|
||
if (rows.length > 1) {
|
||
ElMessage.warning('请选择单个出库单更新运单号')
|
||
return
|
||
}
|
||
const row = rows[0]
|
||
updateExpressTargetRow.value = row
|
||
// 快递公司编码回填;运单号以 waybill_codes 为准(兼容单数 waybill_code)
|
||
updateExpressForm.express_code = String(row?.express_code ?? '')
|
||
updateExpressForm.waybill_codes = normalizeStockoutWaybillCodes(row).join('\n')
|
||
if (!updateInfoExpressOptions.value.length) void loadUpdateInfoSelectOptions()
|
||
updateExpressDialogVisible.value = true
|
||
}
|
||
|
||
async function handleUpdateExpressSubmit() {
|
||
const row = updateExpressTargetRow.value
|
||
if (!row) return
|
||
|
||
// 未传入的字段不会被更新;与原值不同才提交(空值表示清空)
|
||
const payload: StockoutUpdateExpressParams = { id: Number(row.id) }
|
||
let changed = false
|
||
|
||
const expressCode = updateExpressForm.express_code.trim()
|
||
if (expressCode !== String(row?.express_code ?? '').trim()) {
|
||
payload.express_code = expressCode
|
||
changed = true
|
||
}
|
||
|
||
// 运单号统一提交 waybill_codes 数组(非数组会 400);空数组表示清空
|
||
const waybillCodes = [...new Set(splitStockoutWaybillCodes(updateExpressForm.waybill_codes))]
|
||
if (!isSameStockoutWaybillCodes(waybillCodes, normalizeStockoutWaybillCodes(row))) {
|
||
payload.waybill_codes = waybillCodes
|
||
changed = true
|
||
}
|
||
|
||
if (!changed) {
|
||
ElMessage.warning('没有需要更新的字段')
|
||
return
|
||
}
|
||
|
||
updateExpressLoading.value = true
|
||
try {
|
||
const res: any = await stockoutApi.stockoutUpdateExpress(payload)
|
||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
|
||
const data = res.data ?? res
|
||
const expressName = String(data?.express_name ?? '').trim()
|
||
const codeCount = Array.isArray(data?.waybill_codes) ? data.waybill_codes.length : 0
|
||
ElMessage.success(
|
||
`更新成功${expressName ? `:${expressName}` : ''}${codeCount ? `(${codeCount} 个运单号)` : ''}`
|
||
)
|
||
updateExpressDialogVisible.value = false
|
||
loadData()
|
||
} else {
|
||
ElMessage.error(res?.message || '更新失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '更新失败')
|
||
} finally {
|
||
updateExpressLoading.value = false
|
||
}
|
||
}
|
||
|
||
// ── 工具栏状态 ──
|
||
const buttonLoadingMap = computed(() => ({
|
||
loading: loading.value,
|
||
exportLoading: exportLoading.value
|
||
}))
|
||
|
||
const buttonDisabledMap = computed(() => ({
|
||
hasNoSelection: !hasSelection.value
|
||
}))
|
||
|
||
const buttonLabelMap = computed(() => ({
|
||
detailToggleLabel: detailVisible.value ? '隐藏详情' : '显示详情'
|
||
}))
|
||
|
||
const toolbarLayoutKey = computed(() =>
|
||
JSON.stringify({
|
||
loading: buttonLoadingMap.value,
|
||
disabled: buttonDisabledMap.value,
|
||
labels: buttonLabelMap.value
|
||
})
|
||
)
|
||
|
||
function resolveButtonLoading(loadingKey?: string) {
|
||
if (!loadingKey) return false
|
||
return Boolean((buttonLoadingMap.value as Record<string, boolean>)[loadingKey])
|
||
}
|
||
|
||
function resolveButtonDisabled(disabledKey?: string) {
|
||
if (!disabledKey) return false
|
||
return Boolean((buttonDisabledMap.value as Record<string, boolean>)[disabledKey])
|
||
}
|
||
|
||
function resolveButtonLabel(defaultLabel: string, dynamicLabelKey?: string) {
|
||
if (!dynamicLabelKey) return defaultLabel
|
||
return (buttonLabelMap.value as Record<string, string>)[dynamicLabelKey] || defaultLabel
|
||
}
|
||
|
||
const toolbarActionMap: Record<string, () => void> = {
|
||
loadData: () => { void loadData() },
|
||
handleExportWaybill: () => { void handleExport('waybill') },
|
||
handleExportItem: () => { void handleExport('item') },
|
||
openColumnConfigPanel: () => openColumnConfigPanel(),
|
||
toggleDetailVisible: () => toggleDetailVisible(),
|
||
handleCreateStockout: () => handleCreateStockout(),
|
||
handleImport: () => handleImport(),
|
||
handleUpdateExpress: () => openUpdateExpressDialog(),
|
||
handleOpenPrintDialog: () => { void handleOpenPrintDialog() },
|
||
confirmBatchCancel: () => { void confirmBatchCancel() }
|
||
}
|
||
|
||
function handleToolbarButtonClick(action: ToolbarButtonConfig['action']) {
|
||
const handler = toolbarActionMap[action]
|
||
if (!handler) return
|
||
safeInvoke(() => handler())
|
||
}
|
||
|
||
const quickSearch = ref('')
|
||
const currentSort = reactive({ prop: '', order: '' })
|
||
const currentCondition = ref<any>(null)
|
||
|
||
const componentMap: Record<string, any> = {
|
||
details: stockoutdetail,
|
||
product: product,
|
||
logs: log
|
||
}
|
||
|
||
const activeComponent = computed(() => componentMap[activeTab.value] || componentMap.details)
|
||
|
||
const selectedRow = computed(() => {
|
||
return list.value.find((i: any) => i.id === selectedStockoutId.value) || null
|
||
})
|
||
|
||
onMounted(() => {
|
||
// 先加载筛选相关数据,保证 ScanBox 的选项可用
|
||
loadFilterData()
|
||
|
||
// 支持从 URL 预设筛选(例如 ?id=xxx 或 ?delivery_order_code=xxx 或 ?q=xxx)
|
||
const idParam = route.query.id || route.query.delivery_order_code || route.query.q
|
||
const id = Array.isArray(idParam) ? idParam[0] : idParam
|
||
if (id) {
|
||
// 与 receiving 页面一致,设置 ScanBox 的初始条件用于在 UI 中显示
|
||
initialConditions.value = {
|
||
type: 'custom',
|
||
conditions: {
|
||
delivery_order_code: { value: String(id), operator: 'eq', field: 'delivery_order_code', type: 'text' }
|
||
}
|
||
}
|
||
|
||
// 使用包含 operator 的完整条件触发搜索,避免丢失操作符
|
||
handleConditionChange(initialConditions.value)
|
||
} else {
|
||
loadData()
|
||
}
|
||
})
|
||
|
||
async function loadData() {
|
||
if (loading.value) return
|
||
loading.value = true
|
||
const start = Date.now()
|
||
try {
|
||
// 优先使用由 ScanBox 提交并经过规范化的条件(包含 operator 等信息)
|
||
const where = currentCondition.value || {}
|
||
const params: any = {
|
||
pagination: { page: pagination.currentPage, pageSize: pagination.pageSize },
|
||
where,
|
||
sort: currentSort.prop ? { sortField: currentSort.prop, sortOrder: currentSort.order === 'ascending' ? 'ASC' : 'DESC' } : undefined
|
||
}
|
||
|
||
if (quickSearch.value) {
|
||
params.where = { ...(params.where || {}), delivery_order_code: quickSearch.value }
|
||
}
|
||
|
||
const res: any = await stockoutApi.stockoutList(params)
|
||
if (res && (res.code === 200 || res.code === 1 || res.flag === 'success')) {
|
||
const data = res.data || res
|
||
list.value = formatStockoutData(data.list || [])
|
||
pagination.currentPage = data.pagination?.page || data.pagination?.currentPage || pagination.currentPage
|
||
pagination.pageSize = data.pagination?.pageSize || pagination.pageSize
|
||
pagination.total = data.pagination?.total || 0
|
||
} else {
|
||
ElMessage.error(res?.message || '加载失败')
|
||
}
|
||
} catch (e) {
|
||
console.error(e)
|
||
ElMessage.error('加载出库单失败')
|
||
} finally {
|
||
loading.value = false
|
||
queryTime.value = Date.now() - start
|
||
}
|
||
}
|
||
|
||
async function loadFilterData() {
|
||
try {
|
||
// 与 receiving 页面一致,按业务类型加载 store 列表和 presetTree,避免 ScanBox options 不匹配
|
||
const [storesRes, presetRes]: any = await Promise.all([
|
||
indexApi.loadStores(),
|
||
indexApi.fastWhereTree('stockout')
|
||
])
|
||
if (storesRes && storesRes.code === 200) {
|
||
const f = availableFieldsRef.find((i: any) => i.value === 'store_id')
|
||
if (f) f.options = storesRes.stores || []
|
||
}
|
||
if (presetRes && presetRes.code === 200) {
|
||
presetTree.value = presetRes.presetTree || []
|
||
}
|
||
} catch (e) {
|
||
console.error('加载筛选配置失败', e)
|
||
}
|
||
}
|
||
|
||
function handleConditionChange(condition: any) {
|
||
// 保存原始条件
|
||
currentConditionRaw.value = condition
|
||
|
||
// 将条件规范化为后端期望结构:{ operator, value, type }
|
||
currentCondition.value = normalizeToWhere(condition)
|
||
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleSortChange({ prop, order }: any) {
|
||
currentSort.prop = prop
|
||
currentSort.order = order
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleSubmit() {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
const handleConditionClear = () => {
|
||
currentConditionRaw.value = null
|
||
currentCondition.value = null
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleConditionReset() {
|
||
currentConditionRaw.value = null
|
||
currentCondition.value = null
|
||
pagination.currentPage = 1
|
||
if (scanBox.value?.reset) {
|
||
scanBox.value.reset()
|
||
} else if (scanBox.value?.clear) {
|
||
scanBox.value.clear()
|
||
}
|
||
loadData()
|
||
}
|
||
|
||
function onSelectionChange(rows: any[]) {
|
||
selectionRows.value = rows || []
|
||
hasSelection.value = selectionRows.value.length > 0
|
||
}
|
||
|
||
// ── 打印出库单 ──
|
||
async function handleOpenPrintDialog() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先选择要打印的出库单')
|
||
return
|
||
}
|
||
|
||
// 仅“已完成”状态的出库单可打印
|
||
const invalidRows = selectionRows.value.filter(
|
||
row => String(row.order_status || '').toUpperCase() !== 'COMPLETED'
|
||
)
|
||
if (invalidRows.length > 0) {
|
||
ElMessage.warning(`只有“已完成”状态的单据才能打印。当前选中包含 ${invalidRows.length} 个非已完成单据。`)
|
||
return
|
||
}
|
||
|
||
printDialogVisible.value = true
|
||
}
|
||
|
||
async function fetchPrintData(row: any, _index: number) {
|
||
// 打印时间:打开打印对话框时生成
|
||
const now = new Date()
|
||
const pad = (n: number) => String(n).padStart(2, '0')
|
||
const nowStr = `${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(now.getMinutes())}:${pad(now.getSeconds())}`
|
||
|
||
// 运单号:以 waybill_codes(复数)为准,兼容单数 waybill_code 与已废弃的 express_codes
|
||
const waybillCodes = normalizeStockoutWaybillCodes(row, { includeLegacy: true })
|
||
|
||
// 单据头:优先对齐出库单A5模板字段名(field_code),兼容列表字段名与 order 字段名
|
||
const formData: any = {
|
||
// 模板字段(供 getPreviewValue 按 field_code 取用)
|
||
delivery_order_code: row.stockout_order_code || row.delivery_order_code || '',
|
||
name: row.receiver_name || row.name || '',
|
||
mobile: row.receiver_mobile || row.mobile || '',
|
||
province: row.receiver_province || row.province || '',
|
||
city: row.receiver_city || row.city || '',
|
||
area: row.receiver_area || row.area || '',
|
||
detail_address: row.receiver_detail_address ?? row.detail_address ?? row.detailAddress ?? '',
|
||
logistics_name: row.express_name || row.logistics_name || '',
|
||
wave_no: row.wave_no || '',
|
||
create_at: row.created_at || row.create_at || '',
|
||
print_time: nowStr,
|
||
remark: row.remark || '',
|
||
// 其余单据信息
|
||
stockout_order_code: row.stockout_order_code || '',
|
||
express_code: row.express_code || '',
|
||
// 运单号:模板字段名 express_codes 保留以兼容旧模板,取值以 waybill_codes 口径为准
|
||
express_codes: waybillCodes.join(','),
|
||
waybill_code: waybillCodes[0] || '',
|
||
waybill_codes: waybillCodes.join(','),
|
||
order_type: row.order_type || '',
|
||
source_type: row.source_type || '',
|
||
order_status: row.order_status || '',
|
||
sync_status: row.sync_status || '',
|
||
store_name: row.store_name || row['store.remask'] || row['store.store_remask'] || '',
|
||
total_order_lines: row.total_order_lines ?? '',
|
||
order_create_time: row.order_create_time || '',
|
||
created_at: row.created_at || '',
|
||
updated_at: row.updated_at || '',
|
||
details: []
|
||
}
|
||
|
||
try {
|
||
const res: any = await stockoutApi.stockoutListItems({ id: Number(row.id) })
|
||
if (res && (res.code === 200 || res.code === 1 || res.flag === 'success')) {
|
||
const payload = res.data || res
|
||
const order = payload.order || {}
|
||
const orderWaybillCodes = order && Object.keys(order).length
|
||
? normalizeStockoutWaybillCodes(order, { includeLegacy: true })
|
||
: []
|
||
const rows = Array.isArray(payload.list)
|
||
? payload.list
|
||
: Array.isArray(payload.items)
|
||
? payload.items
|
||
: []
|
||
formData.details = formatStockoutListItems(rows)
|
||
|
||
// 从 order 中取值:优先模板字段名,兼容列表字段名;取不到保留列表行值
|
||
const pick = (keys: string[], fallback: any) => {
|
||
for (const k of keys) {
|
||
if (order[k] !== undefined && order[k] !== null && String(order[k]).trim() !== '') return order[k]
|
||
}
|
||
return fallback
|
||
}
|
||
Object.assign(formData, {
|
||
delivery_order_code: pick(['delivery_order_code', 'stockout_order_code'], formData.delivery_order_code),
|
||
name: pick(['name', 'receiver_name'], formData.name),
|
||
mobile: pick(['mobile', 'receiver_mobile'], formData.mobile),
|
||
province: pick(['province', 'receiver_province'], formData.province),
|
||
city: pick(['city', 'receiver_city'], formData.city),
|
||
area: pick(['area', 'receiver_area'], formData.area),
|
||
detail_address: pick(['detail_address', 'detailAddress', 'receiver_detail_address', 'receiver_detail'], formData.detail_address),
|
||
logistics_name: pick(['logistics_name', 'express_name'], formData.logistics_name),
|
||
wave_no: pick(['wave_no'], formData.wave_no),
|
||
create_at: pick(['create_at', 'created_at'], formData.create_at),
|
||
stockout_order_code: order.stockout_order_code || formData.stockout_order_code,
|
||
express_code: order.express_code ?? formData.express_code,
|
||
express_codes: orderWaybillCodes.length ? orderWaybillCodes.join(',') : formData.express_codes,
|
||
waybill_code: orderWaybillCodes[0] || formData.waybill_code,
|
||
waybill_codes: orderWaybillCodes.length ? orderWaybillCodes.join(',') : formData.waybill_codes,
|
||
order_type: order.order_type ?? formData.order_type,
|
||
source_type: order.source_type ?? formData.source_type,
|
||
order_status: order.order_status ?? formData.order_status,
|
||
store_name: order.store_name ?? formData.store_name,
|
||
total_order_lines: order.total_order_lines ?? formData.total_order_lines,
|
||
remark: order.remark ?? formData.remark,
|
||
order_create_time: order.order_create_time ?? formData.order_create_time
|
||
})
|
||
}
|
||
} catch (e) {
|
||
console.error('加载出库单打印明细失败', e)
|
||
}
|
||
|
||
return formData
|
||
}
|
||
|
||
// 将 scan-box 返回的条件标准化为后端推荐结构:{ operator, value, type }
|
||
function normalizeToWhere(condition: any) {
|
||
if (!condition) return {}
|
||
|
||
// 如果是字符串或简单值,默认映射为单号模糊查询(出库单号为 delivery_order_code)
|
||
if (typeof condition === 'string' || typeof condition === 'number') {
|
||
return { delivery_order_code: { operator: 'like', value: condition, type: 'text' } }
|
||
}
|
||
|
||
const getFieldConfig = (key: string) => {
|
||
return availableFields.find((f: any) => f.value === key)
|
||
}
|
||
|
||
const mapType = (type: string, value: any) => {
|
||
if (type === 'daterange' || Array.isArray(value)) return 'daterange'
|
||
if (type === 'number' || typeof value === 'number') return 'number'
|
||
if (type === 'boolean' || typeof value === 'boolean') return 'boolean'
|
||
return 'text'
|
||
}
|
||
|
||
const processConditionValue = (k: string, c: any) => {
|
||
const config = getFieldConfig(k)
|
||
const fieldType = config?.type || 'text'
|
||
|
||
if (c && typeof c === 'object' && !Array.isArray(c)) {
|
||
if ('operator' in c || 'value' in c || 'type' in c) {
|
||
return {
|
||
operator: c.operator || (Array.isArray(c.value) ? 'in' : (fieldType === 'daterange' ? 'between' : 'eq')),
|
||
value: c.value,
|
||
type: c.type || mapType(fieldType, c.value)
|
||
}
|
||
}
|
||
}
|
||
|
||
if (c === null || c === undefined || c === '' || (Array.isArray(c) && c.length === 0)) return null
|
||
|
||
const simpleOp = fieldType === 'daterange' ? 'between' : 'eq'
|
||
const simpleType = mapType(fieldType, c)
|
||
return { operator: simpleOp, value: c, type: simpleType }
|
||
}
|
||
|
||
if (condition.conditions && typeof condition.conditions === 'object') {
|
||
const where: any = {}
|
||
Object.keys(condition.conditions).forEach(k => {
|
||
const result = processConditionValue(k, condition.conditions[k])
|
||
if (result) where[k] = result
|
||
})
|
||
return where
|
||
}
|
||
|
||
if (typeof condition === 'object') {
|
||
const where: any = {}
|
||
Object.keys(condition).forEach(k => {
|
||
const result = processConditionValue(k, condition[k])
|
||
if (result) where[k] = result
|
||
})
|
||
return where
|
||
}
|
||
|
||
return {}
|
||
}
|
||
|
||
async function handleRowClick(row: any) {
|
||
selectedStockoutId.value = row?.id || null
|
||
}
|
||
|
||
function handlePageChange(page: number) {
|
||
pagination.currentPage = page
|
||
loadData()
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pagination.pageSize = size
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function onQuickSearch() {
|
||
pagination.currentPage = 1
|
||
loadData()
|
||
}
|
||
|
||
function handleCreateStockout() {
|
||
ElMessage.info('新建出库单功能')
|
||
}
|
||
|
||
/** 单行一键出库 */
|
||
async function handleSingleRowStockout(row: any) {
|
||
try {
|
||
await ElMessageBox.confirm(
|
||
`确定要一键出库出库单「${row.stockout_order_code || row.id}」吗?确认后状态将变更为"已完成"。请确保已填写运单号。`,
|
||
'一键出库',
|
||
{ type: 'warning', confirmButtonText: '确认', cancelButtonText: '取消' }
|
||
)
|
||
} catch {
|
||
return
|
||
}
|
||
|
||
row._stockoutLoading = true
|
||
try {
|
||
const res: any = await stockoutApi.stockoutConfirm({ id: row.id })
|
||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
|
||
const data: StockoutConfirmResponse = res?.data || res
|
||
// expressCode 是快递公司编码(历史遗留命名,不是运单号)
|
||
if (data?.expressCode) row.express_code = data.expressCode
|
||
if (data?.order_status) row.order_status = data.order_status
|
||
// expressCodes 已废弃(取自已废弃列 express_codes,通常为 null),运单号以 waybill_codes 为准,不再回写
|
||
// qimenSync 为外部回传结果:确认本身已成功(状态已推进 COMPLETED),回传失败仅提示,可由后端重试
|
||
if (String(data?.qimenSync ?? '').toLowerCase() === 'failure') {
|
||
ElMessage.warning(
|
||
`出库已确认,但外部回传失败:${data?.qimenSyncMessage || '未知原因'}(状态已变更为已完成,可稍后重试回传)`
|
||
)
|
||
} else {
|
||
ElMessage.success('出库成功')
|
||
}
|
||
loadData()
|
||
} else {
|
||
ElMessage.error(res?.message || '出库失败')
|
||
}
|
||
} catch (e: any) {
|
||
ElMessage.error(e?.message || '出库失败')
|
||
} finally {
|
||
row._stockoutLoading = false
|
||
}
|
||
}
|
||
|
||
async function confirmBatchCancel() {
|
||
if (!selectionRows.value.length) {
|
||
ElMessage.warning('请先选择要作废的出库单')
|
||
return
|
||
}
|
||
try {
|
||
await ElMessageBox.confirm(`确定要批量作废 ${selectionRows.value.length} 个出库单吗?`, '确认', { type: 'warning' })
|
||
let successCount = 0
|
||
let failCount = 0
|
||
for (const row of selectionRows.value) {
|
||
try {
|
||
const res: any = await stockoutApi.stockoutCancel({ id: row.id })
|
||
if (res && (res.code === 1 || res.code === 200 || res.code === 20000 || res.flag === 'success')) {
|
||
successCount += 1
|
||
} else {
|
||
failCount += 1
|
||
}
|
||
} catch {
|
||
failCount += 1
|
||
}
|
||
}
|
||
ElMessage.success(`批量作废完成:成功 ${successCount} 条${failCount ? `,失败 ${failCount} 条` : ''}`)
|
||
loadData()
|
||
} catch (e) {}
|
||
}
|
||
|
||
async function handleExport(mode: 'waybill' | 'item' = 'waybill') {
|
||
const sourceRows = selectionRows.value.length ? selectionRows.value : list.value
|
||
if (!sourceRows.length) {
|
||
ElMessage.warning('当前无数据可导出')
|
||
return
|
||
}
|
||
exportLoading.value = true
|
||
try {
|
||
const exportColumns = columns.value.filter((col: any) => col.prop && col.label)
|
||
|
||
if (mode === 'waybill') {
|
||
const headers = exportColumns.map((col: any) => col.label)
|
||
const data = sourceRows.map((row: any) =>
|
||
exportColumns.map((col: any) => {
|
||
const val = row[col.prop]
|
||
if (col.prop === 'order_status') {
|
||
return statusConfig[val as keyof typeof statusConfig]?.text || val || ''
|
||
}
|
||
if (col.prop === 'sync_status') {
|
||
return syncStatusConfig[val as keyof typeof syncStatusConfig]?.text || val || ''
|
||
}
|
||
return val === null || val === undefined ? '' : val
|
||
})
|
||
)
|
||
const ws = XLSX.utils.aoa_to_sheet([headers, ...data])
|
||
const wb = XLSX.utils.book_new()
|
||
XLSX.utils.book_append_sheet(wb, ws, '出库单列表')
|
||
XLSX.writeFile(wb, `出库单列表_${Date.now()}.xlsx`)
|
||
ElMessage.success('导出成功')
|
||
return
|
||
}
|
||
|
||
const detailRows: any[] = []
|
||
for (const row of sourceRows) {
|
||
try {
|
||
const res: any = await stockoutApi.stockoutListItems({ id: row.id })
|
||
const items = res?.data?.list || res?.list || res?.data || []
|
||
const listData = Array.isArray(items) ? items : []
|
||
listData.forEach((item: any) => {
|
||
detailRows.push({
|
||
'出库单号': row.stockout_order_code || row.id,
|
||
'商品编码': item.item_code || item.product_code || '',
|
||
'商品名称': item.item_name || item.product_name || '',
|
||
'计划数量': item.plan_qty ?? item.quantity ?? '',
|
||
'实发数量': item.actual_qty ?? item.shipped_qty ?? '',
|
||
'库位': item.space_id || item.space_name || '',
|
||
'备注': item.remark || ''
|
||
})
|
||
})
|
||
} catch (e) {
|
||
console.warn(`获取出库单 ${row.id} 明细失败`, e)
|
||
}
|
||
}
|
||
|
||
if (!detailRows.length) {
|
||
ElMessage.warning('未获取到可导出的出库明细')
|
||
return
|
||
}
|
||
|
||
const ws = XLSX.utils.json_to_sheet(detailRows)
|
||
const wb = XLSX.utils.book_new()
|
||
XLSX.utils.book_append_sheet(wb, ws, '出库明细')
|
||
XLSX.writeFile(wb, `出库明细_${Date.now()}.xlsx`)
|
||
ElMessage.success('导出成功')
|
||
} catch (e) {
|
||
console.error('导出失败:', e)
|
||
ElMessage.error('导出失败')
|
||
} finally {
|
||
exportLoading.value = false
|
||
}
|
||
}
|
||
|
||
function handleExportAction(action: string) {
|
||
void handleExport(action === 'handleExportItem' ? 'item' : 'waybill')
|
||
}
|
||
|
||
function handleImport() {
|
||
ElMessage.info('导入功能')
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
@use "../../order/orderManagement/styles/order-sub.scss";
|
||
|
||
/* 详情区外壳与 stock/external_stock 保持一致:不留上/下间距(各详情组件自带
|
||
padding: 6px 10px 8px),只保留左右 10px,避免与组件内边距叠加 */
|
||
.order-sub-container .main-content .lower-level .detail-container {
|
||
padding: 0 10px;
|
||
overflow: auto;
|
||
}
|
||
|
||
.empty-tip {
|
||
text-align: center;
|
||
font-size: 14px;
|
||
}
|
||
|
||
.update-express-tip {
|
||
margin-top: 4px;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
}
|
||
</style>
|