<template>
  <h3>
    搜索 - {{ search_query }}
  </h3>
  <hr>
  <button class="d-block my-2 btn btn-info" @click="$router.go(-1)">返回</button>
  <div class="fade-in">
    <div v-if="!entries.length" class="alert alert-info">
      没有数据
    </div>
    <table v-else class="table">
      <thead>
        <tr>
          <th>
            名称
          </th>
          <th>创建时间</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="e, i in entries" :key="i">
          <td>
            <a target="_blank" :href="file_link(e)">{{ show_name(e) }}</a>
          </td>
          <td>{{ show_time(e) }}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
export default {
  name: 'EstorSearch',
  props: [],
  components: {
  },
  data: function () {
    return {
      entries: [],
    };
  },
  computed: {
    search_query() {
      return this.$route.query.q;
    },
  },
  methods: {
    file_link(e) {
      return this.$root.estor_file_link(e.path);
    },
    show_name(e) {
      return e.path.split('/').slice(-1)[0];
    },
    show_time(e) {
      var ctime = e.ts.ctime;
      var t = new Date(ctime * 1000);
      return this.$root.show_time(t);
    },
    async reload() {
      var r = await this.$root.estor_call("Search", {
        space: this.$root.estor_space,
        query: this.search_query,
      });
      this.entries = r.data.data;
      console.log(r, this.entries);
    },
  },
  mounted() {
    this.reload();
  },
}
</script>

<style scoped>
</style>
