fix: 🧩 修复bug
This commit is contained in:
@@ -112,6 +112,7 @@ const handleButtonClickCallback = (item: any) => {
|
||||
if (type === "preview") {
|
||||
if (!dataStore.id) {
|
||||
useMsg("warning", "请先保存数据 !");
|
||||
return;
|
||||
}
|
||||
$router.push({
|
||||
path: "/foundation/set/goods/preview",
|
||||
@@ -124,6 +125,30 @@ const handleButtonClickCallback = (item: any) => {
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
//去重
|
||||
const uniqueArrayObject = (arr: any[], uniqueKey: any = "value") => {
|
||||
// 边界处理:如果传入的不是数组,直接返回空数组
|
||||
if (!Array.isArray(arr)) {
|
||||
console.warn("传入的参数不是数组,返回空数组");
|
||||
return [];
|
||||
}
|
||||
// 方法1:Map 实现(高效,保留顺序)
|
||||
const uniqueMap = new Map();
|
||||
arr.forEach(item => {
|
||||
// 确保对象存在该字段,避免报错
|
||||
if (item.hasOwnProperty(uniqueKey)) {
|
||||
// 以 uniqueKey 的值为键,重复键会自动覆盖(保留最后一次出现?不,forEach 顺序遍历,后出现的会覆盖前面的,如需保留首次出现,用下面的逻辑)
|
||||
// 如需保留首次出现:只有 Map 中没有该键时才添加
|
||||
if (!uniqueMap.has(item[uniqueKey])) {
|
||||
uniqueMap.set(item[uniqueKey], item);
|
||||
}
|
||||
}
|
||||
});
|
||||
// 转换为数组返回
|
||||
return Array.from(uniqueMap.values());
|
||||
};
|
||||
|
||||
//仓库列表 /foundation/set/goods/preview
|
||||
const getWarehousesList = async () => {
|
||||
const result = await getWarehousesListApi({ use_org_number: dataStore.ruleForm.use_org_number });
|
||||
@@ -133,26 +158,46 @@ const getWarehousesList = async () => {
|
||||
let options: any = [];
|
||||
data.forEach((item: any) => {
|
||||
options.push({
|
||||
id: item.id,
|
||||
// id: item.id,
|
||||
value: item.warehouse_number,
|
||||
label: item.warehouse_name
|
||||
});
|
||||
});
|
||||
dataStore.formData[1].options = options;
|
||||
console.log(12121212);
|
||||
console.log(dataStore.ruleForm);
|
||||
console.log(dataStore.ruleForm.warehouse_number, "=dataStore.ruleForm=");
|
||||
if (dataStore.ruleForm.warehouse_name) {
|
||||
console.log("走到了这里");
|
||||
dataStore.formData[1].options.push({
|
||||
value: dataStore.ruleForm.warehouse_number,
|
||||
label: dataStore.ruleForm.warehouse_name
|
||||
});
|
||||
|
||||
dataStore.formData[1].options = uniqueArrayObject(dataStore.formData[1].options);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
const handleChange = (item: any) => {
|
||||
console.log(item);
|
||||
getGoodsCheckExistsw();
|
||||
if (item.prop === "warehouse_number") {
|
||||
if (!dataStore.ruleForm.use_org_number || !dataStore.ruleForm.warehouse_number) {
|
||||
return;
|
||||
}
|
||||
getGoodsCheckExistsw();
|
||||
}
|
||||
};
|
||||
//监听当前组织
|
||||
watch(
|
||||
() => dataStore.ruleForm.use_org_number,
|
||||
(newVal: any) => {
|
||||
if (newVal) {
|
||||
getWarehousesList();
|
||||
if (!newVal) {
|
||||
dataStore.ruleForm.warehouse_number = "";
|
||||
dataStore.formData[1].options = [];
|
||||
return;
|
||||
}
|
||||
getWarehousesList();
|
||||
},
|
||||
{
|
||||
deep: true,
|
||||
|
||||
Reference in New Issue
Block a user