<template>
    <div class="appoint_test">
        <el-dialog
            title="预约考试"
            :visible.sync="appointModal"
            width="600px"
            class="appoint-modal"
            :close-on-click-modal="false"
            :close-on-press-escape="false"
            :before-close="cancel"
        >
            <div class="appoint-modal__content">
                <el-radio
                    v-for="(appointChild, appointIndex) in appointItem.examApplyGoodsList"
                    v-model="applyId"
                    :key="appointIndex"
                    :label="appointChild.applyId"
                >
                    {{ appointChild.applyName }}
                </el-radio>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button @click="cancel()">取 消</el-button>
                <el-button type="primary" @click="confirmAppoint">立即预约</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
export default {
    name: 'appoint_test',
    props: {
        appointModal: {
            type: Boolean,
            default: false,
        },
        appointItem: {
            type: Object,
            default: () => {}
        },
    },
    data() {
        return {
            applyId: "",
        }
    },
    methods: {
        cancel() {
            this.$emit('update:appointModal', false)
        },
        confirmAppoint() {
            if (!this.applyId) {
                this.$message.warning("请选择要预约的考试");
                return;
            }
            var data = {
                goodsId: this.appointItem.goodsId,
                gradeId: this.appointItem.gradeId,
                applyId: this.applyId,
                orderGoodsId: this.appointItem.orderGoodsId,
            };
            this.$request.getApplysubscribe(data).then((res) => {
                this.$router.push({
                    path: "/person-center/my-classhour/appointment",
                    query: {
                    goodsId: this.appointItem.goodsId,
                    gradeId: this.appointItem.gradeId,
                    orderGoodsId: this.appointItem.orderGoodsId,
                    applyId: this.applyId,
                    },
                });
            }).catch((err) => {
                this.$message({
                    type: "warning",
                    message: err.msg,
                });
            });
        },
    }
}
</script>