744 lines
25 KiB
Vue
744 lines
25 KiB
Vue
<template>
|
||
<div class="app-container">
|
||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
||
<el-form-item label="出库类型" prop="outType">
|
||
<el-select v-model="queryParams.outType" placeholder="请选择出库类型" clearable>
|
||
<el-option
|
||
v-for="dict in dict.type.out_stockout_out_type"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="单据来源" prop="stockSource">
|
||
<el-select v-model="queryParams.stockSource" placeholder="请选择单据来源" clearable>
|
||
<el-option
|
||
v-for="dict in dict.type.out_stockout_stock_source"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
<el-form-item label="单据状态" prop="status">
|
||
<el-select v-model="queryParams.status" placeholder="请选择单据状态" clearable>
|
||
<el-option
|
||
v-for="dict in dict.type.out_stockout_status"
|
||
:key="dict.value"
|
||
:label="dict.label"
|
||
:value="dict.value"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
|
||
<el-form-item label="上位单号" prop="erpBill">
|
||
<el-input
|
||
v-model="queryParams.erpBill"
|
||
placeholder="请输入上位单号"
|
||
clearable
|
||
@keyup.enter.native="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="仓库名称" prop="warehouseName">
|
||
<el-input
|
||
v-model="queryParams.warehouseName"
|
||
placeholder="请输入仓库名称"
|
||
clearable
|
||
@keyup.enter.native="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="用户名称" prop="userName">
|
||
<el-input
|
||
v-model="queryParams.userName"
|
||
placeholder="请输入用户名称"
|
||
clearable
|
||
@keyup.enter.native="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="部门名称" prop="deptName">
|
||
<el-input
|
||
v-model="queryParams.deptName"
|
||
placeholder="请输入部门名称"
|
||
clearable
|
||
@keyup.enter.native="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="客户名称" prop="customerName">
|
||
<el-input
|
||
v-model="queryParams.customerName"
|
||
placeholder="请输入客户名称"
|
||
clearable
|
||
@keyup.enter.native="handleQuery"
|
||
/>
|
||
</el-form-item>
|
||
<el-form-item label="创建时间">
|
||
<el-date-picker
|
||
v-model="daterangeCreateDate"
|
||
style="width: 240px"
|
||
value-format="yyyy-MM-dd"
|
||
type="daterange"
|
||
range-separator="-"
|
||
start-placeholder="开始日期"
|
||
end-placeholder="结束日期"
|
||
></el-date-picker>
|
||
</el-form-item>
|
||
<el-form-item label="开始时间">
|
||
<el-date-picker
|
||
v-model="daterangeStartDate"
|
||
style="width: 240px"
|
||
value-format="yyyy-MM-dd"
|
||
type="daterange"
|
||
range-separator="-"
|
||
start-placeholder="开始日期"
|
||
end-placeholder="结束日期"
|
||
></el-date-picker>
|
||
</el-form-item>
|
||
<el-form-item label="结束时间">
|
||
<el-date-picker
|
||
v-model="daterangeFinishDate"
|
||
style="width: 240px"
|
||
value-format="yyyy-MM-dd"
|
||
type="daterange"
|
||
range-separator="-"
|
||
start-placeholder="开始日期"
|
||
end-placeholder="结束日期"
|
||
></el-date-picker>
|
||
</el-form-item>
|
||
<el-form-item>
|
||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
||
</el-form-item>
|
||
</el-form>
|
||
|
||
<el-row :gutter="10" class="mb8">
|
||
<el-col :span="1.5">
|
||
<el-button
|
||
type="danger"
|
||
plain
|
||
icon="el-icon-close"
|
||
size="mini"
|
||
:disabled="single"
|
||
@click="handleCancel"
|
||
v-hasPermi="['out:stockout:cancel']"
|
||
>手动作废
|
||
</el-button>
|
||
</el-col>
|
||
<el-col :span="1.5">
|
||
<el-button
|
||
type="warning"
|
||
plain
|
||
icon="el-icon-s-check"
|
||
size="mini"
|
||
:disabled="single"
|
||
@click="handleAudit"
|
||
v-hasPermi="['out:stockout:audit']"
|
||
>审核单据
|
||
</el-button>
|
||
</el-col>
|
||
<el-col :span="1.5">
|
||
<el-button
|
||
type="success"
|
||
plain
|
||
icon="el-icon-check"
|
||
size="mini"
|
||
:disabled="single"
|
||
@click="handleFinish"
|
||
v-hasPermi="['out:stockout:finish']"
|
||
>完成单据
|
||
</el-button>
|
||
</el-col>
|
||
<el-col :span="1.5">
|
||
<el-button
|
||
type="primary"
|
||
plain
|
||
icon="el-icon-magic-stick"
|
||
size="mini"
|
||
:disabled="single"
|
||
@click="openAutoAssignDialog"
|
||
v-hasPermi="['out:stockout:autoAssign']"
|
||
>自动分配
|
||
</el-button>
|
||
</el-col>
|
||
<el-col :span="1.5">
|
||
<el-button
|
||
type="info"
|
||
plain
|
||
icon="el-icon-s-operation"
|
||
size="mini"
|
||
:disabled="detailSingle"
|
||
@click="openAssignDialog"
|
||
v-hasPermi="['out:stockout:manualAssign']"
|
||
>手动分配
|
||
</el-button>
|
||
</el-col>
|
||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||
</el-row>
|
||
|
||
<el-table v-loading="loading" :data="stockoutList" @selection-change="handleSelectionChange"
|
||
@row-click="handleRowClick" highlight-current-row>
|
||
<el-table-column type="selection" width="55" align="center"/>
|
||
<el-table-column label="出库订单" align="center" prop="stockoutId" width="160"/>
|
||
<el-table-column label="出库类型" align="center" prop="outType">
|
||
<template slot-scope="scope">
|
||
<dict-tag :options="dict.type.out_stockout_out_type" :value="scope.row.outType"/>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="单据来源" align="center" prop="stockSource">
|
||
<template slot-scope="scope">
|
||
<dict-tag :options="dict.type.out_stockout_stock_source" :value="scope.row.stockSource"/>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="单据状态" align="center" prop="status">
|
||
<template slot-scope="scope">
|
||
<dict-tag :options="dict.type.out_stockout_status" :value="scope.row.status"/>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="上位单号" align="center" prop="erpBill"/>
|
||
<el-table-column label="仓库名称" align="center" prop="warehouseName"/>
|
||
<el-table-column label="用户名称" align="center" prop="userName"/>
|
||
<el-table-column label="部门名称" align="center" prop="deptName"/>
|
||
<el-table-column label="客户名称" align="center" prop="customerName" width="100" show-overflow-tooltip/>
|
||
<el-table-column label="创建时间" align="center" prop="createDate" width="160">
|
||
<template slot-scope="scope">
|
||
<span>{{ parseTime(scope.row.createDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="开始时间" align="center" prop="startDate" width="160">
|
||
<template slot-scope="scope">
|
||
<span>{{ parseTime(scope.row.startDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="结束时间" align="center" prop="finishDate" width="160">
|
||
<template slot-scope="scope">
|
||
<span>{{ parseTime(scope.row.finishDate, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
|
||
<pagination
|
||
v-show="total>0"
|
||
:total="total"
|
||
:page.sync="queryParams.pageNum"
|
||
:limit.sync="queryParams.pageSize"
|
||
@pagination="getList"
|
||
/>
|
||
|
||
<!-- 出库子单详情 -->
|
||
<div class="detail-panel" style="margin-top: 20px;">
|
||
<div class="detail-header" style="margin-bottom: 10px; display: flex; align-items: center; gap: 8px;">
|
||
<span style="font-size: 14px; font-weight: 600; color: #303133;">出库子单详情</span>
|
||
<el-tag v-if="currentStockout" type="primary" size="small" style="margin-left: 4px;">
|
||
主单:{{ currentStockout.stockoutId }}
|
||
</el-tag>
|
||
<span v-else
|
||
style="font-size: 12px; color: #909399; margin-left: 4px;">(请点击上方主单行查看对应子单数据)</span>
|
||
</div>
|
||
<el-table
|
||
v-loading="detailLoading"
|
||
:data="detailList"
|
||
border
|
||
stripe
|
||
size="small"
|
||
style="width: 100%;"
|
||
:header-cell-style="{ background: '#f5f7fa', color: '#606266' }"
|
||
@selection-change="handleDetailSelectionChange"
|
||
ref="detailTable"
|
||
>
|
||
<el-table-column type="selection" width="55" align="center"/>
|
||
<el-table-column label="子单ID" align="center" prop="stockoutDetailId" width="180"/>
|
||
<el-table-column label="批次" align="center" prop="lotNo" width="150"/>
|
||
<el-table-column label="物料编码" align="center" prop="productId" width="150"/>
|
||
<el-table-column label="物料名称" align="center" prop="productName" min-width="150" show-overflow-tooltip/>
|
||
<el-table-column label="库存明细" align="center" prop="stockDetailId" width="160" show-overflow-tooltip/>
|
||
<el-table-column label="托盘类型" align="center" prop="trayType" width="90"/>
|
||
<el-table-column label="计划数量" align="center" prop="quantity" width="100"/>
|
||
<el-table-column label="分配数量" align="center" prop="allotNum" width="100"/>
|
||
<el-table-column label="实际数量" align="center" prop="assignNum" width="100"/>
|
||
<el-table-column label="备注" align="center" prop="remark" min-width="120" show-overflow-tooltip/>
|
||
<template slot="empty">
|
||
<div style="padding: 30px 0; color: #909399; font-size: 13px;">
|
||
<i class="el-icon-document" style="font-size: 28px; display: block; margin-bottom: 8px;"></i>
|
||
{{ currentStockout ? '暂无子单数据' : '请先选择上侧主单行' }}
|
||
</div>
|
||
</template>
|
||
</el-table>
|
||
<pagination
|
||
v-show="detailTotal > 0"
|
||
:total="detailTotal"
|
||
:page.sync="detailQueryParams.pageNum"
|
||
:limit.sync="detailQueryParams.pageSize"
|
||
@pagination="getDetailList"
|
||
style="margin-top: 0;"
|
||
/>
|
||
</div>
|
||
|
||
<!-- ===================== 手动分配弹窗 ===================== -->
|
||
<el-dialog
|
||
title="选择出库口"
|
||
:visible.sync="exitDialogVisible"
|
||
width="420px"
|
||
append-to-body
|
||
>
|
||
<el-form label-width="110px" size="small">
|
||
<el-form-item
|
||
v-for="trayType in autoAssignTrayTypes"
|
||
:key="trayType"
|
||
:label="formatTrayTypeLabel(trayType)"
|
||
required
|
||
>
|
||
<el-select
|
||
v-model="selectedExitByTrayType[trayType]"
|
||
placeholder="请选择出库口"
|
||
clearable
|
||
filterable
|
||
style="width: 100%;"
|
||
:loading="exitLoading"
|
||
>
|
||
<el-option
|
||
v-for="point in getExitOptionsByTrayType(trayType)"
|
||
:key="point.pointId"
|
||
:label="formatExitLabel(point)"
|
||
:value="point.pointId"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-form>
|
||
<div slot="footer" class="dialog-footer">
|
||
<el-button @click="exitDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" @click="confirmAutoAssign">确认分配</el-button>
|
||
</div>
|
||
</el-dialog>
|
||
|
||
<el-dialog
|
||
title="选择出库库存"
|
||
:visible.sync="assignDialogVisible"
|
||
width="80%"
|
||
append-to-body
|
||
>
|
||
<el-form v-if="manualAssignTrayTypes.length > 0" label-width="110px" size="small" style="margin-bottom: 12px;">
|
||
<el-form-item
|
||
v-for="trayType in manualAssignTrayTypes"
|
||
:key="trayType"
|
||
:label="formatTrayTypeLabel(trayType)"
|
||
required
|
||
>
|
||
<el-select
|
||
v-model="selectedExitByTrayType[trayType]"
|
||
placeholder="请选择出库口"
|
||
clearable
|
||
filterable
|
||
style="width: 320px;"
|
||
:loading="exitLoading"
|
||
>
|
||
<el-option
|
||
v-for="point in getExitOptionsByTrayType(trayType)"
|
||
:key="point.pointId"
|
||
:label="formatExitLabel(point)"
|
||
:value="point.pointId"
|
||
/>
|
||
</el-select>
|
||
</el-form-item>
|
||
</el-form>
|
||
<el-table
|
||
v-loading="stockLoading"
|
||
:data="stockList"
|
||
border
|
||
size="small"
|
||
ref="stockTable"
|
||
@selection-change="handleStockSelectionChange"
|
||
>
|
||
<el-table-column type="selection" width="55" align="center"/>
|
||
<el-table-column label="库存ID" prop="stockId" align="center"/>
|
||
<el-table-column label="明细ID" prop="detailId" align="center" width="160" show-overflow-tooltip/>
|
||
<el-table-column label="物料编码" prop="productId" align="center"/>
|
||
<el-table-column label="物料名称" prop="productName" align="center"/>
|
||
<el-table-column label="批次" prop="lotNo" align="center"/>
|
||
<el-table-column label="货位" prop="cargoSpaceName" align="center"/>
|
||
<el-table-column label="托盘号" prop="trayCode" align="center"/>
|
||
<el-table-column label="托盘类型" prop="trayType" align="center" width="90"/>
|
||
<el-table-column label="可用数量" prop="availableQuantity" align="center"/>
|
||
</el-table>
|
||
|
||
<div slot="footer" class="dialog-footer">
|
||
<el-button @click="assignDialogVisible = false">取消</el-button>
|
||
<el-button type="primary" @click="confirmManualAssign">确认分配</el-button>
|
||
</div>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import {
|
||
listStockout,
|
||
cancelStockout,
|
||
auditStockout,
|
||
finishStockout,
|
||
autoAssignStockout,
|
||
manualAssignStockout
|
||
} from "@/api/out/stockout"
|
||
import { listStockoutdetail } from "@/api/out/stockoutdetail"
|
||
import { listStockDetail } from "@/api/bas/stock"
|
||
import { listStationPoint } from "@/api/bas/stationpoint"
|
||
|
||
export default {
|
||
name: "Stockout",
|
||
dicts: ['out_stockout_stock_source', 'out_stockout_status', 'out_stockout_out_type'],
|
||
data() {
|
||
return {
|
||
loading: true,
|
||
ids: [],
|
||
selectedRows: [],
|
||
single: true,
|
||
multiple: true,
|
||
showSearch: true,
|
||
total: 0,
|
||
stockoutList: [],
|
||
daterangeCreateDate: [],
|
||
daterangeStartDate: [],
|
||
daterangeFinishDate: [],
|
||
queryParams: {
|
||
pageNum: 1,
|
||
pageSize: 10,
|
||
outType: null,
|
||
stockSource: null,
|
||
status: null,
|
||
createDate: null,
|
||
startDate: null,
|
||
finishDate: null,
|
||
erpBill: null,
|
||
warehouseName: null,
|
||
userName: null,
|
||
deptName: null,
|
||
customerName: null
|
||
},
|
||
// 子单
|
||
currentStockout: null,
|
||
detailLoading: false,
|
||
detailTotal: 0,
|
||
detailList: [],
|
||
detailQueryParams: {
|
||
pageNum: 1,
|
||
pageSize: 10,
|
||
stockoutId: null,
|
||
status: null
|
||
},
|
||
// 子单选中ID
|
||
detailIds: [],
|
||
detailSingle: true,
|
||
|
||
// 手动分配弹窗
|
||
exitDialogVisible: false,
|
||
assignDialogVisible: false,
|
||
exitLoading: false,
|
||
stockLoading: false,
|
||
exitOptions: [],
|
||
stockList: [],
|
||
selectedExitId: null,
|
||
selectedExitByTrayType: {},
|
||
selectedStockList: [],
|
||
autoAssignDetails: [],
|
||
defaultTrayTypeKey: '__DEFAULT__'
|
||
}
|
||
},
|
||
computed: {
|
||
autoAssignTrayTypes() {
|
||
return this.collectTrayTypes(this.autoAssignDetails)
|
||
},
|
||
manualAssignTrayTypes() {
|
||
return this.collectTrayTypes(this.selectedStockList)
|
||
}
|
||
},
|
||
created() {
|
||
this.getList()
|
||
},
|
||
methods: {
|
||
getList() {
|
||
this.loading = true
|
||
this.queryParams.params = {}
|
||
if (this.daterangeCreateDate && this.daterangeCreateDate.length > 0) {
|
||
this.queryParams.params.beginCreateDate = this.daterangeCreateDate[0]
|
||
this.queryParams.params.endCreateDate = this.daterangeCreateDate[1]
|
||
}
|
||
if (this.daterangeStartDate && this.daterangeStartDate.length > 0) {
|
||
this.queryParams.params.beginStartDate = this.daterangeStartDate[0]
|
||
this.queryParams.params.endStartDate = this.daterangeStartDate[1]
|
||
}
|
||
if (this.daterangeFinishDate && this.daterangeFinishDate.length > 0) {
|
||
this.queryParams.params.beginFinishDate = this.daterangeFinishDate[0]
|
||
this.queryParams.params.endFinishDate = this.daterangeFinishDate[1]
|
||
}
|
||
listStockout(this.queryParams).then(res => {
|
||
this.stockoutList = res.rows
|
||
this.total = res.total
|
||
this.loading = false
|
||
})
|
||
},
|
||
handleQuery() {
|
||
this.queryParams.pageNum = 1
|
||
this.getList()
|
||
},
|
||
resetQuery() {
|
||
this.daterangeCreateDate = []
|
||
this.daterangeStartDate = []
|
||
this.daterangeFinishDate = []
|
||
this.resetForm("queryForm")
|
||
this.handleQuery()
|
||
this.resetDetailList()
|
||
},
|
||
resetDetailList() {
|
||
this.detailList = []
|
||
this.detailQueryParams.stockoutId = null
|
||
this.detailQueryParams.status = null
|
||
this.currentStockout = null
|
||
this.detailTotal = 0
|
||
},
|
||
handleSelectionChange(selection) {
|
||
this.ids = selection.map(item => item.stockoutId)
|
||
this.selectedRows = selection
|
||
this.single = selection.length !== 1
|
||
},
|
||
handleRowClick(row) {
|
||
this.currentStockout = row
|
||
this.detailQueryParams.stockoutId = row.stockoutId
|
||
this.detailQueryParams.status = row.status
|
||
this.detailQueryParams.pageNum = 1
|
||
this.getDetailList()
|
||
},
|
||
getDetailList() {
|
||
if (!this.detailQueryParams.stockoutId) return
|
||
this.detailLoading = true
|
||
listStockoutdetail(this.detailQueryParams).then(res => {
|
||
this.detailList = res.rows
|
||
this.detailTotal = res.total
|
||
this.detailLoading = false
|
||
})
|
||
},
|
||
|
||
// 子单多选事件
|
||
handleDetailSelectionChange(val) {
|
||
this.detailIds = val.map(item => item.stockoutDetailId)
|
||
this.detailSingle = val.length !== 1
|
||
},
|
||
|
||
// ===================== 手动分配:打开弹窗 =====================
|
||
openAssignDialog() {
|
||
if (this.detailIds.length === 0) {
|
||
this.$modal.msgWarning("请选择子单")
|
||
return
|
||
}
|
||
if (!this.currentStockout) {
|
||
this.$modal.msgWarning("请先选择出库主单")
|
||
return
|
||
}
|
||
const detail = this.detailList.find(item => item.stockoutDetailId === this.detailIds[0])
|
||
this.selectedExitId = null
|
||
this.selectedExitByTrayType = {}
|
||
this.selectedStockList = []
|
||
this.assignDialogVisible = true
|
||
this.stockLoading = true
|
||
this.loadExitOptions(this.currentStockout.warehouseId)
|
||
// 根据物料编码查询可用库存明细
|
||
listStockDetail({
|
||
productId: detail.productId,
|
||
warehouseId: this.currentStockout ? this.currentStockout.warehouseId : null,
|
||
stockStatus: '1'
|
||
}).then(res => {
|
||
this.stockList = res.rows || []
|
||
this.stockLoading = false
|
||
})
|
||
},
|
||
|
||
loadExitOptions(warehouseId) {
|
||
if (!warehouseId) {
|
||
this.exitOptions = []
|
||
return Promise.resolve()
|
||
}
|
||
this.exitLoading = true
|
||
return listStationPoint({
|
||
warehouseId: warehouseId,
|
||
status: '0'
|
||
}).then(res => {
|
||
const rows = res.rows || res.data || []
|
||
this.exitOptions = rows.filter(point => {
|
||
return ['2', '3'].includes(String(point.pointType)) && String(point.pointStatus || '0') === '0'
|
||
})
|
||
this.exitLoading = false
|
||
}).catch(() => {
|
||
this.exitOptions = []
|
||
this.exitLoading = false
|
||
})
|
||
},
|
||
|
||
formatExitLabel(point) {
|
||
const typeName = String(point.pointType) === '3' ? '入出库' : '出库'
|
||
const trayType = point.trayType ? `,${point.trayType}类托盘` : ''
|
||
return `${point.pointName || point.pointId}(${point.pointId},${typeName}${trayType})`
|
||
},
|
||
|
||
getTrayTypeKey(row) {
|
||
return row && row.trayType ? String(row.trayType) : this.defaultTrayTypeKey
|
||
},
|
||
|
||
collectTrayTypes(rows) {
|
||
const types = []
|
||
;(rows || []).forEach(row => {
|
||
const key = this.getTrayTypeKey(row)
|
||
if (!types.includes(key)) {
|
||
types.push(key)
|
||
}
|
||
})
|
||
return types
|
||
},
|
||
|
||
formatTrayTypeLabel(trayType) {
|
||
return trayType === this.defaultTrayTypeKey ? '默认出库口' : `${trayType}类托盘`
|
||
},
|
||
|
||
pointSupportsTrayType(point, trayType) {
|
||
if (trayType === this.defaultTrayTypeKey) {
|
||
return true
|
||
}
|
||
if (!point.trayType) {
|
||
return true
|
||
}
|
||
return String(point.trayType).split(',').map(item => item.trim()).includes(trayType)
|
||
},
|
||
|
||
getExitOptionsByTrayType(trayType) {
|
||
return this.exitOptions.filter(point => this.pointSupportsTrayType(point, trayType))
|
||
},
|
||
|
||
resetExitSelections(trayTypes) {
|
||
this.selectedExitByTrayType = {}
|
||
;(trayTypes || []).forEach(trayType => {
|
||
this.$set(this.selectedExitByTrayType, trayType, null)
|
||
})
|
||
},
|
||
|
||
ensureExitSelections(trayTypes) {
|
||
;(trayTypes || []).forEach(trayType => {
|
||
if (!Object.prototype.hasOwnProperty.call(this.selectedExitByTrayType, trayType)) {
|
||
this.$set(this.selectedExitByTrayType, trayType, null)
|
||
}
|
||
})
|
||
},
|
||
|
||
validateExitSelections(trayTypes) {
|
||
const missingType = (trayTypes || []).find(trayType => !this.selectedExitByTrayType[trayType])
|
||
if (missingType) {
|
||
this.$modal.msgWarning(`请选择${this.formatTrayTypeLabel(missingType)}的出库口`)
|
||
return false
|
||
}
|
||
return true
|
||
},
|
||
|
||
buildExitByTrayType(trayTypes) {
|
||
const exitByTrayType = {}
|
||
;(trayTypes || []).forEach(trayType => {
|
||
if (trayType !== this.defaultTrayTypeKey) {
|
||
exitByTrayType[trayType] = this.selectedExitByTrayType[trayType]
|
||
}
|
||
})
|
||
return exitByTrayType
|
||
},
|
||
|
||
// 库存选中事件
|
||
handleStockSelectionChange(val) {
|
||
this.selectedStockList = val
|
||
this.ensureExitSelections(this.manualAssignTrayTypes)
|
||
},
|
||
|
||
// 确认分配
|
||
confirmManualAssign() {
|
||
if (this.selectedStockList.length === 0) {
|
||
this.$modal.msgWarning("请选择要出库的库存")
|
||
return
|
||
}
|
||
const trayTypes = this.manualAssignTrayTypes
|
||
if (!this.validateExitSelections(trayTypes)) {
|
||
return
|
||
}
|
||
const stockIdList = Array.from(new Set(this.selectedStockList.map(item => item.detailId || item.stockDetailId || item.stockId)))
|
||
const exitByStockId = {}
|
||
this.selectedStockList.forEach(item => {
|
||
const stockKey = item.detailId || item.stockDetailId || item.stockId
|
||
exitByStockId[stockKey] = this.selectedExitByTrayType[this.getTrayTypeKey(item)]
|
||
})
|
||
const detailId = this.detailIds[0]
|
||
|
||
this.$modal.confirm("确认选中库存进行分配?").then(() => {
|
||
// 调用子单手动分配接口
|
||
return manualAssignStockout({
|
||
stockoutDetailId: detailId,
|
||
exitId: this.selectedExitByTrayType[this.defaultTrayTypeKey] || null,
|
||
exitByTrayType: this.buildExitByTrayType(trayTypes),
|
||
exitByStockId: exitByStockId,
|
||
stockIdList: stockIdList
|
||
})
|
||
}).then(() => {
|
||
this.$modal.msgSuccess("分配成功")
|
||
this.assignDialogVisible = false
|
||
this.getDetailList()
|
||
})
|
||
},
|
||
|
||
handleCancel() {
|
||
cancelStockout(this.ids[0]).then(() => {
|
||
this.$modal.msgSuccess("作废成功")
|
||
this.getList()
|
||
})
|
||
},
|
||
handleAudit() {
|
||
auditStockout(this.ids[0]).then(() => {
|
||
this.$modal.msgSuccess("审核成功")
|
||
this.getList()
|
||
})
|
||
},
|
||
handleFinish() {
|
||
finishStockout(this.ids[0]).then(() => {
|
||
this.$modal.msgSuccess("完成成功")
|
||
this.getList()
|
||
})
|
||
},
|
||
openAutoAssignDialog() {
|
||
const stockout = this.selectedRows[0]
|
||
if (!stockout) {
|
||
this.$modal.msgWarning("请选择出库单据")
|
||
return
|
||
}
|
||
this.selectedExitId = null
|
||
this.selectedExitByTrayType = {}
|
||
this.autoAssignDetails = []
|
||
this.exitDialogVisible = true
|
||
this.loadExitOptions(stockout.warehouseId)
|
||
const detailPromise = this.currentStockout && this.currentStockout.stockoutId === stockout.stockoutId && this.detailList.length > 0
|
||
? Promise.resolve(this.detailList)
|
||
: listStockoutdetail({ stockoutId: stockout.stockoutId, status: stockout.status, pageNum: 1, pageSize: 9999 }).then(res => res.rows || [])
|
||
detailPromise.then(rows => {
|
||
this.autoAssignDetails = rows
|
||
this.resetExitSelections(this.autoAssignTrayTypes)
|
||
})
|
||
},
|
||
confirmAutoAssign() {
|
||
const trayTypes = this.autoAssignTrayTypes
|
||
if (trayTypes.length === 0) {
|
||
this.$modal.msgWarning("未加载到出库明细")
|
||
return
|
||
}
|
||
if (!this.validateExitSelections(trayTypes)) {
|
||
return
|
||
}
|
||
autoAssignStockout(this.ids[0], {
|
||
exitId: this.selectedExitByTrayType[this.defaultTrayTypeKey] || null,
|
||
exitByTrayType: this.buildExitByTrayType(trayTypes)
|
||
}).then(() => {
|
||
this.$modal.msgSuccess("自动分配成功")
|
||
this.exitDialogVisible = false
|
||
this.getDetailList()
|
||
})
|
||
}
|
||
}
|
||
}
|
||
</script>
|