<template>
  <div class="">
    <el-dialog :title="title" :visible.sync="visible" width="500px" append-to-body destroy-on-close :before-close="close" top="10vh">
      <div class="patent-move-select-folder">
        <el-tree ref="tree" :data="folder" show-checkbox node-key="id" check-strictly>
          <div class="custom-filter-tree-node" slot-scope="{ node, data }">
            <span class="name">{{ data.name }}</span>
            <span class="total">({{ data.total }})</span>
          </div>
        </el-tree>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="submit" :loading="btnLoading">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props: ['params', 'moveType'],
  data() {
    return {
      visible: false,
      folder: [],
      btnLoading: false,
      title: '',
      selected: {
        oldFolder: [],
        newFolder: []
      }
    }
  },
  mounted() {
  },
  methods: {
    getList() {
      let params = {
        name: '',
        projectId: this.params.projectId,
        patentTotal: true
      }
      this.$api.getProjectFolderList(params).then(response => {
        this.folder = response.data
      })
    },
    open(title) {
      this.title = title
      this.visible = true
      this.getList()
    },
    close() {
      this.visible = false
      this.$emit('close')
    },
    submit() {
      let data = {
        patentIds: this.params.selected,
        projectId: this.params.projectId,
        oldFolder: this.params.folder ? [this.params.folder] : [],
        newFolder: this.$refs.tree.getCheckedKeys(),
        type: this.moveType
      }
      this.btnLoading = true
      this.$api.updateProjectFolderPatent(data).then(response => {
        this.$message.success('操作成功')
        this.btnLoading = false
        this.visible = false
        this.$emit('submit')
      }).catch(error => {
        this.btnLoading = false
      })
    }
  }
}
</script>

<style lang="scss">
.patent-move-select-folder {
  .tree-title {
    font-weight: bold;
    line-height: 60px;
  }
}
</style>