<template>
    <div class="orderDetail">
        <template v-if="detail">
            <div class="card">
                <div class="hotelName">{{ hotel.hotelName }}</div>
                <div class="address">{{ hotel.address }}</div>
                <div class="btnico flex_r flex_jb">
                    <div class="btn_i" @click="openm">
                        <span class="iconfont">&#xe8ae;</span>
                        <div class="t">查看地图</div>
                    </div>
                    <div class="btn_i" @click="PhoneCall(hotel.phone)">
                        <span class="iconfont">&#xe8ad;</span>
                        <div class="t">联系酒店</div>
                    </div>
                </div>
                <div class="roominfo">
                    <div class="name">{{ detail.roomTypeName }}</div>
                    <div class="days">
                        <span>{{ daydate(detail.checkInDate) }} - {{ daydate(detail.checkOutDate) }}</span>
                        <span class="dn">共{{ detail.numberOfNights }}晚</span>
                    </div>
                    <div class="tegs">
                        <span>{{ detail.bedTypeName }}</span>
                        <span>{{ detail.breakfastDesc }}</span>
                        <span>{{ detail.cancelDesc }}</span>
                    </div>
                    <div class="pli">
                        <div class="label">入住人</div>
                        <span>{{ detail.guestNames }}</span>
                    </div>
                    <div class="pli">
                        <div class="label">联系手机</div>
                        <span>{{ detail.contactMobile }}</span>
                    </div>
                    <div class="pli" v-if="detail.arriveTime">
                        <div class="label">预计到店</div>
                        <span>{{ detail.arriveTime }}</span>
                    </div>
                    <div class="pli" v-else>
                        <div class="label">入住时间</div>
                        <span>{{ daydate2(detail.checkInDate) + " 12:00" }}后</span>
                    </div>
                </div>
            </div>
            <div class="card">
                <div class="tit">订单信息</div>
                <div class="pli">
                    <div class="label">订单编号</div>
                    <span>{{ order.trade_no }}</span>
                </div>
                <div class="pli">
                    <div class="label">磐河编号</div>
                    <span>{{ detail.orderNo }}</span>
                </div>
                <div class="pli">
                    <div class="label">下单时间</div>
                    <span>{{ detail.createTime }}</span>
                </div>

            </div>
        </template>
        <template v-else>
            <div class="card">
                <div class="hotelName">{{ hotel.hotelName }}</div>
                <div class="address">{{ hotel.address }}</div>
                <div class="btnico flex_r flex_jb">
                    <div class="btn_i" @click="openm">
                        <span class="iconfont">&#xe8ae;</span>
                        <div class="t">查看地图</div>
                    </div>
                    <div class="btn_i" @click="PhoneCall(hotel.phone)">
                        <span class="iconfont">&#xe8ad;</span>
                        <div class="t">联系酒店</div>
                    </div>
                </div>
            </div>
        </template>
    </div>
</template>

<script>
import { post } from "@/request/api.js";
export default {
    name: "orderDetail",
    props: {},
    components: {},
    data() {
        return {
            tradeNo: "",
            hotel: {},
            detail: {},
            order: {},
            ratePlan: {}
        };
    },
    methods: {
        daydate(va) {
            return this.$day(va).format("M月DD日")
        },
        daydate2(va) {
            return this.$day(va).format("YYYY-MM-DD")
        },
        getorderDetail(da) {
            post("local/hotel/orderDetail",da).then(res => {
                if (res.code == 0) {
                    this.detail = res.data.detail.data
                    this.order = res.data.order
                    let de = JSON.parse(res.data.order.product_detail)
                    let { hotelID,checkInDate,checkOutDate,ratePlanID } = de
                    this.gethotel({ hotelID,checkInDate,checkOutDate },ratePlanID)
                }
            })
        },
        gethotel(da,ratePlanID){
            post("/local/hotel/detail", da).then((res) => {
                if (res.code == 0) {
                    this.hotel = res.data.data;
                }
            });
            post("/local/hotel/room", da).then((res) => {
                if (res.code == 0) {
                    let da = res.data.data.rooms;
                    for (const a of da) {
                        for (const b of a.ratePlans) {
                            if(b.ratePlanId == ratePlanID){
                                this.ratePlan = Object.assign({},a,b)
                                console.log(this.ratePlan);
                            }
                        }
                    }
                }
            });
        },
        openm() {
            console.log(12);
            let latitude = this.hotel.googleLat;
            let longitude = this.hotel.googleLon;
            let name = this.hotel.hotelName;
            let address = this.hotel.address;
            uni.openLocation({
                latitude, longitude, scale: 18, name, address,
                success: function() {
                    console.log('success');
                }
            });
        },
        PhoneCall(va){
            uni.makePhoneCall({ phoneNumber: va });
        },
    },
    onLoad(da) {
        this.tradeNo = da.trade_no;
        this.getorderDetail(da);
    },
    onShow() {},
    mounted() {},
};
</script>

<style scoped lang='scss'>
.orderDetail{
    padding: 28rpx 32rpx;
    .hotelName{
        font-size: 36rpx;
        font-weight: 600;
    }
    .address{
        font-size: 25rpx;
        color: #555;
        margin-top: 10rpx;
    }
    .btnico{
        padding: 26rpx 36rpx;
        margin-bottom: 10rpx;
        .iconfont{
            font-size: 40rpx;
            font-weight: bold;
        }
        .btn_i{
            text-align: center;
            .t{
                font-size: 22rpx;
                margin-top: 6rpx;
            }
        }
    }
    .roominfo{
        margin-top: 10rpx;
        .name{
            font-size: 32rpx;
            font-weight: 600;
        }
        .days{
            margin-top: 12rpx;
            font-size: 28rpx;
            .dn{
                margin-left: 16rpx;
            }
        }
        .tegs{
            font-size: 26rpx;
            margin: 12rpx 0;
            span{
                margin-right: 12rpx;
                &:last-child{
                    margin-right: 0;
                }
            }
        }
    }
    .pli{
        margin-bottom: 10rpx;
        font-size: 26rpx;
        &:last-child{
            margin-bottom: 0;
        }
       .label{
            width: 150rpx;
            font-weight: 600;
            display: inline-block;
       } 
    }
    .tit{
        font-size: 32rpx;
        font-weight: 600;
        margin-bottom: 16rpx;
    }
}
.card {
    background-color: #fff;
    border-radius: 20rpx;
    margin-bottom: 30rpx;
    padding: 28rpx 30rpx;
    font-size: 32rpx;
    box-shadow: 4rpx 4rpx 26rpx 2rpx rgba(17, 18, 29, 0.1);

    &:last-child {
        margin-bottom: 0;
    }
}
</style>