<template>
  <view class="container">
    <image class="bk" :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/invite/bk.png'" mode=""></image>
    <view class="page">
      <image
        class="illustrate"
        @click="$navigateTo('/pages/rule/rule', { type: 6 })"
        :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/invite/button1.png'"
        mode=""
      ></image>
      <view class="box">
        <view class="item">
          <image
            mode="aspectFit"
            class="label1"
            :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/invite/text2.png'"
          ></image>
          <view class="value">
            {{ person }}
            <image mode="aspectFit" :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/invite/text3.png'"></image>
          </view>
        </view>
        <view class="item">
          <image
            mode="aspectFit"
            class="label2"
            :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/invite/text1.png'"
          ></image>
          <view class="value">
            {{ reward }}
            <image mode="aspectFit" :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/invite/text4.png'"></image>
          </view>
        </view>
      </view>
      <view class="buttons">
        <button open-type="share" class="button">
          <image
            class="button1"
            mode="heightFix"
            :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/invite/button2.png'"
          ></image>
        </button>
        <image
          class="button2"
          mode="heightFix"
          :src="'https://file.rongcyl.cn/festatic/bkm/imgv2/invite/button3.png'"
          @click="promotionCode"
        ></image>
        <!-- 		<view class="m_button">
					邀请好友
				</view> -->
        <!-- <view class="m_button" @click="promotionCode">
					我的推广码
				</view> -->
      </view>
    </view>
    <uni-popup ref="popup" background-color="#fff">
      <view class="popup-content">
        <image class="qrcode" :src="imgUrl" mode=""></image>
      </view>
    </uni-popup>
  </view>
</template>

<script>
import { inviteQrcodeApi, inviteInfoApi } from '@/api/invite.js'
export default {
  data() {
    return {
      imgUrl: '',
      inviteList: [],
      person: '',
      reward: '',
    }
  },
  onLoad() {
    this.getInviteList()
  },
  onShow() {
    this.getInviteList()
  },
  computed: {
    userInfo() {
      return wx.getStorageSync('userInfo')
    },
  },
  onShareAppMessage() {
    let userId = wx.getStorageSync('userId')
    return {
      title: this.userInfo.nickName + '邀请你来潮米卡牌卡牌抽取喜欢的卡牌',
      path: '/pages/index/index?inviteId=' + userId,
    }
  },
  methods: {
    getInviteList() {
      inviteInfoApi().then(res => {
        console.log(res, '我已经邀请的列表')
        this.inviteList = res.data.list
        this.person = res.data.person
        this.reward = res.data.reward
      })
    },
    promotionCode() {
      let _this = this
      inviteQrcodeApi().then(res => {
        console.log(res, '推广码')
        _this.imgUrl = res.data
        _this.$refs.popup.open('center')
      })
    },
  },
}
</script>

<style scoped lang="scss">
.container {
  // background: #e7ffec;
  text-align: center;

  .bk {
    position: absolute;
    height: 100vh;
    width: 100%;
    z-index: -1;
  }

  .page {
    max-height: 100vh;
    overflow: auto;
    padding-top: 600rpx;
  }

  .illustrate {
    position: absolute;
    right: 40rpx;
    top: 80rpx;
    font-size: 24rpx;
    width: 134rpx;
    height: 48rpx;
    // padding: 10rpx 20rpx;
    // border-radius: 8rpx;
  }

  .box {
    background: #fff;
    margin: 40rpx 40rpx;
    padding: 40rpx;
    border-radius: 30rpx;
    display: flex;
    justify-content: space-around;

    .item {
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      width: 50%;

      .label1 {
        width: 100%;
        height: 44rpx;
      }

      .label2 {
        width: 100%;
        height: 44rpx;
      }

      .value {
        font-size: 56rpx;
        font-weight: 600;
        margin-top: 40rpx;
        width: 100%;
        display: flex;
        align-items: center;
        justify-content: center;

        image {
          width: 80rpx;
          height: 44rpx;
        }
      }
    }
  }

  .buttons {
    display: flex;
    justify-content: center;
    margin: 40rpx;
    width: calc(100% - 80rpx);
    image {
      height: 128rpx;
      position: relative;
    }

    .button {
      background: none;
      border: none !important;
      overflow: initial;
      text-align: start;
      padding: 0;
      // width: 100%;
      box-shadow: none;
      -webkit-tap-highlight-color: transparent;
    }
    .button::after {
      border: none;
    }
    .button1 {
      right: -16rpx;
      width: 100%;
    }

    .button2 {
      left: -16rpx;
    }
  }

  .qrcode {
    width: 70vw;
    height: 70vw;
  }
}
</style>
