<template>
  <div>
    <NavHeader color="#0687D2" title="人才政策服务" @back="back" />
    <div class="wrapper">
      <img style="width: 100vw" :src="topBanner" alt="" />
      <div class="bottom-banner">
        <div class="banner one" @click="jumpOne"></div>
        <div class="banner two" @click="jumpTwo"></div>
        <div class="banner three" @click="jumpThree"></div>
      </div>
    </div>
  </div>
</template>

<script>
import NavHeader from "@/components/NavHeader";
export default {
  components: { NavHeader },
  data() {
    return {
      userInfo: {},
      topBanner: require("@/assets/policy/top_banner.png"),
    };
  },
  methods: {
    JSBgetUserInfo() {
      if (window.android !== undefined) {
        const res = window.android.getUserInfo();
        this.verify(res);
      } else if (window.webkit) {
        window.webkit &&
          window.webkit.messageHandlers.getUserInfo.postMessage("getUserInfo");
      } else {
        // this.$dialog
        //   .confirm({
        //     message: "请先登录！",
        //     showCancelButton: false,
        //   })
        //   .then(() => {
        //     this.back();
        //   });
      }
    },
    getUserInfo(res) {
      this.verify(res);
    },
    verify(res) {
      let userInfo = JSON.parse(res);
      if (!userInfo.userId) {
        this.$dialog
          .confirm({
            message: "请先登录！",
            showCancelButton: false,
          })
          .then(() => {
            this.back();
          });
        return;
      }
      sessionStorage.setItem("ZJCD-UserInfo", res);
      this.userInfo = userInfo;
      sessionStorage.setItem('token', this.userInfo.token)
    },
    jumpOne() {
      this.$router.push({ name: "PolicyList" });
    },
    jumpTwo() {
      this.$router.push({ name: "PolicyOnline" });
    },
    jumpThree() {
      this.$router.push({ name: "PolicyReportIndex" });
    },
    back() {
      if (window.android !== undefined) {
        window.android.backHome();
      } else {
        window.webkit && window.webkit.messageHandlers.backHome.postMessage("");
      }
    },
  },
  mounted() {
    window.getUserInfo = this.getUserInfo;
  },
  created() {
    let res = sessionStorage.getItem("ZJCD-UserInfo");
    this.userInfo = JSON.parse(res) || {};
    if (!this.userInfo.idCardNo) {
      this.JSBgetUserInfo();
    } else {
      this.verify(res);
    }
  },
};
</script>

<style lang="stylus" scoped>
.wrapper {
  overflow auto
  background #fff
  height: calc(100vh - 88px);
  .bottom-banner{
    padding: 60px 30px;
  }
  .banner {
    width 690px;
    height 245px;
    margin-bottom 23px;
  }

  .one {
    background url('~@/assets/policy/banner1.png')
    background-size cover
  }
  .two {
    background url('~@/assets/policy/banner2.png')
    background-size cover
  }
  .three {
    background url('~@/assets/policy/banner3.png')
    background-size cover
  }
}
</style>
