<template>
  <div id="list-1">
    <van-row>
      <van-col span="24" class="main">
        <van-col span="24" class="list" v-for="(item, index) in list" :key="index">
          <van-col span="24" class="title textOver">
            {{ item.title }}
          </van-col>
          <van-col span="24" class="other">
            <van-col span="24" class="otherInfo">
              下载进度：<span>{{ item.progress || '暂无' }}</span>
            </van-col>
            <van-col span="24" class="otherInfo">
              创建时间：<span>{{ getDate(item.meta) || '暂无' }}</span>
            </van-col>
          </van-col>
          <van-col span="24" class="btn">
            <van-button type="info" size="small" @click="download(item.uri)">下载文件</van-button>
          </van-col>
        </van-col>
      </van-col>
    </van-row>
  </div>
</template>
<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const moment = require('moment');
export default {
  name: 'list-1',
  props: { list: { type: Array } },
  components: {},
  data: function () {
    return {};
  },
  created() {},
  methods: {
    // 详细信息
    download(data) {
      if (data) {
        window.location.href = `${process.env.VUE_APP_HOST}${data}`;
      } else {
        this.$toast({ type: `fail`, message: `未上传文件` });
      }
    },
    getDate(data) {
      let newDate = moment(data.createdAt).format('YYYY-MM-DD hh:mm:ss');
      if (newDate) return newDate;
    },
  },
  computed: {
    ...mapState(['user']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  margin: 8px 0 0 0;
  .list {
    background-color: #fff;
    margin: 0 0 10px 0;
    box-shadow: 0 0 5px #f1f1f1;
    padding: 8px;
    .title {
      font-size: 16px;
      font-weight: bold;
      margin: 0 0 5px 0;
    }
    .other {
      margin: 0 0 5px 0;
      .otherInfo {
        font-size: 14px;
        color: #666;
        margin: 0 0 5px 0;
        span {
          color: #000;
        }
      }
    }
    .btn {
      text-align: center;
      .van-button {
        margin: 0 10px 5px 10px;
      }
    }
  }
}
</style>
