<template>
  <div>
    <div id="college_box">
      <p class="title">填写信息</p>
      <div class="item">
        <input type="text" placeholder="请输入您的邀请码" v-model="inviteCode">
      </div>
      <div class="tip">
        <img src="../assets/tip3.png" alt="">
        <p>没有邀请码的用户可忽略</p>
      </div>
      <button class="submit" @click="submit">确定</button>
    </div>
  </div>
</template>

<script>

export default {
  data () {
    return {
      inviteCode: '',//邀请码
    }
  },

  mounted () {
    let inviteCode = localStorage.getItem('inviteCode')
    if (inviteCode) {
      this.inviteCode = inviteCode
    }

  },
  methods: {
    submit () {
      let openId = sessionStorage.getItem('openId');
      // openId = 'oQTiTjucAcGORK3vI0XbDNOfld5U';
      let postData = {
        inviteCode: this.inviteCode,
        openId: openId,
      }
      this.$toast.loading({
        message: '加载中',
        duration: 0,
        forbidClick: true
      })
      this.http.initSubscribeUser(postData).then((res) => {
        this.$toast.clear()
        if(!this.inviteCode){
          location.href = `https://payment.myjxt.com/?openId=${this.openId}`;//有openid后跳这个 399
          return;
        }
        if (res.success) {
          this.$toast.success(res.message)
          this.$emit('hidePopup');
          if (res.data) {
            console.log('res.data:', res.data);
            localStorage.setItem('inviteCode', this.inviteCode);
            // location.href = res.data;//邀请码为空或者正确都会有链接返回
            // 如果有邀请码
              location.href = 'https://payment.myjxt.com/#/active?type=3'//顺治1   199
          }
        } else {
          this.$toast.fail('邀请码不存在')
        }
      })
      // return;
      // // 如果有邀请码
      // if (this.inviteCode) {
      //   location.href = 'https://wap.zj.10086.cn/szhy/business/student/h5OneToOne/schoolIndex.html?schoolId=A452C4C25259C362E05330844E0A6645'
      // } else {
      //   // 没有邀请码跳支付
      //   location.href = `https://payment.myjxt.com/?openId=${this.openId}`;//有openid后跳这个
      //   // location.href = 'https://proxy.shunzhi.net/wx/index/getCode'
      // }
    }
  }
}
</script>
<style lang="scss" scoped>
#college_box {
  width: 100%;
  background: #ffffff;
  border-top-left-radius: 24px;
  border-top-right-radius: 24px;
  position: relative;
  box-sizing: border-box;
  padding: 0 40px;
  padding-bottom: 100px;
  .title {
    text-align: center;
    font-size: 30px;
    letter-spacing: 2px;
    font-weight: bold;
    padding: 40px;
  }
  .item {
    width: 670px;
    height: 72px;
    border-radius: 36px;
    background: #f7f7f7;
    box-sizing: border-box;
    font-size: 28px;
    padding: 0 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    p {
      color: #333333;
      &.nodata {
        color: #999999;
      }
    }
    img {
      width: 40px;
    }
    input {
      width: 100%;
      background: transparent;
      border: 0;
      color: #333333;
      padding: 0;
      &::-webkit-input-placeholder {
        color: #999999;
      }
    }
  }
  .tip {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 40px;
    img {
      width: 32px;
    }
    p {
      font-size: 24px;
      color: #999999;
      margin-left: 8px;
    }
  }
  .submit {
    width: 294px;
    height: 72px;
    border: 0;
    background: linear-gradient(135deg, #99c2ff 0%, #1f59ff 100%);
    box-shadow: 0px 4px 8px 0px rgba(189, 189, 189, 0.5),
      0px 8px 12px 0px rgba(87, 137, 255, 0.5);
    border-radius: 34px;
    font-size: 34px;
    color: #ffffff;
    margin: 0 auto;
    display: block;
  }
}
</style>
