<template>
  <div class="photo">
    <div class="header" :class="[isFixed ? 'header-active' : '']">
      <div class="status-bar" :style="{height: statusBarHeight + 'px'}"></div>
      <div class="nav-bar">
        <image src="/static/img/left.png" @click="back"/>
        <h2>文明榜单</h2>
      </div>
    </div>
    <div class="back-wrapper" @click="back" v-show="!isFixed" :style="{marginTop : statusBarHeight + 'px'}">
      <image src="/static/img/left.png"/>
    </div>
    <div class="photo-header">
      <image class="bg-img" src="https://cdn.cunwuyun.cn/wxmp/tianfuxing/wm-bg.png" />
      <h2>文明榜单</h2>
      <p>评选并展示当前积分最多的个人、社区和小区榜单</p>
      <image class="right-icon" mode="aspectFill" src="https://cdn.cunwuyun.cn/wxmp/tianfuxing/right3.png" />
    </div>
    <div class="ranking-wrapper">
      <div class="tab">
        <span @click="changeTab(0)" :class="[currIndex === 0 ? 'active' : '']">个人榜单</span>
        <span @click="changeTab(1)" :class="[currIndex === 1 ? 'active' : '']">社区榜单</span>
        <span @click="changeTab(2)" :class="[currIndex === 2 ? 'active' : '']">小区榜单</span>
      </div>
      <div class="ranking-list">
        <div class="title">
          <span>排行</span>
          <span>个人</span>
          <span>积分</span>
        </div>
        <div class="list-wrapper">
          <div class="item" v-for="(item, index) in list" :key="index">
            <span>{{ index + 1 }}</span>
            <div class="userinfo">
              <image :src="item.avatar_url || 'https://cdn.cunwuyun.cn/wxmp/tianfuxing/avatar.png'" />
              <h3>{{ item.name }}</h3>
            </div>
            <i>{{ item.integral || 0 }}</i>
          </div>
          <AiEmpty v-if="!list.length"></AiEmpty>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import { mapState } from 'vuex'
  export default {
    name: 'Ranking',
    appName: '文明榜单',
    customNavigation: true,

    data () {
      return {
        isFixed: false,
        statusBarHeight: 20,
        list: [],
        currIndex: 0,
        hideStatus: false,
        pageShow: false
      }
    },

    computed: {
      ...mapState(['user', 'token'])
    },

    onLoad () {
      this.getList()
      this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight
    },
    methods: {
      back () {
        uni.navigateBack({
          delta: 1
        })
      },

      changeTab (index) {
        this.currIndex = index

        this.$nextTick(() => {
          this.getList()
        })
      },

      getList () {
        this.$loading()
        this.$instance.post(`/api/appwechatintegraldetail/rankingLis`, null, {
          params: {
            current: 1,
            size: 20,
            type: this.currIndex
          }
        }).then(res => {
          if (res.code === 0) {
            this.$hideLoading()
            this.list = res.data
          }
        }).catch(() => {
          this.$hideLoading()
        })
      }
    },

    onPageScroll (params) {
      this.isFixed = params.scrollTop > 60
    }
  }
</script>

<style lang="scss" socped>
.photo {
  width: 100vw;
  overflow-x: hidden;
  padding-bottom: 40px;

  div {
    box-sizing: border-box;
  }

  .ranking-wrapper {
    margin: 0 32px;

    .ranking-list {
      .title {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 80px;
        padding: 0 32px;

        span {
          font-size: 28px;
          color: #999999;

          &:nth-of-type(1) {
            width: 130px;
          }

          &:nth-of-type(2) {
            flex: 1;
          }

          &:nth-of-type(3) {
            width: 100px;
            text-align: center;
          }
        }
      }

      .item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 80px;
        margin-bottom: 16px;
        padding: 0 32px;
        background: #FFFFFF;
        box-shadow: 0 0 8px 0 rgba(0,0,0,0.02);
        border-radius: 16px;

        span {
          width: 130px;
          font-size: 34px;
          color: #DDDDDD;
          font-style: oblique;
          font-weight: 600;
        }

        &:nth-of-type(1) span {
          color: #2D7DFF;
        }

        &:nth-of-type(2) span {
          color: #3BBC37;
        }

        &:nth-of-type(3) span {
          color: #FF883C;
        }

        image {
          width: 48px;
          height: 48px;
        }

        .userinfo {
          display: flex;
          align-items: center;
          flex: 1;

          h3 {
            margin-left: 16px;
            font-size: 28px;
            color: #333333;
          }
        }

        i {
          width: 100px;
          font-size: 32px;
          color: #FFB94C;
          font-weight: 600;
          text-align: center;
        }
      }
    }

    .tab {
      display: flex;
      align-items: center;
      margin-bottom: 24px;
      border-radius: 8px;
      overflow: hidden;

      span {
        flex: 1;
        height: 68px;
        line-height: 68px;
        text-align: center;
        color: #333333;
        font-size: 28px;
        background: #E1EAF7;

        &.active {
          color: #fff;
          border-radius: 8px;
          background-image: linear-gradient(90deg, #75BDFF 0%, #4783FF 100%);
          box-shadow: 0 8px 12px -4px rgba(133,196,255,0.65);
        }
      }
    }
  }

  .btn-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 32px!important;

    .btn {
      width: 328px;
      background: #2D7DFF;

      &:first-child {
        background: #3BBC37;
      }
    }
  }

  .back-wrapper {
    position: fixed;
    z-index: 11;
    left: 20px;
    top: 24px;
    width: 40px;
    height: 40px;

    image {
      width: 40px;
      height: 40px;
    }
  }

  .header {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 0;
    width: 100%;
    opacity: 0;
    transition: all 0.2s ease;

    &.header-active {
      z-index: 1111;
      opacity: 1;
      background: linear-gradient(180deg, #2D7DFF 0%, #2D7DFF 40%);
    }

    .nav-bar {
      position: relative;
      height: 88px;
      line-height: 88px;
      color: #fff;
      font-size: 32px;
      text-align: center;

      image {
        position: absolute;
        top: 0;
        left: 0;
        z-index: 1;
        width: 40px;
        height: 40px;
        padding: 24px 20px 0 20px;
        box-sizing: content-box;
      }
    }
  }

  .photo-header {
    position: relative;
    height: 448px;
    padding: 150px 48px 0;

    .bg-img {
      position: absolute;
      top: 0;
      left: 0;
      z-index: 1;
      width: 100%;
      height: 448px;
    }

    .right-icon {
      position: absolute;
      top: 105px;
      right: 0;
      z-index: 2;
      width: 304px;
      height: 240px;
    }

    h2 {
      position: relative;
      z-index: 2;
      margin-bottom: 16px;
      font-weight: 700;
      font-size: 64px;
      color: #333333;
    }

    p {
      z-index: 2;
      width: 420px;
      height: 80px;
      line-height: 1.3;
      font-size: 28px;
      color: #658DC1;
    }
  }

  .phone-wrapper {
    margin-top: 26px;
    padding: 0 32px;

    & > h2 {
      margin-bottom: 42px;
      font-size: 34px;
      font-weight: 600;
      color: #333333;
    }
  }
}
</style>
