|
|
@@ -252,7 +252,7 @@ import { ref, reactive, computed, onMounted } from "vue";
|
|
|
import { ElMessage } from "element-plus";
|
|
|
import type { FormInstance, FormRules } from "element-plus";
|
|
|
import { localGet } from "@/utils";
|
|
|
-import { getAllTagType, getAllTag, saveTag } from "@/api/modules/storeDecoration";
|
|
|
+import { getTagList, getAllTag, saveTag } from "@/api/modules/storeDecoration";
|
|
|
|
|
|
const loading = ref(false);
|
|
|
const formRef = ref<FormInstance>();
|
|
|
@@ -359,7 +359,72 @@ const handleSave = async () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 初始化表单数据(从接口获取已保存的数据)
|
|
|
+/** 解析 getTagList 记录里的 labelButtonOptionOne / Two(JSON 字符串) */
|
|
|
+function parseLabelButtonOptions(jsonStr: unknown): Array<{ name: string; value: string | number }> {
|
|
|
+ if (jsonStr == null || jsonStr === "") return [];
|
|
|
+ if (typeof jsonStr !== "string") return [];
|
|
|
+ try {
|
|
|
+ const arr = JSON.parse(jsonStr);
|
|
|
+ if (!Array.isArray(arr)) return [];
|
|
|
+ return arr.map((o: any) => ({
|
|
|
+ name: o?.name ?? "",
|
|
|
+ value: o?.value ?? ""
|
|
|
+ }));
|
|
|
+ } catch {
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+const FORM_BUTTON_TYPES = ["radioDouble", "radio", "radios", "checkbox"] as const;
|
|
|
+
|
|
|
+/** 将 getTagList 单条 record 转为模板使用的 list 项 */
|
|
|
+function mapTagListRecordToItem(raw: Record<string, any>) {
|
|
|
+ const bt = raw.labelButtonType;
|
|
|
+ const labelButtonType = (FORM_BUTTON_TYPES as readonly string[]).includes(bt) ? bt : "radio";
|
|
|
+ const opt2 = parseLabelButtonOptions(raw.labelButtonOptionTwo);
|
|
|
+ const item: {
|
|
|
+ label: string;
|
|
|
+ labelButtonType: (typeof FORM_BUTTON_TYPES)[number];
|
|
|
+ field_1: string;
|
|
|
+ field_2?: string;
|
|
|
+ field_5?: string;
|
|
|
+ field_7?: string;
|
|
|
+ field_11?: string;
|
|
|
+ tips?: string;
|
|
|
+ labelButtonOption_1: Array<{ name: string; value: string | number }>;
|
|
|
+ labelButtonOption_2?: Array<{ name: string; value: string | number }>;
|
|
|
+ } = {
|
|
|
+ label: raw.label ?? "",
|
|
|
+ labelButtonType: labelButtonType as (typeof FORM_BUTTON_TYPES)[number],
|
|
|
+ field_1: raw.field_1 ?? "",
|
|
|
+ tips: raw.labelDescribe || "",
|
|
|
+ labelButtonOption_1: parseLabelButtonOptions(raw.labelButtonOptionOne)
|
|
|
+ };
|
|
|
+ if (raw.field_2) item.field_2 = raw.field_2;
|
|
|
+ if (opt2.length) item.labelButtonOption_2 = opt2;
|
|
|
+ return item;
|
|
|
+}
|
|
|
+
|
|
|
+/** 根据 getTagList 分页 data 构建 tagGroups(左:基础设施 / 右:门店介绍) */
|
|
|
+function buildTagGroupsFromListPageData(data: Record<string, any> | null | undefined) {
|
|
|
+ const records = Array.isArray(data?.records) ? [...data!.records] : [];
|
|
|
+ records.sort((a: any, b: any) => (Number(a?.tagSort) || 0) - (Number(b?.tagSort) || 0));
|
|
|
+ const infraList: ReturnType<typeof mapTagListRecordToItem>[] = [];
|
|
|
+ const introList: ReturnType<typeof mapTagListRecordToItem>[] = [];
|
|
|
+ for (const r of records) {
|
|
|
+ if (!r || typeof r !== "object") continue;
|
|
|
+ const item = mapTagListRecordToItem(r as Record<string, any>);
|
|
|
+ const lt = (r as Record<string, any>).labelType;
|
|
|
+ if (lt === "infrastructure") infraList.push(item);
|
|
|
+ else if (lt === "storeIntroduction") introList.push(item);
|
|
|
+ }
|
|
|
+ const groups: typeof tagGroups.value = [];
|
|
|
+ if (infraList.length) groups.push({ labelName: "基础设施", list: infraList });
|
|
|
+ if (introList.length) groups.push({ labelName: "门店介绍", list: introList });
|
|
|
+ return groups;
|
|
|
+}
|
|
|
+
|
|
|
+// 初始化表单数据(门店已选值:与标签定义分离,仍走原门店关系接口)
|
|
|
const initFormData = async () => {
|
|
|
try {
|
|
|
const userInfo: any = localGet("geeker-user")?.userInfo || {};
|
|
|
@@ -369,12 +434,9 @@ const initFormData = async () => {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 调用获取门店标签数据接口 getAllTag API
|
|
|
const res: any = await getAllTag({ storeId: Number(storeId) });
|
|
|
if (res && (res.code === 200 || res.code === "200") && res.data) {
|
|
|
- // 将接口返回的数据合并到formData中
|
|
|
Object.assign(formData, res.data);
|
|
|
- // 处理checkbox类型的数据(如果是字符串,需要转换为数组)
|
|
|
tagGroups.value.forEach(group => {
|
|
|
group.list.forEach(item => {
|
|
|
if (item.labelButtonType === "checkbox" && item.field_1) {
|
|
|
@@ -383,11 +445,9 @@ const initFormData = async () => {
|
|
|
if (value && typeof value === "string") {
|
|
|
formData[fieldName] = value.split(",").filter(Boolean);
|
|
|
} else if (!value) {
|
|
|
- // 如果字段不存在,初始化为空数组
|
|
|
formData[fieldName] = [];
|
|
|
}
|
|
|
} else if (item.field_1 && formData[item.field_1] === undefined) {
|
|
|
- // 其他类型字段如果不存在,初始化为空值
|
|
|
formData[item.field_1] = "";
|
|
|
}
|
|
|
});
|
|
|
@@ -398,50 +458,24 @@ const initFormData = async () => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 初始化标签选项(从接口获取标签列表)
|
|
|
+// 初始化标签结构(渲染用):来自 getTagList 的 records
|
|
|
const initTagOptions = async () => {
|
|
|
try {
|
|
|
- // 从userInfo中获取businessSection
|
|
|
- const userInfo: any = localGet("geeker-user")?.userInfo || {};
|
|
|
- const businessSection = userInfo.businessSection || localGet("businessSection") || "";
|
|
|
-
|
|
|
- if (!businessSection) {
|
|
|
- console.warn("未找到businessSection参数");
|
|
|
+ const first: any = await getTagList({ pageNum: 1, pageSize: 1 });
|
|
|
+ if (!(first && (first.code === 200 || first.code === "200") && first.data)) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- // 调用获取标签列表接口 getAllTagType API
|
|
|
- const res: any = await getAllTagType({ businessSection });
|
|
|
- if (res && (res.code === 200 || res.code === "200") && res.data) {
|
|
|
- const dataList = Array.isArray(res.data) ? res.data : [];
|
|
|
-
|
|
|
- // 处理checkbox类型的已选状态
|
|
|
- dataList.forEach((item: any) => {
|
|
|
- if (item.labelButtonType === "checkbox") {
|
|
|
- item.labelButtonOption_1.forEach((option: any) => {
|
|
|
- if (formData[item.field_1] && formData[item.field_1].indexOf(option.value) !== -1) {
|
|
|
- option.isChecked = true;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 按labelName分组
|
|
|
- const grouped = dataList.reduce((acc: any[], current: any) => {
|
|
|
- const existing = acc.find(item => item.labelName === current.labelName);
|
|
|
- if (existing) {
|
|
|
- existing.list.push(current);
|
|
|
- } else {
|
|
|
- acc.push({
|
|
|
- labelName: current.labelName,
|
|
|
- list: [current]
|
|
|
- });
|
|
|
- }
|
|
|
- return acc;
|
|
|
- }, []);
|
|
|
-
|
|
|
- tagGroups.value = grouped;
|
|
|
+ const recLen = first.data.records?.length ?? 0;
|
|
|
+ const apiTotal = Number(first.data.total);
|
|
|
+ const targetSize = Number.isFinite(apiTotal) && apiTotal > 0 ? Math.min(apiTotal, 500) : Math.min(Math.max(recLen, 1), 500);
|
|
|
+ let pageData = first.data;
|
|
|
+ if (targetSize > recLen) {
|
|
|
+ const full: any = await getTagList({ pageNum: 1, pageSize: targetSize });
|
|
|
+ if (full && (full.code === 200 || full.code === "200") && full.data) {
|
|
|
+ pageData = full.data;
|
|
|
+ }
|
|
|
}
|
|
|
+ tagGroups.value = buildTagGroupsFromListPageData(pageData);
|
|
|
} catch (error) {
|
|
|
console.error("获取标签列表失败:", error);
|
|
|
}
|