ApproveHistoryTimelineWithPrice.vue 6.26 KB
<template>
    <a-timeline class="mt-10">
        <a-timeline-item v-for="item in approveHistories" :color="auditStateColor(item.auditState)" :key="item.historyId">
            <div class="title-container">
                <div class="title-type">
                    <span class="label">操作类型:</span>
                    {{ $t('enum.auditState.' + item.auditState) }}
                </div>
                <div class="title-type">
                    <span class="label">市场参考价:</span>
                    ¥{{ item.referencePrice }}元
                </div>
                <div class="title-type">
                    <span class="label">起拍价:</span>
                    ¥{{ item.startingBidPrice }}元
                </div>
                <div class="title-type">
                    <span class="label">保留价:</span>
                    ¥{{ item.reservePrice }}元
                </div>
                <div class="title-type">
                    <span class="label">佣金金额:</span>
                    ¥{{ item.fixedCommission ?? '-' }}元
                </div>
                <div class="title-type">
                    <span class="label">成本价:</span>
                    ¥{{ appraiseObj.vehicle?.evaluationTransaction?.purchasePrice }}元
                </div>
                <div class="title-type">
                    <span class="label">预计经销差:</span>
                    ¥{{ expectedProfitMethod(item.reservePrice, appraiseObj.fixedCommission, appraiseObj.vehicle?.evaluationTransaction?.purchasePrice) }}元
                </div>
                <div class="title-remark" v-if="item.remark" :title="item.remark">
                    <span class="label">备注:</span>{{ item.remark }}
                </div>
            </div>
            <p class="time-label">
                <a-tooltip :title="item.user.userName" class="mr-16"> {{ item.user.realName }}</a-tooltip>
                <span> {{ item.createTime }}</span>
            </p>
        </a-timeline-item>
        <a-timeline-item v-if="createTime">
            <div class="title-container">
                <div class="title-type">
                    <span class="label">操作类型:</span>
                    提交审核
                </div>
                <div class="title-type">
                    <span class="label">市场参考价:</span>
                    ¥{{ appraiseObj.referencePrice }}元
                </div>
                <div class="title-type">
                    <span class="label">起拍价:</span>
                    ¥{{ appraiseObj.startingBidPrice }}元
                </div>
                <div class="title-type">
                    <span class="label">保留价:</span>
                    ¥{{ appraiseObj.reservePrice }}元
                </div>
                <div class="title-type">
                    <span class="label">佣金金额:</span>
                    ¥{{ appraiseObj.fixedCommission }}元
                </div>
                <div class="title-type">
                    <span class="label">成本价:</span>
                    ¥{{ appraiseObj.vehicle?.evaluationTransaction?.purchasePrice }}元
                </div>
                <div class="title-type">
                    <span class="label">预计经销差:</span>
                    ¥{{ expectedProfitMethod(appraiseObj.reservePrice, appraiseObj.fixedCommission, appraiseObj.vehicle?.evaluationTransaction?.purchasePrice) }}元
                </div>
                <div class="title-remark" v-if="remark" :title="remark">
                    <span class="label">备注:</span>{{ remark }}
                </div>
            </div>
            <p class="time-label">
                <user-real-name :user-name="starter"></user-real-name>
                <span class="ml-8"> {{ createTime }}</span>
            </p>
        </a-timeline-item>
    </a-timeline>
</template>
<script lang="ts">
import {Component, Prop, Vue} from 'vue-facing-decorator';
import {ApproveHistory, ApproveHistory_ApproveType} from "lib/src/entity/track/entity/ApproveHistory";
import {ApproveController} from "@/api/ApproveController";
import {AuditState} from "lib/src/entity/enum_types";
import UserRealName from "@/components/UserRealName.vue";

@Component({
    components: {UserRealName}
})
export default class ApproveHistoryTimeline extends Vue {

    @Prop({type: String, required: true})
    approveType: ApproveHistory_ApproveType;

    @Prop({type: Number, required: true})
    approveId: number;

    @Prop({type: String, required: false})
    createTime: Date | string;

    @Prop({type: String, required: false})
    starter: string;

    @Prop({type: String, required: false})
    remark: string;

    approveHistories: ApproveHistory[] = [];
    @Prop({type: Object, required: false})
    appraiseObj: appraiseObj = {};
    created(): void {
        ApproveController.getAppraisePricesByVehicleIdExcludingUnaudited(this.axios, this.appraiseObj?.vehicle?.vehicleId).then(res => {
            this.approveHistories = res.data;
        });
    }

    expectedProfitMethod(reservePrice, commission, purchasePrice) {
        // 预计经销差=保留价+佣金-成本价
        if (!reservePrice || !purchasePrice) {
            return '-';
        }

        // 佣金字段可能是0或空,需要特殊处理
        const commissionPrice = commission || 0;

        // 使用 Math.round() 避免精度丢失,保留2位小数
        const margin = Math.round((reservePrice + commissionPrice - purchasePrice) * 100) / 100;
        return margin.toFixed(2);
    }

    auditStateColor(auditState: AuditState): string {
        switch (auditState) {
            case "AUDITED":
                return 'green';
            case "REJECTED":
                return 'red';
            case 'UNAUDITED':
                return 'blue';
        }
        return 'gray';
    }
}
</script>


<style scoped lang="less">
.label {
    color: #777C85FF;
}

.title-container {
    display: flex;
    flex-wrap: wrap;
    width: 100%;
    align-items: center;
}

.title-type {
    display: flex;
    align-items: center;
    margin-right: 20px;
}

.title-remark {
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    flex: 1;
}

.time-label {
    font-size: 12px;
    color: #777C85FF;
}
</style>