<template>
  <div class="partner-home">
    <div class="partner-info">
      <div class="qrcode-title">
        <div class="left">
          <img :src="partnerInfo.PartnerHeadImg" alt="" />
        </div>
        <div class="right" v-if="partnerInfo.PartnerStatusText">
          <span class="partner-name">{{
            partnerInfo.PartnerName || '暂无'
          }}</span>
          <span class="audit-status">{{ partnerInfo.PartnerStatusText }}</span>
        </div>
      </div>
    </div>
    <div class="content">
      <div class="partner-invite">
        <Card class="card" @click.native="handleClick" v-if="partnerInfo.PartnerType === 2">
          <img src="../../../static/imgs/partner/partner-avatar-blue.png" alt="" />
          <h3>邀请医生</h3>
        </Card>

        <Card class="card" @click.native="handleClick" v-if="partnerInfo.PartnerType === 2">
          <img src="../../../static/imgs/partner/partner-avatar-orange.png" alt="" />
          <h3>邀请合伙人</h3>
        </Card>
      </div>
      <div class="partner-menu">
        <Card class="menu-card" @click.native="jumpTo(1)" v-if="partnerInfo.PartnerType === 2">
          <div class="left">
            <img src="../../../static/imgs/partner/attention.png" alt="" />
            <span>下级合伙人</span>
          </div>
          <div class="right">
            <span class="partner-count">{{ partnerInfo.PartnerCount }}</span>
            <van-icon name="arrow" />
          </div>
        </Card>

        <Card class="menu-card" @click.native="handleClick" v-if="partnerInfo.PartnerType === 1">
          <div class="left">
            <img src="../../../static/imgs/partner/invite-icon.png" alt="" />
            <span>邀请医生</span>
          </div>
          <div class="right">
            <van-icon name="arrow" />
          </div>
        </Card>

        <Card class="menu-card" @click.native="jumpTo(0)">
          <div class="left">
            <img src="../../../static/imgs/partner/like.png" alt="" />
            <span>下级医生</span>
          </div>
          <div class="right">
            <span class="doctor-count">{{ partnerInfo.DoctorCount }}</span>
            <van-icon name="arrow" />
          </div>
        </Card>

        <Card class="menu-card" @click.native="jumpTo(2)">
          <div class="left">
            <img src="../../../static/imgs/partner/earnings.png" alt="" />
            <span>我的收益</span>
          </div>
          <div class="right">
            <van-icon name="arrow" />
          </div>
        </Card>
      </div>
    </div>
  </div>
</template>

<script>
  import Card from '../../../components/common/Card'
  import {
    getPartnerInfo
  } from '../../../api/Partner/Partner'
  export default {
    components: {
      Card,
    },
    data() {
      return {
        partnerInfo: {},
      }
    },
    methods: {
      // 跳转下级合伙人链接
      jumpTo(index) {
        if (index == 2) {
          this.$router.push({
            name: 'MyProfitIndex'
          })
          return
        }
        this.$router.push({
          name: 'JuniorPartner',
          query: {
            index
          }
        })
      },
      // 点击邀请合伙人或者医生邀请码
      handleClick() {
        this.$router.push({
          name: 'PartnerQrcode',
          query: {
            QRCode: this.partnerInfo.QRCode,
            PartnerName: this.partnerInfo.PartnerName,
            PartnerHeadImg: this.partnerInfo.PartnerHeadImg
          },
        })
      },
    },

    mounted() {
      getPartnerInfo().then(({
        data
      }) => {
        console.log(data)
        this.partnerInfo = data.ResultObject
        if (data.ResultObject.PartnerStatus === 98) {
          this.partnerInfo.PartnerStatusText = '审核驳回'
          this.$router.push('/partnerToBeCertified')
        } else if (data.ResultObject.PartnerStatus === 99) {
          this.partnerInfo.PartnerStatusText = '待审核'
        } else if (data.ResultObject.PartnerStatus === 1) {
          this.partnerInfo.PartnerStatusText = '审核通过'
        } else if (data.ResultObject.PartnerStatus === 2) {
          this.partnerInfo.PartnerStatusText = '停用'
        } else {
          console.log('this.partnerInfo.PartnerStatusText is null...')
        }
      })
    },
  }
</script>

<style lang="less">
  #app {
    background-color: #f7f7f7;
  }

  .partner-home {
    .partner-info {
      width: 100%;
      height: 2.18rem;
      background-color: #5594fc;

      .qrcode-title {
        display: flex;
        align-items: center;
        margin-right: 0.3rem;
        width: 100%;
        min-height: 1.96rem;

        .left {
          width: 20%;

          img {
            width: 0.96rem;
            height: 0.96rem;
            border-radius: 50%;
          }
        }

        .right {
          display: flex;
          flex-direction: column;
          justify-content: space-evenly;
          align-items: flex-start;
          width: 80%;
          font-size: 0.36rem;

          .partner-name {
            color: #ffffff;
            margin-bottom: 0.2rem;
            letter-spacing: 0.02rem;
          }

          .audit-status {
            color: #fff;
            padding: 0.06rem 0.1rem;
            background-color: #f93232;
            font-size: 0.3rem;
            border-radius: 0.05rem;
          }
        }
      }
    }

    .content {
      padding: 0.2rem;

      .partner-invite {
        display: flex;

        .card {
          display: flex;
          justify-content: center;
          align-items: center;
          min-width: 3.4rem;
          height: 1.64rem;

          &:nth-child(2) {
            margin-left: 0.3rem;
          }

          img {
            display: block;
            width: 0.72rem;
            height: 0.72rem;
          }

          h3 {
            margin-left: 0.2rem;
            color: #000;
            font-size: 0.3rem;
            font-weight: bold;
          }
        }
      }

      .partner-menu {
        margin-top: 0.2rem;

        .menu-card {
          padding: 0 0.2rem;
          display: flex;
          justify-content: space-between;
          align-items: center;

          &:first-child {
            border-bottom: 1px solid #f7f7f7;
          }

          &:last-child {
            margin-top: 0.3rem;
          }
        }

        .left {
          display: flex;
          align-items: center;

          img {
            display: block;
            width: 0.4rem;
            height: 0.4rem;
            margin-right: 0.1rem;
          }

          span {
            font-size: 0.3rem;
            color: #000;
          }
        }

        .right {
          display: flex;
          align-items: center;

          .van-icon {
            font-size: 0.3rem;
            margin-left: 0.1rem;
          }
        }
      }
    }
  }
</style>