<template>
  <div class="full-height full-width flex flex-col">
    <avue-crud ref="crud"
               v-model="form"
               v-model:page="page"
               :before-open="beforeOpen"
               :data="data"
               :option="option"
               :table-loading="loading"
               @row-del="rowDel"
               @current-change="currentChange"
               @size-change="sizeChange"
               @refresh-change="refreshChange"
               @on-load="onLoad">
    </avue-crud>
  </div>
</template>

<route>
{
path: '/recycle',
name: '回收站',
}
</route>

<script>

export default {
  name: 'index',
  data () {
    return {
      keyWords: '',
      loading: false,
      data: [],
      form: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 10
      },
      option: {
        calcHeight: 30,
        refreshBtn: false,
        tip: false,
        columnBtn: false,
        searchShow: true,
        editBtn: true,
        editBtnText: '还原',
        addBtn: false,
        delBtn: true,
        border: true,
        index: true,
        align: 'center',
        viewBtn: false,
        menuWidth: 260,
        dialogClickModal: false,
        column: [
          {
            label: '名称',
            prop: 'name',
            addDisplay: false,
            editDisplay: false
          },
          {
            label: '类型',
            prop: 'type',
            type: 'select',
            dicData: [
              {
                label: '文件夹',
                value: 1
              },
              {
                label: '文件',
                value: 2
              },
              {
                label: '项目',
                value: 3
              },
              {
                label: '阶段',
                value: 4
              },
              {
                label: '专债明细',
                value: 5
              }
            ]
          },
          {
            label: '删除时间',
            prop: 'createTime'
          },
          {
            label: '删除人',
            prop: 'createUserName'
          }]
      }
    }
  },
  methods: {
    onLoad () {
      this.loading = true
      this.page.current = this.page.currentPage
      this.page.size = this.page.pageSize

      this.$api.recycle.recycleList(this.page).then(res => {
        this.loading = false
        if (res.code === 200) {
          this.data = res.data.records
          this.page.total = res.data.total
        }
      })
    },
    beforeOpen (done, type) {
      if (type === 'edit') {
        this.$confirm('确定恢复所选择的文件?', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.$api.recycle.recycleBack({ recycleBinId: this.form.id }).then(res => {
              if (res.code === 200) {
                this.$message.success(res.msg)
                this.onLoad()
              } else {
                this.$message.error(res.msg)
              }
            })
          })
      }
    },
    currentChange (currentPage) {
      this.page.currentPage = currentPage
    },
    sizeChange (pageSize) {
      this.page.size = pageSize
    },
    refreshChange () {
      this.onLoad()
    },
    rowDel (row) {
      this.$confirm('确定彻底删除所选择的文件?', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.$api.recycle.recycleRemove({ ids: row.id }).then(res => {
            if (res.code === 200) {
              this.$message.success(res.msg)
              this.onLoad()
            } else {
              this.$message.error(res.msg)
            }
          })
        })
    }
  }
}
</script>

<style scoped>

</style>
