<template>
  <div class="wrapper">
    <div class="fixed">
      <div class="header">
        <div class="left" @click="showDate=true">{{searchDate}}<u-icon name="arrow-down" color="#333" size="24" style="margin-left: 4px" ></u-icon></div>
        <div class="right">获得积分 <span>{{integral || 0}}</span></div>
      </div>
    </div>
    <div class="list">
      <div class="item" v-for="(item, index) in list" :key="index">
        <div class="left">
          <h2>{{ $dict.getLabel('partyIntegralDetailType', item.type) }}</h2>
          <p v-if="item.createTime">{{item.createTime.substring(5, 16)}}</p>
        </div>
        <div class="right">
          <h2 :class="item.integralType == 1 ? 'color-E6736E' : 'color-F0A046'">{{item.integralType == 1 ? '+' : '-'}}{{item.integral}}</h2>
          <p>{{item.remark}}</p>
        </div>
      </div>
      <AiEmpty v-if="!list.length"/>
    </div>
    <u-picker mode="time" v-model="showDate" :params="dateParams" @confirm="selectDate"></u-picker>
  </div>
</template>
<script>
import {mapState} from 'vuex';

export default {
  name: "pointDetailList",
  appName: "积分明细",
  computed: {
    ...mapState(['user']),
  },
  data() {
    return {
      searchDate: '',
      showDate: false,
      dateParams: {
        year: true,
        month: true,
        day: false,
        hour: false,
        minute: false,
        second: false
      },
      current: 1,
      pages: 2,
      list: [],
      integral: 0
    };
  },
  onLoad() {
    uni.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: "#E76056",
    })
    var datetime = new Date();
    var year = datetime.getFullYear();
    var month = datetime.getMonth() + 1 < 10 ? '0' + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    this.searchDate = `${year}-${month}`
    this.$dict.load("partyIntegralDetailType").then(() => {
      this.getList()
    })
  },
  methods: {
    selectDate(e) {
      this.searchDate = `${e.year}-${e.month}`
      this.getListInit()
    },
    getListInit() {
      this.current = 1
      this.pages = 2
      this.list = []
      this.integral = 0
      this.getList()
    },
    getList() {
      if (this.current > this.pages) return;
      this.$instance.post(`/app/apppartyintegralinfo/integralDetailForWX`, null, {
        params: {
          partyId: this.user.partyId,
          current: this.current,
          year: this.searchDate,
        }
      }).then((res) => {
        if (res.code == 0) {
          this.integral = res.data.integral
          const list = this.current > 1 ? [...this.list, ...res.data.infoIPage.records] : res.data.infoIPage.records
          this.pages = res.data.infoIPage.pages
          this.list = list
        }
      });
    }
  },
  onReachBottom() {
    this.current ++
    this.getList()
  }
};
</script>
<style lang="scss" scope>
@import "~dvcp-wui/common";
.fixed{
  position: fixed;
  top: 0;
  left: 0;
  background-color: #fff;
  width: 100%;
  .header {
    width: 100%;
    background: #FFF;
    padding: 28px 32px;
    box-sizing: border-box;
    display: flex;
    justify-content: space-between;
  }
  .left{
    padding: 0 24px;
    height: 56px;
    line-height: 56px;
    background: #EEE;
    border-radius: 28px;
    font-size: 26px;
    font-family: PingFangSC-Regular, PingFang SC;
    color: #333;
  }
  .right{
    font-size: 32px;
    font-family: PingFangSC-Regular, PingFang SC;
    color: #333;
    line-height: 44px;
    span{
      display: inline-block;
      margin-left: 8px;
      font-weight: 500;
    }
  }
}
.list{
  padding-top: 120px;
  .item{
    padding: 32px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    background-color: #fff;
    h2{
      font-size: 32px;
      font-family: PingFangSC-Medium, PingFang SC;
      font-weight: 500;
      color: #333;
      line-height: 44px;
      margin-bottom: 8px;
    }
    p{
      font-size: 26px;
      font-family: PingFangSC-Regular, PingFang SC;
      color: #999;
      line-height: 36px;
      overflow:hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
    }
    .left{
      width: calc(100% - 480px);
    }
    .right{
      width: 480px;
      text-align: right;
      h2{
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
      }
    }
    .color-E6736E{
      color: #E6736E;
    }
    .color-F0A046{
      color: #F0A046;
    }
  }
}
  
</style>
