Selaa lähdekoodia

change: indent创建询价.sku选择窗口接入AI搜索.

peter 2 viikkoa sitten
vanhempi
commit
b8ec22a082
2 muutettua tiedostoa jossa 20 lisäystä ja 10 poistoa
  1. 1 0
      package.json
  2. 19 10
      src/pages/indent-manage/indent/components/skuSelect.vue

+ 1 - 0
package.json

@@ -11,6 +11,7 @@
   },
   "dependencies": {
     "@element-plus/icons-vue": "^2.1.0",
+    "algoliasearch": "^4.23.3",
     "axios": "~0.27.2",
     "dayjs": "^1.11.13",
     "element-plus": "2.9.11",

+ 19 - 10
src/pages/indent-manage/indent/components/skuSelect.vue

@@ -109,7 +109,7 @@
 <script lang="ts" setup>
 import { defineComponent, ref, inject, watch } from 'vue'
 import { ElButton, ElInput, ElTree, ElDialog, ElPagination } from 'element-plus'
-
+import algoliasearch from 'algoliasearch'
 import { getCategoryTree, getSkuList } from '@/api/indent.js'
 import skuApply from './skuApply.vue'
 defineComponent({
@@ -193,16 +193,22 @@ const getCategory = () => {
     })
   })
 }
+
+let index = ref({} as any)
+const initAI = () => {
+  const client = algoliasearch('7BX4P6RSP2', 'aa9ec8e7e12a6633e7924fab6487e6af')
+  index.value = client.initIndex('indent_app')
+}
 const getSku = () => {
-  const params = Object.assign(
-    { keywords: keywords.value, category: currentCategory.value },
-    pageForm.value,
-  )
   loading.value = true
-  getSkuList(params)
+  index.value
+    .search(keywords.value, {
+      hitsPerPage: pageForm.value.limit,
+      page: pageForm.value.page - 1,
+    })
     .then((response: any) => {
-      const res = response.result
-      skuList.value = res.data.map((item: any) => {
+      const res = response.hits
+      skuList.value = res.map((item: any) => {
         const t =
           typeof item.images === 'string'
             ? `${item.images}`.split(',').filter((i: string) => i.length > 0)
@@ -216,7 +222,7 @@ const getSku = () => {
           }),
         }
       })
-      total.value = res.total
+      total.value = response.nbHits > 1000 ? 1000 : response.nbHits
     })
     .finally(() => {
       loading.value = false
@@ -228,7 +234,10 @@ watch(
     show.value = visible
     resetData()
     if (show.value) {
-      getSku()
+      initAI()
+      setTimeout(() => {
+        getSku()
+      }, 500)
       getCategory()
     }
   },