<!-- 拼优医确认订单 && 订单详情 -->
<template>
    <div style="background:#f5f5f7;padding-bottom: 1.2rem;">
        <div class="bg"></div>
        <main>
            <div class="container">
                <div class="doctorInfo">
                    <van-image
                            round
                            fit="cover"
                            width="1.3rem"
                            height="1.3rem"
                            :src="UnionData.DissertationImg?UnionData.DissertationImg:require('@/assets/images/union/liver.png')"
                            class="doctorAvatar"
                    >
                        <template v-slot:loading>
                            <van-loading type="spinner" size="20"/>
                        </template>
                    </van-image>

                    <div class="doctorTitle">{{UnionData.DissertationName}}</div>
                </div>

                <div class="seekInfo">
                    <div>
                        <span>就诊城市</span>
                        <p>{{UnionData.AreaName || '未知' }}</p>
                    </div>
                    <div>
                        <span>就诊地点</span>
                        <p>{{UnionData.HospitalName || '未知' }}</p>
                    </div>
                    <div>
                        <span>就诊日期</span>
                        <p>{{(UnionData.VisitDay || '未知') | getTime}} {{UnionData.VisitDay | getWeek}}</p>
                    </div>
                    <div>
                        <span>就诊时段</span>
                        <p>{{UnionData.TimeSlot || '未知'}}</p>
                    </div>
                    <div>
                        <span>预约费用</span>
                        <p style="color: #ff0000;">{{UnionData.Price == 0?'免费':(UnionData.Price/100).toFixed(2)}}</p>
                    </div>
                </div>
            </div>
            <router-link :to="'/familyMember?pageType=1'" class="patient">
                <span>就诊人</span>
                <p>
                    {{FamilyMemberData.FamilyMemberName || '请选择就诊人'}}
                    <van-tag
                            round
                            type="primary"
                            style="vertical-align: middle;margin: 0 .1rem;"
                            v-if="FamilyMemberData.UserRelationship"
                    >{{FamilyMemberData.UserRelationship | filterRelation}}
                    </van-tag>
                    <van-icon name="arrow"/>
                </p>
            </router-link>
            <!--<p class="hint">*当前已有{{UnionData.SourceNumber}}人报名，还差{{UnionData.SurplusNumber}}人报名，医生即可成行坐诊。如不能成行，预约费用将会原路退回。</p>-->

            <div class="bottom-button">
                <div class="actualPayment">
                    实付款:
                    <span>￥{{UnionData.Price | getPrice()}}</span>
                </div>
                <div class="button-pay" @click="toPay">立即支付</div>
            </div>
        </main>
    </div>
</template>

<script>
    export default {
        name: "uOrderDetails",
        data() {
            return {
                Data: {}, //预约坐诊初始化数据
                FamilyMemberData: {}, // 用户选择就诊人的数据
                UnionData: {} // 预览数据
            };
        },
        created() {
            this.Data = this.$route.query;
            this.FamilyMemberData = JSON.parse(sessionStorage.getItem("FamilyMemberData")) || {};
            this.ParticipateInTable();
        },
        methods: {


            toPay() {
                if (JSON.stringify(this.FamilyMemberData) == "{}") {
                    this.$toast("请选择就诊人");
                    return;
                }
                this.AddOrder();
            },

            AddOrder(){
                this.$toast({
                    message:'加载中...',
                    type:'loading',
                    duration:0,
                    forbidClick:true,
                });
                var data =  this.GetData();

                var str = this.Data.isMeStart == '1' ? this.$http.AddGroupTable(data) : this.$http.AddParticipateInTable(data);

                str.then(({data})=>{
                    this.$toast.clear();
                    if (data.IsSuccess) {
                        // this.UnionData = data.ResultObject;
                        this.$router.replace({path:'/confirmPay',query:{ordercode:data.ResultObject,price:this.UnionData.Price}})
                    } else {
                        this.$toast(data.ResultMsg)
                    }
                })
            },

            // 预览自己发起拼团 or 预览参加别人拼团
            ParticipateInTable() {
                var data = this.GetData();

                var str = this.Data.isMeStart == '1' ? this.$http.AddPreviewTable(data) : this.$http.ParticipateInTable(data);
                this.$toast({
                    message:'加载中...',
                    type:'loading',
                    duration:0,
                    forbidClick:true,
                });
                str.then(({data}) => {
                    this.$toast.clear();
                    if (data.IsSuccess) {
                        this.UnionData = data.ResultObject;
                    } else {
                        this.$toast(data.ResultMsg)
                    }
                })
            },

            GetData() {
                return {
                    dissertaionDetailId: this.Data.dissertaionDetailId, //天ID
                    dissertationDateId: this.Data.dissertationDateId, //时间段ID
                    areaCode: this.Data.areaCode, //城市Code
                    hospitalID: this.Data.hospitalID, // 医院ID
                    hospitalName:this.Data.hospitalName, //医院名称
                    familyMemberId: this.FamilyMemberData.ID, // 家人ID
                    groupTableID: this.Data.ID // 该团的ID
                }
            }

        }
    };
</script>

<style scoped lang="less">
    main {
        text-align: left;
    }

    .bg {
        width: 7.5rem;
        height: 3.13rem;
        background: url("../../../assets/images/doctor-bg.png") no-repeat 0 0;
        -webkit-background-size: 7.5rem 3.13rem;
        background-size: 7.5rem 3.13rem;
    }

    .container {
        width: 7.1rem;
        margin: -1.85rem auto 0;
        box-sizing: border-box;

        .doctorInfo {
            display: flex;
            align-items: center;
            margin-bottom: 0.4rem;
            border-radius: 5px;
            box-shadow: 0px 2px 3px 2px #f1f1f2;
            padding: 0.4rem 0.3rem;
            background-color: #fff;

            .doctorAvatar {
                margin-right: 0.2rem;
                flex-shrink: 0;
            }

            .doctorTitle {
                font-size: 0.34rem;
                color: #333333;
                line-height: 1.5;
            }
        }

        .seekInfo {
            padding: 0.2rem 0.3rem;
            background-color: #fff;
            border-radius: 5px;
            box-shadow: 0px 2px 3px 2px #f1f1f2;

            > div {
                display: flex;
                justify-content: space-between;
                align-items: center;
                height: 1rem;

                > span {
                    font-size: 0.26rem;
                    color: #666666;
                }

                > p {
                    font-size: 0.28rem;
                    color: #333333;
                    width: 4.5rem;
                    text-align: right;
                }
            }
        }
    }

    .patient {
        display: flex;
        justify-content: space-between;
        align-items: center;
        height: 1rem;
        box-sizing: border-box;
        padding: 0 0.3rem;
        box-shadow: 0px 2px 3px 2px #f1f1f2;
        width: 7.1rem;
        margin: 0.2rem auto 0;
        border-radius: 5px;
        background: #fff;

        > span {
            font-size: 0.26rem;
            color: #666666;
        }

        > p {
            font-size: 0.28rem;
            color: #333333;
            display: flex;
            align-items: center;
        }

        i {
            font-size: 0.32rem;
        }
    }

    .hint {
        font-size: 0.22rem;
        color: #666666;
        padding: 0 0.3rem;
        margin: 0.2rem auto;
        line-height: 1.2;
    }

    .bottom-button {
        display: flex;
        padding: 0 0.32rem;
        align-items: center;
        justify-content: space-between;
        position: fixed;
        bottom: 0;
        height: 1rem;
        width: 7.5rem;
        background: #fff;
        z-index: 100;
        box-shadow: 0rem -0.01rem 0.26rem 0rem rgba(0, 34, 58, 0.07);

        .actualPayment {
            font-size: 0.28rem;

            span {
                font-size: 0.38rem;
                color: #ff0000;
            }
        }

        .button-pay {
            width: 2.13rem;
            height: 0.68rem;
            background-color: #ffb00f;
            box-shadow: 0.01rem 0.02rem 0.09rem 0rem rgba(255, 176, 15, 0.35);
            border-radius: 0.34rem;
            font-size: 0.32rem;
            text-align: center;
            line-height: 0.68rem;
            color: #fff;
        }
    }
</style>
