<template>
  <div class="record border border-app-blue-3 border-solid rounded-lg">
    <div v-if="hasTitle" class="record-title px-4 text-sm border-0 border-b border-app-blue-3 border-solid leading-10">
      {{ message.name }}
    </div>
    <div class="px-3">
      <div class="flex justify-between items-center px-1 leading-8 pt-3">
        <span class="text-sm">投票时间</span>
        <span class="tet-xs">{{ time }}</span>
      </div>
      <div class="flex justify-between items-center border-0 border-b border-app-blue-3 border-solid px-1 leading-8 pb-3">
        <span class="text-sm">投票数</span>
        <span class="tet-xs">{{ message.amount }}票</span>
      </div>
      <div class="px-1 text-xs py-4 flex justify-between items-center text-app-white">
        <span>HASH</span>
        <div class="flex items-center tracking-tighter" @click="goHash(message.optionId)">
          <span>{{ message.txHash && message.txHash.slice(0, 25) + '...' + message.txHash.slice(-4) || '' }}</span>
          <app-icon class="ml-0" customize size="12px" color="#AB9BD6" type='icon-arrow-right-copy-copy'></app-icon>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
import AppIcon from '@/components/common/Icon.vue'
export default Vue.extend({
  components: {
    AppIcon
  },
  props: {
    hasTitle: {
      type: Boolean,
      default: true
    },
    message: {
      type: Object
    }
  },
  data() {
    return {
      time: ''
    }
  },
  computed: {
    
  },
  methods: {
    goHash(id: string) {
      this.$router.push({ path: '/Browser/MyAttend', query: {...this.$route.query, optionId: id, item: JSON.stringify(this.message)} })
    },
    timer() {
      const timeStamp = +this.message.blockTime * 1000
      return (new Date(timeStamp).getMonth() + 1) + '月' +
        (new Date(timeStamp).getDate()) + '日  ' + (new Date(timeStamp).getHours())
         + ':' + (new Date(timeStamp).getMinutes() < 10 ? '0' + new Date(timeStamp).getMinutes() : new Date(timeStamp).getMinutes())
    }
  },
  created() {
    this.time = this.timer()
  },
  watch: {
    message: {
      deep: true,
      handler() {
        this.time = this.timer()
      }
    }
  }
})
</script>

<style scoped>
  .record-title {
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap
  }
</style>
