product_list.ts
841 Bytes
import { getProductList } from './../service'
import { ref } from 'vue'
import { defineStore } from 'pinia'
import type { Product, ProductListQuery } from '@/type'
export const useProductListStore = defineStore('productList', () => {
const list = ref<Product[]>([])
const productCategoryId = ref('') // 选中的类别
const keywork = ref(null)
const pageNo = ref('')
const pageSize = ref(20)
const total = ref(0)
const getList = (params: ProductListQuery) => {
if (params.productCategoryId) {
getProductList(params).then((res) => {
const data = res.data?.data || {}
list.value = data?.records || []
total.value = data?.total || 0
})
}
}
const updateCategory = (value: string) => {
productCategoryId.value = value
}
return { total, list, getList, updateCategory }
})