ViewAuctionOrder.vue 24.3 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 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563
<template>

    <a-card :bordered="false" size="small">
        <template #title>
            <title-tip-icon/>
            订单概览
        </template>
        <template #extra>
            <a-button v-if="auctionOrder && auctionOrder.orderState !== 'COMPLETED'&& auctionOrder.orderState !== 'CANCELED'" type="default" @click="cancelOrder">
                取消订单
            </a-button>
            <a-button v-sec="'auction_order_27'" v-if="auctionOrder && auctionOrder.orderState !== 'COMPLETED'&& auctionOrder.orderState !== 'CANCELED'"
                      :disabled="breaches?.length===0" type="primary" @click="changeOtherOrder" class="ml-10">修改成交人
            </a-button>
        </template>
        <a-descriptions v-if="auctionOrder" :bordered="false" :column="4" size="small">
            <a-descriptions-item label="订单号" name="orderCode">
                {{ auctionOrder.orderCode }}
            </a-descriptions-item>
            <a-descriptions-item label="订单状态" name="orderState">
                <auction-order-state-tag :order-state="auctionOrder.orderState"></auction-order-state-tag>
            </a-descriptions-item>
            <a-descriptions-item label="成交价" name="updateTime">
                ¥{{ auctionOrder.orderPrice }}
            </a-descriptions-item>
            <a-descriptions-item label="佣金" name="updateTime">
                ¥{{ auctionOrder.commissionPrice }}
            </a-descriptions-item>
            <a-descriptions-item label="成本价" name="updateTime">
                ¥{{ auctionOrder.vehicle.evaluationTransaction.purchasePrice }}
            </a-descriptions-item>
            <a-descriptions-item label="创建时间" name="createTime">
                {{ auctionOrder.createTime }}
            </a-descriptions-item>
            <a-descriptions-item label="保留价" name="updateTime">
                ¥{{ auctionOrder.vehicle.reservePrice }}
            </a-descriptions-item>
            <a-descriptions-item label="预计经销差" name="updateTime">
                ¥{{ expectedProfitMargin }}
            </a-descriptions-item>
            <a-descriptions-item label="溢价金额" name="updateTime">
                ¥{{ premiumAmount }}
            </a-descriptions-item>
            <a-descriptions-item label="实际经销差" name="updateTime">
                ¥{{ actualProfitMargin }}
            </a-descriptions-item>
        </a-descriptions>
    </a-card>
    <a-card class="mt-10" :bordered="false" size="small">
        <template #title>
            <title-tip-icon/>
            车辆档案
        </template>
        <vehicle-base-info :vehicle="auctionOrder?.vehicle" :bordered="false" :column="4"></vehicle-base-info>
    </a-card>
    <a-card v-sec="'auction_order_17'" class="mt-10" :bordered="false" size="small">
        <template #title>
            <title-tip-icon/>
            交易方信息
        </template>
        <a-descriptions v-if="account" :bordered="false" :column="4" size="small">
            <a-descriptions-item label="买受方" name="accountName">
                {{ account.accountName }} <span v-sec="'auction_order_10'"> {{ account.mobile }}</span> (ID: {{ account.accountId }})

                <router-link v-sec="'auction_order_19'" :to="{path:'/account/view',query:{accountId:account.accountId}}">查看详情</router-link>
            </a-descriptions-item>
            <a-descriptions-item label="出售方" name="accountId">
                平台
            </a-descriptions-item>
        </a-descriptions>
    </a-card>
    <a-card v-sec="'auction_order_20'" class="mt-10" :bordered="false" size="small">
        <template #title>
            <title-tip-icon/>
            合同信息
        </template>
        <a-table :columns="columns" :data-source="contracts" :bordered="false" @resizeColumn="this.$filters.tableResizeColumn"
                 size="small" :pagination="false" :row-key="record => record.contractId">
            <template #bodyCell="{column,record}">
                <template v-if="column.key === 'action'">
                    <a-button v-sec="'auction_order_21'" type="link" size="small" @click="viewContract(record)">查看合同</a-button>
                </template>
                <template v-if="column.key === 'signed'">
                    <a-tag v-if="record.signed" color="#E8F8F2" style="color: #00AD74">已签署</a-tag>
                    <a-tag v-else color="#FCF4E1" style="color: #F0A700">待签署</a-tag>
                </template>
            </template>
            <!--合同列表end-->
        </a-table>
    </a-card>

    <a-card class="mt-10" v-sec="'auction_order_23'" :bordered="false" size="small">
        <template #title>
            <title-tip-icon/>
            支付信息
        </template>
        <a-table v-if="deposit" :columns="amountColumns" :data-source="amountData" :bordered="false" @resizeColumn="this.$filters.tableResizeColumn"
                 size="small" :pagination="false" :row-key="record => record.contractId">
            <template #bodyCell="{column,record}">
                <template v-if="column.key === 'payAmount'">
                    <template v-if="record.payType==='拍卖保证金'">
                        {{ record.payAmount }}
                    </template>
                    <template v-else-if="orderTransaction">
                        {{ record.payAmount }}
                    </template>
                    <template v-else>
                        -
                    </template>
                </template>
                <template v-if="column.key === 'payState'">
                    <template v-if="record.payType==='拍卖保证金'">
                        <deposit-state-tag :deposit-state="record.payState"></deposit-state-tag>
                    </template>
                    <template v-else-if="record.payType === '优惠券抵扣'">
                        <a-tag color="green">已抵扣</a-tag>
                    </template>
                    <template v-else-if="orderTransaction">
                        <audit-state-tag :audit-state="orderTransaction.auditState"></audit-state-tag>
                    </template>
                    <template v-else>
                        -
                    </template>
                </template>
                <template v-if="column.key === 'payMethod'">
                    <template v-if="record.payType==='拍卖保证金'">
                        {{ record.payMethod }}
                    </template>
                    <template v-else-if="record.payType === '优惠券抵扣'">-</template>
                    <template v-else-if="orderTransaction">
                        {{ $t(`enum.orderTransaction.paymentType.${orderTransaction.paymentType}`) }}
                    </template>
                    <template v-else>
                        -
                    </template>
                </template>
                <template v-if="column.key === 'payEndTime'">
                    <template v-if="record.payType==='拍卖保证金'">
                        {{ record.payEndTime }}
                    </template>
                    <template v-else>
                        -
                    </template>
                </template>
                <template v-if="column.key === 'payTime'">
                    <template v-if="record.payType==='拍卖保证金'">
                        {{ record.payTime }}
                    </template>
                    <template v-else-if="record.payType === '优惠券抵扣'">-</template>
                    <template v-else-if="orderTransaction">
                        {{ orderTransaction.createTime }}
                    </template>
                    <template v-else>
                        -
                    </template>
                </template>
                <template v-if="column.key === 'action'">
                    <template v-if="record.payType==='拍卖保证金'">
                        <router-link v-sec="'deposit_7'" :to="{path: '/finance/deposit/view', query: {depositId: deposit.depositId}}">
                            <a-button type="link" size="small">查看</a-button>
                        </router-link>
                    </template>
                    <template v-else-if="record.payType === '优惠券抵扣'">
                        <a-button type="link" size="small" @click="viewCoupon(record)">查看</a-button>
                    </template>
                    <template v-else-if="orderTransaction">
                        <a-button type="link" size="small" @click="viewOrderTransaction(orderTransaction)">查看</a-button>
                    </template>
                    <template v-else>
                        -
                    </template>
                </template>
            </template>
            <!--合同列表end-->
        </a-table>
    </a-card>
    <a-card class="mt-10" v-sec="'auction_order_25'" :bordered="false" size="small">
        <template #title>
            <title-tip-icon/>
            违约记录
        </template>
        <template #extra>
            <a-button v-sec="'auction_order_26'" type="primary" @click="addBreachRecord">新增违约记录</a-button>
        </template>
        <a-table :columns="breachColumns" :data-source="breaches" :bordered="false" @resizeColumn="this.$filters.tableResizeColumn"
                 size="small" :pagination="false" :row-key="record => record.contractId">
            <template #bodyCell="{column,record}">

            </template>
            <!--合同列表end-->
        </a-table>
    </a-card>
    <a-card class="mt-10" :bordered="false" size="small">
        <template #title>
            <title-tip-icon/>
            操作日志
        </template>
    </a-card>

</template>
<script lang="ts">

import {Component, Vue} from "vue-facing-decorator";
import {AuctionOrder} from "lib/src/entity/auction/entity/AuctionOrder";
import {AuctionOrderController} from "@/api/AuctionOrderController";
import VehicleBaseInfo from "@/views/vehicle/inventory/VehicleBaseInfo.vue";
import {Account} from "lib/src/entity/account/entity/Account";
import {DepositController} from "@/api/DepositController";
import {Deposit} from "lib/src/entity/finance/entity/Deposit";
import {message, TableColumnsType} from "ant-design-vue";
import {DeleteFilled, EditFilled} from "@ant-design/icons-vue";
import {Contract} from "lib/src/entity/auction/entity/Contract";
import {ContractController} from "@/api/ContractController";
import {BreachRecord} from "lib/src/entity/auction/entity/BreachRecord";
import {BreachController} from "@/api/BreachController";
import {ModalService} from "@/components/ModalService";
import BreachRecordForm from "@/views/auction/order/BreachRecordForm.vue";
import AuctionOrderStateTag from "@/views/auction/order/AuctionOrderStateTag.vue";
import CreateAuctionOrder from "./CreateAuctionOrder.vue";
import TitleTipIcon from "@/components/icons/TitleTipIcon.vue";
import ViewContract from "@/views/business/contract/ViewContract.vue";
import {OrderTransaction} from "lib/src/entity/finance/entity/OrderTransaction";
import {TransactionController} from "@/api/TransactionController";
import DepositStateTag from "@/views/finance/deposit/DepositStateTag.vue";
import AuditStateTag from "@/views/common/AuditStateTag.vue";
import ViewOrderTransaction from "@/views/finance/order-transaction/ViewOrderTransaction.vue";
import CancelAuctionOrder from "@/views/auction/order/CancelAuctionOrder.vue";
import ViewOrderCoupon from "@/views/auction/order/ViewOrderCoupon.vue";

@Component({
    components: {AuditStateTag, DepositStateTag, TitleTipIcon, AuctionOrderStateTag, EditFilled, DeleteFilled, VehicleBaseInfo}
})
export default class ViewAuctionOrder extends Vue {

    orderId: any;

    auctionOrder: AuctionOrder | null = null;

    deposit: Deposit = null;

    contracts: Contract[] = [];

    breaches: BreachRecord[] = [];

    orderTransaction: OrderTransaction = null;

    couponUseData: any = null;

    /**
     * 表格列配置
     */
    columns: TableColumnsType = [
        {
            title: '合同类型', dataIndex: 'templateType', key: 'templateType', align: 'center', width: 100, resizable: true, ellipsis: true, sorter: false,
            customRender: ({text, record, index, column}) => {
                return this.i18n(`enum.contractTemplate.templateType.${text}`);
            }
        },
        {title: '合同编号', dataIndex: 'contractCode', key: 'contractCode', width: 100, resizable: true, ellipsis: true, sorter: false},
        {title: '合同状态', dataIndex: 'signed', key: 'signed', align: 'center', width: 100, resizable: true, ellipsis: true, sorter: false},
        {title: '创建时间', dataIndex: 'createTime', key: 'createTime', align: 'center', width: 170, resizable: true, ellipsis: true, sorter: false},
        {title: '签署时间', dataIndex: 'signTime', key: 'signTime', align: 'center', width: 170, resizable: true, ellipsis: true, sorter: false},
        {title: '操作', key: 'action', width: 110, align: 'center', fixed: 'right'},
    ];

    breachColumns: TableColumnsType = [
        {
            title: '违约场景', dataIndex: 'breachScene', key: 'breachScene', align: 'center', width: 200, resizable: true, ellipsis: true, sorter: false,
            customRender: ({text, record, index, column}) => {
                return this.i18n(`enum.breachRecord.breachScene.${text}`);
            }
        },
        {
            title: '违约保证金扣除金额', dataIndex: 'depositDeduct', key: 'depositDeduct', align: 'right', width: 180, resizable: true, ellipsis: true, sorter: false,
            customRender: ({text, record, index, column}) => {
                return '¥' + text;
            }
        },
        {title: '违约备注说明', dataIndex: 'remark', key: 'remark', resizable: true, ellipsis: true, sorter: false},
        {title: '创建时间', dataIndex: 'createTime', key: 'createTime', align: 'center', width: 170, resizable: true, ellipsis: true, sorter: false},
    ];

    amountColumns: TableColumnsType = [
        {title: '支付项目', dataIndex: 'payType', key: 'payType', align: 'center', width: 200, resizable: true, ellipsis: true, sorter: false,},
        {title: '应付金额', dataIndex: 'amount', key: 'amount', align: 'right', width: 160, resizable: true, ellipsis: true, sorter: false,},
        {title: '实付金额', dataIndex: 'payAmount', key: 'payAmount', align: 'right', width: 240, resizable: true, ellipsis: true, sorter: false},
        {title: '支付状态', dataIndex: 'payState', key: 'payState', align: 'center', width: 110, resizable: true, ellipsis: true, sorter: false},
        {title: '支付形式', dataIndex: 'payMethod', key: 'payMethod', align: 'center', width: 110, resizable: true, ellipsis: true, sorter: false},
        {title: '支付截止时间', dataIndex: 'payEndTime', key: 'payEndTime', align: 'center', resizable: true, ellipsis: true, sorter: false},
        {title: '支付时间', dataIndex: 'payTime', key: 'payTime', align: 'center', width: 170, resizable: true, ellipsis: true, sorter: false},
        {title: '操作', key: 'action', width: 110, align: 'center', fixed: 'right'},
    ];

    created(): void {
        this.orderId = Number(this.$route.query.orderId);
        AuctionOrderController.getAuctionOrderDetailById(this.axios, this.orderId).then(response => {
            this.auctionOrder = response.data;
            this.loadDeposit(this.account.accountId, this.auctionOrder.vehicle.vehicleId, this.auctionOrder.auction.auctionId);
        });
        ContractController.getContractsByOrderId(this.axios, this.orderId).then(response => {
            this.contracts = response.data;
        });
        TransactionController.getOrderTransactionByOrderId(this.axios, this.orderId).then(response => {
            this.orderTransaction = response.data;
        });
        AuctionOrderController.getAuctionOrderCouponUseData(this.axios, this.orderId).then(response => {
            this.couponUseData = response.data?.data;
        });
        this.loadBreachs();
    }

    loadBreachs(): void {
        BreachController.getBreachRecordsByOrderId(this.axios, this.orderId).then(response => {
            this.breaches = response.data;
        });
    }

    loadDeposit(accountId: number, vehicleId: number, auctionId: number): void {
        DepositController.getDepositByAccountAndVehicleAndAuction(this.axios, accountId, vehicleId, auctionId).then(response => {
            this.deposit = response.data;
        });
    }

    get amountData() {
        let reduceAmount = "";
        const reduceDeposit = (this.deposit.amount + this.deposit.transaction.amount);
        if (reduceDeposit !== 0) {
            reduceAmount = "(已扣违约金:¥" + (-reduceDeposit) + ")";
        }
        const baozhengjin = {
            payType: '拍卖保证金',
            amount: '¥' + (-this.deposit.transaction.amount),
            payAmount: '¥' + (-this.deposit.transaction.amount) + reduceAmount,
            payState: this.deposit.depositState,
            payMethod: '微信',
            payEndTime: this.deposit.createTime,
            payTime: this.deposit.createTime
        }
        const cheliangkuan = {
            payType: '车辆款',
            amount: '¥' + this.auctionOrder.orderPrice,
            payAmount: '¥' + this.auctionOrder.orderPrice,
            payState: '-',
            payMethod: '-',
            payEndTime: '-',
            payTime: '-'
        }
        const youhuiquan = {
            payType: '优惠券抵扣',
            amount: '-¥' + this.couponUseData?.actualDeduction,
            payAmount: '-',
            payState: '已抵扣',
            payMethod: '-',
            payEndTime: '-',
            payTime: '-'
        }
        const yongjin = {
            payType: '拍卖佣金',
            amount: '¥' + this.auctionOrder.commissionPrice,
            payAmount: '¥' + this.auctionOrder.commissionPrice,
            payState: '-',
            payMethod: '-',
            payEndTime: '-',
            payTime: '-'
        }
        console.log(this.couponUseData)
        if (Object.keys(this.couponUseData || {}).length > 0) {
            return [baozhengjin, cheliangkuan, youhuiquan, yongjin];
        } else {
            return [baozhengjin, cheliangkuan, yongjin];
        }

    }

    addBreachRecord(): void {
        const modal = ModalService.confirm({
            title: '新增违约记录', component: BreachRecordForm, closable: true, appContext: this.$.appContext,
            props: {
                auctionOrder: this.auctionOrder,
                deposit: this.deposit
            },
            onOk: (component): void => {
                component.submitForm();
            },
            emits: {
                handleOk: (e) => {
                    modal.destroy();
                    this.loadBreachs();
                    this.loadDeposit(this.account.accountId, this.auctionOrder.vehicle.vehicleId, this.auctionOrder.auction.auctionId);
                }
            },
        });
    }

    changeOtherOrder(): void {
        const modal = ModalService.confirm({
            title: '选择新的成交人', component: CreateAuctionOrder, closable: true, appContext: this.$.appContext,
            props: {
                auctionOrder: this.auctionOrder,
            },
            onOk: (component): void => {
                component.submitForm();
            },
            emits: {
                handleOk: (order: AuctionOrder) => {
                    modal.destroy();
                    if (order) {
                        message.success('新的订单已经生成,订单号:' + order.orderCode);
                        this.$router.push({path: '/auction/order'});
                    }
                }
            },
        });
    }

    cancelOrder(): void {
        const modal = ModalService.confirm({
            title: '取消订单', component: CancelAuctionOrder, closable: true, appContext: this.$.appContext,
            props: {
                auctionOrder: this.auctionOrder,
            },
            onOk: (component): void => {
                component.submitForm();
            },
            emits: {
                handleOk: (order: AuctionOrder) => {
                    modal.destroy();
                    if (order) {
                        this.$router.push({path: '/auction/order'});
                    }
                }
            },
        });
    }

    i18n(text: string): string {
        return this.$t(text);
    }

    get account(): Account {
        return this.auctionOrder?.account;
    }

    /**
     * 预计经销差 = 保留价 + 佣金 - 成本价
     * 使用 Math.round() 避免精度丢失
     */
    get expectedProfitMargin(): string {
        if (!this.auctionOrder) return '-';

        const reservePrice = this.auctionOrder.vehicle?.reservePrice;
        const commissionPrice = this.auctionOrder.commissionPrice;
        const purchasePrice = this.auctionOrder.vehicle?.evaluationTransaction?.purchasePrice;

        // 如果任一值为空,返回 '-'
        if (!reservePrice || !commissionPrice || !purchasePrice) {
            return '-';
        }

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

    /**
     * 溢价金额 = 成交价 + 佣金 - 保留价
     * 使用 Math.round() 避免精度丢失
     */
    get premiumAmount(): string {
        if (!this.auctionOrder) return '-';

        const orderPrice = this.auctionOrder.orderPrice;
        const commissionPrice = this.auctionOrder.commissionPrice;
        const reservePrice = this.auctionOrder.vehicle?.reservePrice;

        // 如果任一值为空,返回 '-'
        if (!orderPrice || !commissionPrice || !reservePrice) {
            return '-';
        }

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

    /**
     * 实际经销差 = 成交价 + 佣金 - 成本价
     * 使用 Math.round() 避免精度丢失
     */
    get actualProfitMargin(): string {
        if (!this.auctionOrder) return '-';

        const orderPrice = this.auctionOrder.orderPrice;
        const commissionPrice = this.auctionOrder.commissionPrice;
        const purchasePrice = this.auctionOrder.vehicle?.evaluationTransaction?.purchasePrice;

        // 如果任一值为空,返回 '-'
        if (!orderPrice || !commissionPrice || !purchasePrice) {
            return '-';
        }

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

    viewContract(contract: Contract): void {
        contract.auctionOrder = this.auctionOrder;
        const modal = ModalService.confirm({
            title: '合同详情', component: ViewContract, closable: true, appContext: this.$.appContext,
            props: {
                contract: contract
            },
            onOk: (component): void => {
                component.submitForm();
            },
            emits: {
                handleOk: (e) => {
                    modal.destroy();
                }
            },
        });
    }

    viewOrderTransaction(orderTransaction: OrderTransaction): void {
        orderTransaction.auctionOrder = this.auctionOrder;
        const modal = ModalService.confirm({
            title: '交易详情', component: ViewOrderTransaction, closable: true, appContext: this.$.appContext,
            props: {
                orderTransaction: orderTransaction
            },
            onOk: (component): void => {
                modal.destroy()
            },
            emits: {
                handleOk: (e) => {
                    modal.destroy();
                }
            },
        });
    }
    viewCoupon(): void {
        const modal = ModalService.confirm({
            title: '优惠券使用详情', component: ViewOrderCoupon, closable: true, appContext: this.$.appContext, width: 650,
            props: {
                couponData: this.couponUseData
            },
            onOk: (component): void => {
                modal.destroy()
            },
            emits: {
                handleOk: (e) => {
                    modal.destroy();
                }
            },
        });
    }
}
</script>

<style scoped>

</style>