<template>
  <div class="card">
    <div class="cell">
      <p class="label">个人托管档案编号</p>
      <p class="text">{{ detail.bdc634 }}</p>
    </div>
    <div class="cell">
      <p class="label">档案状态</p>
      <p class="text">{{ detail.bae121 }}</p>
    </div>
    <div class="cell">
      <p class="label">姓名</p>
      <p class="text">{{ detail.aac003 }}</p>
    </div>
    <div class="cell">
      <p class="label">性别</p>
      <p class="text">{{ detail.aac004 }}</p>
    </div>
    <div class="cell">
      <p class="label">身份证号</p>
      <p class="text">{{ detail.aae135 }}</p>
    </div>
    <div class="cell">
      <p class="label">档案调动日期</p>
      <p class="text">{{ detail.aae036 }}</p>
    </div>
    <div class="cell">
      <p class="label">档案接收经办机构</p>
      <p class="text">{{ detail.bae532 }}</p>
    </div>
  </div>
</template>

<script>
import { social } from "@/api/insurance";
export default {
  data() {
    return {
      detail: {},
      userInfo: {},
    };
  },
  methods: {
    init() {
      let params = {
        aae135: this.userInfo.idCardNo,
        busCode: "WS-D0003",
        encryptIdCard: this.userInfo.idCardNo
      };
      this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: "加载中...",
      });
      social(params).then((res) => {
        this.$toast.clear();
        console.log(res);
        if (res.data.tradeMsg.data.busiId !== "0000") {
          this.$toast("未查询到相关个人档案信息");
          return;
        }
        this.detail = res.data.tradeMsg.data;
      });
    },
    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.$toast("请先登录镇合意app");
        // let userInfo = {
        //   mobileNo: 17372670270,
        //   userId: 37393,
        //   userName: "孙辉",
        //   realName: "孙涵",
        //   idCardNo: "K6btm7WPGZj8eLFjTy1a1+P7Z0zFoM/r",
        // };
        // this.verify(JSON.stringify(userInfo));
      }
    },
    getUserInfo(res) {
      this.verify(res);
    },
    verify(res) {
      sessionStorage.setItem("ZJCD-UserInfo", res);
      sessionStorage.setItem('token', JSON.parse(res).token);
      let userInfo = JSON.parse(res);
      if (!userInfo.idCardNo) {
        this.$dialog
          .confirm({
            message: "请进入“我的”完成实名认证！",
            showCancelButton: false,
          })
          .then(() => {
            this.back();
          });
        return;
      }
      this.userInfo = userInfo;
      this.init();
    },
    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");
    let userInfo = JSON.parse(res);
    sessionStorage.setItem('token', JSON.parse(res).token);
    if (userInfo) {
      if (!userInfo.idCardNo) {
        this.$dialog
          .confirm({
            message: "请进入“我的”完成实名认证！",
            showCancelButton: false,
          })
          .then(() => {
            this.back();
          });
        return;
      }
      this.userInfo = userInfo;
      this.init();
    } else {
      this.JSBgetUserInfo();
    }
  },
};
</script>

<style lang="stylus" scoped>
.card {
  margin: 20px 10px;
  background #fff
  border-radius: 5px;
  box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 4px 10px 0 rgba(0, 0, 0, 0.19);

  .cell {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    margin: 0 20px;
    border-bottom: 1px solid #eee;
    .label {
      width: 35%;
      font-size: 24px;
      color: #333333;
    }
    .text {
      width: 62%;
      font-size: 24px;
      color: #333333;
    }
  }
  .cell:last-child {
    border-bottom: 0;
  }
}
</style>
