<template>
  <div class="select-roles">
    <van-popup
      v-model="show"
      :close-on-click-overlay="false"
    >
      <div class="popup-container">
        <h2 class="title">选择角色</h2>
        <div
          class="btn"
          :class="currentIndex===0?'active':''"
          @click="handleBtnChange(0)"
        >医生</div>
        <div
          class="btn"
          :class="currentIndex===1?'active':''"
          @click="handleBtnChange(1)"
        >合伙人</div>
      </div>
    </van-popup>
  </div>
</template>

<script>

var host2 = process.env.VUE_APP_Url; 
export default {
  data() {
    return {
      partnerID: "",
      show: true,   // 是否显示弹出层
      currentIndex: 0,
      jumpParam: {    // 点击角色跳转链接
        doctorRolesUrl: null,
        partnerRolesUrl: null
      }
    }
  },
  methods: {
    // 选择角色选项变化的处理函数
    handleBtnChange(index) {
      this.currentIndex = index;
      let obj = {};
      switch (index) {
        case 0:
          obj.identity = 1;
          obj.partnerID = this.partnerID;
          window.location.href = this.jumpParam.doctorRolesUrl
          break;

        case 1:
          obj.identity = 2;
          obj.partnerID = this.partnerID;
          window.location.href = this.jumpParam.partnerRolesUrl
          break;
      }
    }
  },
  mounted() {
    if(location.href.indexOf('?')!==-1) {
      console.log("current URL：", location.href)
      let partnerID = location.href.split('?')[1].split('=')[1];
      this.partnerID = partnerID;
      // this.jumpParam.doctorRolesUrl = `http://mem.360lj.com/ymlyf/api/Home/Login?identity=1&portId=3&appAppId=5&backurl=https://mem.360lj.com/uilyf/SignUp?SuperiorPartnerID=${partnerID}`
      // this.jumpParam.partnerRolesUrl = `http://mem.360lj.com/ymlyf/api/Home/Login?identity=2&portId=3&appAppId=5&backurl=https://mem.360lj.com/uilyf/SignUp?SuperiorPartnerID=${partnerID}`
      this.jumpParam.doctorRolesUrl = host2+`/ymallWechat/code?id=${partnerID}&identity=1&redirectCode=signUp&visit=3_5`;
      this.jumpParam.partnerRolesUrl = host2+`/ymallWechat/code?id=${partnerID}&identity=2&redirectCode=signUp&visit=3_5`;
    }else {
      // this.jumpParam.doctorRolesUrl = 'http://mem.360lj.com/ymlyf/api/Home/Login?identity=1&portId=3&appAppId=5&backurl=https://mem.360lj.com/uilyf/SignUp'
      // this.jumpParam.partnerRolesUrl = 'http://mem.360lj.com/ymlyf/api/Home/Login?identity=2&portId=3&appAppId=5&backurl=https://mem.360lj.com/uilyf/SignUp'
      this.jumpParam.doctorRolesUrl = host2+`/ymallWechat/code?identity=1&redirectCode=signUp&visit=3_5`;
      this.jumpParam.partnerRolesUrl = host2+`/ymallWechat/code?identity=2&redirectCode=signUp&visit=3_5`;
    }
  }
}
</script>

<style lang="less">
.van-popup {
  width: 90%;
  height: 30%;
  border-radius: 0.2rem;
  .popup-container {
    padding: 0.4rem 1.2rem;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    height: 100%;
    .title {
      font-size: 0.34rem;
      color: #333333;
    }
    .btn {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 4.26rem;
      height: 0.72rem;
      border: 1px solid #333333;
      margin-top: 0.4rem;
      font-size: 0.3rem;
    }
    .active {
      color: #478bfb;
      border-color: currentColor;
    }
  }
}
</style>