<template>
  <div class="gridIntegral">
    <div class="bg-blue"></div>
    <div class="header-content">
      <img src="https://cdn.cunwuyun.cn/dvcp/credit/head.png" alt="">
      <div class="headerDataPane">
        <div class="header-user" flex>
          <div class="user-name">{{info.userName}}</div>
          <div class="headerItem top">
            <div v-text="`积分余额`"/>
            <b v-text="info.integral||0"/>
          </div>
        </div>
        <div class="header-rank" flex>
          <div class="headerItem">
            <div v-text="`历史累计积分`"/>
            <b v-text="info.totalIntegral||0"/>
          </div>
          <div class="divider"/>
          <div class="headerItem">
            <div v-text="`积分排名`"/>
            <b v-text="rankNum"/>
          </div>
        </div>
      </div>
    </div>
    <div class="detail-content" v-if="list.length">
      <div flex>
        <div class="title fill">积分明细</div>
        <!-- <u-icon name="question-circle" label="积分规则" color="#3F8DF5" label-color="#3F8DF5" @click="gotoRules"/> -->
      </div>
      <u-gap/>
      <div class="item" v-for="(item, index) in list" :key="index">
        <div class="item-info">
          <p v-text="item.eventDesc||item.integralRuleName"/>
          <span v-text="item.doTime"/>
        </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: "gridIntegral",
  computed: {
    ...mapState(['user'])
  },
  data() {
    return {
      info: {},
      list: [],
      current: 1,
      pages: 0,
      userId: '',
      rankNum: ''
    }
  },
  created() {
    this.getInfo()
    this.getList()
  },
  onLoad(option) {
    this.rankNum = option.rankNum
    this.userId = option.userId
  },
  onShow() {
    document.title = '积分明细'
  },
  methods: {
    // 积分排行
    getInfo() {
      this.$http.post(`/app/appintegraluser/integralUserInfoFD?integralUserId=${this.userId}`).then(res => {
        if (res?.data) {
          this.info = res.data
        }
      })
    },
    getList() {
      this.$http.post(`/app/appintegraldetail/list`, null, {
        params: {current: this.current, size: 10, integralUserId: this.userId}
      }).then(res => {
        if (res?.data) {
          this.list = [this.list, res.data.records || []].flat()
        }
      })
    },
    gotoRules() {
      uni.navigateTo({url: './integralRules'})
    }
  },
  onReachBottom() {
    this.current++
    this.getList()
  }
}
</script>
<style scoped lang="scss">
.gridIntegral {
  width: 100vw;
  min-height: 100vh;
  background-color: #f3f6f9;
  display: flex;
  flex-direction: column;
  align-items: center;

  .bg-blue {
    width: 100%;
    height: 270px;
    background-color: #3975C6;
  }

  .header-content {
    width: 690px;
    height: 408px;
    margin: -130px 0 40px;
    padding: 32px;
    box-sizing: border-box;
    position: relative;
    background: #FFF;
    border-radius: 16px;

    .headerDataPane {
      
      top: 76px;
      left: 0;
      right: 0;
      position: absolute;
      z-index: 9;
      

      .header-rank {
        flex-wrap: wrap;
        justify-content: space-around;
      }
      .header-user {
        padding: 0 64px;
        display: flex;
        justify-content: space-between;
        .user-name {
          font-size: 50px;
          font-weight: 500;
        }
      }
      .headerItem {
        text-align: center;
        font-size: 28px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #999999;
        line-height: 40px;

        b {
          display: block;
          line-height: 50px;
          color: #000;
          font-size: 36px;
          font-family: DIN, DINAlternate-Bold, DINAlternate;
          margin-bottom: 10px;
        }

        &.top {
          b {
            font-size: 104px;
            line-height: 122px;
          }
        }
      }
    }

    & > img {
      position: absolute;
      width: 342px;
      height: 220px;
      top: -60px;
      right: 10px;
      z-index: 2;
    }
  }

  .mar-b4 {
    margin-bottom: 8px;
  }

  .mar-b8 {
    margin-bottom: 16px;
  }

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

    .title {
      font-size: 34px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #333;
      line-height: 48px;
    }

    .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;
      }
    }
  }


  .color-1 {
    color: #2C51CE !important;
  }

  .color-0 {
    color: #E6736E !important;
  }

  .divider {
    width: 2px;
    height: 60px;
    background: #ededed;
  }
}
</style>
