AuctionSessionPage.vue 6.9 KB
<template>
    <view class="page-container">
        <view class="bg-image" :style="{  backgroundImage:`url(${backgroundImageUrl})` }"></view>
        <custom-nav-bar :title="auction?.auctionName" :show-back="true" :status-bar-height="statusBarHeight"></custom-nav-bar>
        <view class="header" :style="{ top: statusBarHeight+44 + 'px'   }">
            <!-- 筛选和排序区域 -->
            <van-dropdown-menu>
                <van-dropdown-item title="排序" :value="sortOption" :options="sortOptions" @change="onTimeSortChange"/>
                <van-dropdown-item title="品牌" use-before-toggle @before-toggle="filterByBrand"/>
                <van-dropdown-item title="车价" id="priceFilterItem" :style="{display:  priceShow?'block' : 'none'}" @open="priceShow=true" @close="priceShow=false">
                    <vehicle-price-range-filter @priceChange="onPriceChange"></vehicle-price-range-filter>
                </van-dropdown-item>
                <van-dropdown-item title="筛选" use-before-toggle @before-toggle="moreFilter"/>
            </van-dropdown-menu>
            <search-query-filter :search-query="searchQuery" @clear-all="clearAllFilters" @change="pageFilterReload"></search-query-filter>

        </view> 
        <view class="auction-session-container" :style="{ paddingTop: statusBarHeight+filterHeight + 'px'   }">
            <!-- 车辆列表 -->
            <scroll-view class="scroll-content" scroll-y :refresher-enabled="true" :refresher-triggered="loading" @scrolltolower="doInfinite()" @refresherrefresh="pageReload">
                <view class="car-list">
                    <template v-if="contents.length>0" v-for="(car, index) in contents" :key="index">
                        <auction-vehicle-item :auction-vehicle="car" @emitLoadList="pageReload"></auction-vehicle-item>
                    </template>
                    <van-empty class="search-empty" v-else image="https://img02.glsx.com.cn/aus/images/empty_2.png" width="100" height="100" description="未找到相关车源,为你推荐以下车源"/>
                </view>
            </scroll-view>
        </view>
    </view>
</template>
<script lang="ts">
import {Component, Hook} from "vue-facing-decorator";
import {onLoad, onShow} from "@dcloudio/uni-app";
import {Auction} from "lib/src/entity/auction/entity/Auction";
import {AuctionController} from "@/api/AuctionController";
// import {PaginationComponent} from "@/components/PaginationComponent";
import {Order} from "lib/src/core/page/Pagination";
import AuctionVehicleItem from "@/components/AuctionVehicleItem.vue";
import CustomNavBar from "@/components/CustomNavBar.vue";
import {BACKGROUND_IMAGE_1} from "@/static/ResourceConstants";
import AuctionVehicleFilter from "@/components/filter/AuctionVehicleFilter";
import SearchQueryFilter from "@/components/filter/SearchQueryFilter.vue";
import VehiclePriceRangeFilter from "@/components/filter/VehiclePriceRangeFilter.vue";
import {AuctionVehicle} from "lib/src/entity/auction/entity/AuctionVehicle";


@Component({
    components: {VehiclePriceRangeFilter, SearchQueryFilter, CustomNavBar, AuctionVehicleItem}
})
export default class AuctionSessionPage extends AuctionVehicleFilter {


    auctionId: number;

    auction: Auction = null;

    statusBarHeight = 0;// 用于接收头部总高度,设置内容区 padding
    backgroundImageUrl = BACKGROUND_IMAGE_1;

    sortOptions = [
        {text: '上架时间由近到远', value: 0},
        {text: '里程由短到长', value: 1},
        {text: '里程由长到短', value: 2},
        {text: '车龄由小到大', value: 3},
        {text: '车龄由大到小', value: 4},
    ];

    sortOption = 0;


    created(): void {
        this.init(this.axios, AuctionController.PAGE_LIGHT_AUCTION_VEHICLE);
        onLoad((option) => {
            this.auctionId = option.auctionId;
            this.statusBarHeight = uni.getWindowInfo().statusBarHeight;
            this.loadAuctionVehicles();
            this.initSearch(option);
            // this.pagination.setDefaultSort('createTime', Order.desc);
            this.pagination.addDefaultFilter("auction.auctionId", this.auctionId);
            this.pageFilterReload();
        });
        onShow(options => {
            this.pageFilterReload();
        });
    }

    onTimeSortChange(detail: any): void {
        console.log(detail);
        this.sortOption = detail.detail;
        switch (this.sortOption) {
            case 0:
                this.pagination.setDefaultSort('auctionStartTime', Order.desc);
                break;
            case 1:
                this.pagination.setDefaultSort('vehicle.baseInfo.mileage', Order.asc);
                break;
            case 2:
                this.pagination.setDefaultSort('vehicle.baseInfo.mileage', Order.desc);
                break;
            case 3:
                this.pagination.setDefaultSort('vehicle.coreSpecs.productionDate', Order.desc);
                break;
            case 4:
                this.pagination.setDefaultSort('vehicle.coreSpecs.productionDate', Order.asc);
                break;
        }
        this.pageReload();
    }

    get filterHeight(): number {
        return this.searchQuery != null ? 120 : 85;
    }

    get contents(): AuctionVehicle[] {
        const list = (this.pagination.content || []).map(item => {
            const vehicleObj = item.vehicle || {};
            return { ...item, auctionState: vehicleObj.vehicleState || item.auctionState }
        });
        return list;
    }

    loadAuctionVehicles() {
        AuctionController.getAuctionById(this.axios, this.auctionId).then(res => {
            this.auction = res.data;
            uni.setNavigationBarTitle({title: this.auction.auctionName});
        });
    }

    @Hook('onShareAppMessage')
    onShareAppMessage(res: any) {
        console.debug('分享来源:', res.from);
        const title = `${this.auction.auctionName}`;
        return {
            title: title,
            path: '/module/auction/AuctionSessionPage?auctionId=' + this.auctionId,
            imageUrl: 'https://dj-oss-fastdfs-release.oss-cn-shenzhen.aliyuncs.com/auction/f0e4f6add8afa743af09294e791c2f9b.png', // 分享图片(建议尺寸 5:4,默认使用页面截图)
        };
    }

}
</script>

<style lang="scss" scoped>
.auction-session-container {
    background-color: #ffffff;
}


.filter-sort-bar {
    display: flex;
    background-color: #fff;
    padding: 6px 16px;
    height: 56px;
    border-bottom: 1px solid #eee;
}

.filter-item {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    font-size: 14px;
    color: #333;
}

.filter-item text {
    margin-right: 4px;
}

.car-list {
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.separator {
    margin: 0 8px;
}


.countdown {
    font-size: 12px;
    color: #666;
}

.countdown-label {
    margin-right: 4px;
}

.countdown-time {
    color: #FF5722;
}

.scroll-content {
    height: calc(100vh - 180px);
}
</style>