| 
					
				 | 
			
			
				@@ -1,6 +1,6 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 <script setup lang="tsx"> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import { nextTick, ref } from 'vue'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import { NButton, NImage, type UploadFileInfo } from 'naive-ui'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { nextTick, ref, useTemplateRef } from 'vue'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import { NButton, NImage } from 'naive-ui'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import type { InternalRowData } from 'naive-ui/es/data-table/src/interface'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   fetchGategoryImport, 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -12,11 +12,9 @@ import { fetchGetAllTagList } from '@/service/api/goods/tag'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { useAppStore } from '@/store/modules/app'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { useModalFrom } from '@/components/zt/ModalForm/hooks/useModalForm'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import { useForm } from '@/components/zt/Form/hooks/useForm'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-import type { ModalMethods } from '@/components/zt/Modal/types'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const appStore = useAppStore(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const deskData = ref<Api.goods.ShopCategory[]>([]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const loading = ref(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-const fileList = ref<UploadFileInfo[]>([]); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const [registerSearchForm, { getFieldsValue: getSearchForm }] = useForm({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   schemas: [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -31,7 +29,7 @@ const [registerSearchForm, { getFieldsValue: getSearchForm }] = useForm({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				       componentProps: { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         api: fetchGetAllStoreList, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         labelFeild: 'shopName', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        valueFeild: 'hbStationId', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        valueFeild: 'shopId', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         onUpdateValue: () => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				           nextTick(() => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             getData(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -48,7 +46,7 @@ const [registerSearchForm, { getFieldsValue: getSearchForm }] = useForm({ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   }, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   collapsedRows: 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-const importTemplateRef = ref<ModalMethods>(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+const importTemplateRef = useTemplateRef('importTemplateRef'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 const tableColumns: NaiveUI.TableColumn<InternalRowData>[] = [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     title: '分类名称', 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -146,8 +144,8 @@ const [ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-async function handleSubmit() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  const { error } = await fetchGategoryImport(fileList.value[0].file as File); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+async function handleSubmit(file: File) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  const { error } = await fetchGategoryImport(file); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   if (!error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     importTemplateRef.value?.closeModal(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -155,13 +153,13 @@ async function handleSubmit() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 function edit(row: Recordable) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   openModalForm(row); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  setModalFormValue({ ...row }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  setModalFormValue({ ...row, label: Number(row.label) }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 async function getData() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   const { data, error } = await fetchGetDeskCategoryList(getSearchForm()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   if (!error) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    deskData.value = data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    deskData.value = buildTree(data); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 async function handleSubmitForm() { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -175,6 +173,49 @@ async function handleSubmitForm() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 function handleOpen() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   importTemplateRef.value?.openModal(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 </script> 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 <template> 
			 |