<template>
    <div class="active-container" v-show="isPageShow">
        <div class="header">
            <van-icon name="passed" size="80" color="green" v-if="isActive"/>
            <van-icon name="warning-o" size="80" color="red" v-else/>
        </div>
        <div class="main">
            <div class="text success" v-if="isActive">
                <p>激活成功，请重启设备，看到连接平台</p>
                <div class="img">图标<img src="../../assets/online.png"/>后，则可正常使用。</div>
            </div>
            <div class="text fail" v-else>
                <p>电话卡激活失败！请进行实名认证与绑定SIM卡。如您已实名认证，请5分钟后，再进行设备绑定。</p>
            </div>
        </div>
        <van-button type="primary" size="large" @click="onBackHome">返回首页</van-button>
    </div>
</template>

<script>
import { isNotNull} from "@/utils/index";
import APIWx from "@/api/wx";
export default {
  name:'',
  data(){
   return {
       isPageShow: false,
       isActive: null,
   }
  },
  created() {
    this.effective();
  },
  methods: {
      // 激活接口
        effective() {
            this.$toast.loading('激活中,请稍候...');
            let reqBody = {
                imei: this.$route.query.serialNo,
                iccid: this.$route.query.iccid || '',
                issue: Number(this.$route.query.issue) || 0
            };
            APIWx.Effective(reqBody)
                .then(res => {
                    console.log("res", res);
                    let data = res.data;
                    console.log("data", data);
                    this.$toast.clear();
                    if(data.stateCode !== 1) {
                        /* this.$dialog.confirm({
                            title: '温馨提示',
                            message: `${data.message}`,
                            showCancelButton: false
                        }) */
                        this.isPageShow = true;
                        this.isActive = false;
                    } else if(data.stateCode === 0 && data.message !== null) {
                         /* this.$dialog.confirm({
                            title: '温馨提示',
                            message: `电话卡激活失败！请进行实名认证与绑定SIM卡。如您已实名认证，请5分钟后，再进行设备绑定。`,
                            showCancelButton: false
                        }) */
                        this.isPageShow = true;
                        this.isActive = false;
                        } else if (data.stateCode === 1 && data.message !== 'ok') {
                            /* this.$dialog.confirm({
                                title: "SIM卡激活成功",
                                message: '卡激活成功，5分钟后则可正常使用。',
                                showCancelButton: false,
                                confirmButtonText: '返回首页'}).then(() => {
                                    document.location.replace(" https://xrpt.jiankangtongxue.cn/WCUParentWebUI.WX/Home/")
                                }); */
                                this.isPageShow = true;
                                this.isActive = true;
                        } else if (data.stateCode === 1 && data.message === 'ok') {
                            /* this.$dialog.confirm({
                                title: "SIM卡激活成功",
                                message: '卡激活成功，5分钟后则可正常使用。',
                                showCancelButton: false,
                                confirmButtonText: '返回首页'
                                }).then(() => {
                                    document.location.replace(" https://xrpt.jiankangtongxue.cn/WCUParentWebUI.WX/Home/")
                                }); */
                                this.isPageShow = true;
                                this.isActive = true;
                    }
                })
                .catch(error => {
                    console.log("出错了:;", error);
                    this.$dialog.confirm({
                        title: '温馨提示',
                        message: `${error.message}`,
                        showCancelButton: false
                    })
                }).finally(() => {
                    this.$toast.clear();
                })
        },
        onBackHome() {
            document.location.replace(" https://xrpt.jiankangtongxue.cn/WCUParentWebUI.WX/Home/")
        }
  }
}
</script>

<style scoped lang="scss">
    .active-container {
        height: 100vh;
        padding: 40px 40px;
        .header {
            padding: 10px 0;
            @include center();
        }
        .main {
            width: 100%;
            padding: 10px;
            display: flex;
            justify-content: flex-start;
            align-items: flex-start;
            flex-direction: column;
            .text, p {
                width: 100%;
                font-size: 16px;
                text-align: left;
                font-weight: 500;
                margin: 5px 0;
                img {
                    height: 25px;
                    width: 60px;
                    margin: 0 5px;
                }
                .img {
                    display: flex;
                    justify-content: flex-start;
                    align-items: center;
                }
            }
        }
        .van-button {
            margin-top: 20px;
        }
    }
</style>
