完善团课前后端交互
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { ref, computed } from 'vue'
|
||||
import { getGroupCoursePage, getTypeLabels } from '@/api/groupCourse.js'
|
||||
import { ref, computed, watch } from 'vue'
|
||||
import { getGroupCoursePage, getTypeLabels, searchGroupCourse } from '@/api/groupCourse.js'
|
||||
|
||||
export function useGroupCourseList() {
|
||||
const pageNum = ref(0)
|
||||
@@ -14,11 +14,14 @@ export function useGroupCourseList() {
|
||||
const searchKeyword = ref('')
|
||||
const hotKeywords = ref(['燃脂', '瑜伽', '单车', '普拉提', '高强度'])
|
||||
|
||||
const courseType = ref(null)
|
||||
const courseTypes = ref([])
|
||||
|
||||
const sortOptions = ref([
|
||||
{ label: '默认排序', value: 'id', order: 'asc' },
|
||||
{ label: '价格从低到高', value: 'storedValueAmount', order: 'asc' },
|
||||
{ label: '价格从高到低', value: 'storedValueAmount', order: 'desc' },
|
||||
{ label: '剩余名额最多', value: 'currentMembers', order: 'asc' }
|
||||
{ label: '默认排序', value: 'default', priceSort: null, remainingMost: false },
|
||||
{ label: '价格从低到高', value: 'priceAsc', priceSort: 'asc', remainingMost: false },
|
||||
{ label: '价格从高到低', value: 'priceDesc', priceSort: 'desc', remainingMost: false },
|
||||
{ label: '剩余名额最多', value: 'remainingMost', priceSort: null, remainingMost: true }
|
||||
])
|
||||
const sortIndex = ref(0)
|
||||
|
||||
@@ -73,6 +76,13 @@ export function useGroupCourseList() {
|
||||
return result
|
||||
})
|
||||
|
||||
// 监听排序方式变化,重新获取数据
|
||||
watch(sortIndex, () => {
|
||||
console.log('[useGroupCourseList] 排序方式变化,触发重新查询')
|
||||
pageNum.value = 0
|
||||
fetchCourseList()
|
||||
})
|
||||
|
||||
const getAllSearchParams = (searchBarRef, filterSectionRef, timePeriodRef, timeRangePickerRef) => {
|
||||
const searchParams = searchBarRef?.getSearchParams?.() || { keyword: searchKeyword.value }
|
||||
const filterParams = filterSectionRef?.getFilterParams?.() || { sortType: sortOptions.value[sortIndex.value].value }
|
||||
@@ -99,6 +109,8 @@ export function useGroupCourseList() {
|
||||
|
||||
const onTimePeriodChange = (option) => {
|
||||
console.log('[useGroupCourseList] 时间段选择:', option)
|
||||
pageNum.value = 0
|
||||
fetchCourseList()
|
||||
}
|
||||
|
||||
const onTimeRangeConfirm = (params) => {
|
||||
@@ -108,6 +120,19 @@ export function useGroupCourseList() {
|
||||
timeRangeText.value = params.timeRangeText
|
||||
}
|
||||
|
||||
const onCourseTypeChange = (typeId) => {
|
||||
console.log('[useGroupCourseList] 课程类型选择:', typeId)
|
||||
courseType.value = typeId
|
||||
pageNum.value = 0
|
||||
fetchCourseList()
|
||||
}
|
||||
|
||||
const clearCourseType = () => {
|
||||
courseType.value = null
|
||||
pageNum.value = 0
|
||||
fetchCourseList()
|
||||
}
|
||||
|
||||
const handleBooking = (course) => {
|
||||
console.log('[useGroupCourseList] 预约课程:', course)
|
||||
uni.showToast({
|
||||
@@ -123,33 +148,75 @@ export function useGroupCourseList() {
|
||||
})
|
||||
}
|
||||
|
||||
const buildSearchParams = () => {
|
||||
const sortOption = sortOptions.value[sortIndex.value]
|
||||
const timePeriod = timePeriodOptions.value[timePeriodIndex.value]
|
||||
|
||||
const params = {
|
||||
page: pageNum.value,
|
||||
size: pageSize.value
|
||||
}
|
||||
|
||||
if (searchKeyword.value) {
|
||||
params.courseName = searchKeyword.value
|
||||
}
|
||||
|
||||
if (courseType.value) {
|
||||
params.courseType = courseType.value
|
||||
}
|
||||
|
||||
if (startDate.value) {
|
||||
params.startDate = startDate.value
|
||||
}
|
||||
|
||||
if (endDate.value) {
|
||||
params.endDate = endDate.value
|
||||
}
|
||||
|
||||
if (timePeriod.value && timePeriod.value !== 'all') {
|
||||
params.timePeriod = timePeriod.value
|
||||
}
|
||||
|
||||
if (sortOption.priceSort) {
|
||||
params.priceSort = sortOption.priceSort
|
||||
}
|
||||
|
||||
if (sortOption.remainingMost) {
|
||||
params.remainingMost = sortOption.remainingMost
|
||||
}
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
const hasActiveFilters = () => {
|
||||
return searchKeyword.value ||
|
||||
courseType.value ||
|
||||
startDate.value ||
|
||||
endDate.value ||
|
||||
timePeriodOptions.value[timePeriodIndex.value].value !== 'all' ||
|
||||
sortIndex.value !== 0
|
||||
}
|
||||
|
||||
const fetchCourseList = async (isLoadMore = false) => {
|
||||
if (loading.value) return
|
||||
|
||||
loading.value = true
|
||||
|
||||
try {
|
||||
const sortOption = sortOptions.value[sortIndex.value]
|
||||
console.log('[useGroupCourseList] 请求参数:', {
|
||||
page: isLoadMore ? pageNum.value + 1 : pageNum.value,
|
||||
size: pageSize.value,
|
||||
sort: sortOption.value,
|
||||
order: sortOption.order,
|
||||
keyword: searchKeyword.value
|
||||
})
|
||||
|
||||
const result = await getGroupCoursePage({
|
||||
page: isLoadMore ? pageNum.value + 1 : pageNum.value,
|
||||
size: pageSize.value,
|
||||
sort: sortOption.value,
|
||||
order: sortOption.order,
|
||||
keyword: searchKeyword.value
|
||||
})
|
||||
const currentPage = isLoadMore ? pageNum.value + 1 : pageNum.value
|
||||
pageNum.value = currentPage
|
||||
|
||||
const searchParams = buildSearchParams()
|
||||
searchParams.page = currentPage
|
||||
|
||||
console.log('[useGroupCourseList] 请求参数:', JSON.stringify(searchParams, null, 2))
|
||||
|
||||
const result = await searchGroupCourse(searchParams)
|
||||
|
||||
console.log('[useGroupCourseList] 响应结果:', JSON.stringify(result, null, 2))
|
||||
|
||||
if (result && result.content) {
|
||||
const { content: list, totalElements: totalCount, currentPage, totalPages: pages } = result
|
||||
if (result && result.data && result.data.content) {
|
||||
const { content: list, totalElements: totalCount, currentPage: respPage, totalPages: pages } = result.data
|
||||
|
||||
if (isLoadMore) {
|
||||
courseList.value = [...courseList.value, ...list]
|
||||
@@ -158,7 +225,6 @@ export function useGroupCourseList() {
|
||||
}
|
||||
|
||||
total.value = totalCount
|
||||
pageNum.value = currentPage
|
||||
totalPages.value = pages
|
||||
hasMore.value = currentPage < pages - 1
|
||||
|
||||
@@ -213,6 +279,8 @@ export function useGroupCourseList() {
|
||||
courseList,
|
||||
searchKeyword,
|
||||
hotKeywords,
|
||||
courseType,
|
||||
courseTypes,
|
||||
sortOptions,
|
||||
sortIndex,
|
||||
timePeriodOptions,
|
||||
@@ -227,9 +295,13 @@ export function useGroupCourseList() {
|
||||
handleSearch,
|
||||
onTimePeriodChange,
|
||||
onTimeRangeConfirm,
|
||||
onCourseTypeChange,
|
||||
clearCourseType,
|
||||
handleBooking,
|
||||
goDetail,
|
||||
fetchCourseList,
|
||||
buildSearchParams,
|
||||
hasActiveFilters,
|
||||
loadMore,
|
||||
onScrollToLower
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user