|
|
@@ -187,12 +187,12 @@ const tableColumns: NaiveUI.TableColumn<Api.goods.ShopCategory>[] = [
|
|
|
width: 230,
|
|
|
render: row => (
|
|
|
<div class="flex-center gap-8px">
|
|
|
- {row.level == 2 && (
|
|
|
+ {row.level == 1 && (
|
|
|
<NButton type="primary" size="small" quaternary onClick={() => add(row)}>
|
|
|
添加三级分类
|
|
|
</NButton>
|
|
|
)}
|
|
|
- {row.level == 3 && (
|
|
|
+ {row.level == 2 && (
|
|
|
<NButton type="primary" size="small" quaternary onClick={() => handleOpenRelatedGoods(row)}>
|
|
|
关联商品
|
|
|
</NButton>
|
|
|
@@ -203,7 +203,7 @@ const tableColumns: NaiveUI.TableColumn<Api.goods.ShopCategory>[] = [
|
|
|
</NButton>
|
|
|
}
|
|
|
|
|
|
- {row.level == 3 && (
|
|
|
+ {row.level == 2 && (
|
|
|
<NButton type="primary" size="small" quaternary onClick={() => del(row)}>
|
|
|
删除
|
|
|
</NButton>
|
|
|
@@ -293,7 +293,7 @@ async function handleSubmit(file: File) {
|
|
|
}
|
|
|
function edit(row: Api.goods.ShopCategory) {
|
|
|
openModalForm(row);
|
|
|
- setModalProps({ title: `修改${row.level}级分类` });
|
|
|
+ setModalProps({ title: `修改${Number(row.level) + 1}级分类` });
|
|
|
setModalFormValue({ ...row, label: row.label });
|
|
|
}
|
|
|
function add(row: Api.goods.ShopCategory) {
|
|
|
@@ -302,7 +302,7 @@ function add(row: Api.goods.ShopCategory) {
|
|
|
const level2Name = current.name;
|
|
|
openModalForm();
|
|
|
setModalProps({ title: `新增三级分类` });
|
|
|
- setModalFormValue({ level: 3, pid: row.id, parentCode: row.code, BreadName: `${level1Name} > ${level2Name}` });
|
|
|
+ setModalFormValue({ level: 2, pid: row.id, parentCode: row.code, BreadName: `${level1Name} > ${level2Name}` });
|
|
|
}
|
|
|
function del(row: Api.goods.ShopCategory) {
|
|
|
window.$dialog?.info({
|
|
|
@@ -322,8 +322,7 @@ async function getData() {
|
|
|
const { data, error } = await fetchGetDeskCategoryList(getSearchForm());
|
|
|
|
|
|
if (!error) {
|
|
|
- deskData.value = buildTree(data).sort((a, b) => b.num - a.num);
|
|
|
- console.log(deskData.value);
|
|
|
+ deskData.value = data;
|
|
|
}
|
|
|
}
|
|
|
function handleOpenRelatedGoods(row: Api.goods.ShopCategory) {
|
|
|
@@ -337,7 +336,7 @@ async function handleSubmitForm() {
|
|
|
const form = await getModalFormValue();
|
|
|
const level = form.level;
|
|
|
const { error } =
|
|
|
- level != 3 ? await fetchUpdateCategory(form) : await fetchAddCategory({ ...form, shopId: getSearchForm().shopId });
|
|
|
+ level != 2 ? await fetchUpdateCategory(form) : await fetchAddCategory({ ...form, shopId: getSearchForm().shopId });
|
|
|
if (!error) {
|
|
|
closeModalForm();
|
|
|
getData();
|
|
|
@@ -363,49 +362,7 @@ function hanleExportFailure(taskCode: string) {
|
|
|
'_blank'
|
|
|
);
|
|
|
}
|
|
|
-interface BuildTreeOptions {
|
|
|
- idKey?: string;
|
|
|
- pidKey?: string;
|
|
|
- childrenKey?: string;
|
|
|
-}
|
|
|
-
|
|
|
-function buildTree<T>(items: T[], options: BuildTreeOptions = {}): T[] {
|
|
|
- const { idKey = 'id', pidKey = 'pid', childrenKey = 'children' } = options;
|
|
|
-
|
|
|
- const itemMap = new Map<number, T>();
|
|
|
-
|
|
|
- items.forEach(item => {
|
|
|
- const id = item[idKey as keyof T];
|
|
|
- if (typeof id === 'number') {
|
|
|
- itemMap.set(id, { ...item, [childrenKey]: [] });
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- const tree: T[] = [];
|
|
|
|
|
|
- items.forEach(item => {
|
|
|
- const id = item[idKey as keyof T];
|
|
|
- const pid = item[pidKey as keyof T];
|
|
|
-
|
|
|
- if (typeof id !== 'number' || typeof pid !== 'number') {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- const currentNode = itemMap.get(id);
|
|
|
- if (!currentNode) return;
|
|
|
-
|
|
|
- if (pid === 0) {
|
|
|
- tree.push(currentNode);
|
|
|
- } else {
|
|
|
- const parentNode = itemMap.get(pid);
|
|
|
- if (parentNode && parentNode[childrenKey as keyof T]) {
|
|
|
- (parentNode[childrenKey as keyof T] as T[]).push(currentNode);
|
|
|
- }
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- return tree;
|
|
|
-}
|
|
|
function getRowHierarchyInfo(
|
|
|
row: Api.goods.ShopCategory,
|
|
|
allData: Api.goods.ShopCategory[]
|