<template>
  <el-dropdown style="border-left:1px solid #dcdfe6" v-show="checklist.length === 1" >
    <el-button size="small">
      <i class="el-icon-more"></i>
    </el-button>
    <el-dropdown-menu slot="dropdown">
      <el-dropdown-item v-if="checklist[0].postfix !== 'FOLDER'" @click.native="showShareurl">分 享</el-dropdown-item>
      <el-dropdown-item @click.native="restName">重命名</el-dropdown-item>
      <el-dropdown-item v-if="checklist[0].postfix === 'FOLDER'" @click.native="changeAuthData">修改授权</el-dropdown-item>
      <el-dropdown-item @click.native="showFileTree">移动到</el-dropdown-item>
    </el-dropdown-menu>
    <modifyLocation ref="modefy" :checklist="checklist" @onChangeFolderModify="onChangeFolderModify"></modifyLocation>
    <el-dialog title="分享" :visible.sync="urlDialog" width="500px">
      <div class="border">
      <el-input placeholder="链接地址" v-model="checklist[0].url">
        <el-button slot="append" @click="test">复制</el-button>
      </el-input>
      </div>
    </el-dialog>
  </el-dropdown>
</template>

<script>
import modifyLocation from './modifyLocation.vue'
export default {
  components:{
    modifyLocation
  },
  props:['checklist'],
  data () {
    return {
      urlDialog:false,
    }
  },
  methods:{
    showShareurl () {
      this.urlDialog = true
    },
    restName () {
      this.$emit('restName')
    },
    changeAuthData () {
      console.log('edit')
      this.$emit('changeAuthData')
    },
    async confirmRestName (folder) {
      let param = {
        "classname": "system.attachment.MediaCenter",
        "method": "changeAttachment",
        "content": {
          "files": [
            {
              "attachmentid": folder.attachmentid,
              "document": folder.document,
              "parentid":folder.parentid//文件夹iD
            }
          ]
        }
      }
      const res = await this.$api.requested(param)
      if (res.code === 1) {
        this.$emit('onSuccess')
        this.$message({
          message:'重命名成功',
          type:'success'
        })
      } else {
        this.$message({
          message:res.data,
          type:'error'
        })
      }
    },
    showFileTree () {
      this.$refs.modefy.dialogTreeVisible = true
      let id = JSON.parse(sessionStorage.getItem('folderid')).salematerialfolderid
      this.$refs.modefy.queryAttachment(id)
    },
    onChangeFolderModify () {
      this.$emit('onSuccess')
    },
    test () {
      var input = document.createElement("input"); // 创建input对象
      input.value = this.checklist[0].url; // 设置复制内容
      document.body.appendChild(input); // 添加临时实例
      input.select(); // 选择实例内容
      document.execCommand("Copy"); // 执行复制
      document.body.removeChild(input); // 删除临时实例
      this.$message({
        message:'复制成功,快去分享给好友吧!',
        type:'success'
      })
    }
  }
}

</script>
<style>
</style>