cloudroam
19 小时以前 500078714411487af00161e01bd7e0b5efdc3414
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<template>
  <view :class="['app', theme]">
    <view style="padding-top: 10rpx;">
      <up-search height="70rpx" placeholder="搜索" search-icon-size="40rpx" margin="0rpx 30rpx" v-model="search"
                 :show-action="true" @search="onSearch" />
    </view>
    <view class="list-view">
      <up-waterfall v-model="films">
        <template #left="{ leftList }">
          <LocaltionCard v-for="(item, index) in leftList" :key="index" :item="item" @click="handleDetailClick(item)" />
        </template>
        <template #right="{ rightList }">
          <LocaltionCard v-for="(item, index) in rightList" :key="index" :item="item" @click="handleDetailClick(item)" />
        </template>
      </up-waterfall>
      <up-loadmore :status="filmStatus" :line="true" />
    </view>
  </view>
</template>
 
<script setup lang="ts">
import { ref } from 'vue'
import { onLoad, onShow, onPullDownRefresh, onReachBottom } from '@dcloudio/uni-app'
import { FilmLocationVO, FilmLocationQueryDTO } from '@/types/index'
import { useGlobal } from '@/composables/useGlobal'
const { $http, $message } = useGlobal()
import { useNavigator } from '@/composables/useNavigator'
const { navigateTo } = useNavigator()
import { getFilmLocationBase } from '@/sub-pages/utils/api'
import LocaltionCard from "../../components/card/localtion-card.vue";
 
const theme = ref('light')
const search = ref('')
const films = ref<FilmLocationVO[]>([])
const filmPage = ref(1)
const filmSize = 10
const filmStatus = ref('loading')
 
const onSearch = () => {
  filmPage.value = 1
  films.value = []
  filmStatus.value = 'loadmore'
  getFilmLocation(search.value)
}
 
const handleDetailClick = (item: FilmLocationVO) => {
  const url = `/sub-pages/hot-spot/spot-detail?id=${item.id}`
  navigateTo(url)
}
 
onLoad(() => {
  const storedTheme = uni.getStorageSync('theme') || 'light'
  theme.value = storedTheme
})
 
onShow(() => {
  getFilmLocation()
})
 
onPullDownRefresh(async () => {
  filmPage.value = 1
  getFilmLocation()
  uni.stopPullDownRefresh()
})
 
onReachBottom(() => {
  getFilmLocation()
})
 
const getFilmLocation = async (keyword = '') => {
  if (filmStatus.value === 'nomore') return
  filmStatus.value = 'loading'
 
  try {
  const query: FilmLocationQueryDTO = {
    locationName: keyword,
    current: filmPage.value,
    size: filmSize,
    isEnabled: 1
  }
  const records = await getFilmLocationBase(query)
  if (records && records.length > 0) {
    const existingIds = new Set(films.value.map(item => item.id))
    const uniqueRecords = records.filter(item => !existingIds.has(item.id))
    films.value = [...films.value, ...uniqueRecords]
    if (records.length < filmSize) {
      filmStatus.value = 'noMore'
    }
    filmPage.value++
  } else {
    filmStatus.value = 'noMore'
  }
  } catch (e) {
    filmStatus.value = 'loadmore' // 重置状态允许重试
    $message.error('加载失败,请重试')
  }
}
</script>
 
<style lang="scss" scoped></style>