<template>
  <div class="myIntegral">
    <div class="header-content">
      <div class="top">
        <div class="total">
          <h1>{{info.integral || '0'}}</h1>
          <p>积分余额</p>
        </div>
      </div>
      <div class="bottom">
        <div class="item">
          <div class="num">{{ info.serialNo || '0'}}</div>
          <div class="label">积分排行</div>
        </div>
        <div class="item">
          <div class="num">{{ info.totalIntegral|| '0'}}</div>
          <div class="label">历史累计获取</div>
        </div>
      </div>
      <img src="https://cdn.cunwuyun.cn/dvcp/credit/head.png" alt="">
    </div>
    <div class="detail-content" v-if="list && list.length">
      <div class="item" v-for="(item, index) in list" :key="index">
        <div class="item-info">
          <p>{{ item.integralRuleName || ''}}
            <span v-if="item.integralRuleName && item.eventDesc">:</span>
            {{ item.eventDesc || '' }}</p>
          <span>&nbsp;&nbsp;&nbsp;{{ item.doTime }}</span>
        </div>
        <div class="item-num" :class="'color-'+ item.integralCalcType">
          {{ (item.integralCalcType == 1 ? '+' : '-') + item.changeIntegral }}
        </div>
      </div>
    </div>
    <AiEmpty v-else/>
  </div>
</template>
<script>
import { mapState } from 'vuex'

export default {
  name: "myIntegral",
  appName: "我的积分",
  computed: {
    ...mapState(['user', 'token'])
  },
  data() {
    return {
      info: {},
      current: 1,
      list: [],
    }
  },
  mounted() {
    this.getToatl()
  },
  methods: {
    getToatl() {
      this.$instance.post(`/app/appintegraluser/integralUserInfoFD`).then(res => {
        if (res?.data) {
          this.info = res.data
          this.getList()
        }
      })
    },
    getList() {
      this.$instance.post(`/app/appintegraldetail/list?integralUserId=${this.info.id}&current=${this.current}&size=10`).then(res => {
        if (res?.data) {
          if (this.current > res.data.pages) {
            return
          }
          this.list = this.current > 1 ? [...this.list, ...res.data.records] : res.data.records
        }
      })
    },
  },
  onReachBottom() {
    this.current++
    this.getList()
  }
}
</script>
<style scoped lang="scss">
.myIntegral {
  width: 100vw;
  overflow-x: hidden;
  height: calc(100% - 136px);
  background-color: #f3f6f9;
  padding-bottom: 30px;

  .header-content {
    width: 690px;
    height: 358px;
    background: #FFF;
    border-radius: 16px;
    margin: 70px 0 40px 30px;
    position: relative;
    .top {
      width: 100%;
      height: 213px;
      z-index: 99;
      .total {
        width: 50%;
        padding-top: 48px;
        box-sizing: border-box;
        text-align: center;
        h1 {
          font-size: 68px;
          color: #5AAD6A;
        }
        p {
          font-size: 28px;
          font-weight: 400;
          color: #999999;
        }
      }
    }
    .bottom {
      display: flex;
      justify-content: space-around;
      width: 100%;
      height: 145px;
      padding: 16px 0;
      box-sizing: border-box;
      border-top: 2px solid #EEEEEE;
      .item {
        text-align: center;
        z-index: 99;

        .num {
          font-family: DIN;
          font-size: 48px;
          font-weight: bold;
          color: #333333;
        }

        .label {
          font-size: 24px;
          color: #999;
          margin-top: 10px;
        }
      }
    }

    img {
      position: absolute;
      width: 360px;
      height: 250px;
      top: -40px;
      right: 0;
    }
  }

  .detail-content {
    width: 690px;
    background: #FFF;
    border-radius: 16px;
    margin: 0 0 0 32px;
    padding: 16px 30px;
    box-sizing: border-box;

    .item {
      padding: 34px 0 32px 0;
      border-bottom: 2px solid #ddd;
      display: flex;

      .item-info {
        width: 500px;

        p {
          word-break: break-all;
          font-size: 32px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #333;
          line-height: 44px;
        }

        span {
          display: inline-block;
          margin-top: 8px;
          font-size: 24px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #999;
          line-height: 34px;
        }
      }

      .item-num {
        width: calc(100% - 500px);
        text-align: right;
        font-size: 36px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        line-height: 50px;
      }
    }
    .item:last-child {
      border-bottom: none;
    }
  }
  .color-1 {
    color: #2C51CE !important;
  }

  .color-0 {
    color: #E6736E !important;
  }
}
</style>
