<template>
  <!--申请已提交-->
  <!--签署协议：初始化、待签约、已提交待核对、已提交审核通过-->
  <!--欢迎您成功加入房客邦：初始化、去推广-->
  <div class="wrapper">
    <div class="header">
      <h2>申请进度</h2>
      <a :href="'tel:' + commanyPhone">
        <img src="./image/btn_dianhua@2x.png" alt="">
        <span>专属客服</span>
      </a>
    </div>
    <ul class="content">
      <li class="flow flow-0 has-border" :class="checks[0].checkStatus === 0 ? 'init' : 'active'" v-if="checks[0]">
        <div class="left-wrap"></div>
        <div class="right-wrap" v-if="orderUserName">
          <p class="title">
            <span>已提交申请成为推手</span>
          </p>
          <p class="description">
            <span>{{ orderUserPhone }}</span>
            <span class="line">|</span>
            <span>{{ orderUserName }}</span>
          </p>
          <p class="time">{{ checks[0].updatedAt }}</p>
          <p class="tip">1个工作日内会有专席客服与您取得联系</p>
        </div>
      </li>
      <template v-if="orderFinalStatus !== 2">
        <!--checkStatus: 0-初始化 1-进行中 2-成功 3-失败-->
        <li class="flow flow-1 has-border" :class="checks[1].checkStatus === 0 ? 'init' : 'active'" v-if="checks[1]">
          <div class="left-wrap"></div>
          <div class="right-wrap">
            <p class="title">
              <span>签署协议</span>
              <template v-if="checks[1].checkStatus === 2">
                <span style="font-weight: 600; color: #D73634;" v-if="checks[2].checkStatus === 0">（等待核对）</span>
                <span style="color: #4BD863;" v-if="checks[2].checkStatus === 1">（通过审核）</span>
              </template>
            </p>
            <router-link class="jump-compact" :to="{path: '/partner/compact?id=' + id}"
                         v-if="checks[1].checkStatus === 1">
              在线签约
            </router-link>
            <template v-if="checks[1].checkStatus === 2">
              <p class="description">
                <span v-if="checks[2].checkStatus === 0">您已完成在线签约</span>
                <span style="color: #4BD863;" v-else>您已签约成功</span>
              </p>
              <p class="time">{{ checks[1].updatedAt }}</p>
            </template>
          </div>
        </li>
        <li class="flow flow-4" :class="checks[2].checkStatus === 0 ? 'init' : 'active'" v-if="checks[2]">
          <div class="left-wrap"></div>
          <div class="right-wrap">
            <p class="title">
              <span v-if="checks[2].checkStatus === 2">欢迎您成功加入妥妥推手</span>
              <span v-else>加入成功</span>
            </p>
            <router-link class="jump-goods" :to="{path: '/partner/goods?partnerId=' + partnerId}"
                         v-if="checks[2].checkStatus === 2">去推广
            </router-link>
            <template v-if="checks[2].checkStatus === 1">
              <p class="description">
                <span>审核中</span>
              </p>
              <p class="time">{{ checks[2].updatedAt }}</p>
            </template>
          </div>
        </li>
      </template>
      <li class="fail" v-if="orderFinalStatus === 2">
        <p class="title">
          <span>{{ orderFinalRemark }}</span>
        </p>
        <router-link class="jump-join"
                     :to="{path: '/partner/join' + (this.partnerInviteCode ? '?inviteCode=' + this.partnerInviteCode : '')}">
          重新申请
        </router-link>
      </li>
      <li class="order-info border-top-1px">
        <p v-if="orderFinalStatus === 1">合伙人编号：{{ inviteCode }}</p>
        <template v-else>
          <p>创建时间：{{ createdAt }}</p>
          <p>申请单号：{{ orderNumber }}</p>
        </template>
      </li>
      <li class="qrcode-wrap">
        <div class="qrcode">
          <img src="./image/public_qrcode.jpg" alt="">
        </div>
        <div class="tip">
          <p>长按识别二维码</p>
          <p>关注"妥妥推手"公众号</p>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import { Toast } from 'vant'
import { orderDetail } from './api'

export default {
  name: 'detail',
  props: ['id'],
  data () {
    return {
      partnerInviteCode: '', // 邀请人的邀请码
      orderUserPhone: '',
      orderUserName: '',
      createdAt: '',
      orderNumber: '',
      orderFinalStatus: 0, // 订单最终状态: 0-进行中 1-成功 2-失败
      commanyPhone: '',
      orderFinalRemark: '',
      checks: [],
      inviteCode: '',
      partnerId: ''
    }
  },
  created () {
    this.funInit()
  },
  async mounted () {
    await this.$nextTick()
    this.$refreshTitle('申请进度')
  },
  methods: {
    funInit () {
      const id = this.id
      orderDetail(id).then(res => {
        if (res.status) {
          const { partnerInviteCode, orderUserPhone, orderUserName, createdAt, orderNumber, orderFinalStatus, commanyPhone, orderFinalRemark, checks, inviteCode, partnerId } = res.data
          this.partnerInviteCode = partnerInviteCode
          this.orderUserPhone = orderUserPhone
          this.orderUserName = orderUserName
          this.createdAt = createdAt
          this.orderNumber = orderNumber
          this.orderFinalStatus = orderFinalStatus
          this.commanyPhone = commanyPhone
          this.orderFinalRemark = orderFinalRemark
          this.checks = checks
          this.inviteCode = inviteCode
          this.partnerId = partnerId
        } else {
          Toast(res.msg)
        }
      }).catch(err => {
        Toast(err)
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 15px 0 91px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 343px;

  h2 {
    padding-left: 8px;
    line-height: 33px;
    font-size: 24px;
    font-weight: 500;
    color: #333;
  }

  a {
    display: flex;
    align-items: center;
    padding: 11px 12px;
    background: #FFFFFF;
    border-radius: 100px 0 0 100px;

    img {
      width: 29px;
      height: 29px;
    }

    span {
      margin-left: 3px;
      line-height: 22px;
      font-size: 16px;
      font-weight: 500;
      color: #C7AC8B;
    }
  }
}

.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 343px;
  padding-top: 28px;
  margin-top: 16px;
  border-radius: 4px;
  background: #FFFFFF;
}

.flow {
  position: relative;
  left: 0;
  top: 0;
  display: flex;
  width: 295px;
  min-height: 68px;
  margin-top: 24px;

  &:nth-of-type(1) {
    margin-top: 0;
  }
}

.init {
  &.has-border:before {
    position: absolute;
    left: 7px;
    top: 3px;
    content: '';
    width: 1px;
    height: calc(100% - 3px);
    border-left: 1px dashed #D8D8D8;
  }

  .left-wrap {
    border: 4px solid #FAF9FA;
    background: #D8D8D8;
  }

  .title {
    color: #999;
  }
}

.active {
  &.has-border:before {
    position: absolute;
    left: 7px;
    top: 3px;
    content: '';
    width: 1px;
    height: calc(100% - 3px);
    border-left: 1px dashed #CBB091;
  }

  .left-wrap {
    border: 4px solid #EEEDEE;
    background: linear-gradient(90deg, #DBC3A9 0%, #C7AB8A 100%);
  }

  .title {
    color: #333;
  }
}

.flow-0 {
  .time {
    margin-top: 18px;
  }
}

.flow-1 {
  .title {
    span:nth-of-type(2) {
      padding-top: 3px;
      line-height: 20px;
      font-size: 14px;
    }
  }

  .time {
    margin-top: 6px;
  }
}

.flow-4 {
  margin-bottom: 14px;

  .time {
    margin-top: 18px;
  }
}

.left-wrap {
  position: relative;
  left: 0;
  top: 3px;
  z-index: 1;
  width: 16px;
  height: 16px;
  border-radius: 50%;
}

.right-wrap {
  margin-left: 24px;
}

.title {
  display: flex;

  span {
    line-height: 22px;
    font-size: 16px;
    font-weight: 500;
    color: inherit;
  }
}

.description {
  display: flex;
  margin-top: 6px;

  span {
    line-height: 20px;
    font-size: 15px;
    color: #333;

    &.line {
      margin: 0 6px;
    }
  }
}

.jump-compact,
.jump-goods,
.jump-join {
  display: block;
  width: 106px;
  height: 44px;
  margin: 20px 0 23px;
  border-radius: 4px;
  line-height: 44px;
  font-size: 14px;
  text-align: center;
  color: #fff;
  background: linear-gradient(90deg, #DBC3A9 0%, #C7AB8A 100%);
  box-shadow: 0 14px 9px -10px rgba(219, 208, 194, 1);
}

.time {
  line-height: 17px;
  font-size: 12px;
  color: #666;
}

.tip {
  margin-top: 15px;
  line-height: 20px;
  font-size: 15px;
  font-weight: 600;
  color: #D73634;
}

.success {
  margin-top: 2px;
  line-height: 25px;
  font-size: 18px;
  font-weight: 600;
  word-break: break-all;
  color: #D73634;
}

.fail {
  width: 311px;
  padding-left: 8px;
  margin: 12px 0 23px;

  .title {
    span {
      line-height: 25px;
      font-size: 18px;
      font-weight: 600;
      word-break: break-all;
      color: #D73634;
    }
  }

  .jump-join {
    margin-left: 40px;
  }
}

.order-info {
  width: 329px;
  padding-top: 20px;
  @include border-top-1px(#E8E8E8);

  p {
    padding-left: 17px;
    line-height: 20px;
    font-size: 14px;
    color: #666;

    &:nth-of-type(2) {
      margin-top: 2px;
    }
  }
}

.qrcode-wrap {
  display: flex;
  align-items: center;
  width: 329px;
  padding-bottom: 24px;
  margin-top: 10px;

  .qrcode {
    width: 129px;
    height: 129px;

    img {
      display: block;
      width: 100%;
    }
  }

  .tip {
    p {
      margin-left: 5px;

      &:nth-of-type(1) {
        line-height: 22px;
        font-size: 16px;
        font-weight: 500;
        color: #333;
      }

      &:nth-of-type(2) {
        line-height: 20px;
        font-size: 14px;
        color: #666;
      }
    }
  }
}
</style>
