This commit is contained in:
2025-08-28 23:32:17 +08:00
parent 2b25709c14
commit ade1177294
16 changed files with 1929 additions and 649 deletions

View File

@ -56,7 +56,7 @@
<el-table-column label="操作" align="center" min-width="150" fixed="right">
<template #default="scope">
<el-button link type="primary" icon="View" @click="handleView(scope.row)" v-hasPermi="['materials:materialIssue:query']">查看</el-button>
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['materials:materialIssue:edit']">修改</el-button>
<!-- <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['materials:materialIssue:edit']">修改</el-button> -->
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['materials:materialIssue:remove']"
>删除</el-button
>
@ -130,8 +130,8 @@
:prop="`itemList.${index}.name`"
:rules="[{ required: true, message: '名称不能为空', trigger: 'blur' }]"
>
<el-select v-model="item.name" placeholder="请选择名称" @change="(value) => getNameChange(value, index, item)">
<el-option v-for="opt in optionsName" :key="opt.id" :label="opt.materialsName" :value="opt.materialsName" />
<el-select v-model="item.inventoryId" placeholder="请选择名称" @change="(value) => getNameChange(value, index, item)">
<el-option v-for="opt in optionsName" :key="opt.id" :label="opt.materialsName" :value="opt.id" />
</el-select>
</el-form-item>
</el-col>
@ -141,7 +141,7 @@
:prop="`itemList.${index}.specification`"
:rules="[{ required: true, message: '规格不能为空', trigger: 'blur' }]"
>
<el-input v-model="item.specification" placeholder="请输入规格" />
<el-input disabled v-model="item.specification" placeholder="请输入规格" />
</el-form-item>
</el-col>
<el-col :span="12">
@ -150,10 +150,10 @@
:prop="`itemList.${index}.unit`"
:rules="[{ required: true, message: '单位不能为空', trigger: 'blur' }]"
>
<el-input v-model="item.unit" placeholder="请输入单位" />
<el-input disabled v-model="item.unit" placeholder="请输入单位" />
</el-form-item>
</el-col>
<el-col :span="12">
<!-- <el-col :span="12">
<el-form-item
label="库存"
:prop="`itemList.${index}.stockQuantity`"
@ -169,29 +169,19 @@
@blur="handleStockChange(index)"
/>
</el-form-item>
</el-col>
</el-col> -->
<el-col :span="12">
<el-form-item
label="领取"
:prop="`itemList.${index}.issuedQuantity`"
:rules="[
{ required: true, message: '领取数量不能为空', trigger: 'blur' },
{ type: 'number', min: 0, message: '领取数量不能小于0', trigger: ['blur', 'change'] },
{
validator: (rule, value, callback) => validateIssuedQuantity(rule, value, callback, index),
trigger: ['blur', 'change']
}
]"
>
<el-form-item label="领取" :prop="`itemList.${index}.issuedQuantity`">
<el-input
v-model.number="item.issuedQuantity"
disabled
placeholder="请输入领取数量"
@input="handleIssuedChange(index)"
@blur="handleIssuedChange(index)"
/>
</el-form-item>
</el-col>
<el-col :span="12">
<!-- <el-col :span="12">
<el-form-item
label="剩余"
:prop="`itemList.${index}.remainingQuantity`"
@ -204,7 +194,7 @@
<el-form-item label="备注" :prop="`itemList.${index}.remark`">
<el-input v-model="item.remark" placeholder="请输入内容" />
</el-form-item>
</el-col>
</el-col> -->
<el-col :span="12" v-if="form.itemList.length > 1">
<div class="item-actions">
<el-button type="danger" link @click="removeItem(index)" icon="Delete">删除</el-button>
@ -263,6 +253,7 @@ import {
delMaterialIssue,
addMaterialIssue,
updateMaterialIssue,
inventoryList,
getMaterialName
} from '@/api/materials/materialIssue';
@ -399,7 +390,9 @@ const getList = async () => {
// 获取材料名称列表
const getName = async () => {
try {
const res = await getMaterialName(currentProject.value.id);
const res = await inventoryList(currentProject.value.id);
console.log(res);
if (res.code == 200) {
optionsName.value = res.data;
}
@ -410,14 +403,15 @@ const getName = async () => {
// 材料名称选择变化处理修改select的value为名称而非ID
const getNameChange = (value, index, item) => {
const selected = optionsName.value.find((opt) => opt.materialsName === value);
const selected = optionsName.value.find((opt) => opt.id === value);
if (selected) {
item.name = selected.materialsName; // 直接赋值名称
item.materialsId = selected.id; // 保留ID用于后端
item.specification = selected.typeSpecificationName;
item.unit = selected.weightId;
item.issuedQuantity = selected.number;
item.stockQuantity = Number(selected.inventoryNumber) || 0;
calculateRemaining(index); // 计算剩余数量
// calculateRemaining(index); // 计算剩余数量
}
};
@ -504,14 +498,14 @@ const watchItemChanges = (index: number) => {
itemWatchStopFns.value[index]();
}
// 监听库存和领取数量变化
const stop = watch(
() => [form.value.itemList[index].stockQuantity, form.value.itemList[index].issuedQuantity],
() => {
calculateRemaining(index);
},
{ immediate: true }
);
// // 监听库存和领取数量变化
// const stop = watch(
// () => [form.value.itemList[index].stockQuantity, form.value.itemList[index].issuedQuantity],
// () => {
// calculateRemaining(index);
// },
// { immediate: true }
// );
itemWatchStopFns.value[index] = stop;
};