AbstractVehicleItem.ts 4.12 KB
import {Component, Prop, Vue} from "vue-facing-decorator";
import {AuctionVehicle} from "lib/src/entity/auction/entity/AuctionVehicle";
import dayjs from "dayjs";
import {Vehicle} from "lib/src/entity/vehicle/entity/Vehicle";
import {BurialPoint} from "@/common/BurialPoint";
import {AuthService} from "@/common/AuthService";
import {maskNumberStr} from "@/common/CommonUtils";

@Component({})
export default class AbstractVehicleItem extends Vue {
    @Prop({type: Object, required: true})
    auctionVehicle: AuctionVehicle;

    get productionYear(): number {
        return dayjs(this.vehicle.coreSpecs.productionDate as string).year();
    }

    get mileage(): string {
        return (this.vehicle.baseInfo.mileage / 10000).toFixed(2);
    }

    get vehicle(): Vehicle {
        return this.auctionVehicle.vehicle;
    }

    get licensePlate(): string {
        return this.vehicle.baseInfo?.licensePlate.substring(0, 2);
    }

    get cityName(): string {
        if (this.vehicle.ownership.carCityName) {
            return this.vehicle.ownership.carCityName.replace("市", "");
        }
        return this.vehicle.ownership.carCityName;
    }

    get ageLess1Year(): boolean {
        return dayjs().add(-1, 'years').isBefore(dayjs(this.vehicle.coreSpecs.productionDate as string));
    }

    get efficient(): boolean {
        return (this.vehicle.coreSpecs.vehicleClass === '小型车' || this.vehicle.coreSpecs.vehicleClass === '紧凑型车');
    }

    get hasBidPrivilege(): boolean {
        const authService: AuthService = this.$auth as AuthService;
        if (authService.isLogin() && authService.getAuthentication().accountType !== 'COMMON') {
            return true;
        } else {
            return false;
        }
    }

    get maskBidPrice(): string {
        return maskNumberStr((this.vehicle.startingBidPrice / 10000).toFixed(2));
    }


    viewCarDetail() {
        BurialPoint.burialPoint(this.$auth.getAuthentication(), 'auction_home_vehiclecard_click', this.auctionVehicle.aucvehId.toString(), '/module/auction/AuctionVehiclePage');
        uni.navigateTo({url: '/module/auction/AuctionVehiclePage?aucvehId=' + this.auctionVehicle.aucvehId});
    }

    /**
     * 是否小于24小时开拍
     */
    get previewLessThen24h(): boolean {
        // const now = dayjs();
        // const startTime = dayjs(this.auctionVehicle.auctionStartTime as string);
        // return (startTime.diff(now) <= 24 * 60 * 60 * 1000);

        return (this.auctionVehicle.bidStartRemaining <= 24 * 60 * 60 * 1000);
    }

    /**
     * 预览倒计时
     */
    get previewCountDown(): number {
        // const now = dayjs();
        // const startTime = dayjs(this.auctionVehicle.auctionStartTime as string);
        // return startTime.diff(now);
        return this.auctionVehicle.bidStartRemaining;
    }

    /**
     * 预览中显示状态信息
     */
    get previewStatus(): string {
        const now = dayjs();
        const startTime = dayjs(this.auctionVehicle.auctionStartTime as string);
        return startTime.format('YYYY/MM/DD HH:mm');
    }

    // /**
    //  * 拍卖中显示状态信息
    //  */
    // get auctionStatus(): string {
    //     const now = dayjs();
    //     const endTime = dayjs(this.auctionVehicle.auctionEndTime as string);
    //     return '剩余 ' + dayjs.duration(endTime.diff(now)).format('HH:mm:ss');
    // }

    /**
     * 是否只剩下5分钟拍卖结束
     */
    get remaining5m(): boolean {
        // const now = dayjs();
        // const endTime = dayjs(this.auctionVehicle.auctionEndTime as string);
        // return endTime.diff(now) < 5 * 60 * 1000;

        return this.auctionVehicle.bidEndRemaining < 5 * 60 * 1000;
    }

    /**
     * 只剩下5分钟拍卖结束倒计时
     */
    get endRemaining() {
        // const now = dayjs();
        // const endTime = dayjs(this.auctionVehicle.auctionEndTime as string);
        // return endTime.diff(now);
        return this.auctionVehicle.bidEndRemaining;
    }

    countDownBidStart(): void {
        this.auctionVehicle.auctionState = 'AUCTIONING';
    }

    countDownBidEnd(): void {
        this.auctionVehicle.auctionState = 'SOLD';
    }
}