From 3f15d0eef89e52f3fd6d1be13ff3af010b6f0ee9 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期三, 05 十一月 2025 15:27:44 +0800
Subject: [PATCH] 录入日期改为可选择
---
src/views/inventoryManagement/receiptManagement/index.vue | 159 ++++++++++++++++++++++++++++++++++++++++++----------
1 files changed, 127 insertions(+), 32 deletions(-)
diff --git a/src/views/inventoryManagement/receiptManagement/index.vue b/src/views/inventoryManagement/receiptManagement/index.vue
index 1de9809..2414a5c 100644
--- a/src/views/inventoryManagement/receiptManagement/index.vue
+++ b/src/views/inventoryManagement/receiptManagement/index.vue
@@ -54,22 +54,26 @@
<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"
- />
- </template>
- </el-input>
+ <el-option
+ v-for="item in purchaseOptions"
+ :key="item.purchaseContractNumber"
+ :label="formatPurchaseOption(item)"
+ :value="item.purchaseContractNumber"
+ />
+ </el-select>
</el-form-item>
<el-table
:data="productList"
@@ -92,7 +96,7 @@
<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" />
@@ -128,7 +132,7 @@
<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 {
@@ -138,6 +142,7 @@
delStockIn,
selectProductRecordListByPuechaserId
} from "@/api/inventoryManagement/stockIn.js";
+import { purchaseListPage } from "@/api/procurementManagement/procurementLedger.js";
const userStore = useUserStore()
const { proxy } = getCurrentInstance()
@@ -145,6 +150,9 @@
const tableData = ref([])
const selectedRows = ref([])
const userList = ref([])
+
+const purchaseOptions = ref([])
+const loadingPurchaseOptions = ref(false)
const loading = ref(false);
@@ -188,6 +196,75 @@
})
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 = () => {
@@ -214,10 +291,10 @@
// 璋冪敤selectProductRecordListByPuechaserId杩欎釜鏂规硶鏍规嵁鍚堝悓鏌ヨ鍒癷d锛屽啀璋冪敤getProductRecordByhetong杩欎釜鏂规硶鏍规嵁id鏌ヨ鍒颁骇鍝佽鍗曡褰�
// 鏂板鏍规嵁鍚堝悓鍙锋煡璇骇鍝佽褰曠殑鏂规硶
-const searchByContractNo = async () =>
+const fetchProductsByContract = async () =>
{
if (!form.value.purchaseContractNumber) {
- proxy.$modal.msgWarning('璇疯緭鍏ュ悎鍚屽彿')
+ proxy.$modal.msgWarning('璇烽�夋嫨鍚堝悓鍙�')
return
}
try {
@@ -235,7 +312,8 @@
// 澶勭悊浜у搧鏁版嵁锛屾坊鍔犳湰娆″叆搴撴暟閲忓瓧娈�
productList.value = productRes.data.map(item => ({
...item,
- quantityStock: 0 // 鍒濆鍖栨湰娆″叆搴撴暟閲忎负0
+ quantityStock: 0,
+ originalQuantityStock: Number(item.quantityStock ?? item.inboundQuantity ?? 0),
}))
} catch (error) {
console.error('鏌ヨ浜у搧璁板綍澶辫触:', error)
@@ -252,6 +330,7 @@
operationType.value = type
dialogFormVisible.value = true
selectedRows.value = []
+ await loadPurchaseOptions();
if (type === 'add') {
// 鏂板鏃跺垵濮嬪寲琛ㄥ崟
@@ -277,10 +356,11 @@
purchaseContractNumber: form.value.purchaseContractNumber,
id: row.id
});
- productList.value = res.data.map(item => ({
- ...item,
- quantityStock: row.inboundNum // 濡傛灉宸叉湁鍏ュ簱鏁伴噺鍒欎繚鐣�
- }))
+ productList.value = res.data.map(item => ({
+ ...item,
+ quantityStock: Number(item.quantityStock ?? item.inboundQuantity ?? row.inboundNum ?? 0),
+ originalQuantityStock: Number(item.quantityStock ?? item.inboundQuantity ?? row.inboundNum ?? 0),
+ }))
selectedRows.value = productList.value
} catch (error) {
console.error('鍔犺浇浜у搧澶辫触:', error)
@@ -293,8 +373,22 @@
}
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),// 浣跨敤鏂版牸寮忓寲鍑芥暟
@@ -309,7 +403,7 @@
const submitForm = async () => {
// 楠岃瘉鑷冲皯閫夋嫨浜嗕竴涓骇鍝�
if (selectedRows.value.length === 0) {
- proxy.$modal.msgError('璇峰厛鏌ヨ骞堕�夋嫨浜у搧')
+ proxy.$modal.msgWarning('璇峰厛閫夋嫨閲囪喘鍚堝悓骞堕�夋嫨浜у搧')
return
}
if(operationType.value !== 'add'){
@@ -319,29 +413,31 @@
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)
@@ -370,7 +466,6 @@
const handleSelectionChange = (selection) => {
// 杩囨护鎺夊瓙鏁版嵁
selectedRows.value = selection.filter(item => item.id);
- console.log('selection', selectedRows.value)
}
const expandedRowKeys = ref([])
--
Gitblit v1.9.3