278 lines
12 KiB
Plaintext
278 lines
12 KiB
Plaintext
@model HHWMS.Web.ShipmentHeaderVM
|
||
|
||
<div id="shipment-allocate-@Model.Entity.ID">
|
||
<a-space direction="vertical" fill size="large">
|
||
<a-alert type="info">
|
||
ERP单号:{{ header.SourceCode || '-' }};WMS单号:{{ header.Code || '-' }}。
|
||
分配只保存人员填写的数量,同一托盘下发一个WCS任务。
|
||
</a-alert>
|
||
|
||
<a-card title="出库明细">
|
||
<template #extra>
|
||
<a-button type="text" @@click="loadData">刷新</a-button>
|
||
</template>
|
||
<a-table :data="details" :pagination="false" row-key="ID">
|
||
<template #columns>
|
||
<a-table-column title="物料编码" data-index="MaterialCode"></a-table-column>
|
||
<a-table-column title="图号" data-index="MaterialType"></a-table-column>
|
||
<a-table-column title="物料名称" data-index="MaterialName"></a-table-column>
|
||
<a-table-column title="需求数量" data-index="Qty"></a-table-column>
|
||
<a-table-column title="已分配" data-index="DividedQty"></a-table-column>
|
||
<a-table-column title="已出库" data-index="CompletedQty"></a-table-column>
|
||
<a-table-column title="可分配" data-index="RemainingQty"></a-table-column>
|
||
<a-table-column title="状态" data-index="Status"></a-table-column>
|
||
<a-table-column title="操作" :width="110">
|
||
<template #cell="{ record }">
|
||
<a-button type="primary" size="small" :disabled="record.RemainingQty <= 0"
|
||
@@click="openInventory(record)">选择库存</a-button>
|
||
</template>
|
||
</a-table-column>
|
||
</template>
|
||
</a-table>
|
||
</a-card>
|
||
|
||
<a-card title="托盘任务">
|
||
<a-empty v-if="tasks.length === 0" description="尚未分配库存"></a-empty>
|
||
<a-card v-for="task in tasks" :key="task.ID" :title="task.TaskNo" size="small"
|
||
style="margin-bottom: 12px">
|
||
<template #extra>
|
||
<a-space>
|
||
<span>托盘:{{ task.ContainerCode }};库位:{{ task.LocationCode || '-' }};状态:{{ task.Status }}</span>
|
||
<a-select v-if="task.CanDispatch" v-model="task.SelectedOutPort"
|
||
popup-container="#shipment-allocate-@Model.Entity.ID"
|
||
placeholder="选择出库口" style="width: 150px">
|
||
<a-option v-for="port in outPorts" :key="port.Value" :value="port.Value">
|
||
{{ port.Label }}
|
||
</a-option>
|
||
</a-select>
|
||
<a-button v-if="task.CanDispatch" type="primary" :loading="task.Loading"
|
||
@@click="dispatchTask(task)">下发任务</a-button>
|
||
<a-button v-if="task.CanCancel" status="danger" :disabled="task.Loading"
|
||
@@click="cancelTask(task)">取消整托分配</a-button>
|
||
</a-space>
|
||
</template>
|
||
<a-table :data="task.Details" :pagination="false" row-key="ID" size="small">
|
||
<template #columns>
|
||
<a-table-column title="ERP单号" data-index="ShipmentCode"></a-table-column>
|
||
<a-table-column title="库存ID" data-index="InventoryId"></a-table-column>
|
||
<a-table-column title="物料编码" data-index="MaterialCode"></a-table-column>
|
||
<a-table-column title="分配数量" data-index="Qty"></a-table-column>
|
||
<a-table-column title="状态" data-index="Status"></a-table-column>
|
||
<a-table-column title="操作" :width="100">
|
||
<template #cell="{ record }">
|
||
<a-button v-if="record.CanCancel" type="text" status="danger"
|
||
@@click="cancelAllocation(record)">取消分配</a-button>
|
||
</template>
|
||
</a-table-column>
|
||
</template>
|
||
</a-table>
|
||
</a-card>
|
||
</a-card>
|
||
|
||
<a-modal v-model:visible="inventoryVisible" title="选择库存并填写分配数量"
|
||
width="1000px" :ok-loading="saving" :style="{ zIndex: inventoryModalZIndex }"
|
||
@@before-ok="saveAllocation">
|
||
<a-alert type="warning" style="margin-bottom: 12px">
|
||
本明细剩余可分配 {{ currentDetail.RemainingQty || 0 }}。同一库存可以分给多个明细,但累计不能超过库存数量。
|
||
</a-alert>
|
||
<a-table :data="inventories" :pagination="{ pageSize: 10 }" row-key="ID">
|
||
<template #columns>
|
||
<a-table-column title="选择" :width="65">
|
||
<template #cell="{ record }">
|
||
<a-checkbox v-model="record.Selected"></a-checkbox>
|
||
</template>
|
||
</a-table-column>
|
||
<a-table-column title="库存ID" data-index="ID" :width="90"></a-table-column>
|
||
<a-table-column title="托盘" data-index="ContainerCode"></a-table-column>
|
||
<a-table-column title="库位" data-index="LocationCode"></a-table-column>
|
||
<a-table-column title="公司" data-index="CompanyName"></a-table-column>
|
||
<a-table-column title="批次" data-index="Batch"></a-table-column>
|
||
<a-table-column title="库存数量" data-index="Qty"></a-table-column>
|
||
<a-table-column title="已被分配" data-index="AllocatedQty"></a-table-column>
|
||
<a-table-column title="可用数量" data-index="AvailableQty"></a-table-column>
|
||
<a-table-column title="本次分配" :width="150">
|
||
<template #cell="{ record }">
|
||
<a-input-number v-model="record.AllocationQty" :min="0"
|
||
:max="record.AvailableQty" :precision="4"
|
||
:disabled="!record.Selected" style="width: 125px"></a-input-number>
|
||
</template>
|
||
</a-table-column>
|
||
</template>
|
||
</a-table>
|
||
</a-modal>
|
||
</a-space>
|
||
</div>
|
||
|
||
<script>
|
||
(() => {
|
||
const allocationApp = Vue.createApp({
|
||
data() {
|
||
return {
|
||
headerId: @Model.Entity.ID,
|
||
header: {},
|
||
details: [],
|
||
tasks: [],
|
||
outPorts: [],
|
||
inventoryVisible: false,
|
||
inventories: [],
|
||
currentDetail: {},
|
||
saving: false,
|
||
inventoryModalZIndex: 2000
|
||
};
|
||
},
|
||
mounted() {
|
||
this.loadData();
|
||
},
|
||
methods: {
|
||
notifyError(message) {
|
||
const zIndex = this.getInventoryModalZIndex() + 2;
|
||
this.$notification.error({ content: message || '操作失败', duration: 5000, closable: true });
|
||
this.$nextTick(() => {
|
||
document.querySelectorAll('.arco-notification-list').forEach(element => {
|
||
element.style.zIndex = String(zIndex);
|
||
});
|
||
});
|
||
},
|
||
getInventoryModalZIndex() {
|
||
const root = document.getElementById(`shipment-allocate-${this.headerId}`);
|
||
const hostLayer = root ? root.closest('.layui-layer') : null;
|
||
const hostZIndex = hostLayer
|
||
? Number.parseInt(window.getComputedStyle(hostLayer).zIndex, 10)
|
||
: 0;
|
||
return hostZIndex > 0 ? hostZIndex + 2 : 2000;
|
||
},
|
||
loadData() {
|
||
axios.get('/shipment/ShipmentHeader/GetAllocationData', { params: { headerId: this.headerId } })
|
||
.then(response => {
|
||
const json = response.data;
|
||
if (Number(json.Code) !== 200) {
|
||
this.notifyError(json.Msg);
|
||
return;
|
||
}
|
||
this.header = json.Data.Header || {};
|
||
this.details = json.Data.Details || [];
|
||
this.tasks = (json.Data.Tasks || []).map(task => ({
|
||
...task,
|
||
SelectedOutPort: task.ToLocation || '',
|
||
Loading: false
|
||
}));
|
||
this.outPorts = json.Data.OutPorts || [];
|
||
})
|
||
.catch(error => this.notifyError(error.message));
|
||
},
|
||
openInventory(detail) {
|
||
this.currentDetail = detail;
|
||
axios.get('/shipment/ShipmentHeader/GetAvailableInventories', { params: { detailId: detail.ID } })
|
||
.then(response => {
|
||
const json = response.data;
|
||
if (Number(json.Code) !== 200) {
|
||
this.notifyError(json.Msg);
|
||
return;
|
||
}
|
||
this.inventories = (json.Data || []).map(item => ({
|
||
...item,
|
||
Selected: false,
|
||
AllocationQty: 0
|
||
}));
|
||
this.inventoryModalZIndex = this.getInventoryModalZIndex();
|
||
this.inventoryVisible = true;
|
||
})
|
||
.catch(error => this.notifyError(error.message));
|
||
},
|
||
saveAllocation(done) {
|
||
const rows = this.inventories
|
||
.filter(item => item.Selected && Number(item.AllocationQty) > 0)
|
||
.map(item => ({ InventoryId: item.ID, Qty: item.AllocationQty }));
|
||
if (rows.length === 0) {
|
||
this.notifyError('请选择库存并填写大于0的分配数量');
|
||
if (done) done(false);
|
||
return;
|
||
}
|
||
const total = rows.reduce((sum, item) => sum + Number(item.Qty), 0);
|
||
if (total > Number(this.currentDetail.RemainingQty)) {
|
||
this.notifyError('本次分配总数不能超过明细剩余可分配数量');
|
||
if (done) done(false);
|
||
return;
|
||
}
|
||
this.saving = true;
|
||
axios.post('/shipment/ShipmentHeader/AllocateInventories', {
|
||
DetailId: this.currentDetail.ID,
|
||
Rows: rows
|
||
}).then(response => {
|
||
const json = response.data;
|
||
if (Number(json.Code) === 200) {
|
||
this.$message.success('分配成功');
|
||
this.inventoryVisible = false;
|
||
this.loadData();
|
||
if (done) done(true);
|
||
} else {
|
||
this.notifyError(json.Msg);
|
||
if (done) done(false);
|
||
}
|
||
}).catch(error => {
|
||
this.notifyError(error.message);
|
||
if (done) done(false);
|
||
}).finally(() => {
|
||
this.saving = false;
|
||
});
|
||
},
|
||
postForm(url, values) {
|
||
const data = new URLSearchParams();
|
||
Object.keys(values).forEach(key => data.append(key, values[key]));
|
||
return axios.post(url, data);
|
||
},
|
||
cancelAllocation(record) {
|
||
if (!window.confirm(`确认取消库存 ${record.InventoryId} 的分配吗?`)) return;
|
||
this.postForm('/shipment/ShipmentHeader/CancelAllocation', { id: record.ID })
|
||
.then(response => {
|
||
const json = response.data;
|
||
if (Number(json.Code) === 200) {
|
||
this.$message.success('取消分配成功');
|
||
this.loadData();
|
||
} else {
|
||
this.notifyError(json.Msg);
|
||
}
|
||
}).catch(error => this.notifyError(error.message));
|
||
},
|
||
cancelTask(task) {
|
||
if (!window.confirm(`确认取消托盘 ${task.ContainerCode} 的全部待下发分配吗?`)) return;
|
||
task.Loading = true;
|
||
this.postForm('/shipment/ShipmentHeader/CancelPendingTask', { id: task.ID })
|
||
.then(response => {
|
||
const json = response.data;
|
||
if (Number(json.Code) === 200) {
|
||
this.$message.success('整托分配已取消');
|
||
this.loadData();
|
||
} else {
|
||
this.notifyError(json.Msg);
|
||
}
|
||
}).catch(error => this.notifyError(error.message))
|
||
.finally(() => { task.Loading = false; });
|
||
},
|
||
dispatchTask(task) {
|
||
if (!task.SelectedOutPort) {
|
||
this.notifyError('请先选择出库口');
|
||
return;
|
||
}
|
||
task.Loading = true;
|
||
this.postForm('/shipment/ShipmentHeader/DispatchPendingTask', {
|
||
id: task.ID,
|
||
outPort: task.SelectedOutPort
|
||
}).then(response => {
|
||
const json = response.data;
|
||
if (Number(json.Code) === 200) {
|
||
this.$message.success('WCS任务下发成功');
|
||
this.loadData();
|
||
} else {
|
||
this.notifyError(json.Msg);
|
||
}
|
||
}).catch(error => this.notifyError(error.message))
|
||
.finally(() => { task.Loading = false; });
|
||
}
|
||
}
|
||
});
|
||
allocationApp.use(ArcoVue);
|
||
allocationApp.mount('#shipment-allocate-@Model.Entity.ID');
|
||
})();
|
||
</script>
|