<template>
  <div class="hrrq">
    <div
      class="card"
      v-for="(item, index) in list"
      :key="index"
      @click="jump(index)"
    >
      <img class="icon" :src="item.url" alt="" />
      <p class="title">{{ item.title }}</p>
    </div>
  </div>
</template>

<script>
import { queryListUser } from "@/api/rqfy.js";
export default {
  data() {
    return {
      list: [
        {
          url: require("./images/hrrq1.png"),
          title: "燃气缴费查询",
        },
        {
          url: require("./images/hrrq2.png"),
          title: "燃气费充值",
        },
        {
          url: require("./images/hrrq3.png"),
          title: "预约上门安检",
        },
        {
          url: require("./images/hrrq4.png"),
          title: "预约上门维修",
        },
        {
          url: require("./images/hrrq5.png"),
          title: "预约通气点火",
        },
      ],
      userInfo: {},
    };
  },
  created() {
    if (window.android !== undefined) {
      const res = window.android.getUserInfo(); // 这是一个json字符串
      sessionStorage.setItem("ZJCD-UserInfo", res);
      this.userInfo = JSON.parse(res);
    } else if (window.webkit) {
      window.webkit &&
        window.webkit.messageHandlers.getUserInfo.postMessage("getUserInfo");
    } else {
      this.$toast("请先登录镇合意app");
    }
    let res = sessionStorage.getItem("ZJCD-UserInfo");
    this.userInfo = JSON.parse(res);
    this.initData();
  },
  methods: {
    getUserInfo(res) {
      sessionStorage.setItem("ZJCD-UserInfo", res);
      this.userInfo = JSON.parse(res);
      this.initData();
    },
    initData() {
      let params = {
        uid: this.userInfo.userId,
        appId: 1234,
      };
      queryListUser(params).then((res) => {
        if (res && res.length > 0) {
          console.log(res);
        } else {
          this.$router.push({ name: "RqfyIndex", query: { type: 6 } });
        }
      });
    },
    jump(index) {
      console.log(index);
      if (index == 0) {
        this.$router.push({ name: "Payrecord" });
      } else if (index == 1) {
        this.$router.push({ name: "Recharge" });
      } else if (index == 2) {
        this.$router.push({ name: "Check1" });
      } else if (index == 3) {
        this.$router.push({ name: "Repair" });
      } else if (index == 4) {
        this.$router.push({ name: "Fire" });
      }
    },
  },
  mounted() {
    window.getUserInfo = this.getUserInfo;
  },
};
</script>

<style lang="stylus" scoped>
.hrrq {
  padding: 20px 30px;
  display: flex;
  flex-wrap: wrap;
  background-color: #FFF;

  .card {
    width: 33%;
    height: 160px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    .icon {
      width: 80px;
      height: 80px;
    }

    .title {
      font-size: 24px;
      margin-top: 16px;
      color: #333333;
    }
  }
}
</style>