<template>
  <div>
    <el-button size="small" icon="el-icon-plus" @click="createFolder(dialogFolderVisible = true)">新建文件夹</el-button>
    <el-dialog title="新建文件夹" :visible.sync="dialogFolderVisible">
      <div class="flex-align-center container">
        <p style="width:100px">文件夹名称</p>
        <el-input size="small" v-model="folder.document" placeholder="输入文件夹名称"></el-input>
      </div>
      <scopeOfauth :scrollHeight="'200px'" :defaultData="defaultData" obiectName="sat_salematerial" :obiectId="0" appidname="attachmentid" @onChecked="onChecked">
        <p slot="title">授权文件夹</p>
      </scopeOfauth>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogFolderVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="createFolderComplete(folder)" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import scopeOfauth from '@/components/scopeOfAuthority/index.vue'
export default {
  components:{
    scopeOfauth,
  },
  data () {
    return {
      dialogFolderVisible:false,
      defaultData:{},
      folder:{
        document:''
      },
      attachmentid:null,
      params:{
        "classname": "system.attachment.MediaCenter",
        "method": "createFolder",
        "content": {
          "foldername": "文件夹名称",
          "parentid": JSON.parse(sessionStorage.getItem('folderid')).salematerialfolderid,
        }
      }
    }
  },
  methods:{
    createFolder () {},
     // 获取保存授权范围数据
    onChecked (param) {
      this.authData = param
    },
    async createFolderComplete (folder) {
      let id = this.$route.query.id?this.$route.query.id:JSON.parse(sessionStorage.getItem("folderid")).salematerialfolderid
      this.params.content.parentid = id
      this.params.content.foldername = folder.document
      const res = await this.$api.requested(this.params)
      this.$emit('onSuccess')
      this.tool.showMessage(res,()=>{this.dialogFolderVisible = false})
      res.code === 1?this.insertCoursewareauth(res.data.attachmentid):''
    },
    // 新增授权范围
    async insertCoursewareauth (attachmentid) {
      this.authData.attachmentid = attachmentid
      const res = await this.$api.requested({
        "classname": "webmanage.saletool.salematerial.salematerialAuth",
        "method": "insertOrUpdate",
        "content": this.authData
      })
      res.code === 0?this.$notify({
        title:'失败',
        message:res.data,
        type:'error'
      }):''
    },
  }
}

</script>
<style>
</style>