<template>
    <nav-bar :navbar-data="navbarData"></nav-bar>
    <view class="wait-settlment-box">
        <wait-settlment ref="waitSettlment" :hospCode="hospCode" :hospName="hospName" :settlmentData="settlmentData" @statusChange="statusChange" />
    </view>
</template>

<script>
    import Util from '@/utils/utils';
    import httpConfig from '@/utils/httpConfig';
    import navBar from '@/components/navBar/index'
    import WaitSettlment from '@/components/wait-settlement/index'
    const app = getApp();
    export default {
        components: {
            'navBar': navBar,
            'wait-settlment': WaitSettlment
        },
        data() {
            return {
                imgHost: httpConfig && httpConfig.imgHost,
                height: app.globalData.height,
                navbarData: {
                    isGoHome: false,
                    isGoBack: true,
                    title: "医保确认支付"
                },
                hospName: '',
                hospCode: '',
                settlmentData: null, //结算数据
                paySuccessStatus: false, // 支付状态 
            }
        },
        onLoad(options) {
            // console.log('waitYbSettlement页面获取到参数')
            // console.log(options)
            const userData = this.$cache.get('userData')
            if (userData) {
                this.setData({
                    hospName: userData.hospDesc,
                    hospCode: userData.hisHospID
                })
            }
            const eventChannel = this.getOpenerEventChannel()
            eventChannel.on("settlmentData", (data) => {
                if (data.settlmentData) {
                    console.log('waitYbSettlement settlmentData')
                    console.log(data.settlmentData)
                    this.setData({
                        settlmentData: data.settlmentData
                    });
                }
            })
        },
        onUnload() {
            uni.hideLoading()
            // 应用卸载时处理未支付订单
            const {
                settlmentData: {
                    payTradeNum
                }
            } = this
            // console.log('settlmentData')
            // console.log(this.data.settlmentData)
            // console.log('payTradeNum')
            // console.log(payTradeNum)
            if (!this.paySuccessStatus) {
                Util.abnormalOrderDeal({
                    payTradeNum
                })
                this.$refs.waitSettlment.setPaymethodStatus()
            }
        },
        methods: {
            statusChange(e) {
                // console.log('支付状态')
                // console.log(e)
                if (e.detail.paySuccessStatus) {
                    this.setData({
                        paySuccessStatus: e.detail.paySuccessStatus
                    })
                }
            }
        }
    }
</script>

<style></style>