<template>
|
<div>
|
<el-dialog
|
v-model="isShow"
|
:title="operationType === 'frozen' ? '冻结库存' : '解冻库存'"
|
width="800"
|
@close="closeModal"
|
>
|
<el-form label-width="140px" :model="formState" ref="formRef">
|
<el-form-item
|
label="库存类型"
|
prop="stockType"
|
:rules="[
|
{
|
required: true,
|
message: '请选择库存类型',
|
trigger: 'change',
|
}
|
]"
|
>
|
<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' ? '冻结数量:' : '解冻数量:'" 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>
|
|
<template #footer>
|
<div class="dialog-footer">
|
<el-button type="primary" @click="handleSubmit">确认</el-button>
|
<el-button @click="closeModal">取消</el-button>
|
</div>
|
</template>
|
</el-dialog>
|
</div>
|
</template>
|
|
<script setup>
|
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",
|
},
|
type: {
|
type: String,
|
required: true,
|
default: "qualified",
|
},
|
record: {
|
type: Object,
|
default: () => ({}),
|
},
|
});
|
|
const emit = defineEmits(["update:visible", "completed"]);
|
|
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({
|
stockType: "qualified",
|
lockedQuantity: 0.01,
|
});
|
|
const isShow = computed({
|
get() {
|
return props.visible;
|
},
|
set(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);
|
});
|
|
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 = {
|
stockType: "qualified",
|
lockedQuantity: 0.01,
|
};
|
isShow.value = false;
|
};
|
|
const handleSubmit = () => {
|
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" : "解冻数量必须大于0");
|
return;
|
}
|
if (formState.value.lockedQuantity > maxCount.value) {
|
proxy.$modal.msgError("操作数量不能超过可操作库存");
|
return;
|
}
|
|
if (!targetStockId.value) {
|
proxy.$modal.msgError("未找到对应库存ID,无法提交");
|
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(() => {
|
initFormData();
|
});
|
|
defineExpose({
|
closeModal,
|
handleSubmit,
|
isShow,
|
});
|
</script>
|