<template>
  <view class="page">
    <view class="timePicker" @click="show = true">{{ `${year}年${month}月` }}
      <u-icon class="icon" size="10" color="#CCCCCC" style="margin-left: 8rpx;" name="arrow-down-fill"></u-icon>
    </view>
    <view class="card">
      <view class="item" v-for="(item, index) in list" :key="index">
        <view class="phone_amount">
          <view class="phone">
            {{ item.phone || '匿名' }}
          </view>
          <view class="amount">
            ￥{{ currency(item.total, { fromCents: true }) }}
          </view>
        </view>
        <view class="date_type">
          <view class="date">{{ $u.timeFormat(new Date(item.receiptsTime), 'yyyy-mm-dd') }}</view>
          <view class="type">{{ item.planningName }}</view>
        </view>
      </view>
    </view>
    <u-empty iconSize="90px" textSize="14px" v-if="list.length == 0"></u-empty>

    <u-datetime-picker :show="show" v-model="time" mode="year-month" @cancel="show = false" @close="show = false"
      @confirm="confirm"></u-datetime-picker>

  </view>
</template>

<script>
import { rewardDetailList } from "@/api/invite"
import currency from '@/utils/currency'
export default {
  data() {
    return {
      show: false,
      currency: currency,
      month: '',
      year: '',
      list: [],
      time: new Date()
    };
  },
  methods: {
    getRewardDetailList(query) {
      rewardDetailList(query).then(({ content }) => {
        if (content) {
          this.list = content
        }
      })
    },
    confirm({ value }) {
      this.year = new Date(value).getFullYear()
      this.month = new Date(value).getMonth() + 1
      this.getRewardDetailList({
        year: this.year,
        month: this.month
      })
      this.show = false
    }
  },
  onShow() {
    console.log(currency)
    const date = new Date()
    this.year = date.getFullYear()
    this.month = date.getMonth() + 1
    this.getRewardDetailList({
      year: this.year,
      month: this.month
    })
  }
};
</script>
<style lang="scss" scoped>
.page {
  min-height: 100vh;
  background-color: #F9F9F9;
  padding: 20rpx 24rpx;

  .timePicker {
    color: #181818;
    font-size: 28rpx;
    display: flex;
    align-items: center;
  }

  .card {
    background-color: #ffffff;
    border-radius: 16rpx;

    .item {
      border-top: 1px solid #F0F0F0;
      padding: 28rpx 24rpx;
      margin-top: 20rpx;

      &:first-child {
        border-top: none;
      }

      .phone_amount {
        display: flex;
        justify-content: space-between;

        .phone {
          font-size: 28rpx;
          color: #181818;
        }

        .amount {
          font-size: 28rpx;
          color: #FF3E3E;
          font-weight: bold;
        }

        margin-bottom: 8rpx;
      }

      .date_type {
        display: flex;
        justify-content: space-between;

        .date {
          font-size: 22rpx;
          color: #CCCCCC;
        }

        .type {
          font-size: 22rpx;
          color: #CCCCCC;
        }
      }
    }

  }
}
</style>