<template>
  <div id="material">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <data-table @query="search" :fields="fields" :opera="opera" :data="list" :usePage="false" @download="toDownload"> </data-table>
        </el-col>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { mapState, createNamespacedHelpers } from 'vuex';
const { mapActions } = createNamespacedHelpers('digital_files');
export default {
  name: 'material',
  props: {},
  components: {},
  data: function () {
    return {
      fields: [
        { label: '电子材料类型', model: 'type' },
        { label: '电子材料名称', model: 'name' },
        { label: '文件地址', model: 'el_img' },
      ],
      opera: [{ label: '下载', method: 'download' }],
      list: [],
    };
  },
  created() {},
  mounted() {
    this.search();
  },
  methods: {
    ...mapActions(['query']),
    async search() {
      let res = await this.query({ main_id: this.id });
      if (this.$checkRes(res)) {
        this.$set(this, `list`, res.data);
      }
    },
    // 下载
    toDownload({ data }) {
      window.open(`${process.env.VUE_APP_HOST}${data.el_img}`, '_blank');
    },
  },
  computed: {
    ...mapState(['user']),
    id() {
      return this.$route.query.id;
    },
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped></style>
