<template>
  <div class="purchase">
    <NavHeader
      color="#0687D2"
      title="购房补贴申领服务指南"
      @back="$router.go(-1)"
    />
    <div class="form">
      <div class="card" v-if="!existsEnterprise" @click="jump">
        <div class="info">
          <div class="details">
            <p class="name">请填报企业(单位)信息</p>
          </div>
        </div>
        <div class="img">
          <img src="./img/qiye.png" alt="" />
        </div>
      </div>
      <div class="card" v-else>
        <div class="info">
          <div class="details">
            <p class="name">企业(单位)信息已填报</p>
            <div class="button">
              <p @click="jump">编辑</p>
            </div>
          </div>
        </div>
        <div class="img">
          <img src="./img/qiye.png" alt="" />
        </div>
      </div>
      <div class="card" v-if="!existsStaff" @click="next">
        <div class="info">
          <div class="details">
            <p class="name">请填报申请人信息</p>
          </div>
        </div>
        <div class="img">
          <img src="./img/qiye.png" alt="" />
        </div>
      </div>
      <div class="card" v-else>
        <div class="info">
          <div class="details">
            <p class="name">申请人信息已填报</p>
            <div class="button">
              <p @click="next">编辑</p>
            </div>
          </div>
        </div>
        <div class="img">
          <img src="./img/qiye.png" alt="" />
        </div>
      </div>
    </div>
    <div class="operation">
      <div class="unchecked" v-if="!existsEnterprise && !existsStaff">
        提交
      </div>
      <div class="select" v-else @click="submit">
        提交
      </div>
    </div>
  </div>
</template>

<script>
import NavHeader from "@/components/NavHeader";
import { mattersHouseUnSubmitGet, addMattersHouse } from "@/api/policy";

// import { encryptByDES } from "@/utils/utils";
export default {
  components: { NavHeader },
  data() {
    return {
      departmentCode: "",
      guideId: "",
      talentCode: "",
      matterType: "",
      userInfo: {},
      existsEnterprise: "", //初始化查询有无企业信息
      existsStaff: "", //初始化查询有无员工信息
    };
  },
  methods: {
    init() {
      // alert(JSON.stringify(encryptByDES('37393', "MnuYbhGv")))
      let params = {
        guideId: this.guideId,
        // userId: this.userInfo.userId,
      };
      mattersHouseUnSubmitGet(params).then((res) => {
        console.log(res);
        this.existsEnterprise = res.data.existsEnterprise;
        this.existsStaff = res.data.existsStaff;
      });
    },
    submit() {
      let params = {
        departmentCode: this.departmentCode,
        guideId: this.guideId,
        // userId: this.userInfo.userId,
      };
      alert(JSON.stringify(params))
      addMattersHouse(params).then((res) => {
        alert(JSON.stringify(res))
        console.log(res);
        this.$router.push({
          name: "PolicyPurchaseSubmit",
        });
      });
    },
    // 跳转企业信息填报
    jump() {
      this.$router.push({
        name: "PolicyPurchaseEnterprise",
        query: {
          departmentCode: this.departmentCode,
          guideId: this.guideId,
          talentCode: this.talentCode,
          matterType: this.matterType,
          userInfo: this.userInfo,
        },
      });
    },
    // 跳转申请人信息填报
    next() {
      this.$router.push({
        name: "PolicyPurchaseApplidetail",
        query: {
          departmentCode: this.departmentCode,
          guideId: this.guideId,
          talentCode: this.talentCode,
          matterType: this.matterType,
          userInfo: this.userInfo,
        },
      });
    },
    // 获取userInfo信息
    getUserInfo(res) {
      sessionStorage.setItem("ZJCD-UserInfo", res);
      this.userInfo = JSON.parse(res);
    },
  },
  mounted() {
    window.getUserInfo = this.getUserInfo;
  },
  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.departmentCode = this.$route.query.departmentCode;
    this.guideId = this.$route.query.guideId;
    this.talentCode = this.$route.query.talentCode;
    this.matterType = this.$route.query.matterType;
    this.init();
  },
};
</script>

<style lang="stylus" scoped>
.purchase{
    background: #fff;
}
.form{
    height: calc(100vh - 220px);
    overflow-y: auto;
}
.refuse{
    width: 690px;
    background: #F3F6F9;
    margin 20px 30px;
    display flex;
    flex-direction column;
    .title{
        display flex;
        align-items center;
        img{
            width 24px;
            height 24px;
            padding 20px 10px 20px 30px;
        }
        p{
            font-size: 28px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #0687D2;
        }
    }
    .reason{
        font-size: 28px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #999999;
        line-height 35px;
        padding 0 20px 20px 20px;
    }
}
.card{
    background: #FFFFFF;
    box-shadow: 0px 0px 15px 0px rgba(51, 51, 51, 0.15);
    border-radius: 4px;
    display flex;
    align-items center;
    justify-content space-around;
    margin: 20px 30px;
    .details{
        width 320px;
        display flex;
        flex-direction column;
        justify-content space-around;
        align-items flex-start;
        .name{
            font-size: 32px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #333333;
            padding 20px 0;
        }
        .button{
            width: 160px;
            height: 50px;
            border-radius: 25px;
            border: 2px solid #0687D2;
            text-align center;
            margin 20px 0;
            p{
                font-size: 28px;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #0687D2;
                line-height 50px;
            }
        }
    }
    .img{
        width 238px;
        height 202px;
        padding 20px;
        img{
            width 100%;
            height 100%;
        }
    }
}
.operation{
    // position: fixed;
    // bottom 0px;
    display flex;
    .unchecked{
        width: 100%;
        height: 90px;
        background: #BFBFBF;
        text-align center;
        font-size: 36px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #FFFFFF;
        line-height: 90px;
        margin 20px;
        border-radius 50px;
    }
    .select{
        width: 100%;
        height: 90px;
        background: #0687D2;
        text-align center;
        font-size: 36px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #FFFFFF;
        line-height: 90px;
        margin 20px;
        border-radius 50px;
    }
}
</style>
