OrderComplete.vue 9.92 KB
<template>
    <view class="page-container">
        <view class="bg-image" :style="{  backgroundImage:`url(${backgroundImageUrl})` }"></view>
        <custom-nav-bar title="交易完成" :show-back="true" :status-bar-height="statusBarHeight"></custom-nav-bar>
        <view class="transaction-complete-container" :style="{ paddingTop: statusBarHeight+44 + 'px'    }">
            <!-- 交易成功提示 -->
            <view class="success-container">
                <view class="success-tip">
                    <text class="success-title">交易已圆满完成!</text>
                    <view class="success-desc">恭喜您,开启您的精彩旅程吧!</view>
                </view>
                <view>
                    <image class="success-icon" src="https://img02.glsx.com.cn/aus/images/order/complete.png" mode="aspectFill"></image>
                </view>
            </view>


            <!-- 车辆信息卡片 -->
            <view class="car-info-card">
                <!-- 车辆信息 -->
                <order-vehicle-item v-if="order" :order="order"></order-vehicle-item>
                <view class="action-buttons">
                    <view class="contract-btn" @click="viewContract">电子合同</view>
                    <view class="certificate-btn" @click="viewCertificate">过户凭证</view>
                </view>
            </view>


            <!-- 尊享服务 -->
            <!--            <view class="service-section">-->
            <!--                <view class="section-title">尊享服务</view>-->

            <!--                &lt;!&ndash; 车辆保险方案 &ndash;&gt;-->
            <!--                <view class="service-item" @click="viewInsurance">-->
            <!--                    <view class="service-icon ">-->
            <!--                        <image src="https://img02.glsx.com.cn/aus/images/order/baoxian.png" class="service-image"></image>-->
            <!--                    </view>-->
            <!--                    <view class="service-info">-->
            <!--                        <view class="service-name">车辆保险方案</view>-->
            <!--                        <view class="service-desc">为您甄选高性价比车险,一键投保</view>-->
            <!--                    </view>-->
            <!--                    <uni-icons type="right" size="16" color="#ccc"></uni-icons>-->
            <!--                </view>-->

            <!--                &lt;!&ndash; 官方认证延保 &ndash;&gt;-->
            <!--                <view class="service-item" @click="viewWarranty">-->
            <!--                    <view class="service-icon ">-->
            <!--                        <image src="https://img02.glsx.com.cn/aus/images/order/yanbao.png" class="service-image"></image>-->
            <!--                    </view>-->
            <!--                    <view class="service-info">-->
            <!--                        <view class="service-name">官方认证延保</view>-->
            <!--                        <view class="service-desc">核心部件再享两年质保,用车无忧</view>-->
            <!--                    </view>-->
            <!--                    <uni-icons type="right" size="16" color="#ccc"></uni-icons>-->
            <!--                </view>-->
            <!--            </view>-->
        </view>
    </view>
</template>
<script lang="ts">
import {Component, Vue} from "vue-facing-decorator";
import OrderVehicleItem from "@/module/order/OrderVehicleItem.vue";
import {BACKGROUND_IMAGE_2} from "@/static/ResourceConstants";
import {onLoad, onShow} from "@dcloudio/uni-app";
import {AuctionOrder} from "lib/src/entity/auction/entity/AuctionOrder";
import {AuctionOrderController} from "@/api/AuctionOrderController";
import CustomNavBar from "@/components/CustomNavBar.vue";

@Component({
    components: {CustomNavBar, OrderVehicleItem}
})
export default class OrderComplete extends Vue {
    orderId: number;
    order: AuctionOrder = null;
    backgroundImageUrl = BACKGROUND_IMAGE_2;
    statusBarHeight = 0;// 用于接收头部总高度,设置内容区 padding

    created(): void {
        onLoad((option) => {
            this.statusBarHeight = uni.getWindowInfo().statusBarHeight;
            this.orderId = option.orderId;
            this.loadData();
        });
        // 每次都加载
        onShow((option) => {
        });
    }

    loadData(): void {
        AuctionOrderController.getAuctionOrderDetailById(this.axios, this.orderId).then(res => {
            this.order = res.data;
        });
    }


    viewContract() {
        // 查看电子合同的逻辑
        AuctionOrderController.getContractsByOrderId(this.axios, this.orderId).then(res => {
            const contracts = res.data.filter(item => item.templateType === 'AUCTION');
            if (contracts.length > 0 && contracts[0].contractFiles.length > 0) {
                this.openRemotePdf(contracts[0].contractFiles[0].url);
            } else {
                uni.showToast({title: '暂无电子合同', icon: 'none'});
            }
        });
    }

    // 查看过户凭证的逻辑
    viewCertificate() {
        uni.navigateTo({url: '/module/order/transfer/ViewTransferPage?orderId=' + this.orderId})

    }

    viewInsurance() {
        // 查看车辆保险方案的逻辑
        uni.showToast({
            title: '查看车辆保险方案',
            icon: 'none'
        })
    }

    viewWarranty() {
        // 查看官方认证延保的逻辑
        uni.showToast({
            title: '查看官方认证延保',
            icon: 'none'
        })
    }

    async openRemotePdf(pdfUrl: string) {

        try {
            // 1. 显示加载中提示
            uni.showLoading({title: '加载中...'});

            // 2. 下载 PDF 到临时路径(注意:微信小程序需配置 downloadFile 合法域名)
            uni.downloadFile({
                url: pdfUrl, // 远程 PDF 地址
                success: function (res) {
                    var filePath = res.tempFilePath;
                    uni.openDocument({
                        fileType: "pdf", // 文档类型(必传)
                        filePath: filePath,
                        showMenu: true,
                        success: function (res) {
                            console.log("打开文档成功");
                        },
                    });
                },
                fail: function (res) {
                    uni.showToast({title: '下载失败,请重试', icon: 'none'});
                },
            });

            // 3. 下载成功后,打开 PDF
            // if (downloadRes.statusCode === 200) {
            //     await new Promise<any>(
            //         (resolve, reject) => {
            //             uni.openDocument({
            //                 fileType: "pdf", // 文档类型(必传)
            //                 filePath: downloadRes.tempFilePath, // 临时文件路径
            //                 showMenu: true, // 显示右上角菜单(支持转发、保存)
            //                 success: resolve,
            //                 fail: reject,
            //             });
            //         }
            //     );
            //     uni.showToast({title: '打开成功', icon: 'none'});
            // } else {
            //     uni.showToast({title: '下载失败', icon: 'none'});
            // }
        } catch (error) {
            console.error("打开 PDF 失败:", error);
            uni.showToast({title: '打开失败,请重试', icon: 'none'});
        } finally {
            // 关闭加载提示
            uni.hideLoading();
        }
    }
}
</script>

<style lang="scss" scoped>
.transaction-complete-container {
    padding-bottom: 20px;
    position: relative;
}

.page-container {
    background-color: #f5f5f5;
}


/* 交易成功提示 */
.success-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.success-tip {
    padding: 20px 16px;
    text-align: left;
    display: flex;
    flex-direction: column;
    margin-bottom: 2px;
}

.success-title {
    font-size: 26px;
    font-weight: 600;
    color: #1989fa;
    margin-bottom: 2px;
}

.success-icon {
    margin-right: 12px;
    width: 100px;
    height: 100px;
}

.success-desc {
    font-size: 13px;
    color: #333;
}

.success-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 12px;
    padding-bottom: 30px;
    background-color: #fff;
}

.success-subtitle {
    font-size: 14px;
    color: #666;
}

/* 车辆信息卡片 */
.car-info-card {
    background-color: #fff;
    margin: 12px;
    border-radius: 12px;
}

.action-buttons {
    display: flex;
    justify-content: space-between;
    padding: 0 16px 16px 16px;
}

.contract-btn,
.certificate-btn {
    flex: 1;
    height: 44px;
    border-radius: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.contract-btn {
    background-color: #F8F9FBFF;
    color: #333;
    margin-right: 8px;
}

.certificate-btn {
    background-color: #185EFEFF;
    color: #fff;
    margin-left: 8px;
}

/* 尊享服务 */
.service-section {
    background-color: #fff;
    margin: 12px;
    border-radius: 12px;
    padding: 16px;
}

.section-title {
    font-size: 16px;
    font-weight: 500;
    color: #333;
    margin-bottom: 16px;
}

.service-item {
    display: flex;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid #f0f0f0;
}

.service-item:last-child {
    border-bottom: none;
}

.service-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    border: 1px solid #E7EBF4FF;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-right: 12px;
}


.service-image {
    height: 32px;
    width: 32px;
}

.service-info {
    flex: 1;
}

.service-name {
    font-size: 15px;
    color: #333;
    margin-bottom: 4px;
}

.service-desc {
    font-size: 13px;
    color: #999;
}
</style>