useBrandData.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { getBrandListApi } from '~/api/model/brand'
  2. import { PageSizeEnum } from '~/enums/sizeEnum'
  3. export function useBrandData(options?: any) {
  4. const selectedCategoryId = ref('')
  5. const currentPage = ref(PageSizeEnum.PAGE)
  6. const page_size = ref(12)
  7. const total = ref()
  8. const activeIndex = ref<any>('')
  9. const brandList = ref<any>([])
  10. const getBrandList = async (
  11. params?: any,
  12. pageNo = currentPage.value,
  13. pageSize = page_size.value,
  14. ) => {
  15. const data: any = await getBrandListApi({
  16. ...params,
  17. pageNo,
  18. pageSize,
  19. })
  20. total.value = data.total
  21. currentPage.value = data.current
  22. brandList.value = data.records
  23. }
  24. const handleSelectedCategory = (key: any) => {
  25. selectedCategoryId.value = key
  26. getBrandList({ categoryId: key }, PageSizeEnum.PAGE, page_size.value)
  27. }
  28. const changePage = (current: number, size: number) => {
  29. getBrandList({ categoryId: selectedCategoryId.value || '' }, current, size)
  30. const dom: any = document.getElementById('app-scroller')
  31. dom.scrollTo({
  32. top: 400,
  33. behavior: 'smooth',
  34. })
  35. }
  36. const updateGoodsList = () => {
  37. changePage(currentPage.value, page_size.value)
  38. }
  39. return { handleSelectedCategory, page_size, brandList, currentPage, selectedCategoryId, changePage, updateGoodsList, getBrandList, total, activeIndex }
  40. }