From 5b3cbcef771cd23ef8db1bf29dd15e2ddd98744f Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 24 四月 2026 14:58:53 +0800
Subject: [PATCH] fix: 库存管理页面修改,领用、冻结与解冻区分
---
src/views/inventoryManagement/stockManagement/FrozenAndThaw.vue | 262 +++++++++++++++++++++++++++++++++------------------
1 files changed, 169 insertions(+), 93 deletions(-)
diff --git a/src/views/inventoryManagement/stockManagement/FrozenAndThaw.vue b/src/views/inventoryManagement/stockManagement/FrozenAndThaw.vue
index 463cb83..05c57b4 100644
--- a/src/views/inventoryManagement/stockManagement/FrozenAndThaw.vue
+++ b/src/views/inventoryManagement/stockManagement/FrozenAndThaw.vue
@@ -1,17 +1,38 @@
<template>
<div>
<el-dialog
- v-model="isShow"
- :title="operationType === 'frozen' ? '鍐荤粨搴撳瓨' : '瑙e喕搴撳瓨'"
- width="800"
- @close="closeModal"
+ v-model="isShow"
+ :title="operationType === 'frozen' ? '鍐荤粨搴撳瓨' : '瑙e喕搴撳瓨'"
+ width="800"
+ @close="closeModal"
>
<el-form label-width="140px" :model="formState" ref="formRef">
<el-form-item
- :label="operationType === 'frozen' ? '鍐荤粨鏁伴噺锛�' : '瑙e喕鏁伴噺锛�'"
- prop="lockedQuantity"
+ label="搴撳瓨绫诲瀷"
+ prop="stockType"
+ :rules="[
+ {
+ required: true,
+ message: '璇烽�夋嫨搴撳瓨绫诲瀷',
+ trigger: 'change',
+ }
+ ]"
>
- <el-input-number v-model="formState.lockedQuantity" :step="1" :min="1" precision="0" style="width: 100%" :max="maxCount" />
+ <el-select v-model="formState.stockType" placeholder="璇烽�夋嫨搴撳瓨绫诲瀷" style="width: 100%">
+ <el-option label="鍚堟牸搴撳瓨" value="qualified" />
+ <el-option label="涓嶅悎鏍煎簱瀛�" value="unqualified" />
+ </el-select>
+ </el-form-item>
+
+ <el-form-item :label="operationType === 'frozen' ? '鍐荤粨鏁伴噺锛�' : '瑙e喕鏁伴噺锛�'" prop="lockedQuantity">
+ <el-input-number
+ v-model="formState.lockedQuantity"
+ :step="0.01"
+ :min="inputMin"
+ :precision="2"
+ style="width: 100%"
+ :max="maxCount"
+ />
</el-form-item>
</el-form>
@@ -26,39 +47,67 @@
</template>
<script setup>
-import {ref, computed, getCurrentInstance} from "vue";
-import {frozenStockInventory, thawStockInventory} from "@/api/inventoryManagement/stockInventory.js";
-import {frozenStockUninventory, thawStockUninventory} from "@/api/inventoryManagement/stockUninventory.js";
+import { ref, computed, getCurrentInstance, onMounted, watch } from "vue";
+import { frozenStockInventory, thawStockInventory } from "@/api/inventoryManagement/stockInventory.js";
+import { frozenStockUninventory, thawStockUninventory } from "@/api/inventoryManagement/stockUninventory.js";
const props = defineProps({
visible: {
type: Boolean,
required: true,
},
-
operationType: {
type: String,
required: true,
- default: 'frozen',
+ default: "frozen",
},
-
type: {
type: String,
required: true,
- default: 'qualified',
+ default: "qualified",
},
-
record: {
type: Object,
- default: () => {},
- }
+ default: () => ({}),
+ },
});
-const emit = defineEmits(['update:visible', 'completed']);
+const emit = defineEmits(["update:visible", "completed"]);
-// 鍝嶅簲寮忔暟鎹紙鏇夸唬閫夐」寮忕殑 data锛�
+const toNumber = (value) => {
+ const num = Number(value);
+ return Number.isFinite(num) ? num : 0;
+};
+
+const getQualifiedUnLockedStock = (row) => {
+ return toNumber(
+ row?.qualifiedUnLockedQuantity ??
+ row?.unLockedQuantity ??
+ row?.qualifiedQuantity ??
+ row?.qualitity
+ );
+};
+
+const getUnqualifiedUnLockedStock = (row) => {
+ return toNumber(
+ row?.unQualifiedUnLockedQuantity ??
+ row?.unqualifiedUnLockedQuantity ??
+ row?.unQualifiedQuantity ??
+ row?.unqualifiedQuantity
+ );
+};
+
+const getQualifiedLockedStock = (row) => {
+ return toNumber(row?.qualifiedLockedQuantity ?? row?.lockedQuantity);
+};
+
+const getUnqualifiedLockedStock = (row) => {
+ return toNumber(row?.unQualifiedLockedQuantity ?? row?.unqualifiedLockedQuantity);
+};
+
const formState = ref({
- lockedQuantity: 0,
+ stockType: "qualified",
+ lockedQuantity: 0.01,
});
const isShow = computed({
@@ -66,95 +115,122 @@
return props.visible;
},
set(val) {
- emit('update:visible', val);
+ emit("update:visible", val);
},
});
+const maxCount = computed(() => {
+ const isQualified = formState.value.stockType === "qualified";
+ if (props.operationType === "frozen") {
+ return isQualified ? getQualifiedUnLockedStock(props.record) : getUnqualifiedUnLockedStock(props.record);
+ }
+ return isQualified ? getQualifiedLockedStock(props.record) : getUnqualifiedLockedStock(props.record);
+});
-let { proxy } = getCurrentInstance()
+const inputMin = computed(() => (maxCount.value > 0 ? 0.01 : 0));
+
+const targetStockId = computed(() => {
+ if (formState.value.stockType === "unqualified") {
+ return props.record?.unQualifiedId ?? props.record?.unqualifiedId ?? props.record?.id;
+ }
+ return props.record?.qualifiedId ?? props.record?.id;
+});
+
+const initFormData = () => {
+ formState.value.stockType = props.type === "unqualified" ? "unqualified" : "qualified";
+ if (props.operationType === "thaw") {
+ formState.value.lockedQuantity = maxCount.value;
+ } else {
+ formState.value.lockedQuantity = maxCount.value > 0 ? 0.01 : 0;
+ }
+};
+
+watch(
+ () => props.record,
+ () => {
+ initFormData();
+ },
+ { deep: true }
+);
+
+watch(
+ () => props.operationType,
+ () => {
+ initFormData();
+ }
+);
+
+watch(
+ maxCount,
+ (val) => {
+ if (val <= 0) {
+ formState.value.lockedQuantity = 0;
+ return;
+ }
+ if (!formState.value.lockedQuantity || formState.value.lockedQuantity < 0.01) {
+ formState.value.lockedQuantity = 0.01;
+ } else if (formState.value.lockedQuantity > val) {
+ formState.value.lockedQuantity = val;
+ }
+ },
+ { immediate: true }
+);
+
+const { proxy } = getCurrentInstance();
const closeModal = () => {
- // 閲嶇疆琛ㄥ崟鏁版嵁
formState.value = {
- lockedQuantity: undefined
+ stockType: "qualified",
+ lockedQuantity: 0.01,
};
isShow.value = false;
};
-const maxCount = computed(() => {
- // 鍐荤粨搴撳瓨鏈�澶ф暟閲忎负鏈В鍐绘暟閲�
- if (props.operationType === 'frozen') {
- return props.record.unLockedQuantity
- }
- // 瑙e喕搴撳瓨鏈�澶ф暟閲忎负宸插喕缁撴暟閲�
- return props.record.lockedQuantity
-})
-
const handleSubmit = () => {
- proxy.$refs["formRef"].validate(valid => {
- if (valid) {
- const data = Object.assign({id: props.record.id}, formState.value);
- if (props.type === 'qualified') {
- // 鍐荤粨
- if (props.operationType === 'frozen') {
- frozenStockInventory(data).then(res => {
- if (res.code === 200) {
- // 鍏抽棴妯℃�佹
- isShow.value = false;
- // 鍛婄煡鐖剁粍浠跺凡瀹屾垚
- emit('completed');
- proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
- } else {
- proxy.$modal.msgError(res.msg);
- }
- })
- } else {
- thawStockInventory(data).then(res => {
- if (res.code === 200) {
- // 鍏抽棴妯℃�佹
- isShow.value = false;
- // 鍛婄煡鐖剁粍浠跺凡瀹屾垚
- emit('completed');
- proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
- } else {
- proxy.$modal.msgError(res.msg);
- }
- })
- }
- } else {
- if (props.operationType === 'frozen') {
- frozenStockUninventory(data).then(res => {
- if (res.code === 200) {
- // 鍏抽棴妯℃�佹
- isShow.value = false;
- // 鍛婄煡鐖剁粍浠跺凡瀹屾垚
- emit('completed');
- proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
- } else {
- proxy.$modal.msgError(res.msg);
- }
- })
- } else {
- thawStockUninventory(data).then(res => {
- if (res.code === 200) {
- // 鍏抽棴妯℃�佹
- isShow.value = false;
- // 鍛婄煡鐖剁粍浠跺凡瀹屾垚
- emit('completed');
- proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
- } else {
- proxy.$modal.msgError(res.msg);
- }
- })
- }
- }
+ proxy.$refs["formRef"].validate((valid) => {
+ if (!valid) return;
+
+ if (!formState.value.stockType) {
+ proxy.$modal.msgError("璇烽�夋嫨搴撳瓨绫诲瀷");
+ return;
}
- })
+ if (!formState.value.lockedQuantity || formState.value.lockedQuantity <= 0) {
+ proxy.$modal.msgError(props.operationType === "frozen" ? "鍐荤粨鏁伴噺蹇呴』澶т簬0" : "瑙e喕鏁伴噺蹇呴』澶т簬0");
+ return;
+ }
+ if (formState.value.lockedQuantity > maxCount.value) {
+ proxy.$modal.msgError("鎿嶄綔鏁伴噺涓嶈兘瓒呰繃鍙搷浣滃簱瀛�");
+ return;
+ }
+
+ if (!targetStockId.value) {
+ proxy.$modal.msgError("鏈壘鍒板搴斿簱瀛業D锛屾棤娉曟彁浜�");
+ return;
+ }
+
+ const data = Object.assign({ id: targetStockId.value }, formState.value);
+ let submitApi;
+ if (formState.value.stockType === "qualified") {
+ submitApi = props.operationType === "frozen" ? frozenStockInventory : thawStockInventory;
+ } else {
+ submitApi = props.operationType === "frozen" ? frozenStockUninventory : thawStockUninventory;
+ }
+
+ submitApi(data).then((res) => {
+ if (res.code === 200) {
+ isShow.value = false;
+ emit("completed");
+ proxy.$modal.msgSuccess("鎻愪氦鎴愬姛");
+ } else {
+ proxy.$modal.msgError(res.msg);
+ }
+ });
+ });
};
onMounted(() => {
- formState.value.lockedQuantity = maxCount.value;
-})
+ initFormData();
+});
defineExpose({
closeModal,
--
Gitblit v1.9.3