<template>
    <div class="orderDetail">
        <div class="Detail_con">
            <div class="p_t">{{ order.product_name }}</div>
        </div>
        <div class="money card">
            <div class="li flex_r flex_jb">
                <span>消费金额</span>
                <span>￥{{ order.attachment.custom_price || 0 }}</span>
            </div>
            <div class="li flex_r flex_jb">
                <span>消费金抵扣</span>
                <span class="corg">-￥{{ order.attachment.custom_integral || 0 }}</span>
            </div>
            <div class="li flex_r flex_jb">
                <span>实付金额</span>
                <span>￥{{ order.actually_paid || order.pay_amount }}</span>
            </div>
        </div>
        <div class="money card">
            <div class="li flex_r flex_jb">
                <span>赠送茶宝</span>
                <span>{{ order.attachment.chabao || 0 }}</span>
            </div>
        </div>
        <div class="info card">
            <p>产品品牌：{{ order.restaurant_name }}</p>
            <p>产品名称：{{ order.product_name }}</p>
            <p>充值手机号：{{ order.phone }}</p>
            <p>订单金额：￥{{ order.actually_paid || order.pay_amount }}</p>
            <p>订单编号：{{ order.trade_no }}</p>
            <p>下单时间：{{ order.create_time }}</p>
        </div>
        <div class="footbtn" v-if="order.status == 0" @click="pay">立即支付</div>
    </div>
</template>

<script>
import { ToPayOpre } from "@/utils/reqTools.js";
let toPayOpre = new ToPayOpre();
import { post } from "@/request/api.js";
export default {
    name: "orderDetail",
    props: {},
    data() {
        return {
            order: {},
            orders: [],
            pda: {},
            // Integral: 0,
            // deduction: 0,
        };
    },
    methods: {
        getOrderDetail(da) {
            post("local/ofpay/orderDetail", da).then(res => {
                if (res.code == 0) {
                    let da = res.data.order
                    da.product_name = da.orderGoods[0].product_name;
                    if(da.orderGoods[0]?.attachment){
                        da.attachment = JSON.parse(da.orderGoods[0].attachment);
                    }
                    delete da.orderGoods;
                    this.order = da;
                    // this.getIntegral()
                }
            })
        },
        // getIntegral() {
        //     post("local/getIntegral", { type: 6 }).then(res => {
        //         if (res.code == 0) {
        //             let i1 = res.data.integral;
        //             this.Integral = this.$h.Mul(i1, 100);
        //             this.deduction = this.$h.Mul(this.order.order_amount, i1).toFixed(2);
        //         }
        //     })
        // },
        pay() {
            let type = "";
            // #ifdef  H5
			type = "H5";
			// #endif
			// #ifdef  APP
			type = "app";
			// #endif
			// #ifdef  MP-WEIXIN
			type = "jsapi";
			// #endif
            post("local/goOrderPay", { trade_no: this.order.trade_no,trade_type: type }).then(res => {
                if(res.data && res.data != 200){
                    let data = JSON.parse(res.data)
                    data.prepayid = data.package?data.package.split('prepay_id=')[1]:''
                    if (res.code == 0 && data.prepayid) {
                        toPayOpre.toPay(data, (rea) => {
                            if (!rea) {
                                // 支付成功
                                this.getOrderDetail(this.pda);
                            } else {
                                // 支付失败
                            }
                        });
                    }
                }
            })
        },
    },
    onLoad(da) {
        this.getOrderDetail(da);
        this.pda = da;
    },
    onShow() {},
    mounted() {},
};
</script>

<style scoped lang='scss'>
.orderDetail{
    padding: 28rpx 30rpx;
}
.Detail_con{
    background-color: #fff;
    border-radius: 20rpx;
    padding: 28rpx 30rpx;
    margin-bottom: 30rpx;
    box-shadow: 4rpx 4rpx 8rpx 4rpx rgba(0, 0, 0, 0.12);
    .p_t{
        font-size: 30rpx;
        font-weight: bold;
    }
}
.info{
    p{
        font-size: 28rpx;
        color: #666;
        margin-bottom: 8rpx;
        &:last-child {
            margin-bottom: 0;
        }
    }
}
.card {
    background-color: #fff;
    border-radius: 20rpx;
    margin-bottom: 30rpx;
    padding: 28rpx 30rpx;
    font-size: 32rpx;
    box-shadow: 4rpx 4rpx 8rpx 4rpx rgba(0, 0, 0, 0.12);

    &:last-child {
        margin-bottom: 0;
    }
}
.footbtn {
    width: calc(100% - 60rpx);
    height: 80rpx;
    background: #17bb87;
    border-radius: 45rpx;
    position: fixed;
    bottom: 50rpx;
    left: 30rpx;
    color: #fff;
    font-size: 36rpx;
    text-align: center;
    line-height: 80rpx;
}
.money{
    .li{
        margin-bottom: 16rpx;
        &:last-child{
            margin-bottom: 0;
        }
        span{
            font-size: 30rpx;
        }
    }
    .corg{
        color: #18bb88;
        margin-left: 5rpx;
    }
}
</style>