<template>
  <div class="page">
    <div class="bg-blue"></div>
    <div class="header-content">
      <div class="left-content" flex>
        <div class="fill">
          <span>总积分：</span>
          <div class="info num" v-text="info.sysUserIntegral"/>
        </div>
        <div class="btn" @click="gotoGive">积分赠送</div>
      </div>
      <img src="https://cdn.cunwuyun.cn/dvcp/credit/head.png" alt="">
    </div>
    <div class="detail-content" v-if="list.length">
      <div class="title">积分明细</div>
      <div class="item" v-for="(item, index) in list" :key="index">
        <div class="item-info">
          <p v-text="item.eventDesc"/>
          <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 {mapActions, mapState} from 'vuex'

export default {
  name: "sysUserIntegral",
  appName: "员工积分",
  computed: {
    ...mapState(['user', 'token']),
    ...mapActions(['selectEnterpriseContact'])
  },
  data() {
    return {
      info: {},
      list: [],
      current: 1,
      pages: 0
    }
  },
  created() {
    this.getInfo()
    uni.$on("reachBottom", () => {
      this.current++;
      this.getInfo()
    })
    uni.$on('updateIntegral', () => {
      this.current = 1
      this.list = []
      this.getInfo()
    })
  },
  methods: {
    // 积分排行
    getInfo() {
      let {current, user: {id: userId}, info: {details}} = this
      if (!details?.pages || current <= details.pages) {
        this.$http.post('/app/appvillagerintegraldetail/sysUserIntegralList', null, {
          params: {userId, current, size: 10}
        }).then(res => {
          if (res?.data) {
            this.info = res.data
            this.list = [this.list, res.data.details?.records || []].flat()
          }
        })
      }
    },
    gotoGive() {
      uni.navigateTo({url: "./giveIntegral"})
    }
  },
  destroyed() {
    uni.$off("reachBottom")
    uni.$off("onShow")
  }
}
</script>
<style scoped lang="scss">
.page {
  width: 100vw;
  background-color: #f3f6f9;

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

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

    .left-content {
      position: absolute;
      left: 32px;
      right: 32px;
      z-index: 99;
      align-items: flex-end;

      .btn {
        border-radius: 28px;
        border: 2px solid #3975C6;
        padding: 0 28px;
        line-height: 56px;
        color: #3975C6;
      }
    }

    span {
      width: 140px;
      color: #999;
    }

    .info {
      height: 40px;
      font-size: 28px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #333;
      line-height: 40px;
    }

    .num {
      margin-top: 20px;
      font-size: 40px;
      font-family: DINAlternate-Bold, DINAlternate;
      font-weight: bold;
      color: #5AAD6A;
      line-height: 48px;
      margin-bottom: 10px;
    }

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

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

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

  .detail-content {
    width: 690px;
    background: #FFF;
    border-radius: 16px;
    margin: 0 0 0 32px;
    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;
      margin-bottom: 30px;
    }

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