sanmu
authored
|
1
|
import { getProductList } from './../service'
|
sanmu
authored
|
2
|
import { ref, watchEffect } from 'vue'
|
sanmu
authored
|
3
|
import { defineStore } from 'pinia'
|
sanmu
authored
|
4
|
import type { Product, ProductImage, ProductListQuery } from '@/type'
|
sanmu
authored
|
5
6
7
8
9
|
export const useProductListStore = defineStore('productList', () => {
const list = ref<Product[]>([])
const productCategoryId = ref('') // 选中的类别
const keywork = ref(null)
|
sanmu
authored
|
10
|
const pageNo = ref(1)
|
sanmu
authored
|
11
12
|
const pageSize = ref(20)
const total = ref(0)
|
sanmu
authored
|
13
|
const params = ref()
|
sanmu
authored
|
14
|
|
sanmu
authored
|
15
|
const getList = async (params: ProductListQuery) => {
|
sanmu
authored
|
16
|
if (params.productCategoryId) {
|
sanmu
authored
|
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
const res = await getProductList(params)
const data = res.data?.data || {}
list.value =
(data?.records || []).map((record: Product) => ({
...record,
// http://112.74.45.244:8100/api/show/image?fileKey=ac82abea34243b7f7a56e5c3ca03f3a9
imgList: JSON.parse(record.productimageliststore as unknown as string).map(
(item: ProductImage) => ({
url: `${(window as any).IMG_BASE_URL}/api/show/image?fileKey=${
item.fileKey
}&psize=p256`
})
)
})) || []
total.value = data?.total || 0
|
sanmu
authored
|
32
33
34
|
}
}
|
sanmu
authored
|
35
36
37
38
|
const updatePageNo = (value: number) => {
pageNo.value = value
}
|
sanmu
authored
|
39
40
41
42
|
const updateCategory = (value: string) => {
productCategoryId.value = value
}
|
sanmu
authored
|
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
const updateParams = (value: any) => {
params.value = value
}
return {
pageNo,
pageSize,
total,
list,
params,
getList,
updateCategory,
updatePageNo,
updateParams
}
|
sanmu
authored
|
58
|
})
|