| | |
| | | <el-dialog v-model="dialogFormVisible" :title="operationType === 'add' ? '新增入库' : '编辑入库'" width="70%" |
| | | @close="closeDia"> |
| | | <el-form :model="form" label-width="140px" label-position="top" :rules="rules" ref="formRef"> |
| | | <el-form-item label="采购订单号" prop="salesContractNo"> |
| | | <el-input |
| | | <el-form-item label="采购订单号" prop="purchaseContractNumber"> |
| | | <el-select |
| | | v-model="form.purchaseContractNumber" |
| | | placeholder="请输入合同号" |
| | | placeholder="请选择采购订单号" |
| | | clearable |
| | | @change="searchByContractNo" |
| | | filterable |
| | | remote |
| | | :remote-method="loadPurchaseOptions" |
| | | :loading="loadingPurchaseOptions" |
| | | @change="handlePurchaseChange" |
| | | :disabled="operationType === 'edit'" |
| | | style="width: 100%" |
| | | > |
| | | <template #append> |
| | | <el-button |
| | | icon="Search" |
| | | @click="searchByContractNo" |
| | | :loading="loadingProducts" |
| | | <el-option |
| | | v-for="item in purchaseOptions" |
| | | :key="item.purchaseContractNumber" |
| | | :label="formatPurchaseOption(item)" |
| | | :value="item.purchaseContractNumber" |
| | | /> |
| | | </template> |
| | | </el-input> |
| | | </el-select> |
| | | </el-form-item> |
| | | <el-table |
| | | :data="productList" |
| | |
| | | <el-table-column label="待入库数量" prop="quantity0" width="100" /> |
| | | <el-table-column label="本次入库数量" prop="quantityStock" width="150"> |
| | | <template #default="scope"> |
| | | <el-input-number :step="0.01" :min="0" style="width: 100%" v-model="scope.row.quantityStock" :max="scope.row.quantity0" /> |
| | | <el-input-number :step="0.01" :min="0" style="width: 100%" v-model="scope.row.quantityStock" /> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column label="税率(%)" prop="taxRate" width="120" /> |
| | |
| | | |
| | | <script setup> |
| | | import pagination from '@/components/PIMTable/Pagination.vue' |
| | | import { ref } from 'vue' |
| | | import { ref, reactive, toRefs, onMounted, getCurrentInstance } from 'vue' |
| | | import { ElMessageBox } from "element-plus"; |
| | | import useUserStore from '@/store/modules/user' |
| | | import { |
| | |
| | | delStockIn, |
| | | selectProductRecordListByPuechaserId |
| | | } from "@/api/inventoryManagement/stockIn.js"; |
| | | import { purchaseListPage } from "@/api/procurementManagement/procurementLedger.js"; |
| | | |
| | | const userStore = useUserStore() |
| | | const { proxy } = getCurrentInstance() |
| | |
| | | const tableData = ref([]) |
| | | const selectedRows = ref([]) |
| | | const userList = ref([]) |
| | | |
| | | const purchaseOptions = ref([]) |
| | | const loadingPurchaseOptions = ref(false) |
| | | |
| | | |
| | | const loading = ref(false); |
| | |
| | | }) |
| | | const { searchForm, form, rules } = toRefs(data) |
| | | |
| | | const formatPurchaseOption = (item = {}) => { |
| | | const contract = item.purchaseContractNumber || '--'; |
| | | const supplier = item.supplierName ? ` · ${item.supplierName}` : ''; |
| | | return `${contract}${supplier}`; |
| | | }; |
| | | |
| | | const loadPurchaseOptions = async (keyword = '') => { |
| | | try { |
| | | loadingPurchaseOptions.value = true; |
| | | const res = await purchaseListPage({ |
| | | current: -1, |
| | | size: -1, |
| | | purchaseContractNumber: keyword, |
| | | }); |
| | | const records = res.data?.records || []; |
| | | purchaseOptions.value = records; |
| | | if ( |
| | | form.value.purchaseContractNumber && |
| | | !purchaseOptions.value.find( |
| | | (item) => item.purchaseContractNumber === form.value.purchaseContractNumber |
| | | ) |
| | | ) { |
| | | purchaseOptions.value.push({ |
| | | purchaseContractNumber: form.value.purchaseContractNumber, |
| | | supplierName: form.value.supplierName, |
| | | supplierId: form.value.supplierId, |
| | | }); |
| | | } |
| | | } finally { |
| | | loadingPurchaseOptions.value = false; |
| | | } |
| | | }; |
| | | |
| | | const handlePurchaseChange = (value) => { |
| | | form.value.purchaseContractNumber = value || ''; |
| | | const matched = purchaseOptions.value.find( |
| | | (item) => item.purchaseContractNumber === value |
| | | ); |
| | | if (matched) { |
| | | form.value.supplierName = matched.supplierName || form.value.supplierName; |
| | | form.value.supplierId = matched.supplierId || form.value.supplierId; |
| | | } |
| | | if (!value) { |
| | | productList.value = []; |
| | | return; |
| | | } |
| | | fetchProductsByContract(); |
| | | }; |
| | | const exceedsAddLimit = (product) => { |
| | | const stock = Number(product?.quantityStock ?? 0); |
| | | const waiting = Number(product?.quantity0 ?? 0); |
| | | if (!Number.isFinite(stock) || !Number.isFinite(waiting)) { |
| | | return false; |
| | | } |
| | | return stock > waiting; |
| | | }; |
| | | |
| | | const exceedsEditLimit = (product) => { |
| | | const stock = Number(product?.quantityStock ?? 0); |
| | | const waiting = Number(product?.quantity0 ?? 0); |
| | | const original = Number(product?.originalQuantityStock ?? 0); |
| | | if (!Number.isFinite(stock) || !Number.isFinite(waiting) || !Number.isFinite(original)) { |
| | | return false; |
| | | } |
| | | return stock > waiting + original; |
| | | }; |
| | | const formattedNumber = (row, column, cellValue) => { |
| | | return parseFloat(cellValue).toFixed(2); |
| | | }; |
| | | // 查询列表 |
| | | /** 搜索按钮操作 */ |
| | | const handleQuery = () => { |
| | |
| | | |
| | | // 调用selectProductRecordListByPuechaserId这个方法根据合同查询到id,再调用getProductRecordByhetong这个方法根据id查询到产品订单记录 |
| | | // 新增根据合同号查询产品记录的方法 |
| | | const searchByContractNo = async () => |
| | | const fetchProductsByContract = async () => |
| | | { |
| | | if (!form.value.purchaseContractNumber) { |
| | | proxy.$modal.msgWarning('请输入合同号') |
| | | proxy.$modal.msgWarning('请选择合同号') |
| | | return |
| | | } |
| | | try { |
| | |
| | | // 处理产品数据,添加本次入库数量字段 |
| | | productList.value = productRes.data.map(item => ({ |
| | | ...item, |
| | | quantityStock: 0 // 初始化本次入库数量为0 |
| | | quantityStock: 0, |
| | | originalQuantityStock: Number(item.quantityStock ?? item.inboundQuantity ?? 0), |
| | | })) |
| | | } catch (error) { |
| | | console.error('查询产品记录失败:', error) |
| | |
| | | operationType.value = type |
| | | dialogFormVisible.value = true |
| | | selectedRows.value = [] |
| | | await loadPurchaseOptions(); |
| | | |
| | | if (type === 'add') { |
| | | // 新增时初始化表单 |
| | |
| | | }); |
| | | productList.value = res.data.map(item => ({ |
| | | ...item, |
| | | quantityStock: row.inboundNum // 如果已有入库数量则保留 |
| | | quantityStock: Number(item.quantityStock ?? item.inboundQuantity ?? row.inboundNum ?? 0), |
| | | originalQuantityStock: Number(item.quantityStock ?? item.inboundQuantity ?? row.inboundNum ?? 0), |
| | | })) |
| | | selectedRows.value = productList.value |
| | | } catch (error) { |
| | |
| | | const updatePro = async () => { |
| | | // 准备提交数据 |
| | | // 准备提交数据 - 修改为后端需要的格式 |
| | | if (selectedRows.value.length === 0) { |
| | | proxy.$modal.msgWarning('请先选择产品'); |
| | | return; |
| | | } |
| | | const target = selectedRows.value[0]; |
| | | const stock = Number(target?.quantityStock ?? 0); |
| | | if (!Number.isFinite(stock) || stock <= 0) { |
| | | proxy.$modal.msgWarning('请填写有效的入库数量'); |
| | | return; |
| | | } |
| | | if (exceedsEditLimit(target)) { |
| | | proxy.$modal.msgError('本次入库数量不能超过原入库数量与待入库数量之和'); |
| | | return; |
| | | } |
| | | const stockInData = { |
| | | id: selectedRows.value[0].recordId, |
| | | quantityStock: Number(selectedRows.value[0].quantityStock),// 使用新格式化函数 |
| | |
| | | const submitForm = async () => { |
| | | // 验证至少选择了一个产品 |
| | | if (selectedRows.value.length === 0) { |
| | | proxy.$modal.msgError('请先查询并选择产品') |
| | | proxy.$modal.msgWarning('请先选择采购合同并选择产品') |
| | | return |
| | | } |
| | | if(operationType.value !== 'add'){ |
| | |
| | | try { |
| | | await proxy.$refs.formRef.validate() |
| | | // 验证入库数量 |
| | | const invalidProducts = selectedRows.value.filter( |
| | | product => product.quantityStock <= 0 || product.quantityStock > product.quantity0 |
| | | ) |
| | | const invalidProducts = selectedRows.value.filter((product) => { |
| | | const stock = Number(product?.quantityStock ?? 0); |
| | | if (!Number.isFinite(stock) || stock <= 0) { |
| | | return true; |
| | | } |
| | | return exceedsAddLimit(product); |
| | | }) |
| | | |
| | | if (invalidProducts.length > 0) { |
| | | proxy.$modal.msgError('请为所有产品输入有效的入库数量') |
| | | proxy.$modal.msgError('本次入库数量需大于0,且不能超过待入库数量') |
| | | return |
| | | } |
| | | |
| | | // 准备提交数据 |
| | | // 准备提交数据 - 修改为后端需要的格式 |
| | | const stockInData = { |
| | | // 入库单基本信息 |
| | | ...form.value, |
| | | inboundTime: formatDateTime(form.value.inboundTime), |
| | | nickName: userStore.nickName,// 使用新格式化函数 |
| | | nickName: userStore.nickName, |
| | | details: selectedRows.value.map(product => ({ |
| | | id: product.id, |
| | | // id: product.salesLedgerProductId, |
| | | inboundQuantity: Number(product.quantityStock) |
| | | })), |
| | | }; |
| | | console.log('准备提交的数据:', JSON.parse(JSON.stringify(stockInData))); |
| | | // 调用API |
| | | loading.value = true |
| | | await addSutockIn(stockInData) |
| | |
| | | const handleSelectionChange = (selection) => { |
| | | // 过滤掉子数据 |
| | | selectedRows.value = selection.filter(item => item.id); |
| | | console.log('selection', selectedRows.value) |
| | | } |
| | | |
| | | const expandedRowKeys = ref([]) |