<template>
  <div class='flex flex-col full-height'>
    <div class="full-height white-bg">
      <current :id="id" :data="fileData" :total="total" @reFiles="getFileList" @change='changePage'/>
    </div>
    <div class="full-height full-width white-bg mt-10">
      <historical :folderList="historyFolder" :total="total"/>
    </div>
  </div>
</template>

<route>
{
name:'项目文件',
}
</route>

<script>
import current from './component/current.vue'
import historical from './component/historical.vue'

export default {
  name: 'files',
  components: { current, historical },
  data () {
    return {
      id: '',
      fileData: '',
      historyFolder: [],
      total: '',
      page: {
        current: 1,
        size: 10
      }
    }
  },
  created () {
    this.id = this.$route.query.id
    this.getFileList()
    this.getFolderAll()
    this.$bus.on('delete', () => {
      this.getFileList()
    })
    this.$bus.on('reFolder', () => {
      this.getFolderAll()
    })
  },
  methods: {
    getFileList () {
      const data = { folderId: this.id }
      this.$api.project.fileList(Object.assign(data, this.page)).then(res => {
        if (res.code === 200) {
          this.fileData = res.data
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    getFolderAll () {
      this.$api.project.folderListAll({ parentId: this.id, type: 1 }).then(res => {
        if (res.code === 200) {
          this.historyFolder = res.data.records.map(e => {
            e.folderName = e.title
            e.fileNumber = e.childrenNumber
            return e
          })
          this.total = res.data.total
        }
      })
    },
    changePage (page) {
      this.page.current = page
      this.getFileList()
    }
  }
}
</script>

<style scoped>

</style>
