<template>
<div>
  <div class="floatBox">
      <div class="head">
        <img class="bg" :src="rankBg" alt>
        <div class="content">
          <div class="avatar">
            <img class="header-icon" :src="userDetail.avatar">
            <span class="name">{{userDetail.nickname}}</span>
          </div>
          <div class="text">
            <div class="count">{{starNum}}</div>
            <div>星星总数</div>
          </div>
        </div>
      </div>
      <div class="secTitle" v-if="starNum==0">还没有星星记录哦~</div>
      <div class="secTitle" v-if="starNum!=0">
        <span class="line"></span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 星星记录 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <span class="line"></span>
      </div>
    </div>
  <scroll class="scroll" :data="starList" :pullup="pullup" :bounce="false" @pullup="onReachBottom">
    <div class="itemBox">
      <div class="item" v-for="item in starList">
        <div class="left">
          <p>{{item.desc}}</p>
          <p class="date">{{item.created_at}}</p>
        </div>
        <div class="right">
          <span v-if="item.is_add==1" class="add">+{{item.value}}</span>
          <span v-if="item.is_add==0" class="reduce">-{{item.value}}</span>
          <img :src="star_inner" alt>
        </div>
      </div>
      <div v-if="finished" class="none">没有更多了~</div>
    </div>
  </scroll>
</div>
</template>

<script>
import rankBg from "../../assets/rankBg.png";
import star_inner from "../../assets/star_inner.png";
import { getUserIntegralApi, getUserIntegralListApi } from "../../service/api";
import { Toast } from "vant";
export default {
  name: "index",
  data() {
    return {
      pullup: true,
      rankBg: rankBg,
      starNum: "",
      userDetail: {},
      loading: true,
      finished: false,
      star_inner: star_inner,
      starList: [],
      page: 1,
      offset: 30
    };
  },
  components: {},
  methods: {
    onReachBottom() {
      // console.log("bottom");
      if (!this.finished&&this.loading) {
        this.loading = false
        Toast.loading({
          mask: true,
          message: ""
        });
        this.page++;
        let json = {
          page: this.page,
          limit: "18"
        };
        getUserIntegralListApi(json).then(res => {
          this.loading = true
          if (res.list.length > 0){
            res.list.forEach(element => {
              this.starList.push(element);
            });
            if(res.total==this.starList.length){
              this.finished = true;
            }
            // this.loading = false;
          }
          Toast.clear();
        });
      }
    },
    initPage() {
      this.userDetail = JSON.parse(localStorage.getItem("userDesc"));
      getUserIntegralApi().then(res => {
        this.starNum = res.last_value;
      });
      let json = {
        page: this.page,
        limit: "18"
      };
      getUserIntegralListApi(json).then(res => {
        this.starList = res.list;
        // console.log(res);
        // console.log(109)
      });
    }
  },
  mounted() {
    this.initPage();
  }
};
</script>

<style scoped lang="less">
@import "../../util/public";
.star-activity-page {
  border-top: 1px solid transparent;
}
.floatBox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background: white;
  z-index: 100;
  padding-bottom: 10 * @toVw;
}
.head {
  height: 160 * @toVw;
  .bg {
    width: 368 * @toVw;
    position: absolute;
    left: 4 * @toVw;
    top: 4 * @toVw;
  }
  .content {
    position: relative;
    z-index: 1;
    .text {
      text-align: center;
      color: #f27321;
      padding-top: 52 * @toVw;
      .count {
        font-size: 41 * @toVw;
        line-height: 42 * @toVw;
        margin-bottom: 10 * @toVw;
      }
    }
    .avatar {
      position: absolute;
      top: 20 * @toVw;
      left: 22 * @toVw;
      display: flex;
      height: 42 * @toVw;
      // vertical-align: top;
      img {
        width: 40 * @toVw;
        border-radius: 40 * @toVw;
        border: 2px solid white;
      }
      span {
        text-overflow:ellipsis;
        white-space: nowrap;
        overflow: hidden;
        width: 98 * @toVw;
        display: inline-block;
        margin-left: 8 * @toVw;
        font-size: 14 * @toVw;
        color: #999999;
      }
    }
  }
}
.secTitle {
  text-align: center;
  color: #999999;
  font-size: 13 * @toVw;
  .line {
    display: inline-block;
    width: 120 * @toVw;
    border-bottom: 1px solid #e2e2e2;
    position: relative;
    top: -3 * @toVw;
  }
}
// .scrollP{position: relative;height: 100vh;width: 100%;transform:none;}
.scroll {
  padding: 10 * @toVw 20 * @toVw 0;
  // margin-top: 180* @toVw;
  height: 100%;
  overflow: hidden;
  position: fixed;
  width: 100%;
  box-sizing: border-box;
  background: white;
  .itemBox {
    padding-top: 180 * @toVw;
    .none {
      height: 53 * @toVw;
      line-height: 40 * @toVw;
      text-align: center;
      color: #999999;
      font-size: 12px;
    }
  }
  .item {
    display: -webkit-flex;
    justify-content: space-between;
    border-bottom: 1px solid #e2e2e2;
    padding: 9 * @toVw 2 * @toVw;
    div {
      flex: 1;
    }
    .left {
      font-size: 15 * @toVw;
      // font-family: Regular;
      .date {
        color: #999999;
        font-size: 13 * @toVw;
        margin-top: 4 * @toVw;
      }
    }
    .right {
      text-align: right;
      font-size: 18 * @toVw;
      color: #f27321;
      font-weight: 800;
      // font-family: Arial-Black;
      img {
        width: 20 * @toVw;
        position: relative;
        top: 3 * @toVw;
        margin-left: 3 * @toVw;
      }
      span {
      }
      .add{}
      .reduce{color: #9BC912;}
    }
  }
}
 @media screen and (orientation: landscape) {
  //  .child-view{height: 300vh;}
   .floatBox {
    //  height: 300vh;
      position: relative;
      top: 0;
      left: 0;
      width: 100%;
      background: white;
      z-index: 100;
      padding-bottom: 10 * @toVw;
    }
    // .child-view{height: 200vh;}
    .scroll{position: relative;
    height: 50vh;
    .itemBox{padding-top: 0 * @toVw;padding-bottom: 10vh;}
    }
 }
</style>
<style>
</style>
