<style>
  .app-attachment .el-dialog__wrapper {
    z-index: 99999 !important;
  }

  .cloud_Table {
    text-align: center;
  }

</style>
<template id="app-attachment">
  <div class="app-attachment" style="z-index:99999">
    <el-dialog class="app-attachment-dialog" style="width:1000px;height:800px;margin:0 auto;z-index:99999"
      :title="title ? title : '选择文件'" :visible.sync="dialogVisible" @opened="dialogOpened"
      :close-on-click-modal="false">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="本地文件" name="first">
          <el-upload class="upload-demo" action="" :accept="accept" :show-file-list="false"
            :http-request="UploadAttachment" :multiple="uploadMultple" ref="my-upload">
            <div class="app-upload" flex="main:center cross:center"
              style="width: 200px; height: 120px;font-size:67px;border:1px dashed #d1d1d1;">
              <i class="el-icon-upload" style="font-size:64px;"></i>
            </div>
          </el-upload>
        </el-tab-pane>
      </el-tabs>
      <div style="margin-top:20px;text-align:right">
        <el-button size="small" type="primary" @click="SelectAttachment">选定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    props: {
      //上传单选还是多选
      uploadMultple: {
        type: Boolean,
        value: false,
      },
      //文件单选还是多选
      chooseMultple: {
        type: Boolean,
        value: false,
      },
      //上传类型(1-图片,2-附件,3-音频)
      uploadType: {
        type: String,
        default: '1',
      },
      //是否显示弹窗
      openDialog: {
        type: Boolean,
        default: false,
      },
    },
    computed: {
      accept: {
        get() {
          if (this.uploadType === '1') {
            return 'image/*';
          }
          if (this.uploadType === '2') {
            return '*/*';
          }
          if (this.uploadType === '3') {
            return 'audio/*';
          }
          return '*/*';
        },
      },
    },
    watch: {
      openDialog: {
        handler(newValue) {
          this.dialogVisible = newValue;
        },
        immediate: true
      },
      uploadType: {
        handler(newValue) {
          if (newValue) {
            switch (newValue) {
              case "1":
                this.title = "图片";
                break;
              case "2":
                this.title = "附件";
                break;
              case "3":
                this.title = "音频";
                break;
            }
          }
        },
        immediate: true
      },
      dialogVisible(newVal, oldVal) {
        if (!newVal) {
          this.$emit("closed");
        }
      },
    },
    data() {
      return {
        dialogVisible: false,
        title: "",
        activeName: "first",
        fileDataList: [],
        chooseFileArray: []
      };
    },
    created() {
      this.chooseFileArray = [];
    },
    mounted() {
      this.chooseFileArray = [];
    },
    methods: {
      //选择文件
      SelectAttachment() {
        this.$emit("selected", this.chooseFileArray);
      },
      //上传附件
      UploadAttachment(files) {
        let newArr = [];
        newArr.push(files.file);
        var that=this;
        this.UploadSelfFileT('Attachment', newArr, res => {
          if (res.data.StatusCode == 1) {
            this.chooseFileArray.push({
              fileName: res.data.FileName,
              fileUrl: that.domainManager().ViittoFileUrl + res.data.FilePath
            })
            this.$emit("selected", this.chooseFileArray);
            this.chooseFileArray = [];
          }
        })
      },
      dialogOpened() {

      },
      handleClick() {

      },
    },
  };

</script>