<template>
  <div class="dv-timer-viewer" :class="{ isLoading: isLoading }">
    <div class="dv-timer-viewer-container">
      <span>{{title}}: {{time}}</span>
      <icon class="dv-timer-viewer-loading" name="loading" v-if="isLoading"></icon>
      <el-tooltip content="刷新数据" v-else>
        <div class="dv-timer-viewer-refresh-icon-wrap" @click="refreshTime">
          <icon class="dv-timer-viewer-refresh-icon" name="refresh"></icon>
        </div>
      </el-tooltip>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'DvTimeViewer',
    props: {
      isLoading: {
        type: Boolean,
        default: false
      },
      title: {
        type: String,
        default: '当前'
      },
      value: null
    },
    data () {
      return {
        time: null
      };
    },
    watch: {
      value(value) {
        this.time = value;
      }
    },
    methods: {
      refreshTime () {
        this.$emit('refreshTime', this.time);
      },
      initializeTime (time) {
        this.time = time;
      },
      setTime (time) {
        this.time = time;
      }
    }
  };
</script>
