index.vue
11.4 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
<!--
* @Date: 2022-09-19 14:11:06
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2025-08-18 16:34:15
* @FilePath: /jgdl/src/pages/myCar/index.vue
* @Description: 文件描述
-->
<template>
<view class="my-car-page">
<!-- 车辆列表 -->
<view class="flex-1">
<!-- 滚动列表 -->
<scroll-view
:style="scrollStyle"
:scroll-y="true"
@scrolltolower="loadMore"
@scroll="scroll"
:lower-threshold="50"
:enable-flex="false"
>
<!-- 空状态 -->
<view v-if="!loading && carList.length === 0" class="empty-state">
<!-- <image src="/static/images/empty-car.png" class="empty-image" mode="aspectFit" /> -->
<text class="empty-text">暂无车源信息</text>
<!-- <nut-button color="#f97316" @click="goToSell">发布车源</nut-button> -->
</view>
<!-- 车辆列表 -->
<view v-else class="space-y-4">
<view
v-for="car in carList"
:key="car.id"
@tap="() => goToCarDetail(car.id)"
style="border-bottom: 1px solid #e5e7eb"
>
<view class="flex p-4">
<view class="w-24 h-24 relative">
<image
:src="car.front_photo"
mode="aspectFill"
class="w-full h-full object-cover rounded-lg"
/>
</view>
<view class="flex-1 ml-4">
<text class="font-medium text-base block"><text v-if="car.manufacture_year">{{ car.manufacture_year }}款</text> <text v-if="car.brand">{{ car.brand }}</text> <text v-if="car.model">{{ car.model }}</text></text>
<!-- 状态标识 -->
<view class="status-badges">
<!-- <view v-if="car.verification_status" class="status-badge" :class="getVerificationStatusClass(car.verification_status)">
<text>{{ verifyStatus[car.verification_status] }}</text>
</view> -->
<!-- 审核状态为3时显示上架/下架状态,否则显示审核状态 -->
<view v-if="car.review_status === 3 && car.status === 5" class="status-badge offline">
<text>{{ carStatus[car.status] }}</text>
</view>
<view v-else-if="car.review_status && car.review_status !== 3" class="status-badge review">
<text>{{ reviewStatus[car.review_status] }}</text>
</view>
</view>
<text class="text-sm text-gray-500 mt-1 block"><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 v-if="car.review_reason" class="verification-reason mt-1">
<nut-config-provider :theme-vars="themeVars">
<nut-ellipsis :content="'审核结果: ' + car.review_reason" direction="end" rows="2" expand-text="展开" collapse-text="收起"></nut-ellipsis>
</nut-config-provider>
</view>
<view class="mt-2 flex justify-between items-center">
<view>
<text v-if="car.price" class="text-orange-500 font-bold" style="font-size: 1.2rem;" :class="{ 'sold-price': car.is_sold }">
¥{{ car.price.toLocaleString() }}
</text>
<text v-if="car.is_sold" class="sold-label ml-2" style="color: red; font-size: 26rpx;">已售出</text>
<text v-if="car.market_price && !car.is_sold" class="text-gray-400 text-xs line-through ml-2">
¥{{ car.market_price.toLocaleString() }}
</text>
</view>
</view>
<!-- 操作按钮 只能修改未卖出的车 -->
<view v-if="!car.is_sold" class="action-buttons mt-4">
<nut-button
@click.stop="editCar(car.id)"
size="small"
type="default"
class="px-3 py-1 rounded-full text-sm mr-2"
>
编辑
</nut-button>
<!-- 只有审核状态为3时才显示上架/下架按钮 -->
<nut-button
v-if="car.review_status === 3"
@click.stop="toggleOffline(car)"
size="small"
:type="car.status === 5 ? 'success' : 'warning'"
class="px-3 py-1 rounded-full text-sm mr-2"
>
{{ car.status === 5 ? '上架' : '下架' }}
</nut-button>
<nut-button
v-if="car.review_status === 5"
@click.stop="toggleOnline(car)"
size="small"
type="success"
class="px-3 py-1 rounded-full text-sm mr-2"
>
上架
</nut-button>
<!-- <nut-button
v-if="car.verification_status === 1 || car.verification_status === 7 || car.verification_status === 2"
@click.stop="authCar(car.id)"
size="small"
type="primary"
color="orange"
class="px-3 py-1 rounded-full text-sm"
>
认证
</nut-button> -->
</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 && carList.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-dialog
v-model:visible="offlineDialogVisible"
title="温馨提示"
@ok="confirmOffline"
@cancel="cancelOffline"
>
<template #default>
<view>
<text style="font-size: 1rem;">{{ offlineDialogContent }}</text>
</view>
</template>
<template #footer>
<view class="flex gap-4 p-4">
<nut-button plain class="flex-1" size="small" @click="cancelOffline">
取消
</nut-button>
<nut-button type="warning" class="flex-1" size="small" color="orange" @click="confirmOffline">
确认
</nut-button>
</view>
</template>
</nut-dialog>
</view>
</template>
<script setup>
import { ref, computed } from 'vue'
import Taro, { useDidShow } from '@tarojs/taro'
import './index.less'
// 导入接口
import { getMyListingVehicleAPI, changeVehicleStatusAPI } from '@/api/car';
const themeVars = {
ellipsisExpandCollapseColor: '#f97316'
}
// 认证状态映射
const verifyStatus = ref({
1: '未认证',
2: '认证待付款',
3: '认证待审核',
5: '已认证',
7: '认证失败'
})
// 上架状态映射
const carStatus = ref({
3: '已上架',
5: '已下架',
})
// 审核状态映射
const reviewStatus = ref({
1: '待审核',
3: '审核成功',
5: '审核失败'
})
/**
* 获取认证状态样式类
* @param {number} status - 认证状态 (1=未认证, 3=认证待审核, 5=已认证, 7=认证失败)
*/
const getVerificationStatusClass = (status) => {
const classMap = {
1: 'unverified',
3: 'review',
5: 'verified',
7: 'failed'
}
return classMap[status] || 'unverified'
}
/**
* 滚动样式 - 考虑header和TabBar的高度
*/
const scrollStyle = computed(() => {
return {
height: 'calc(92vh)' // 减去header和TabBar的高度
}
})
// 页面状态
const loading = ref(false)
const hasMore = ref(true)
const currentPage = ref(0)
const pageSize = ref(10)
// 车辆列表数据
const carList = ref([])
// 下架确认弹窗
const offlineDialogVisible = ref(false)
const offlineDialogContent = ref('')
const currentOfflineCar = ref(null)
/**
* 跳转到发布车源页面
*/
// const goToSell = () => {
// Taro.navigateTo({
// url: '/pages/sell/index'
// })
// }
/**
* 编辑车源
*/
const editCar = (carId) => {
Taro.navigateTo({
url: `/pages/sell/index?id=${carId}&mode=edit&type=myCar`
})
}
/**
* 认证车源
*/
const authCar = (carId) => {
Taro.navigateTo({
url: `/pages/setAuthCar/index?id=${carId}&mode=edit`
})
}
/**
* 切换上下架状态
*/
const toggleOffline = (car) => {
currentOfflineCar.value = car
offlineDialogContent.value = car.status === 5 ? '确认要上架此车源吗?' : '确认要下架此车源吗?'
offlineDialogVisible.value = true
}
// 上架
const toggleOnline = (car) => {
currentOfflineCar.value = car
offlineDialogContent.value = '确认要上架此车源吗?'
offlineDialogVisible.value = true
}
/**
* 确认上下架操作
*/
const confirmOffline = async () => {
if (currentOfflineCar.value) {
const car = currentOfflineCar.value
let status = car.status
if (car.status === 3) {
car.status = 5
status = 5
} else {
status = 3
}
// 调用API更新车源状态
const { code, msg, data } = await changeVehicleStatusAPI({ id: car.id, status: status })
if (code) {
car.status = data.status;
Taro.showToast({
title: status === 5 ? '下架成功' : msg,
icon: 'none',
duration: 2000
})
}
}
offlineDialogVisible.value = false
currentOfflineCar.value = null
}
/**
* 取消上下架操作
*/
const cancelOffline = () => {
offlineDialogVisible.value = false
currentOfflineCar.value = null
}
/**
* 获取车辆列表数据
*/
const fetchCarList = async (page = 0, append = false) => {
loading.value = true
try {
// 调用真实API获取车辆列表
const response = await getMyListingVehicleAPI({ page, limit: pageSize.value, review_status: [1, 3, 5] })
if (response.code === 1) {
const { list, total } = response.data
if (append) {
carList.value.push(...list)
} else {
carList.value = list
}
// 根据总数和当前数据量判断是否还有更多数据
const currentTotal = append ? carList.value.length : list.length
hasMore.value = currentTotal < total
currentPage.value = page
} else {
showToast(response.msg || '获取车辆列表失败', 'error')
}
} catch (error) {
console.error('获取车辆列表失败:', error)
showToast('加载失败,请重试', 'error')
} finally {
loading.value = false
}
}
/**
* 滚动事件处理
*/
const scroll = (e) => {
// 可以在这里处理滚动事件,比如记录滚动位置
}
/**
* 加载更多数据
*/
const loadMore = () => {
if (!hasMore.value || loading.value) return
fetchCarList(currentPage.value + 1, true)
}
/**
* 显示提示信息
*/
const showToast = (message, type = 'success') => {
Taro.showToast({
title: message,
icon: type === 'success' ? 'success' : 'none'
})
}
/**
* 跳转到车源详情页
*/
const goToCarDetail = (carId) => {
Taro.navigateTo({
url: `/pages/productDetail/index?id=${carId}`
})
}
// 页面加载时获取数据
useDidShow(() => {
fetchCarList(0, false)
})
</script>
<script>
export default {
name: "demoPage",
};
</script>