index.vue
10.1 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-04 10:30:09
* @FilePath: /jgdl/src/pages/authCar/index.vue
* @Description: 认证车源
-->
<template>
<view class="auth-car-page">
<!-- Banner轮播图 -->
<view class="p-4">
<nut-swiper :init-page="0" :pagination-visible="true" pagination-color="#ffffff" auto-play="3000"
class="rounded-lg overflow-hidden" height="160">
<nut-swiper-item v-for="(image, index) in bannerImages" :key="index">
<image :src="image" mode="aspectFill" class="w-full h-40 object-cover" />
</nut-swiper-item>
</nut-swiper>
</view>
<!-- 我要认证按钮 -->
<view class="px-16 mt-5">
<nut-button color="#fb923c" size="large" block @click="handleAuth" class="auth-button">
<view class="flex items-center justify-center">
<Check class="mr-2" size="20" color="#ffffff" />
<text class="text-white font-medium">我要认证</text>
</view>
</nut-button>
</view>
<!-- 认证车源列表 -->
<view v-show="authCars.length" class="px-4 mt-6">
<view class="flex justify-between items-center mb-4">
<text class="text-lg font-medium">认证车源</text>
</view>
<!-- 滚动列表 -->
<scroll-view class="auth-car-list" :style="scrollStyle" :scroll-y="true" @scrolltolower="loadMore"
@scroll="scroll" :lower-threshold="50" :enable-flex="false">
<view class="space-y-4">
<view v-for="car in authCars" :key="car.id" class="bg-white rounded-lg shadow-sm overflow-hidden mb-3"
@tap="() => onCarClick(car)">
<view class="flex">
<view class="w-32 h-24 relative p-2">
<image :src="car.front_photo" :alt="car.name" mode="aspectFill"
class="w-full h-full object-cover rounded-lg" />
</view>
<view class="flex-1 p-3 relative">
<view class="absolute top-2 right-4" @tap.stop="() => toggleFavorite(car)">
<Heart1 v-if="!car.is_favorite" size="22" :color="'#9ca3af'" />
<HeartFill v-else size="22" :color="'#ef4444'" />
</view>
<text class="font-medium text-sm block">{{ car.brand }} {{ car.model }}</text>
<text class="text-xs text-gray-600 mt-1 block">
<!-- {{ car.manufacture_year }} · -->
<text v-if="car.range_km">续航{{ car.range_km }}km</text>
<text v-if="car.max_speed_kmh"> 最高时速{{ car.max_speed_kmh }}km/h</text>
</text>
<view class="mt-2">
<text class="text-orange-500 font-bold" style="font-size: 1.2rem;">
¥{{ car.price.toLocaleString() }}
</text>
<text class="text-xs text-gray-500 mt-1 block">{{ car.school_name }}</text>
</view>
<!-- 认证信息 -->
<!-- <view class="mt-1">
<text class="text-xs text-green-600">认证时间 · {{ car.authDate }}</text>
</view> -->
</view>
</view>
</view>
</view>
<!-- Loading indicator -->
<view v-if="loading" class="loading-container py-4 text-center">
<text class="loading-text text-gray-500">加载中...</text>
</view>
<!-- 没有更多数据 -->
<view v-if="!hasMore && authCars.length > 0" class="no-more-container py-4 text-center">
<text class="text-gray-400 text-sm no-more-text">没有更多数据了</text>
</view>
</scroll-view>
</view>
<!-- 成功提示 -->
<nut-toast v-model:visible="toastVisible" :msg="toastMessage" :type="toastType" />
<!-- 认证费用说明弹窗 -->
<nut-popup
v-model:visible="showAuthInfoPopup"
position="bottom"
:style="{ width: '100%', height: '100%' }"
closeable
close-icon-position="top-right"
@close="showAuthInfoPopup = false"
>
<view class="auth-info-popup">
<!-- 标题 -->
<view class="popup-header">
<text class="popup-title">认证费用说明</text>
</view>
<!-- 滚动内容区域 -->
<scroll-view class="popup-content" :scroll-y="true">
<view class="popup-content-text">
<view class="auth-fee-item">
<text class="auth-fee-label">认证费用:</text>
<text class="auth-fee-value">¥{{ authFee }}</text>
</view>
<view class="auth-desc-item">
<text class="auth-desc-label">认证说明:</text>
<text class="auth-desc-text">{{ authDesc }}</text>
</view>
</view>
</scroll-view>
<!-- 底部按钮 -->
<view class="popup-footer">
<nut-button
plain
class="footer-btn cancel-btn"
@click="showAuthInfoPopup = false"
>
关闭
</nut-button>
<nut-button
type="warning"
class="footer-btn confirm-btn"
color="#fb923c"
@click="handleConfirmAuth"
>
知道了
</nut-button>
</view>
</view>
</nut-popup>
</view>
</template>
<script setup>
import Taro from '@tarojs/taro'
import { ref, computed, onMounted } from 'vue'
import { Check, Heart1, HeartFill } from '@nutui/icons-vue-taro'
import { useFavorite } from '@/composables/useFavorite'
import './index.less'
// 接口导入
import { getVehicleListAPI } from '@/api/car';
import { getVerificationPriceAPI } from '@/api/other';
import { DEFAULT_COVER_IMG } from '@/utils/config'
// Banner图片数据
const bannerImages = ref([
'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=800&h=400&fit=crop',
'https://images.unsplash.com/photo-1571068316344-75bc76f77890?w=800&h=400&fit=crop',
'https://images.unsplash.com/photo-1571068316344-75bc76f77890?w=800&h=400&fit=crop'
])
// 认证车源数据
const authCars = ref([])
// 认证费用和说明
const authFee = ref('180')
const authDesc = ref('认证服务包含车辆基础信息验证、车况检测、平台担保等服务,认证通过后可获得平台认证标识,提升车辆可信度和成交率。认证费用一经支付不可退还,认证有效期为1年。')
// 收藏状态
// 收藏功能现在使用基于对象属性的模式
// 加载状态
const loading = ref(false)
const hasMore = ref(true)
const currentPage = ref(0)
const pageSize = ref(10)
// Toast提示
const toastVisible = ref(false)
const toastMessage = ref('')
const toastType = ref('success')
// 认证费用说明弹窗
const showAuthInfoPopup = ref(false)
// 滚动样式
const scrollStyle = computed(() => {
return {
height: 'calc(100vh - 400rpx)'
}
})
/**
* 处理认证按钮点击
*/
const handleAuth = () => {
// 显示认证费用说明弹窗
showAuthInfoPopup.value = true
}
/**
* 确认认证,跳转到认证页面
*/
const handleConfirmAuth = () => {
// 关闭弹窗
showAuthInfoPopup.value = false
// 跳转到认证页面
Taro.navigateTo({ url: '/pages/setAuthCar/index' })
}
/**
* 处理车辆点击
*/
const onCarClick = (car) => {
// 跳转到车辆详情页
Taro.navigateTo({ url: `/pages/productDetail/index?id=${car.id}` })
}
/**
* 切换收藏状态
*/
// 使用收藏功能composables
const { toggleFavorite } = useFavorite()
/**
* 加载认证车辆数据
* @param {boolean} isLoadMore - 是否为加载更多
*/
const loadAuthCarData = async (isLoadMore = false) => {
if (loading.value) return
loading.value = true
try {
// 构建请求参数 - 只获取认证车辆
const params = {
page: currentPage.value,
limit: pageSize.value,
verification_status: 5 // 只获取已认证的车辆
}
const response = await getVehicleListAPI(params)
if (response && response.code === 1 && response.data) {
const vehicleList = response.data.list || []
// 处理图片数据
const processedData = vehicleList.map(item => ({
...item,
front_photo: item.front_photo || DEFAULT_COVER_IMG,
}))
if (isLoadMore) {
authCars.value.push(...processedData)
} else {
authCars.value = processedData
}
// 检查是否还有更多数据 - 基于总数和当前已加载数量
const totalLoaded = (currentPage.value + 1) * pageSize.value
hasMore.value = totalLoaded < response.data.total
} else {
console.error('API返回错误:', response)
showToast(response?.msg || '获取数据失败', 'error')
}
} catch (error) {
console.error('加载认证车辆数据失败:', error)
showToast('网络错误,请稍后重试', 'error')
} finally {
loading.value = false
}
}
/**
* 加载更多数据
*/
const loadMore = async () => {
if (loading.value || !hasMore.value) return
currentPage.value++
await loadAuthCarData(true)
}
/**
* 滚动事件处理
*/
const scroll = (e) => {
// 可以在这里处理滚动事件
}
/**
* 显示提示信息
*/
const showToast = (message, type = 'success') => {
toastMessage.value = message
toastType.value = type
toastVisible.value = true
}
/**
* 获取认证费用
*/
const getVerificationPrice = async () => {
try {
const response = await getVerificationPriceAPI()
if (response && response.code === 1 && response.data) {
// 处理认证费用数据
authFee.value = response.data.verification_price
authDesc.value = response.data.verification_desc
}
} catch (error) {
console.error('获取认证费用失败:', error)
showToast('网络错误,请稍后重试', 'error')
}
}
// 初始化
onMounted(async () => {
// 加载初始认证车辆数据
await loadAuthCarData()
// 获取认证费用
await getVerificationPrice()
})
</script>
<script>
export default {
name: 'AuthCarPage'
}
</script>