<template>
  <view>
    <view class="cu-timeline">
      <!-- <view class="cu-time">昨天</view> -->
      <view :key="index" class="cu-item cur" v-for="(item, index) in userSigns">
        <view class="content bg-green shadow-blur">
          <text>{{ generateTime(item.time - 0) }}</text>
          【 {{ item.siteName }} 】打卡
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import { mapState } from 'vuex';

export default {
  data() {
    return {};
  },

  computed: mapState('statistics', ['userSigns']),

  methods: {
    /**
     * 格式化时间为文本
     * @param {number} time ms数
     */
    generateTime(time) {
      let type = 'YYYY-MM-DD HH:mm';
      if (this.$moment().isSame(time, 'day')) {
        return `今天 ${this.$moment(time).format('HH:mm')}`;
      }

      if (this.$moment().isSame(time, 'year')) {
        type = 'MM-DD HH:mm';
      }

      return this.$moment(time).format(type);
    },
  },
};
</script>
