1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- /** @format */
- import { getBrandDetailApi, getBrandGoodsListApi, getDynamicCategoryListApi } from '~/api/model/brand'
- import { PageSizeEnum } from '~/enums/sizeEnum'
- export function useBrandDetailData() {
- const categories = ref<any>([])
- const brandGoodsList = ref<any>([])
- const selectedCategory = ref()
- const page_size = ref(12)
- const currentPage = ref(PageSizeEnum.PAGE)
- const total = ref()
- const detail = ref()
- const getDetailInfo = async () => {
- const route = useRoute()
- const id = route.params.id
- const info: any = await getBrandDetailApi({ id })
- detail.value = info
- // A053_B为禁用,A053_A为启用
- // if (info.brandState === 'A053_B')
- // isDisabled.value = true
- // document.title = info.brandName
- }
- const getCategories = async () => {
- try {
- const route = useRoute()
- const id = route.params.id
- const data = await getDynamicCategoryListApi({ id })
- categories.value = data
- }
- catch (error) {
- console.log(error)
- }
- }
- const getBrandGoodsList = async (
- pageNo = currentPage.value,
- pageSize = page_size.value,
- ) => {
- const route = useRoute()
- const brandId = route.params.id
- const res: any = await getBrandGoodsListApi({
- categoryId: selectedCategory.value,
- brandId,
- pageNo,
- pageSize,
- })
- brandGoodsList.value = res.records
- total.value = res.total
- currentPage.value = res.current
- }
- const handleSelectedCategory = (value: any) => {
- selectedCategory.value = value
- getBrandGoodsList()
- value && addIdParameter(value)
- }
- function addIdParameter(value: any) {
- const currentUrl = new URL(window.location.href)
- currentUrl.searchParams.set('filters', value)
- window.history.pushState({}, '', currentUrl.toString())
- }
- // const updateGoodsList = () => {
- // changePage(currentPage.value, PageSizeEnum.PAGE_SIZE)
- // }
- const changePage = (current: number, size: number) => {
- getBrandGoodsList(current, size)
- }
- return {
- brandGoodsList,
- getCategories,
- categories,
- selectedCategory,
- page_size,
- // updateGoodsList,
- changePage,
- currentPage,
- total,
- getBrandGoodsList,
- detail,
- getDetailInfo,
- handleSelectedCategory,
- }
- }
|