<template>
    <div class="home">
        <!-- <nav-bar url="/" /> -->
        <div class="bj"></div>
        <div class="container">
            <div class="loading-box">
                <img src="..\assets\loading@2x.gif" alt="loading" />
                <p>{{ message }}</p>
            </div>
        </div>
    </div>
</template>

<script>
// @ is an alias to /src
import { findStatus } from '@/request/api.js';
import { Toast } from "vant";

export default {
    components: {},
    mounted() {
        console.log(this.$route.meta.title);
        this.title = this.$route.meta.title;
       // 优先从路由query获取（授权回调后参数在query中）
        this.hosp_out_trade_no = this.$route.query.hosp_out_trade_no || '';
        setTimeout(() => {
           this.queryPayStatus();  
        }, 1000);
       
    },
    data() {
        return {
            title: "",
            message: "正在查询支付结果，请稍后",
            returnData: {},
            hosp_out_trade_no:"",
            times:0
        };
    },
  
    methods: {
        // 查询支付状态
        queryPayStatus() {
            let req = {
                "hosp_out_trade_no": this.hosp_out_trade_no
            };
            console.log("查询请求参数:", req);

            findStatus(req).then(res => {
                console.log("查询结果:", res);
                 let data = encodeURIComponent(JSON.stringify(res.data));
                if (res.code === 200) {
                    this.$router.replace({
                        path: '/ybsuccess',
                        query: { data: data }
                    });
                } else {
                    //   Toast({
                    //     message: '查询失败',
                    //     duration: 2000
                    // });
                  this.$router.replace({
                        path: '/ybsuccess',
                        query: { data: data }
                    });
                }
            })
            // .catch(error => {
            //     console.error('查询支付状态失败:', error);
            //     Toast({
            //         message: '网络异常，请稍后重试',
            //         duration: 2000
            //     });
            // });
        }
    }
};
</script>

<style scoped lang="scss">
.bj {
    background: #ffffff;
    position: fixed;
    width: 100%;
    height: 100%;
    top: 0px;
    left: 0px;
    z-index: -1;
}

.container {
    padding: 0 20px;
}

.loading-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 80vh;
    padding-top: 100px;

    img {
        width: 164rpx;
        height: 164rpx;
        margin-bottom: 40rpx;
    }

    p {
        color: #3B71E8;
        font-size: 32rpx;
        font-weight: 600;
    }
}
</style>