<template>
  <div class="my" v-if="pageShow">
    <div class="my-list">
      <div class="list">
        <div class="item" v-for="(item, index) in list" :key="index">
          <div class="left">
            <h2>{{ item.detail }}</h2>
            <p>{{ item.createTime }}</p>
          </div>
          <div class="right">
            <i>{{ item.calcType === '0' ? '-' : '+' }}</i>
            <span>{{ item.integral || 0 }}</span>
            <em>积分</em>
          </div>
        </div>
        <AiEmpty v-if="!list.length"></AiEmpty>
      </div>
    </div>
  </div>
</template>

<script>
  import { mapState } from 'vuex'
  export default {
    appName: '积分明细',
    name: 'Integral',

    data () {
      return {
        list: [],
        current: 1,
        pageShow: false,
        isMore: false
      }
    },

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

    onLoad () {
      this.$loading()
      this.getList()
    },

    methods: {
      getList () {
        if (this.isMore) return

        this.$instance.post(`/api/appwechatintegraldetail/list`, null, {
          params: {
            current: this.current,
            size: 10,
            openId: this.user.openId
          }
        }).then(res => {
          if (res.code === 0) {
            this.$hideLoading()
            if (this.current > 1) {
              this.list = [...this.list, ...res.data.records]
            } else {
              this.list = res.data.records
            }

            this.pageShow = true

            if (res.data.records.length < 10) {
              this.isMore = true

              return false
            }

            this.current = this.current + 1
          } else {
            this.isMore = true
          }
        }).catch(() => {
          this.$hideLoading()
        })
      }
    },

    onReachBottom () {
      this.getList()
    }
  }
</script>

<style lang="scss" scoped>
  .my {
    padding-top: 32px;
    padding-bottom: 30px;

    div {
      box-sizing: border-box;
    }
    .my-list {
      padding: 0 32px;

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

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

        .right {
          display: flex;
          align-items: baseline;
          line-height: 1;

          i {
            color: #FFB94C;
            font-size: 32px;
          }

          span {
            color: #FFB94C;
            font-size: 40px;
          }

          em {
            font-size: 26px;
            color: #999999;
          }
        }

        .left {
          flex: 1;
          margin-right: 20px;

          h2 {
            line-height: 1.3;
            margin-bottom: 10px;
            font-size: 34px;
            color: #333333;
          }

          p {
            font-size: 26px;
            color: #999999;
          }
        }
      }
    }
  }
</style>
