index.vue 15 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 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
<!--
 * @Date: 2022-09-19 14:11:06
 * @LastEditors: hookehuyr hookehuyr@gmail.com
 * @LastEditTime: 2025-07-04 16:27:02
 * @FilePath: /jgdl/src/pages/goodCarList/index.vue
 * @Description: 特价好车页面
-->
<template>
    <view>
        <view class="flex flex-col bg-white min-h-screen">
            <!-- Header -->
            <nut-sticky>
                <view class="bg-orange-400 p-4 pt-4 pb-4">
                    <nut-row type="flex" justify="center" align="center">
                        <nut-col span="6">
                            <view class="text-xl font-bold text-white">特价好车</view>
                        </nut-col>
                        <nut-col span="18">
                            <!-- Search Bar -->
                            <nut-searchbar v-model="searchValue" placeholder="搜索商品名称、品牌、型号" @blur="onBlurSearch" shape="round" background="transparent" input-background="#ffffff">
                                <template #leftin>
                                    <Search2 />
                                </template>
                            </nut-searchbar>
                        </nut-col>
                    </nut-row>
                </view>

                <!-- Filter options -->
                <nut-menu>
                    <nut-menu-item v-model="selectedBrand" :options="brandOptions" @change="onBrandChange" />
                    <nut-menu-item v-model="selectedYear" :options="yearOptions" @change="onYearChange" />
                    <nut-menu-item v-model="selectedSchool" :options="schoolOptions" @change="onSchoolChange" />
                </nut-menu>
            </nut-sticky>

            <!-- 特价好车列表 -->
            <view class="flex-1 p-4">
                <!-- 滚动列表 -->
                <scroll-view
                    class="good-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 goodCars" :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.imageUrl" :alt="car.name" mode="aspectFill"
                                        class="w-full h-full object-cover rounded-lg" />
                                    <view v-if="car.isSpecial"
                                        class="absolute bottom-3 right-3 bg-red-500 text-white text-xs px-1 rounded flex items-center">
                                        <text class="text-white">特</text>
                                    </view>
                                    <!-- 折扣标签 -->
                                    <view v-if="car.discount"
                                        class="absolute top-3 left-3 bg-red-500 text-white text-xs px-1 rounded">
                                        <text class="text-white">{{ car.discount }}折</text>
                                    </view>
                                </view>
                                <view class="flex-1 p-3 relative">
                                    <view class="absolute top-3 right-4" @tap.stop="() => toggleFavorite(car.id)">
                                        <Heart1 v-if="!favoriteIds.includes(car.id)" size="22" color="#9ca3af" />
                                        <HeartFill v-else size="22" color="#ef4444" />
                                    </view>
                                    <text class="font-medium text-sm block">{{ car.name }}</text>
                                    <text class="text-xs text-gray-600 mt-1 block">
                                        {{ car.year }} ·
                                        <text v-if="car.batteryHealth">电池健康度{{ car.batteryHealth }}%</text>
                                        <text v-if="car.mileage"> 行驶{{ car.mileage }}公里</text>
                                    </text>
                                    <view class="mt-2">
                                        <!-- 原价和现价 -->
                                        <view class="flex items-center">
                                            <text v-if="car.originalPrice" class="text-xs text-gray-400 line-through mr-2">
                                                ¥{{ car.originalPrice.toLocaleString() }}
                                            </text>
                                            <text class="text-orange-500 font-bold" style="font-size: 1.2rem;">
                                                ¥{{ car.price.toLocaleString() }}
                                            </text>
                                        </view>
                                        <text class="text-xs text-gray-500 mt-1 block">{{ car.school }}</text>
                                    </view>
                                    <!-- 特价标签 -->
                                    <view class="mt-1">
                                        <text class="text-xs text-red-600">{{ car.specialTag }}</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 && goodCars.length > 0" class="no-more-container py-4 text-center">
                        <text class="text-gray-400 text-sm">没有更多数据了</text>
                    </view>
                </scroll-view>
            </view>
        </view>

        <!-- 自定义TabBar -->
        <!-- <TabBar /> -->

        <!-- 成功提示 -->
        <nut-toast
            v-model:visible="toastVisible"
            :msg="toastMessage"
            :type="toastType"
        />
    </view>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import { Search2, Addfollow, Follow, Heart1, HeartFill } from '@nutui/icons-vue-taro'
import TabBar from '@/components/TabBar.vue'
import './index.less'

// 响应式数据
const searchValue = ref('')
const onBlurSearch = () => {
    console.warn(searchValue.value)
}
const favoriteIds = ref(['2', '4', '6'])

// Filter states - 使用NutUI Menu组件
const selectedBrand = ref('全部品牌')
const selectedYear = ref('出厂年份')
const selectedSchool = ref('所在学校')

// Menu选项数据
const brandOptions = ref([
    { text: '全部品牌', value: '全部品牌' },
    { text: '雅迪', value: '雅迪' },
    { text: '台铃', value: '台铃' },
    { text: '小鸟', value: '小鸟' },
    { text: '新日', value: '新日' },
    { text: '爱玛', value: '爱玛' },
    { text: '小牛', value: '小牛' }
])

const yearOptions = ref([
    { text: '出厂年份', value: '出厂年份' },
    { text: '2024年', value: '2024年' },
    { text: '2023年', value: '2023年' },
    { text: '2022年', value: '2022年' },
    { text: '2021年', value: '2021年' },
    { text: '2020年', value: '2020年' }
])

const schoolOptions = ref([
    { text: '所在学校', value: '所在学校' },
    { text: '上海理工大学', value: '上海理工大学' },
    { text: '上海复旦大学', value: '上海复旦大学' },
    { text: '上海同济大学', value: '上海同济大学' },
    { text: '上海交通大学', value: '上海交通大学' }
])

// 特价好车数据
const goodCars = ref([
    {
        id: 1,
        name: '雅迪 DE3 电动车',
        year: '2023年',
        batteryHealth: 85,
        mileage: 1200,
        originalPrice: 4800,
        price: 3600,
        discount: 7.5,
        school: '上海理工大学',
        imageUrl: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=400&h=300&fit=crop',
        specialTag: '限时特价',
        isSpecial: true,
        brand: '雅迪'
    },
    {
        id: 2,
        name: '爱玛 A600 电动车',
        year: '2022年',
        batteryHealth: 80,
        mileage: 2000,
        originalPrice: 3800,
        price: 2850,
        discount: 7.5,
        school: '上海大学',
        imageUrl: 'https://images.unsplash.com/photo-1571068316344-75bc76f77890?w=400&h=300&fit=crop',
        specialTag: '急售特价',
        isSpecial: true,
        brand: '爱玛'
    },
    {
        id: 3,
        name: '台铃 TDR-2023 电动车',
        year: '2023年',
        batteryHealth: 88,
        mileage: 800,
        originalPrice: 4200,
        price: 3360,
        discount: 8.0,
        school: '华东理工大学',
        imageUrl: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=400&h=300&fit=crop',
        specialTag: '毕业甩卖',
        isSpecial: true,
        brand: '台铃'
    },
    {
        id: 4,
        name: '小牛 NGT 电动车',
        year: '2022年',
        batteryHealth: 75,
        mileage: 3000,
        originalPrice: 5200,
        price: 3640,
        discount: 7.0,
        school: '上海交通大学',
        imageUrl: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=400&h=300&fit=crop',
        specialTag: '超值特价',
        isSpecial: true,
        brand: '小牛'
    }
])

// 加载状态
const loading = ref(false)
const hasMore = ref(true)
const currentPage = ref(1)
const pageSize = ref(4)

// Toast提示
const toastVisible = ref(false)
const toastMessage = ref('')
const toastType = ref('success')

// 滚动样式 - 考虑navbar、filter和TabBar的高度
const scrollStyle = computed(() => {
    return {
        height: 'calc(100vh - 380rpx)' // 减去header、filter和TabBar的高度
    }
})

/**
 * 切换收藏状态
 * @param {string} carId - 车辆ID
 */
const toggleFavorite = (carId) => {
    const index = favoriteIds.value.indexOf(carId.toString())
    if (index > -1) {
        favoriteIds.value.splice(index, 1)
        showToast('取消收藏', 'success')
    } else {
        favoriteIds.value.push(carId.toString())
        showToast('收藏成功', 'success')
    }
}

/**
 * 点击车辆卡片
 * @param {Object} car - 车辆信息
 */
const onCarClick = (car) => {
    // TODO: 跳转到车辆详情页
    showToast(`查看${car.name}详情`, 'success')
}

// Menu组件事件处理方法
/**
 * 品牌选择变化事件
 * @param {string} value - 选中的品牌值
 */
const onBrandChange = (value) => {
    selectedBrand.value = value
    // 这里可以添加过滤逻辑
    filterCars()
}

/**
 * 年份选择变化事件
 * @param {string} value - 选中的年份值
 */
const onYearChange = (value) => {
    selectedYear.value = value
    // 这里可以添加过滤逻辑
    filterCars()
}

/**
 * 学校选择变化事件
 * @param {string} value - 选中的学校值
 */
const onSchoolChange = (value) => {
    selectedSchool.value = value
    // 这里可以添加过滤逻辑
    filterCars()
}

/**
 * 过滤车辆数据
 */
const filterCars = () => {
    // TODO: 实现过滤逻辑
    showToast('筛选条件已更新', 'success')
}

/**
 * 生成模拟车辆数据
 * @param {number} page - 页码
 * @param {number} size - 每页数量
 * @returns {Array} 车辆数据数组
 */
const generateMockData = (page, size) => {
    const brands = ['雅迪', '台铃', '小鸟', '新日', '爱玛', '小牛', '绿源', '立马']
    const schools = ['上海理工大学', '上海复旦大学', '上海同济大学', '上海交通大学', '华东师范大学', '上海大学']
    const years = ['2024年', '2023年', '2022年', '2021年', '2020年']
    const images = [
        'https://images.unsplash.com/photo-1567922045116-2a00fae2ed03?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
        'https://images.unsplash.com/photo-1573981368236-719bbb6f70f7?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
        'https://images.unsplash.com/photo-1583568671741-c70dafa8e8e7?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
        'https://images.unsplash.com/photo-1595941069915-4ebc5197c14a?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
        'https://images.unsplash.com/photo-1558981285-6f0c94958bb6?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60',
        'https://images.unsplash.com/photo-1558981403-c5f9899a28bc?ixlib=rb-1.2.1&auto=format&fit=crop&w=800&q=60'
    ]
    const specialTags = ['限时特价', '急售特价', '毕业甩卖', '超值特价', '清仓特价', '年底促销']

    const data = []
    for (let i = 0; i < size; i++) {
        const index = (page - 1) * size + i
        const brand = brands[Math.floor(Math.random() * brands.length)]
        const school = schools[Math.floor(Math.random() * schools.length)]
        const year = years[Math.floor(Math.random() * years.length)]
        const image = images[Math.floor(Math.random() * images.length)]
        const specialTag = specialTags[Math.floor(Math.random() * specialTags.length)]
        const originalPrice = Math.floor(Math.random() * 2000) + 3000
        const discount = (Math.floor(Math.random() * 30) + 60) / 10 // 6.0-8.9折
        const price = Math.floor(originalPrice * discount / 10)

        data.push({
            id: `good_${index + 100}`,
            name: `${brand} ${['豪华版', '标准版', '运动版', '经典版'][Math.floor(Math.random() * 4)]}`,
            year: year,
            school: school,
            originalPrice: originalPrice,
            price: price,
            discount: discount,
            imageUrl: image,
            batteryHealth: Math.floor(Math.random() * 30) + 70, // 特价车电池健康度相对较低
            mileage: Math.floor(Math.random() * 3000) + 1000, // 特价车里程相对较高
            brand: brand,
            specialTag: specialTag,
            isSpecial: true
        })
    }
    return data
}

/**
 * 加载更多数据
 */
const loadMore = () => {
    if (loading.value || !hasMore.value) return

    loading.value = true

    // 模拟网络请求延迟
    setTimeout(() => {
        // 模拟最多加载5页数据
        if (currentPage.value >= 5) {
            hasMore.value = false
            loading.value = false
            return
        }

        currentPage.value++
        const newData = generateMockData(currentPage.value, pageSize.value)
        goodCars.value.push(...newData)
        loading.value = false
    }, 1000 + Math.random() * 1000)
}

/**
 * 滚动事件处理
 */
const scroll = (e) => {
    // 可以在这里处理滚动事件
}

/**
 * 显示提示信息
 */
const showToast = (message, type = 'success') => {
    toastMessage.value = message
    toastType.value = type
    toastVisible.value = true
}

// 初始化
onMounted(() => {
    // 可以在这里加载初始数据
})
</script>

<script>
export default {
    name: 'GoodCarListPage'
}
</script>