<template>
  <div id="list-gzj">
    <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.create_number }}
          </van-col>
          <van-col span="24" class="other">
            <van-col span="24" class="otherInfo">
              专利名称：<span>{{ item.patent_name || '暂无' }}</span>
            </van-col>
            <van-col span="24" class="otherInfo">
              接收人：<span>{{ item.to_name || '暂无' }}</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 size="small" type="info" @click="toView(item.file_url)">查看文件</van-button>
          </van-col>
        </van-col>
      </van-col>
    </van-row>
    <van-dialog class="dialog" v-model="show" title="文件下载" :show-confirm-button="false" :show-cancel-button="true" cancel-button-text="返回">
      <van-col span="24" class="list" v-for="(item, index) in fileList" :key="index">
        <van-col span="24" class="name"
          >文件路径：<span>{{ item }}</span></van-col
        >
        <van-col span="24" class="btn">
          <van-button type="info" size="small" @click="download(item)">下载文件</van-button>
        </van-col>
      </van-col>
    </van-dialog>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
var moment = require('moment');
export default {
  name: 'list-gzj',
  props: {
    list: { type: Array },
  },
  components: {},
  data: function () {
    return {
      // 文件下载
      show: false,
      fileList: [],
    };
  },
  created() {},
  methods: {
    // 查看文件
    toView(data) {
      this.$set(this, `fileList`, data);
      this.show = true;
    },
    download(data) {
      if (data) {
        window.location.href = `${process.env.VUE_APP_HOST}/${data}`;
      } else {
        this.$toast({ type: `fail`, message: `未上传文件` });
      }
    },
    getDate(val) {
      let newDate = moment(val.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 {
  padding: 8px 8px 0 8px;
  .list {
    background-color: #fff;
    margin: 0 0 8px 0;
    padding: 8px;
    border-radius: 5px;
    .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 5px;
      }
    }
  }
}
.dialog {
  padding: 0 8px;
  /deep/.van-dialog__content {
    height: 350px;
    overflow-y: auto;
  }
  .list {
    .name {
      font-size: 14px;
      word-break: break-all;
      color: #666;
      margin: 0 0 5px 0;
      span {
        color: #000;
      }
    }
    .btn {
      text-align: center;
    }
  }
}
</style>
