|
@@ -86,9 +86,12 @@
|
|
|
<el-table-column :label="t('stock.requQuantity')" align="center" prop="requisitionQuantity">
|
|
|
<template #default="scope">
|
|
|
<el-input
|
|
|
+ type="number"
|
|
|
+ :controls="false"
|
|
|
v-model="scope.row.requisitionQuantity"
|
|
|
@click.stop=""
|
|
|
@focus="handleInputFocus(scope.row)"
|
|
|
+ @blur="(event) => handleQuantityBlur(event, scope.row)"
|
|
|
/>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
@@ -167,6 +170,17 @@ const selectRow = (row) => {
|
|
|
|
|
|
// 确认选择
|
|
|
const handleConfirm = () => {
|
|
|
+ // 检查是否有未通过校验的行
|
|
|
+ const invalidRows = selectedRows.value.filter(row => {
|
|
|
+ const quantity = parseFloat(row.requisitionQuantity);
|
|
|
+ return isNaN(quantity) || quantity <= 0 || quantity > row.quantity;
|
|
|
+ });
|
|
|
+
|
|
|
+ if (invalidRows.length > 0) {
|
|
|
+ ElMessage.error('存在无效的领用数量,请检查');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
if (selectedRows.value.length === 0) {
|
|
|
ElMessage.warning('请至少选择一个物料')
|
|
|
return
|
|
@@ -206,6 +220,30 @@ const getList = async () => {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// 处理领用数量输入框失焦事件
|
|
|
+const handleQuantityBlur = (event: Event, row: any) => {
|
|
|
+ const inputValue = (event.target as HTMLInputElement).value;
|
|
|
+ let num = parseFloat(inputValue);
|
|
|
+ // 处理无效值
|
|
|
+ if (isNaN(num)) {
|
|
|
+ row.requisitionQuantity = 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 处理小于等于0的情况
|
|
|
+ if (num <= 0) {
|
|
|
+ row.requisitionQuantity = 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 处理超过库存数量的情况
|
|
|
+ if (num > row.quantity) {
|
|
|
+ row.requisitionQuantity = row.quantity;
|
|
|
+ ElMessage.warning('领用数量不能超过库存数量');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 保留两位小数
|
|
|
+ row.requisitionQuantity = parseFloat(num.toFixed(2));
|
|
|
+};
|
|
|
+
|
|
|
// 处理输入框焦点事件(自动选中当前行)
|
|
|
const handleInputFocus = (row: MaterialApi.MaterialVO) => {
|
|
|
// 如果未选中则添加到选中列表
|