<template>
    <div class="qrcode">
        <qrcode @success="success" />
    </div>
</template>
<script>
import { getFun, postFun } from "@/service/table.js";
export default {
    components: {
        // 注册
        qrcode: () => import("@/components/QrCodeReader"),
    },
    mounted() {},
    methods: {
        success(val) {
            // alert(val);
            let formdata = new FormData();
            formdata.append("activityid", val);
            postFun("/train/sign", formdata)
                .then((res) => {
                    this.$toast.clear();
                    // this.$toast.success("扫码成功");
                    res.data.details=res.data.details=='签到成功'?'您已签到':res.data.details;
                    let obj = {
                        您已签到: "success",
                        签到失败: "fail",
                        重复签到: "warn",
                    };
                    this.$router.replace({
                        name: obj[res.data.details],
                        query: {
                            text: res.data.details,
                            content:res.data.details=='签到失败'&&'请联系管理员'
                        },
                    });
                })
                .catch(() => {
                    this.$toast.clear();
                    // this.$toast.fail("扫码失败,请稍后再试");
                     this.$router.replace({
                        name: 'fail',
                        query: {
                            text: '扫码失败',
                            content:'请联系管理员'
                        },
                    });
                });
        },
    },
};
</script>