useBrandDetailData.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /** @format */
  2. import { getBrandDetailApi, getBrandGoodsListApi, getDynamicCategoryListApi } from '~/api/model/brand'
  3. import { PageSizeEnum } from '~/enums/sizeEnum'
  4. export function useBrandDetailData() {
  5. const categories = ref<any>([])
  6. const brandGoodsList = ref<any>([])
  7. const selectedCategory = ref()
  8. const page_size = ref(12)
  9. const currentPage = ref(PageSizeEnum.PAGE)
  10. const total = ref()
  11. const detail = ref()
  12. const getDetailInfo = async () => {
  13. const route = useRoute()
  14. const id = route.params.id
  15. const info: any = await getBrandDetailApi({ id })
  16. detail.value = info
  17. // A053_B为禁用,A053_A为启用
  18. // if (info.brandState === 'A053_B')
  19. // isDisabled.value = true
  20. // document.title = info.brandName
  21. }
  22. const getCategories = async () => {
  23. try {
  24. const route = useRoute()
  25. const id = route.params.id
  26. const data = await getDynamicCategoryListApi({ id })
  27. categories.value = data
  28. }
  29. catch (error) {
  30. console.log(error)
  31. }
  32. }
  33. const getBrandGoodsList = async (
  34. pageNo = currentPage.value,
  35. pageSize = page_size.value,
  36. ) => {
  37. const route = useRoute()
  38. const brandId = route.params.id
  39. const res: any = await getBrandGoodsListApi({
  40. categoryId: selectedCategory.value,
  41. brandId,
  42. pageNo,
  43. pageSize,
  44. })
  45. brandGoodsList.value = res.records
  46. total.value = res.total
  47. currentPage.value = res.current
  48. }
  49. const handleSelectedCategory = (value: any) => {
  50. selectedCategory.value = value
  51. getBrandGoodsList()
  52. value && addIdParameter(value)
  53. }
  54. function addIdParameter(value: any) {
  55. const currentUrl = new URL(window.location.href)
  56. currentUrl.searchParams.set('filters', value)
  57. window.history.pushState({}, '', currentUrl.toString())
  58. }
  59. // const updateGoodsList = () => {
  60. // changePage(currentPage.value, PageSizeEnum.PAGE_SIZE)
  61. // }
  62. const changePage = (current: number, size: number) => {
  63. getBrandGoodsList(current, size)
  64. }
  65. return {
  66. brandGoodsList,
  67. getCategories,
  68. categories,
  69. selectedCategory,
  70. page_size,
  71. // updateGoodsList,
  72. changePage,
  73. currentPage,
  74. total,
  75. getBrandGoodsList,
  76. detail,
  77. getDetailInfo,
  78. handleSelectedCategory,
  79. }
  80. }