585 lines
17 KiB
Vue
585 lines
17 KiB
Vue
<template>
|
||
<div class="app-container">
|
||
<!-- 1. 库区与在库空载具 -->
|
||
<el-card shadow="never" class="box-card">
|
||
<div slot="header" class="card-header">
|
||
<span>1. 选择库区与空托盘</span>
|
||
<div class="toolbar">
|
||
<span class="label">库区:</span>
|
||
<el-select
|
||
v-model="sectCode"
|
||
size="mini"
|
||
filterable
|
||
clearable
|
||
placeholder="请选择库区"
|
||
style="width: 280px;"
|
||
@change="handleSectChange"
|
||
>
|
||
<el-option
|
||
v-for="sect in sects"
|
||
:key="sect.sect_code"
|
||
:label="sectLabel(sect)"
|
||
:value="sect.sect_code"
|
||
/>
|
||
</el-select>
|
||
<el-button size="mini" icon="el-icon-refresh" :disabled="!sectCode" @click="loadPallets">刷新</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<el-alert
|
||
v-if="!sectCode"
|
||
title="请选择库区,系统将列出该库区在库的空载具(库位有托且无在库物料)"
|
||
type="info"
|
||
:closable="false"
|
||
show-icon
|
||
/>
|
||
<template v-else>
|
||
<div class="sub-bar">
|
||
<span class="summary">共 {{ filteredPallets.length }} 个在库空载具</span>
|
||
<el-input
|
||
v-model="palletKeyword"
|
||
size="mini"
|
||
clearable
|
||
placeholder="搜索载具码/库位/上料口"
|
||
style="width: 220px;"
|
||
prefix-icon="el-icon-search"
|
||
/>
|
||
</div>
|
||
<el-table
|
||
ref="palletTable"
|
||
v-loading="palletLoading"
|
||
:data="filteredPallets"
|
||
size="mini"
|
||
border
|
||
max-height="360"
|
||
empty-text="该库区暂无在库空载具"
|
||
@selection-change="handlePalletSelection"
|
||
>
|
||
<el-table-column type="selection" width="50" :selectable="palletSelectable" />
|
||
<el-table-column prop="vehicle_code" label="载具码" min-width="150" show-overflow-tooltip />
|
||
<el-table-column prop="vehicle_type" label="载具类型" width="110" show-overflow-tooltip />
|
||
<el-table-column prop="struct_code" label="所在库位" min-width="120" show-overflow-tooltip />
|
||
<el-table-column label="上料口" min-width="160" show-overflow-tooltip>
|
||
<template slot-scope="{ row }">
|
||
<span v-if="row.load_port">{{ row.load_port_name }}({{ row.load_port }})</span>
|
||
<span v-else class="placeholder">未绑定</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column prop="sect_name" label="库区" min-width="120" show-overflow-tooltip />
|
||
<el-table-column label="状态" width="100" align="center">
|
||
<template slot-scope="{ row }">
|
||
<el-tag v-if="row.selectable" type="success" size="mini">{{ row.state_text }}</el-tag>
|
||
<el-tag v-else type="warning" size="mini">{{ row.state_text }}</el-tag>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
</template>
|
||
</el-card>
|
||
|
||
<!-- 2. 目标区域与空闲点位 -->
|
||
<el-card shadow="never" class="box-card">
|
||
<div slot="header" class="card-header">
|
||
<span>2. 选择目标区域与空闲点位</span>
|
||
<div class="toolbar">
|
||
<span class="label">目标区域:</span>
|
||
<el-select
|
||
v-model="regionCode"
|
||
size="mini"
|
||
filterable
|
||
clearable
|
||
placeholder="请选择目标区域"
|
||
style="width: 260px;"
|
||
@change="handleRegionChange"
|
||
>
|
||
<el-option
|
||
v-for="region in regions"
|
||
:key="region.region_code"
|
||
:label="region.region_name + '(' + region.region_code + ')'"
|
||
:value="region.region_code"
|
||
/>
|
||
</el-select>
|
||
<el-button size="mini" icon="el-icon-refresh" :disabled="!regionCode" @click="loadPoints">刷新</el-button>
|
||
<el-button size="mini" :disabled="!regionCode" @click="autoFillPoints">按空托数自动补选</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<el-alert
|
||
v-if="!regionCode"
|
||
title="请选择目标区域,绿色为空位、灰色为已有托盘、橙色为任务占用,仅空位可勾选"
|
||
type="info"
|
||
:closable="false"
|
||
show-icon
|
||
/>
|
||
<template v-else>
|
||
<div class="legend">
|
||
<span class="legend-item"><i class="dot idle" />空位 {{ countByState('idle') }}</span>
|
||
<span class="legend-item"><i class="dot used" />已有托盘 {{ countByState('used') }}</span>
|
||
<span class="legend-item"><i class="dot busy" />任务占用 {{ countByState('busy') }}</span>
|
||
<span class="summary">已选点位 {{ selectedPoints.length }} 个</span>
|
||
</div>
|
||
<div v-loading="pointLoading" class="point-grid">
|
||
<div
|
||
v-for="point in points"
|
||
:key="point.point_code"
|
||
class="point-chip"
|
||
:class="[point.state, { selected: isPointSelected(point.point_code), disabled: !point.selectable }]"
|
||
@click="togglePoint(point)"
|
||
>
|
||
<div class="point-name">{{ point.point_code }}</div>
|
||
<div class="point-code">{{ point.point_name }}</div>
|
||
<div v-if="point.vehicle_code" class="point-extra">托盘 {{ point.vehicle_code }}</div>
|
||
<div class="point-state">{{ point.state_text }}</div>
|
||
</div>
|
||
<div v-if="!points.length && !pointLoading" class="placeholder empty">该区域暂无已启用点位</div>
|
||
</div>
|
||
</template>
|
||
</el-card>
|
||
|
||
<!-- 汇总与提交 -->
|
||
<el-card shadow="never" class="box-card footer-card">
|
||
<div class="footer-bar">
|
||
<div class="footer-summary">
|
||
<span>已选空托盘 <b>{{ selectedPallets.length }}</b> 个</span>
|
||
<span>已选空闲点位 <b>{{ selectedPoints.length }}</b> 个</span>
|
||
<span v-if="countGap > 0" class="danger-text">还差 {{ countGap }} 个空闲点位</span>
|
||
<span v-else-if="selectedPallets.length" class="ok-text">数量校验通过,将按勾选顺序一一分配点位</span>
|
||
</div>
|
||
<div>
|
||
<el-button size="mini" :disabled="!selectedPallets.length && !selectedPoints.length" @click="clearSelection">
|
||
清空选择
|
||
</el-button>
|
||
<el-button
|
||
type="primary"
|
||
size="mini"
|
||
icon="el-icon-s-promotion"
|
||
:loading="submitting"
|
||
:disabled="!canSubmit"
|
||
@click="submit"
|
||
>
|
||
生成搬运任务
|
||
</el-button>
|
||
</div>
|
||
</div>
|
||
</el-card>
|
||
|
||
<!-- 结果 -->
|
||
<el-dialog title="搬运任务已生成" :visible.sync="resultVisible" width="820px" append-to-body>
|
||
<el-alert
|
||
:title="'已生成 ' + (result.task_count || 0) + ' 个空载具出库任务(' + (result.sect_name || '-') + ' → ' + (result.region_name || '-') + '),任务将由调度定时下发AGV'"
|
||
type="success"
|
||
:closable="false"
|
||
show-icon
|
||
/>
|
||
<el-table :data="result.tasks || []" size="mini" border style="margin-top: 10px;">
|
||
<el-table-column prop="vehicle_code" label="载具码" min-width="140" show-overflow-tooltip />
|
||
<el-table-column prop="task_code" label="任务号" min-width="170" show-overflow-tooltip />
|
||
<el-table-column prop="struct_code" label="起点库位" min-width="120" show-overflow-tooltip />
|
||
<el-table-column prop="load_port" label="上料口" min-width="120" show-overflow-tooltip />
|
||
<el-table-column label="目标点位" min-width="150" show-overflow-tooltip>
|
||
<template slot-scope="{ row }">{{ row.point_name }}({{ row.point_code }})</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
<span slot="footer">
|
||
<el-button type="primary" size="mini" @click="resultVisible = false">关 闭</el-button>
|
||
</span>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
|
||
<script>
|
||
import { getSects, getPallets, getRegions, getPoints, callVehicles } from './emptyCall'
|
||
|
||
export default {
|
||
name: 'EmptyVehicleCall',
|
||
data() {
|
||
return {
|
||
// 库区与空载具
|
||
sects: [],
|
||
sectCode: '',
|
||
pallets: [],
|
||
palletLoading: false,
|
||
palletKeyword: '',
|
||
selectedPallets: [],
|
||
// 目标区域与点位
|
||
regions: [],
|
||
regionCode: '',
|
||
points: [],
|
||
pointLoading: false,
|
||
selectedPoints: [],
|
||
// 提交
|
||
submitting: false,
|
||
resultVisible: false,
|
||
result: {}
|
||
}
|
||
},
|
||
computed: {
|
||
filteredPallets() {
|
||
const keyword = (this.palletKeyword || '').trim().toLowerCase()
|
||
if (!keyword) {
|
||
return this.pallets
|
||
}
|
||
return this.pallets.filter(row => [row.vehicle_code, row.struct_code, row.load_port, row.load_port_name]
|
||
.filter(Boolean)
|
||
.some(value => String(value).toLowerCase().includes(keyword)))
|
||
},
|
||
countGap() {
|
||
return Math.max(this.selectedPallets.length - this.selectedPoints.length, 0)
|
||
},
|
||
canSubmit() {
|
||
return !!this.sectCode && !!this.regionCode &&
|
||
this.selectedPallets.length > 0 &&
|
||
this.selectedPoints.length >= this.selectedPallets.length &&
|
||
!this.submitting
|
||
}
|
||
},
|
||
watch: {
|
||
// 关键字过滤后表格重新渲染,清空勾选避免与不可见行不一致
|
||
palletKeyword() {
|
||
this.selectedPallets = []
|
||
this.$nextTick(() => {
|
||
if (this.$refs.palletTable) {
|
||
this.$refs.palletTable.clearSelection()
|
||
}
|
||
})
|
||
}
|
||
},
|
||
created() {
|
||
this.loadSects()
|
||
this.loadRegions()
|
||
},
|
||
methods: {
|
||
sectLabel(sect) {
|
||
const empty = Number(sect.empty_qty || 0)
|
||
return `${sect.sect_name}(${sect.sect_code})· 空托 ${empty}`
|
||
},
|
||
loadSects() {
|
||
getSects().then(res => {
|
||
this.sects = res.data || []
|
||
}).catch(() => {})
|
||
},
|
||
loadRegions() {
|
||
getRegions().then(res => {
|
||
this.regions = res.data || []
|
||
}).catch(() => {})
|
||
},
|
||
handleSectChange() {
|
||
this.pallets = []
|
||
this.selectedPallets = []
|
||
this.palletKeyword = ''
|
||
if (!this.sectCode) {
|
||
return
|
||
}
|
||
this.loadPallets()
|
||
},
|
||
handleRegionChange() {
|
||
this.points = []
|
||
this.selectedPoints = []
|
||
if (!this.regionCode) {
|
||
return
|
||
}
|
||
this.loadPoints()
|
||
},
|
||
loadPallets() {
|
||
if (!this.sectCode) {
|
||
this.pallets = []
|
||
return
|
||
}
|
||
this.palletLoading = true
|
||
getPallets({ sectCode: this.sectCode }).then(res => {
|
||
this.pallets = res.data || []
|
||
this.selectedPallets = []
|
||
this.$nextTick(() => {
|
||
if (this.$refs.palletTable) {
|
||
this.$refs.palletTable.clearSelection()
|
||
}
|
||
})
|
||
}).catch(() => {
|
||
this.pallets = []
|
||
}).finally(() => {
|
||
this.palletLoading = false
|
||
})
|
||
},
|
||
loadPoints() {
|
||
if (!this.regionCode) {
|
||
this.points = []
|
||
return
|
||
}
|
||
this.pointLoading = true
|
||
getPoints({ regionCode: this.regionCode }).then(res => {
|
||
this.points = res.data || []
|
||
// 刷新后只保留仍可选的已勾选点位
|
||
const idleCodes = this.points.filter(p => p.selectable).map(p => p.point_code)
|
||
this.selectedPoints = this.selectedPoints.filter(code => idleCodes.includes(code))
|
||
}).catch(() => {
|
||
this.points = []
|
||
}).finally(() => {
|
||
this.pointLoading = false
|
||
})
|
||
},
|
||
palletSelectable(row) {
|
||
return !!row.selectable
|
||
},
|
||
handlePalletSelection(rows) {
|
||
this.selectedPallets = rows
|
||
},
|
||
countByState(state) {
|
||
return this.points.filter(p => p.state === state).length
|
||
},
|
||
isPointSelected(code) {
|
||
return this.selectedPoints.includes(code)
|
||
},
|
||
togglePoint(point) {
|
||
if (!point.selectable) {
|
||
return
|
||
}
|
||
const index = this.selectedPoints.indexOf(point.point_code)
|
||
if (index > -1) {
|
||
this.selectedPoints.splice(index, 1)
|
||
} else {
|
||
this.selectedPoints.push(point.point_code)
|
||
}
|
||
},
|
||
autoFillPoints() {
|
||
const need = this.selectedPallets.length - this.selectedPoints.length
|
||
if (need <= 0) {
|
||
this.$message.info('空闲点位已满足当前空托数量')
|
||
return
|
||
}
|
||
const candidates = this.points
|
||
.filter(p => p.selectable && !this.isPointSelected(p.point_code))
|
||
.slice(0, need)
|
||
if (!candidates.length) {
|
||
this.$message.warning('目标区域没有更多空闲点位')
|
||
return
|
||
}
|
||
candidates.forEach(p => this.selectedPoints.push(p.point_code))
|
||
if (candidates.length < need) {
|
||
this.$message.warning(`目标区域空位不足,仅补选 ${candidates.length} 个`)
|
||
}
|
||
},
|
||
clearSelection() {
|
||
this.selectedPallets = []
|
||
this.selectedPoints = []
|
||
if (this.$refs.palletTable) {
|
||
this.$refs.palletTable.clearSelection()
|
||
}
|
||
},
|
||
submit() {
|
||
if (!this.sectCode) {
|
||
this.$message.warning('请先选择库区')
|
||
return
|
||
}
|
||
if (!this.selectedPallets.length) {
|
||
this.$message.warning('请勾选需要出库的空托盘')
|
||
return
|
||
}
|
||
if (!this.regionCode) {
|
||
this.$message.warning('请选择目标区域')
|
||
return
|
||
}
|
||
if (this.selectedPoints.length < this.selectedPallets.length) {
|
||
this.$message.warning(`已选空托 ${this.selectedPallets.length} 个,空闲点位仅 ${this.selectedPoints.length} 个`)
|
||
return
|
||
}
|
||
const vehicles = this.selectedPallets.map(p => p.vehicle_code)
|
||
// 空托数少于空点位时,按勾选顺序取前 N 个点位
|
||
const points = this.selectedPoints.slice(0, vehicles.length)
|
||
this.$confirm(
|
||
`确认将 ${vehicles.length} 个空托盘搬运到目标区域的 ${points.length} 个空闲点位?系统将生成空载具出库搬运任务。`,
|
||
'提示',
|
||
{ type: 'warning' }
|
||
).then(() => {
|
||
this.submitting = true
|
||
return callVehicles({
|
||
sectCode: this.sectCode,
|
||
regionCode: this.regionCode,
|
||
pallets: vehicles,
|
||
points
|
||
})
|
||
}).then(res => {
|
||
this.result = res.data || {}
|
||
this.resultVisible = true
|
||
this.$message.success('搬运任务已生成')
|
||
this.clearSelection()
|
||
this.loadPallets()
|
||
this.loadPoints()
|
||
this.loadSects()
|
||
}).catch(() => {}).finally(() => {
|
||
this.submitting = false
|
||
})
|
||
}
|
||
}
|
||
}
|
||
</script>
|
||
|
||
<style scoped>
|
||
.box-card {
|
||
margin-bottom: 12px;
|
||
}
|
||
.footer-card ::v-deep .el-card__body {
|
||
padding: 10px 20px;
|
||
}
|
||
.card-header {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
font-weight: 600;
|
||
}
|
||
.toolbar {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
font-weight: normal;
|
||
}
|
||
.toolbar .label {
|
||
font-size: 13px;
|
||
color: #606266;
|
||
}
|
||
.sub-bar {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
margin-bottom: 8px;
|
||
}
|
||
.summary {
|
||
color: #606266;
|
||
font-size: 12px;
|
||
}
|
||
.placeholder {
|
||
color: #999;
|
||
font-size: 13px;
|
||
}
|
||
.placeholder.empty {
|
||
padding: 20px 0;
|
||
text-align: center;
|
||
width: 100%;
|
||
}
|
||
.legend {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16px;
|
||
margin-bottom: 10px;
|
||
font-size: 12px;
|
||
color: #606266;
|
||
}
|
||
.legend-item {
|
||
display: inline-flex;
|
||
align-items: center;
|
||
gap: 4px;
|
||
}
|
||
.dot {
|
||
display: inline-block;
|
||
width: 8px;
|
||
height: 8px;
|
||
border-radius: 50%;
|
||
}
|
||
.dot.idle {
|
||
background: #67c23a;
|
||
}
|
||
.dot.used {
|
||
background: #c0c4cc;
|
||
}
|
||
.dot.busy {
|
||
background: #e6a23c;
|
||
}
|
||
.point-grid {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
|
||
gap: 8px;
|
||
max-height: 420px;
|
||
overflow-y: auto;
|
||
}
|
||
.point-chip {
|
||
border: 1px solid #dcdfe6;
|
||
border-radius: 4px;
|
||
padding: 6px 8px;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
cursor: pointer;
|
||
user-select: none;
|
||
background: #fafafa;
|
||
transition: all 0.15s;
|
||
}
|
||
.point-chip .point-name {
|
||
font-weight: 600;
|
||
color: #303133;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
.point-chip .point-code {
|
||
color: #909399;
|
||
font-size: 11px;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
.point-chip .point-extra {
|
||
color: #606266;
|
||
font-size: 11px;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
.point-chip .point-state {
|
||
margin-top: 2px;
|
||
font-size: 11px;
|
||
color: #909399;
|
||
}
|
||
.point-chip.idle {
|
||
border-color: #b3e19d;
|
||
background: #f0f9eb;
|
||
}
|
||
.point-chip.idle .point-state {
|
||
color: #67c23a;
|
||
}
|
||
.point-chip.used,
|
||
.point-chip.busy {
|
||
background: #f5f7fa;
|
||
}
|
||
.point-chip.used {
|
||
border-color: #e4e7ed;
|
||
}
|
||
.point-chip.busy {
|
||
border-color: #f5dab1;
|
||
background: #fdf6ec;
|
||
}
|
||
.point-chip.busy .point-state {
|
||
color: #e6a23c;
|
||
}
|
||
.point-chip.disabled {
|
||
cursor: not-allowed;
|
||
}
|
||
.point-chip.selected {
|
||
border-color: #409eff;
|
||
box-shadow: 0 0 0 1px #409eff inset;
|
||
background: #ecf5ff;
|
||
}
|
||
.point-chip.selected .point-state {
|
||
color: #409eff;
|
||
}
|
||
.footer-bar {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
}
|
||
.footer-summary {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16px;
|
||
font-size: 13px;
|
||
color: #606266;
|
||
}
|
||
.footer-summary b {
|
||
color: #409eff;
|
||
}
|
||
.danger-text {
|
||
color: #f56c6c;
|
||
}
|
||
.ok-text {
|
||
color: #67c23a;
|
||
font-size: 12px;
|
||
}
|
||
</style>
|