<template>
  <div id="files-1">
    <el-row>
      <el-col :span="24" class="main">
        <el-col :span="24" class="one">
          <data-table :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: digital_files } = createNamespacedHelpers('digital_files');
export default {
  name: 'files-1',
  props: {
    basic_id: { type: String },
  },
  components: {},
  data: function () {
    return {
      // 列表
      fields: [
        { label: '电子材料类型', model: 'type' },
        { label: '电子材料名称', model: 'name' },
        { label: '文件地址', model: 'el_img' },
      ],
      opera: [{ label: '下载', method: 'download' }],
      list: [],
    };
  },
  created() {
    if (this.basic_id) this.search();
  },
  methods: {
    ...digital_files(['query', 'create', 'update']),
    async search({ skip = 0, limit = 10, ...info } = {}) {
      info.main_id = this.basic_id;
      let res = await this.query({ skip, limit, ...info });
      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']),
  },
  metaInfo() {
    return { title: this.$route.meta.title };
  },
  watch: {
    test: {
      deep: true,
      immediate: true,
      handler(val) {},
    },
  },
};
</script>

<style lang="less" scoped>
.main {
  .one {
    .one_1 {
      height: 40px;
      line-height: 40px;
      border-bottom: 1px solid #ccc;
      margin: 0 0 10px 0;
      font-size: 18px;
      font-weight: bold;
    }
  }
}
.dialog {
  /deep/.el-dialog__body {
    padding: 10px;
  }
  .btn {
    text-align: center;
  }
}
</style>
